├── .gitignore
├── LICENCE.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── geralt_encore
│ │ └── delightfulsqlbrite
│ │ └── todo
│ │ ├── TodoApp.java
│ │ ├── TodoComponent.java
│ │ ├── TodoModule.java
│ │ ├── db
│ │ ├── DbModule.java
│ │ ├── DbOpenHelper.java
│ │ ├── TodoItem.java
│ │ └── TodoList.java
│ │ └── ui
│ │ ├── ItemsAdapter.java
│ │ ├── ItemsFragment.java
│ │ ├── ListsAdapter.java
│ │ ├── ListsFragment.java
│ │ ├── MainActivity.java
│ │ ├── NewItemFragment.java
│ │ └── NewListFragment.java
│ ├── res
│ ├── anim
│ │ ├── slide_in_left.xml
│ │ ├── slide_in_right.xml
│ │ ├── slide_out_left.xml
│ │ └── slide_out_right.xml
│ ├── layout
│ │ ├── items.xml
│ │ ├── lists.xml
│ │ ├── new_item.xml
│ │ └── new_list.xml
│ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── sqldelight
│ └── geralt_encore
│ └── delightfulsqlbrite
│ └── todo
│ └── data
│ ├── TodoItem.sq
│ └── TodoList.sq
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea
38 |
39 | # Keystore files
40 | *.jks
41 |
42 | # External native build folder generated in Android Studio 2.2 and later
43 | .externalNativeBuild
44 |
45 | # macOS
46 | .DS_Store
47 |
--------------------------------------------------------------------------------
/LICENCE.md:
--------------------------------------------------------------------------------
1 | 11.1 KB
2 |
3 | Apache License
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
178 | END OF TERMS AND CONDITIONS
179 |
180 | APPENDIX: How to apply the Apache License to your work.
181 |
182 | To apply the Apache License to your work, attach the following
183 | boilerplate notice, with the fields enclosed by brackets "[]"
184 | replaced with your own identifying information. (Don't include
185 | the brackets!) The text should be enclosed in the appropriate
186 | comment syntax for the file format. We also recommend that a
187 | file or class name and description of purpose be included on the
188 | same "printed page" as the copyright notice for easier
189 | identification within third-party archives.
190 |
191 | Copyright [yyyy] [name of copyright owner]
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
204 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Delightful SQLBrite
2 |
3 | Showcase application of [SQLDelight](https://github.com/square/sqldelight) and [SQLBrite](https://github.com/square/sqlbrite) working together based on [SQLBrite's sample](https://github.com/square/sqlbrite/tree/master/sample).
4 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.squareup.sqldelight'
3 | apply plugin: 'me.tatarka.retrolambda'
4 |
5 |
6 | android {
7 | compileSdkVersion 25
8 | buildToolsVersion "25.0.2"
9 | defaultConfig {
10 | applicationId "geralt_encore.delightfulsqlbrite"
11 | minSdkVersion 16
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 | }
28 |
29 | dependencies {
30 | // Android dependencies.
31 | compile rootProject.ext.appCompat
32 | compile rootProject.ext.supportV4
33 | compile rootProject.ext.supportAnnotations
34 |
35 | // SQLBrite
36 | compile rootProject.ext.sqlBrite
37 |
38 | // Dagger dependencies.
39 | compile rootProject.ext.dagger
40 | annotationProcessor rootProject.ext.daggerCompiler
41 |
42 | // Third-party dependencies.
43 | compile rootProject.ext.butterKnifeRuntime
44 | annotationProcessor rootProject.ext.butterKnifeCompiler
45 | compile rootProject.ext.timber
46 | compile rootProject.ext.rxJava
47 | compile rootProject.ext.rxAndroid
48 | compile rootProject.ext.rxBinding
49 |
50 | provided rootProject.ext.autoValue
51 | annotationProcessor rootProject.ext.autoValue
52 | annotationProcessor rootProject.ext.autoValueParcel
53 | }
54 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/izorin/.android-sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/TodoApp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo;
17 |
18 | import android.app.Application;
19 | import android.content.Context;
20 |
21 | import geralt_encore.delightfulsqlbrite.BuildConfig;
22 | import timber.log.Timber;
23 |
24 | public final class TodoApp extends Application {
25 | private TodoComponent mainComponent;
26 |
27 | @Override
28 | public void onCreate() {
29 | super.onCreate();
30 |
31 | if (BuildConfig.DEBUG) {
32 | Timber.plant(new Timber.DebugTree());
33 | }
34 |
35 | mainComponent = DaggerTodoComponent.builder().todoModule(new TodoModule(this)).build();
36 | }
37 |
38 | public static TodoComponent getComponent(Context context) {
39 | return ((TodoApp) context.getApplicationContext()).mainComponent;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/TodoComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo;
17 |
18 | import javax.inject.Singleton;
19 |
20 | import dagger.Component;
21 | import geralt_encore.delightfulsqlbrite.todo.ui.ItemsFragment;
22 | import geralt_encore.delightfulsqlbrite.todo.ui.ListsFragment;
23 | import geralt_encore.delightfulsqlbrite.todo.ui.NewItemFragment;
24 | import geralt_encore.delightfulsqlbrite.todo.ui.NewListFragment;
25 |
26 | @Singleton
27 | @Component(modules = TodoModule.class)
28 | public interface TodoComponent {
29 |
30 | void inject(ListsFragment fragment);
31 |
32 | void inject(ItemsFragment fragment);
33 |
34 | void inject(NewItemFragment fragment);
35 |
36 | void inject(NewListFragment fragment);
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/TodoModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo;
17 |
18 | import android.app.Application;
19 |
20 | import dagger.Module;
21 | import dagger.Provides;
22 | import geralt_encore.delightfulsqlbrite.todo.db.DbModule;
23 |
24 | import javax.inject.Singleton;
25 |
26 | @Module(
27 | includes = {
28 | DbModule.class,
29 | }
30 | )
31 | public final class TodoModule {
32 | private final Application application;
33 |
34 | TodoModule(Application application) {
35 | this.application = application;
36 | }
37 |
38 | @Provides
39 | @Singleton
40 | Application provideApplication() {
41 | return application;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/db/DbModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.db;
17 |
18 | import android.app.Application;
19 | import android.database.sqlite.SQLiteOpenHelper;
20 |
21 | import com.squareup.sqlbrite.BriteDatabase;
22 | import com.squareup.sqlbrite.SqlBrite;
23 |
24 | import dagger.Module;
25 | import dagger.Provides;
26 |
27 | import javax.inject.Singleton;
28 |
29 | import rx.schedulers.Schedulers;
30 | import timber.log.Timber;
31 |
32 | @Module
33 | public final class DbModule {
34 | @Provides
35 | @Singleton
36 | SQLiteOpenHelper provideOpenHelper(Application application) {
37 | return new DbOpenHelper(application);
38 | }
39 |
40 | @Provides
41 | @Singleton
42 | SqlBrite provideSqlBrite() {
43 | return SqlBrite.create(message -> Timber.tag("Database").v(message));
44 | }
45 |
46 | @Provides
47 | @Singleton
48 | BriteDatabase provideDatabase(SqlBrite sqlBrite, SQLiteOpenHelper helper) {
49 | BriteDatabase db = sqlBrite.wrapDatabaseHelper(helper, Schedulers.io());
50 | db.setLoggingEnabled(true);
51 | return db;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/db/DbOpenHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.db;
17 |
18 | import android.content.Context;
19 | import android.database.sqlite.SQLiteDatabase;
20 | import android.database.sqlite.SQLiteOpenHelper;
21 |
22 | import geralt_encore.delightfulsqlbrite.todo.data.TodoItemModel;
23 | import geralt_encore.delightfulsqlbrite.todo.data.TodoListModel;
24 |
25 | final class DbOpenHelper extends SQLiteOpenHelper {
26 | private static final int VERSION = 1;
27 |
28 | public DbOpenHelper(Context context) {
29 | super(context, "todo.db", null /* factory */, VERSION);
30 | }
31 |
32 | @Override
33 | public void onCreate(SQLiteDatabase db) {
34 | db.execSQL(TodoList.CREATE_TABLE);
35 | db.execSQL(TodoItem.CREATE_TABLE);
36 |
37 | final TodoList.Insert_todo_list insertTodoList = new TodoListModel.Insert_todo_list(db);
38 | final TodoList.Insert_archived_todo_list insertArchivedTodoList = new TodoListModel
39 | .Insert_archived_todo_list(db);
40 | final TodoItem.Insert_todo_item insertTodoItem = new TodoItemModel.Insert_todo_item(db);
41 | final TodoItem.Insert_completed_todo_item insertCompletedTodoItem = new TodoItemModel
42 | .Insert_completed_todo_item(db);
43 |
44 | insertTodoList.bind("Grocery List");
45 | long groceryListId = insertTodoList.program.executeInsert();
46 | insertTodoItem.bind(groceryListId, "Beer");
47 | insertTodoItem.program.executeInsert();
48 | insertTodoItem.bind(groceryListId, "Point Break on DVD");
49 | insertTodoItem.program.executeInsert();
50 | insertTodoItem.bind(groceryListId, "Bad Boys 2 on DVD");
51 | insertTodoItem.program.executeInsert();
52 |
53 | insertTodoList.bind("Holiday Presents");
54 | long holidayPresentsListId = insertTodoList.program.executeInsert();
55 | insertTodoItem.bind(holidayPresentsListId, "Pogo Stick for Jake W.");
56 | insertTodoItem.program.executeInsert();
57 | insertTodoItem.bind(holidayPresentsListId, "Jack-in-the-box for Alec S.");
58 | insertTodoItem.program.executeInsert();
59 | insertTodoItem.bind(holidayPresentsListId, "Pogs for Matt P.");
60 | insertTodoItem.program.executeInsert();
61 | insertTodoItem.bind(holidayPresentsListId, "Cola for Jesse W.");
62 | insertTodoItem.program.executeInsert();
63 |
64 | insertTodoList.bind("Work Items");
65 | long workListId = insertTodoList.program.executeInsert();
66 | insertCompletedTodoItem.bind(workListId, "Finish SqlBrite library", true);
67 | insertCompletedTodoItem.program.executeInsert();
68 | insertTodoItem.bind(workListId, "Finish SqlBrite sample app");
69 | insertTodoItem.program.executeInsert();
70 | insertTodoItem.bind(workListId, "Publish SqlBrite to GitHub");
71 | insertTodoItem.program.executeInsert();
72 |
73 | insertArchivedTodoList.bind("Birthday Presents", true);
74 | long birthdayPresentsListId = insertArchivedTodoList.program.executeInsert();
75 | insertCompletedTodoItem.bind(birthdayPresentsListId, "New car", true);
76 | insertCompletedTodoItem.program.executeInsert();
77 | }
78 |
79 | @Override
80 | public void onOpen(SQLiteDatabase db) {
81 | super.onOpen(db);
82 | db.execSQL("PRAGMA foreign_keys=ON");
83 | }
84 |
85 | @Override
86 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/db/TodoItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.db;
17 |
18 | import com.google.auto.value.AutoValue;
19 |
20 | import android.database.Cursor;
21 | import android.os.Parcelable;
22 |
23 | import com.squareup.sqldelight.RowMapper;
24 |
25 | import geralt_encore.delightfulsqlbrite.todo.data.TodoItemModel;
26 | import rx.functions.Func1;
27 |
28 | @AutoValue
29 | public abstract class TodoItem implements TodoItemModel, Parcelable {
30 |
31 | @SuppressWarnings("StaticInitializerReferencesSubClass")
32 | public static final Factory FACTORY = new Factory<>(AutoValue_TodoItem::new);
33 |
34 | public static final RowMapper MAPPER = FACTORY.select_all_items_for_listMapper();
35 |
36 | public static final RowMapper COUNT_MAPPER = FACTORY.count_active_items_for_listMapper();
37 |
38 | public static final Func1 MAPPER_FUNCTION = MAPPER::map;
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/db/TodoList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.db;
17 |
18 | import com.google.auto.value.AutoValue;
19 |
20 | import android.database.Cursor;
21 | import android.os.Parcelable;
22 |
23 | import com.squareup.sqldelight.RowMapper;
24 |
25 | import geralt_encore.delightfulsqlbrite.todo.data.TodoListModel;
26 | import rx.functions.Func1;
27 |
28 | // Note: normally I wouldn't prefix table classes but I didn't want 'List' to be overloaded.
29 | @AutoValue
30 | public abstract class TodoList implements TodoListModel, Parcelable {
31 |
32 | @SuppressWarnings("StaticInitializerReferencesSubClass")
33 | public static Factory FACTORY = new Factory<>(AutoValue_TodoList::new);
34 |
35 | public static RowMapper NAME_MAPPER = FACTORY.select_name_by_idMapper();
36 |
37 | public static RowMapper LISTS_ITEM_MAPPER =
38 | FACTORY.select_lists_with_item_countsMapper(AutoValue_TodoList_ListsItem::new);
39 |
40 | public static Func1 LISTS_ITEM_MAPPER_FUNCTION = LISTS_ITEM_MAPPER::map;
41 |
42 | @AutoValue
43 | public static abstract class ListsItem implements Select_lists_with_item_countsModel {}
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/ui/ItemsAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.ui;
17 |
18 | import android.content.Context;
19 | import android.text.SpannableString;
20 | import android.text.style.StrikethroughSpan;
21 | import android.view.LayoutInflater;
22 | import android.view.View;
23 | import android.view.ViewGroup;
24 | import android.widget.BaseAdapter;
25 | import android.widget.CheckedTextView;
26 |
27 | import java.util.Collections;
28 | import java.util.List;
29 |
30 | import geralt_encore.delightfulsqlbrite.todo.db.TodoItem;
31 | import rx.functions.Action1;
32 |
33 | final class ItemsAdapter extends BaseAdapter implements Action1> {
34 | private final LayoutInflater inflater;
35 |
36 | private List items = Collections.emptyList();
37 |
38 | public ItemsAdapter(Context context) {
39 | inflater = LayoutInflater.from(context);
40 | }
41 |
42 | @Override
43 | public void call(List items) {
44 | this.items = items;
45 | notifyDataSetChanged();
46 | }
47 |
48 | @Override
49 | public int getCount() {
50 | return items.size();
51 | }
52 |
53 | @Override
54 | public TodoItem getItem(int position) {
55 | return items.get(position);
56 | }
57 |
58 | @Override
59 | public long getItemId(int position) {
60 | return getItem(position)._id();
61 | }
62 |
63 | @Override
64 | public boolean hasStableIds() {
65 | return true;
66 | }
67 |
68 | @Override
69 | public View getView(int position, View convertView, ViewGroup parent) {
70 | if (convertView == null) {
71 | convertView = inflater.inflate(android.R.layout.simple_list_item_multiple_choice,
72 | parent, false);
73 | }
74 |
75 | TodoItem item = getItem(position);
76 | CheckedTextView textView = (CheckedTextView) convertView;
77 | textView.setChecked(item.complete());
78 |
79 | CharSequence description = item.description();
80 | if (item.complete()) {
81 | SpannableString spannable = new SpannableString(description);
82 | spannable.setSpan(new StrikethroughSpan(), 0, description.length(), 0);
83 | description = spannable;
84 | }
85 |
86 | textView.setText(description);
87 |
88 | return convertView;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/ui/ItemsFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.ui;
17 |
18 | import android.app.Activity;
19 | import android.database.Cursor;
20 | import android.os.Bundle;
21 | import android.support.annotation.Nullable;
22 | import android.support.v4.app.Fragment;
23 | import android.support.v4.view.MenuItemCompat;
24 | import android.view.LayoutInflater;
25 | import android.view.Menu;
26 | import android.view.MenuInflater;
27 | import android.view.MenuItem;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.widget.ListView;
31 |
32 | import com.jakewharton.rxbinding.widget.RxAdapterView;
33 | import com.squareup.sqlbrite.BriteDatabase;
34 | import com.squareup.sqldelight.SqlDelightStatement;
35 |
36 | import javax.inject.Inject;
37 |
38 | import butterknife.BindView;
39 | import butterknife.ButterKnife;
40 | import geralt_encore.delightfulsqlbrite.R;
41 | import geralt_encore.delightfulsqlbrite.todo.TodoApp;
42 | import geralt_encore.delightfulsqlbrite.todo.data.TodoItemModel;
43 | import geralt_encore.delightfulsqlbrite.todo.db.TodoItem;
44 | import geralt_encore.delightfulsqlbrite.todo.db.TodoList;
45 | import rx.Observable;
46 | import rx.android.schedulers.AndroidSchedulers;
47 | import rx.schedulers.Schedulers;
48 | import rx.subscriptions.CompositeSubscription;
49 |
50 | import static android.support.v4.view.MenuItemCompat.SHOW_AS_ACTION_IF_ROOM;
51 | import static android.support.v4.view.MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT;
52 |
53 | public final class ItemsFragment extends Fragment {
54 | private static final String KEY_LIST_ID = "list_id";
55 |
56 | public interface Listener {
57 | void onNewItemClicked(long listId);
58 | }
59 |
60 | private TodoItem.Update_complete updateComplete;
61 |
62 | public static ItemsFragment newInstance(long listId) {
63 | Bundle arguments = new Bundle();
64 | arguments.putLong(KEY_LIST_ID, listId);
65 |
66 | ItemsFragment fragment = new ItemsFragment();
67 | fragment.setArguments(arguments);
68 | return fragment;
69 | }
70 |
71 | @Inject BriteDatabase db;
72 |
73 | @BindView(android.R.id.list) ListView listView;
74 | @BindView(android.R.id.empty) View emptyView;
75 |
76 | private Listener listener;
77 | private ItemsAdapter adapter;
78 | private CompositeSubscription subscriptions;
79 |
80 | private long getListId() {
81 | return getArguments().getLong(KEY_LIST_ID);
82 | }
83 |
84 | @Override
85 | public void onAttach(Activity activity) {
86 | if (!(activity instanceof Listener)) {
87 | throw new IllegalStateException("Activity must implement fragment Listener.");
88 | }
89 |
90 | super.onAttach(activity);
91 | TodoApp.getComponent(activity).inject(this);
92 | setHasOptionsMenu(true);
93 |
94 | listener = (Listener) activity;
95 | adapter = new ItemsAdapter(activity);
96 |
97 | updateComplete = new TodoItemModel.Update_complete(db.getWritableDatabase());
98 | }
99 |
100 | @Override
101 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
102 | super.onCreateOptionsMenu(menu, inflater);
103 |
104 | MenuItem item = menu.add(R.string.new_item)
105 | .setOnMenuItemClickListener(clickedItem -> {
106 | listener.onNewItemClicked(getListId());
107 | return true;
108 | });
109 | MenuItemCompat.setShowAsAction(item, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
110 | }
111 |
112 | @Override
113 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
114 | @Nullable Bundle savedInstanceState) {
115 | return inflater.inflate(R.layout.items, container, false);
116 | }
117 |
118 | @Override
119 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
120 | super.onViewCreated(view, savedInstanceState);
121 | ButterKnife.bind(this, view);
122 | listView.setEmptyView(emptyView);
123 | listView.setAdapter(adapter);
124 |
125 | RxAdapterView.itemClickEvents(listView)
126 | .observeOn(Schedulers.io())
127 | .subscribe(event -> {
128 | boolean newValue = !adapter.getItem(event.position()).complete();
129 | updateComplete.bind(newValue, event.id());
130 | db.executeUpdateDelete(updateComplete.table, updateComplete.program);
131 | });
132 | }
133 |
134 | @Override
135 | public void onResume() {
136 | super.onResume();
137 | long listId = getListId();
138 |
139 | subscriptions = new CompositeSubscription();
140 |
141 | final SqlDelightStatement itemCountStatement = TodoItem.FACTORY
142 | .count_active_items_for_list(listId);
143 | Observable itemCount = db.createQuery(itemCountStatement.tables,
144 | itemCountStatement.statement)
145 | .map(query -> {
146 | Cursor cursor = query.run();
147 | try {
148 | if (!cursor.moveToNext()) {
149 | throw new AssertionError("No rows");
150 | }
151 | return TodoItem.COUNT_MAPPER.map(cursor);
152 | } finally {
153 | cursor.close();
154 | }
155 | });
156 | final SqlDelightStatement listNameStatement = TodoList.FACTORY.select_name_by_id(listId);
157 | Observable listName =
158 | db.createQuery(listNameStatement.tables, listNameStatement.statement)
159 | .map(query -> {
160 | Cursor cursor = query.run();
161 | try {
162 | if (!cursor.moveToNext()) {
163 | throw new AssertionError("No rows");
164 | }
165 | return TodoList.NAME_MAPPER.map(cursor);
166 | } finally {
167 | cursor.close();
168 | }
169 | });
170 | subscriptions.add(
171 | Observable.combineLatest(listName, itemCount,
172 | (listName1, itemCount1) -> listName1 + " (" + itemCount1 + ")")
173 | .observeOn(AndroidSchedulers.mainThread())
174 | .subscribe(title -> {
175 | getActivity().setTitle(title);
176 | }));
177 | final SqlDelightStatement itemsForListStatement = TodoItem.FACTORY
178 | .select_all_items_for_list(listId);
179 | subscriptions.add(db.createQuery(itemsForListStatement.tables,
180 | itemsForListStatement.statement)
181 | .mapToList(TodoItem.MAPPER_FUNCTION)
182 | .observeOn(AndroidSchedulers.mainThread())
183 | .subscribe(adapter));
184 | }
185 |
186 | @Override
187 | public void onPause() {
188 | super.onPause();
189 | subscriptions.unsubscribe();
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/ui/ListsAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.ui;
17 |
18 | import android.content.Context;
19 | import android.view.LayoutInflater;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 | import android.widget.BaseAdapter;
23 | import android.widget.TextView;
24 |
25 | import java.util.Collections;
26 | import java.util.List;
27 |
28 | import geralt_encore.delightfulsqlbrite.todo.db.TodoList.ListsItem;
29 | import rx.functions.Action1;
30 |
31 | final class ListsAdapter extends BaseAdapter implements Action1> {
32 | private final LayoutInflater inflater;
33 |
34 | private List items = Collections.emptyList();
35 |
36 | public ListsAdapter(Context context) {
37 | this.inflater = LayoutInflater.from(context);
38 | }
39 |
40 | @Override
41 | public void call(List items) {
42 | this.items = items;
43 | notifyDataSetChanged();
44 | }
45 |
46 | @Override
47 | public int getCount() {
48 | return items.size();
49 | }
50 |
51 | @Override
52 | public ListsItem getItem(int position) {
53 | return items.get(position);
54 | }
55 |
56 | @Override
57 | public long getItemId(int position) {
58 | return getItem(position)._id();
59 | }
60 |
61 | @Override
62 | public boolean hasStableIds() {
63 | return true;
64 | }
65 |
66 | @Override
67 | public View getView(int position, View convertView, ViewGroup parent) {
68 | if (convertView == null) {
69 | convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
70 | }
71 |
72 | ListsItem item = getItem(position);
73 | ((TextView) convertView).setText(item.name() + " (" + item.item_count() + ")");
74 |
75 | return convertView;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/ui/ListsFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.ui;
17 |
18 | import android.app.Activity;
19 | import android.os.Bundle;
20 | import android.support.annotation.Nullable;
21 | import android.support.v4.app.Fragment;
22 | import android.support.v4.view.MenuItemCompat;
23 | import android.view.LayoutInflater;
24 | import android.view.Menu;
25 | import android.view.MenuInflater;
26 | import android.view.MenuItem;
27 | import android.view.View;
28 | import android.view.ViewGroup;
29 | import android.widget.ListView;
30 |
31 | import com.squareup.sqlbrite.BriteDatabase;
32 |
33 | import java.util.Arrays;
34 |
35 | import javax.inject.Inject;
36 |
37 | import butterknife.BindView;
38 | import butterknife.ButterKnife;
39 | import butterknife.OnItemClick;
40 | import geralt_encore.delightfulsqlbrite.R;
41 | import geralt_encore.delightfulsqlbrite.todo.TodoApp;
42 | import geralt_encore.delightfulsqlbrite.todo.db.TodoItem;
43 | import geralt_encore.delightfulsqlbrite.todo.db.TodoList;
44 | import rx.Subscription;
45 | import rx.android.schedulers.AndroidSchedulers;
46 |
47 | import static android.support.v4.view.MenuItemCompat.SHOW_AS_ACTION_IF_ROOM;
48 | import static android.support.v4.view.MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT;
49 |
50 | public final class ListsFragment extends Fragment {
51 | interface Listener {
52 | void onListClicked(long id);
53 |
54 | void onNewListClicked();
55 | }
56 |
57 | static ListsFragment newInstance() {
58 | return new ListsFragment();
59 | }
60 |
61 | @Inject BriteDatabase db;
62 |
63 | @BindView(android.R.id.list) ListView listView;
64 | @BindView(android.R.id.empty) View emptyView;
65 |
66 | private Listener listener;
67 | private ListsAdapter adapter;
68 | private Subscription subscription;
69 |
70 | @Override
71 | public void onAttach(Activity activity) {
72 | if (!(activity instanceof Listener)) {
73 | throw new IllegalStateException("Activity must implement fragment Listener.");
74 | }
75 |
76 | super.onAttach(activity);
77 | TodoApp.getComponent(activity).inject(this);
78 | setHasOptionsMenu(true);
79 |
80 | listener = (Listener) activity;
81 | adapter = new ListsAdapter(activity);
82 | }
83 |
84 | @Override
85 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
86 | super.onCreateOptionsMenu(menu, inflater);
87 |
88 | MenuItem item = menu.add(R.string.new_list)
89 | .setOnMenuItemClickListener(clickedItem -> {
90 | listener.onNewListClicked();
91 | return true;
92 | });
93 | MenuItemCompat.setShowAsAction(item, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
94 | }
95 |
96 | @Override
97 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
98 | @Nullable Bundle savedInstanceState) {
99 | return inflater.inflate(R.layout.lists, container, false);
100 | }
101 |
102 | @Override
103 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
104 | super.onViewCreated(view, savedInstanceState);
105 | ButterKnife.bind(this, view);
106 | listView.setEmptyView(emptyView);
107 | listView.setAdapter(adapter);
108 | }
109 |
110 | @OnItemClick(android.R.id.list)
111 | void listClicked(long listId) {
112 | listener.onListClicked(listId);
113 | }
114 |
115 | @Override
116 | public void onResume() {
117 | super.onResume();
118 |
119 | getActivity().setTitle("To-Do");
120 |
121 | subscription = db.createQuery(Arrays.asList(TodoList.TABLE_NAME, TodoItem.TABLE_NAME),
122 | TodoList.SELECT_LISTS_WITH_ITEM_COUNTS)
123 | .mapToList(TodoList.LISTS_ITEM_MAPPER_FUNCTION)
124 | .observeOn(AndroidSchedulers.mainThread())
125 | .subscribe(adapter);
126 | }
127 |
128 | @Override
129 | public void onPause() {
130 | super.onPause();
131 | subscription.unsubscribe();
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.ui;
17 |
18 | import android.os.Bundle;
19 | import android.support.v7.app.AppCompatActivity;
20 |
21 | import geralt_encore.delightfulsqlbrite.R;
22 |
23 | public final class MainActivity extends AppCompatActivity
24 | implements ListsFragment.Listener, ItemsFragment.Listener {
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | if (savedInstanceState == null) {
30 | getSupportFragmentManager().beginTransaction()
31 | .add(android.R.id.content, ListsFragment.newInstance())
32 | .commit();
33 | }
34 | }
35 |
36 | @Override
37 | public void onListClicked(long id) {
38 | getSupportFragmentManager().beginTransaction()
39 | .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim
40 | .slide_in_left,
41 | R.anim.slide_out_right)
42 | .replace(android.R.id.content, ItemsFragment.newInstance(id))
43 | .addToBackStack(null)
44 | .commit();
45 | }
46 |
47 | @Override
48 | public void onNewListClicked() {
49 | NewListFragment.newInstance().show(getSupportFragmentManager(), "new-list");
50 | }
51 |
52 | @Override
53 | public void onNewItemClicked(long listId) {
54 | NewItemFragment.newInstance(listId).show(getSupportFragmentManager(), "new-item");
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/ui/NewItemFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.ui;
17 |
18 | import android.app.Activity;
19 | import android.app.AlertDialog;
20 | import android.app.Dialog;
21 | import android.content.Context;
22 | import android.os.Bundle;
23 | import android.support.annotation.NonNull;
24 | import android.support.v4.app.DialogFragment;
25 | import android.view.LayoutInflater;
26 | import android.view.View;
27 | import android.widget.EditText;
28 |
29 | import com.jakewharton.rxbinding.widget.RxTextView;
30 | import com.squareup.sqlbrite.BriteDatabase;
31 |
32 | import javax.inject.Inject;
33 |
34 | import geralt_encore.delightfulsqlbrite.R;
35 | import geralt_encore.delightfulsqlbrite.todo.TodoApp;
36 | import geralt_encore.delightfulsqlbrite.todo.data.TodoItemModel;
37 | import geralt_encore.delightfulsqlbrite.todo.db.TodoItem;
38 | import rx.Observable;
39 | import rx.schedulers.Schedulers;
40 | import rx.subjects.PublishSubject;
41 |
42 | import static butterknife.ButterKnife.findById;
43 |
44 | public final class NewItemFragment extends DialogFragment {
45 | private static final String KEY_LIST_ID = "list_id";
46 |
47 | public static NewItemFragment newInstance(long listId) {
48 | Bundle arguments = new Bundle();
49 | arguments.putLong(KEY_LIST_ID, listId);
50 |
51 | NewItemFragment fragment = new NewItemFragment();
52 | fragment.setArguments(arguments);
53 | return fragment;
54 | }
55 |
56 | private final PublishSubject createClicked = PublishSubject.create();
57 | private TodoItem.Insert_todo_item insertTodoItem;
58 |
59 | @Inject BriteDatabase db;
60 |
61 | private long getListId() {
62 | return getArguments().getLong(KEY_LIST_ID);
63 | }
64 |
65 | @Override
66 | public void onAttach(Activity activity) {
67 | super.onAttach(activity);
68 | TodoApp.getComponent(activity).inject(this);
69 | insertTodoItem = new TodoItemModel.Insert_todo_item(db.getWritableDatabase());
70 | }
71 |
72 | @NonNull
73 | @Override
74 | public Dialog onCreateDialog(Bundle savedInstanceState) {
75 | final Context context = getActivity();
76 | View view = LayoutInflater.from(context).inflate(R.layout.new_item, null);
77 |
78 | EditText name = findById(view, android.R.id.input);
79 | Observable.combineLatest(createClicked, RxTextView.textChanges(name),
80 | (ignored, text) -> text.toString())
81 | .observeOn(Schedulers.io())
82 | .subscribe(description -> {
83 | insertTodoItem.bind(getListId(), description);
84 | db.executeInsert(insertTodoItem.table, insertTodoItem.program);
85 | });
86 |
87 | return new AlertDialog.Builder(context) //
88 | .setTitle(R.string.new_item)
89 | .setView(view)
90 | .setPositiveButton(R.string.create, (dialog, which) -> createClicked.onNext("clicked"))
91 | .setNegativeButton(R.string.cancel, (dialog, which) -> {})
92 | .create();
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/geralt_encore/delightfulsqlbrite/todo/ui/NewListFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Square, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package geralt_encore.delightfulsqlbrite.todo.ui;
17 |
18 | import android.app.Activity;
19 | import android.app.AlertDialog;
20 | import android.app.Dialog;
21 | import android.content.Context;
22 | import android.os.Bundle;
23 | import android.support.annotation.NonNull;
24 | import android.support.v4.app.DialogFragment;
25 | import android.view.LayoutInflater;
26 | import android.view.View;
27 | import android.widget.EditText;
28 |
29 | import com.jakewharton.rxbinding.widget.RxTextView;
30 | import com.squareup.sqlbrite.BriteDatabase;
31 |
32 | import javax.inject.Inject;
33 |
34 | import geralt_encore.delightfulsqlbrite.R;
35 | import geralt_encore.delightfulsqlbrite.todo.TodoApp;
36 | import geralt_encore.delightfulsqlbrite.todo.data.TodoListModel;
37 | import geralt_encore.delightfulsqlbrite.todo.db.TodoList;
38 | import rx.Observable;
39 | import rx.schedulers.Schedulers;
40 | import rx.subjects.PublishSubject;
41 |
42 | import static butterknife.ButterKnife.findById;
43 |
44 | public final class NewListFragment extends DialogFragment {
45 | public static NewListFragment newInstance() {
46 | return new NewListFragment();
47 | }
48 |
49 | private final PublishSubject createClicked = PublishSubject.create();
50 | private TodoList.Insert_todo_list insertTodoList;
51 |
52 | @Inject BriteDatabase db;
53 |
54 | @Override
55 | public void onAttach(Activity activity) {
56 | super.onAttach(activity);
57 | TodoApp.getComponent(activity).inject(this);
58 | insertTodoList = new TodoListModel.Insert_todo_list(db.getWritableDatabase());
59 | }
60 |
61 | @NonNull
62 | @Override
63 | public Dialog onCreateDialog(Bundle savedInstanceState) {
64 | final Context context = getActivity();
65 | View view = LayoutInflater.from(context).inflate(R.layout.new_list, null);
66 |
67 | EditText name = findById(view, android.R.id.input);
68 | Observable.combineLatest(createClicked, RxTextView.textChanges(name),
69 | (ignored, text) -> text.toString())
70 | .observeOn(Schedulers.io())
71 | .subscribe(name1 -> {
72 | insertTodoList.bind(name1);
73 | db.executeInsert(insertTodoList.table, insertTodoList.program);
74 | });
75 |
76 | return new AlertDialog.Builder(context) //
77 | .setTitle(R.string.new_list)
78 | .setView(view)
79 | .setPositiveButton(R.string.create, (dialog, which) -> createClicked.onNext("clicked"))
80 | .setNegativeButton(R.string.cancel, (dialog, which) -> {})
81 | .create();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_in_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
24 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_in_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
24 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_out_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
24 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_out_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
21 |
22 |
24 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/items.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/lists.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/new_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/new_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geralt-encore/Delightful-SQLBrite/2e8069f4136730f646323d8f2595eb50c5b113ed/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geralt-encore/Delightful-SQLBrite/2e8069f4136730f646323d8f2595eb50c5b113ed/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geralt-encore/Delightful-SQLBrite/2e8069f4136730f646323d8f2595eb50c5b113ed/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geralt-encore/Delightful-SQLBrite/2e8069f4136730f646323d8f2595eb50c5b113ed/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geralt-encore/Delightful-SQLBrite/2e8069f4136730f646323d8f2595eb50c5b113ed/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | DelightfulSqlBrite To-Do
4 |
5 | Create
6 | Cancel
7 | New List
8 | Name
9 | New Item
10 | Description
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/sqldelight/geralt_encore/delightfulsqlbrite/todo/data/TodoItem.sq:
--------------------------------------------------------------------------------
1 | CREATE TABLE todo_item(
2 | _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
3 | list_id INTEGER NOT NULL,
4 | description TEXT NOT NULL,
5 | complete INTEGER AS Boolean DEFAULT 0,
6 | FOREIGN KEY (list_id) REFERENCES todo_list(_id)
7 | );
8 |
9 | insert_todo_item:
10 | INSERT INTO todo_item (list_id, description)
11 | VALUES (?, ?);
12 |
13 | insert_completed_todo_item:
14 | INSERT INTO todo_item (list_id, description, complete)
15 | VALUES (?, ?, ?);
16 |
17 | update_complete:
18 | UPDATE todo_item
19 | SET complete = ?
20 | WHERE _id = ?;
21 |
22 | select_all_items_for_list:
23 | SELECT *
24 | FROM todo_item
25 | WHERE list_id = ?
26 | ORDER BY complete ASC;
27 |
28 | count_active_items_for_list:
29 | SELECT COUNT(*)
30 | FROM todo_item
31 | WHERE complete = 0 AND list_id = ?;
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/sqldelight/geralt_encore/delightfulsqlbrite/todo/data/TodoList.sq:
--------------------------------------------------------------------------------
1 | CREATE TABLE todo_list(
2 | _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
3 | name TEXT NOT NULL,
4 | archived INTEGER AS Boolean DEFAULT 0
5 | );
6 |
7 | insert_todo_list:
8 | INSERT INTO todo_list (name)
9 | VALUES (?);
10 |
11 | insert_archived_todo_list:
12 | INSERT INTO todo_list (name, archived)
13 | VALUES (?, ?);
14 |
15 | select_name_by_id:
16 | SELECT name
17 | FROM todo_list
18 | WHERE _id = ?;
19 |
20 | select_lists_with_item_counts:
21 | SELECT todo_list._id, todo_list.name, COUNT(todo_item._id) as item_count
22 | FROM todo_list LEFT OUTER JOIN todo_item ON todo_list._id = todo_item.list_id
23 | GROUP BY todo_list._id;
24 |
25 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.0'
9 | classpath 'com.squareup.sqldelight:gradle-plugin:0.6.0'
10 | classpath 'me.tatarka:gradle-retrolambda:3.4.0'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | ext {
24 |
25 | def SUPPORT_LIBRARY_VERSION = '25.3.0'
26 | def DAGGER_VERSION = '2.9'
27 | def BUTTERKNIFE_VERSION = '8.4.0'
28 |
29 | // Android dependencies.
30 | supportV4 = "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
31 | appCompat = "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
32 | supportAnnotations = "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
33 |
34 | // Dagger dependencies.
35 | dagger = "com.google.dagger:dagger:$DAGGER_VERSION"
36 | daggerCompiler = "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
37 |
38 | // Third-party dependencies.
39 | sqlBrite = 'com.squareup.sqlbrite:sqlbrite:1.1.1'
40 | butterKnifeRuntime = "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
41 | butterKnifeCompiler = "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
42 | timber = 'com.jakewharton.timber:timber:4.3.1'
43 | autoValue = 'com.google.auto.value:auto-value:1.3'
44 | autoValueParcel = 'com.ryanharter.auto.value:auto-value-parcel:0.2.5'
45 | rxJava = 'io.reactivex:rxjava:1.2.7'
46 | rxAndroid = 'io.reactivex:rxandroid:1.2.1'
47 | rxBinding = 'com.jakewharton.rxbinding:rxbinding:0.4.0'
48 | }
49 |
50 | task clean(type: Delete) {
51 | delete rootProject.buildDir
52 | }
53 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geralt-encore/Delightful-SQLBrite/2e8069f4136730f646323d8f2595eb50c5b113ed/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 18 13:46:03 EET 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------