├── .github └── FUNDING.yml ├── .gitignore ├── .idea ├── assetWizardSettings.xml ├── codeStyles │ └── Project.xml ├── copyright │ ├── database.xml │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── markdown-navigator-enh.xml ├── markdown-navigator.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── .project ├── .settings └── org.eclipse.buildship.core.prefs ├── LICENSE ├── README.md ├── app ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── build.gradle ├── deps.txt ├── proguard-rules.pro ├── schemas │ └── promise.base.AppDatabase │ │ └── 2.yml └── src │ ├── androidTest │ └── java │ │ └── promise │ │ └── dbapp │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── promise │ │ │ ├── base │ │ │ ├── AppDatabase.kt │ │ │ ├── AppTypeConverter.kt │ │ │ ├── ID.kt │ │ │ ├── comment │ │ │ │ ├── Like.java │ │ │ │ ├── PostComment.java │ │ │ │ ├── PostCommentDao.java │ │ │ │ └── PostCommentToReplyRelation.java │ │ │ ├── photo │ │ │ │ └── Photo.kt │ │ │ ├── post │ │ │ │ ├── Post.java │ │ │ │ └── PostRepository.kt │ │ │ ├── session │ │ │ │ └── User.kt │ │ │ └── todo │ │ │ │ └── Todo.java │ │ │ └── dbapp │ │ │ ├── ActivityBuildersModule.kt │ │ │ ├── App.kt │ │ │ ├── AppComponent.kt │ │ │ ├── DatabaseDependencies.kt │ │ │ ├── MainActivity.kt │ │ │ ├── ReposModule.kt │ │ │ └── test │ │ │ ├── PostCommentsDaoImpl.java │ │ │ └── TestUtils.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── complex_layout.xml │ │ └── content_main.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── promise │ └── dbapp │ └── ExampleUnitTest.kt ├── blueprint.md ├── build.gradle ├── checkstyle.xml ├── commons ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── bin │ └── main │ │ └── promise │ │ └── db │ │ ├── ColumnInfo.kt │ │ ├── Corrupt.class │ │ ├── DBError.class │ │ ├── DatabaseEntity.class │ │ ├── EntityInfo.kt │ │ ├── Query.kt │ │ ├── Table$CompoundIndex.class │ │ ├── Table$ForeignKey.class │ │ ├── Table$Index.class │ │ ├── Table.class │ │ └── model │ │ └── ITimeAware.class ├── build.gradle └── src │ └── main │ └── java │ └── promise │ └── database │ ├── AddedEntity.kt │ ├── Child.kt │ ├── ColumnInfo.kt │ ├── DAO.kt │ ├── DatabaseEntity.java │ ├── Embedded.kt │ ├── Entity.kt │ ├── ForeignKey.kt │ ├── HasMany.kt │ ├── HasOne.kt │ ├── Ignore.kt │ ├── Index.kt │ ├── Migrate.kt │ ├── MigrationOptions.kt │ ├── Migrations.kt │ ├── Parent.kt │ ├── PrimaryKey.kt │ ├── PrimaryKeyAutoIncrement.kt │ ├── Query.kt │ ├── Relation.kt │ ├── Table.kt │ └── TypeConverter.kt ├── compiler ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── bin │ ├── main │ │ └── promise │ │ │ └── db │ │ │ └── ompiler │ │ │ ├── CodeBlockGenerator.kt │ │ │ ├── DatabaseAbstractFuncsGenerator.kt │ │ │ ├── DatabaseCompanionPropsGenerator.kt │ │ │ ├── DatabaseProcessor.kt │ │ │ ├── DeserializerGenerator.kt │ │ │ ├── EntityProcessor.kt │ │ │ ├── JavaUtils$1.class │ │ │ ├── JavaUtils.class │ │ │ ├── PersistableEntityUtils.kt │ │ │ ├── RegisterColumnsGenerator.kt │ │ │ ├── SerializerGenerator.kt │ │ │ ├── TableColumnPropsGenerator.kt │ │ │ ├── Utils.kt │ │ │ ├── annotation │ │ │ ├── DatabaseAnnotationGenerator.kt │ │ │ └── TableAnnotationGenerator.class │ │ │ ├── migration │ │ │ └── MigrationGenerator.kt │ │ │ └── relations │ │ │ └── RelationsGenerator.kt │ └── test │ │ └── promise │ │ └── db │ │ └── ompiler │ │ └── ExampleUnitTest.kt ├── build.gradle ├── consumer-rules.pro ├── gradle.properties ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── promise │ │ └── db │ │ └── ompiler │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ └── java │ │ └── promise │ │ └── database │ │ └── compiler │ │ ├── AnnotatedClassProcessor.kt │ │ ├── CodeGenerator.kt │ │ ├── DAOAnnotatedProcessor.kt │ │ ├── DatabaseAbstractMethodsGenerator.kt │ │ ├── DatabaseAnnotationGenerator.kt │ │ ├── DatabaseCrudStubMethodsGenerator.kt │ │ ├── DatabaseEntityAnnotatedProcessor.kt │ │ ├── DatabaseMetaDataWriter.kt │ │ ├── DatabaseStaticMethodsGenerator.kt │ │ ├── EntityAnnotatedProcessor.kt │ │ ├── PromiseDatabaseCompiler.kt │ │ ├── RelationsDaoGenerator.java │ │ ├── RelationsDaoProcessor.kt │ │ ├── TableAnnotationGenerator.java │ │ ├── TableColumnFieldsGenerator.kt │ │ ├── TableDeserializerMethodGenerator.kt │ │ ├── TableMetaDataWriter.kt │ │ ├── TableMigrationFieldGenerator.kt │ │ ├── TableRegisteredColumnsMethodGenerator.kt │ │ ├── TableSerializerMethodGenerator.kt │ │ ├── TypeConverterAnnotatedProcessor.kt │ │ ├── migration │ │ ├── DatabaseMetaData.kt │ │ ├── TableMetaData.kt │ │ ├── TableMigration.kt │ │ └── VersionChange.kt │ │ └── utils │ │ ├── Arrangeable.java │ │ ├── Category.java │ │ ├── JavaUtils.java │ │ ├── List.java │ │ ├── LogUtil.java │ │ ├── PersistableEntityUtils.kt │ │ ├── Utils.kt │ │ └── function │ │ ├── BIConsumer.java │ │ ├── Combiner.java │ │ ├── FilterFunction.java │ │ ├── FilterFunction2.java │ │ ├── GroupFunction.java │ │ ├── GroupFunction2.java │ │ ├── GroupFunction3.java │ │ ├── JoinFunction.java │ │ ├── MapFunction.java │ │ ├── MapIndexFunction.java │ │ └── ReduceFunction.java │ └── test │ └── java │ └── promise │ └── database │ └── ompiler │ ├── ExampleUnitTest.kt │ └── PersistableEntityUtilsKtTest.kt ├── database ├── .classpath ├── .gitignore ├── .project ├── .settings │ └── org.eclipse.buildship.core.prefs ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── promise │ │ └── database │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── promise │ │ │ ├── db │ │ │ ├── ActiveRecord.kt │ │ │ ├── Column.java │ │ │ ├── Corrupt.java │ │ │ ├── Crud.kt │ │ │ ├── CrudStore.java │ │ │ ├── DBError.java │ │ │ ├── DDLFunctions.kt │ │ │ ├── DMLFunctions.kt │ │ │ ├── DMLVisitors.kt │ │ │ ├── Database.java │ │ │ ├── DatabaseCreationCallback.kt │ │ │ ├── FastDatabase.kt │ │ │ ├── FastDatabaseImpl.kt │ │ │ ├── FastDatabaseOpenHelper.java │ │ │ ├── FastTable.kt │ │ │ ├── FetchVisitors.kt │ │ │ ├── Migration.kt │ │ │ ├── PromiseDatabase.kt │ │ │ ├── QueryBuilder.java │ │ │ ├── ReactiveCrud.kt │ │ │ ├── ReactiveFastDatabase.kt │ │ │ ├── ReactiveTable.kt │ │ │ ├── Store.java │ │ │ ├── TableCrud.kt │ │ │ ├── TableError.kt │ │ │ ├── Utils.java │ │ │ ├── criteria │ │ │ │ ├── AndCriteria.java │ │ │ │ ├── BasicCriteria.java │ │ │ │ ├── BetweenCriteria.java │ │ │ │ ├── Criteria.java │ │ │ │ ├── ExistsCriteria.java │ │ │ │ ├── InCriteria.java │ │ │ │ ├── NotExistsCriteria.java │ │ │ │ ├── NotInCriteria.java │ │ │ │ ├── OrCriteria.java │ │ │ │ └── ValueBetweenCriteria.java │ │ │ ├── from │ │ │ │ ├── AliasableFrom.java │ │ │ │ ├── From.java │ │ │ │ ├── JoinFrom.java │ │ │ │ ├── SubQueryFrom.java │ │ │ │ └── TableFrom.java │ │ │ ├── management │ │ │ │ ├── DatabaseMigration.kt │ │ │ │ └── TableMetaData.kt │ │ │ ├── order │ │ │ │ ├── Order.java │ │ │ │ ├── OrderAscending.java │ │ │ │ ├── OrderAscendingIgnoreCase.java │ │ │ │ ├── OrderDescending.java │ │ │ │ └── OrderDescendingIgnoreCase.java │ │ │ └── projection │ │ │ │ ├── AggregateProjection.java │ │ │ │ ├── AliasedProjection.java │ │ │ │ ├── CastDateProjection.java │ │ │ │ ├── CastDateTimeProjection.java │ │ │ │ ├── CastIntProjection.java │ │ │ │ ├── CastRealProjection.java │ │ │ │ ├── CastStringProjection.java │ │ │ │ ├── ColumnProjection.java │ │ │ │ ├── ConstantProjection.java │ │ │ │ ├── Projection.java │ │ │ │ └── SubQueryProjection.java │ │ │ ├── model │ │ │ ├── ITimeStamped.java │ │ │ ├── IdentifiableList.java │ │ │ └── TimeStamped.java │ │ │ └── utils │ │ │ ├── Acceptor.kt │ │ │ └── Visitor.kt │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── promise │ └── database │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── package-lock.json ├── schemas └── promise.base.AppDatabase.yml └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: androidpromise 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: dev4vin 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches/build_file_checksums.ser 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | .DS_Store 9 | /build 10 | /captures 11 | .externalNativeBuild 12 | /node_modules 13 | 14 | 15 | -------------------------------------------------------------------------------- /.idea/copyright/database.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | SamplePromiseApp 4 | Project SamplePromiseApp created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.buildship.core.gradleprojectbuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.buildship.core.gradleprojectnature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | arguments= 2 | auto.sync=false 3 | build.scans.enabled=false 4 | connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) 5 | connection.project.dir= 6 | eclipse.preferences.version=1 7 | gradle.user.home= 8 | java.home=C\:/Program Files/Java/jdk-13.0.1 9 | jvm.arguments= 10 | offline.mode=false 11 | override.workspace.settings=true 12 | show.console.view=true 13 | show.executions.view=true 14 | -------------------------------------------------------------------------------- /app/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | app 4 | Project app created by Buildship. 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.buildship.core.gradleprojectbuilder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.buildship.core.gradleprojectnature 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/.settings/org.eclipse.buildship.core.prefs: -------------------------------------------------------------------------------- 1 | connection.project.dir=.. 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /app/deps.txt: -------------------------------------------------------------------------------- 1 | // implementation 'com.google.dagger:dagger:2.27' 2 | // kapt 'com.google.dagger:dagger-compiler:2.27' 3 | // 4 | // implementation 'com.google.dagger:dagger-android:2.27' 5 | // implementation 'com.google.dagger:dagger-android-support:2.27' // if you use the support libraries 6 | // kapt 'com.google.dagger:dagger-android-processor:2.27' -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class tableName to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file tableName. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/promise/dbapp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp 15 | 16 | import androidx.test.InstrumentationRegistry 17 | import androidx.test.runner.AndroidJUnit4 18 | import org.junit.Assert.assertEquals 19 | import org.junit.Test 20 | import org.junit.runner.RunWith 21 | 22 | /** 23 | * Instrumented test, which will execute on an Android device. 24 | * 25 | * See [testing documentation](http://d.android.com/tools/testing). 26 | */ 27 | @RunWith(AndroidJUnit4::class) 28 | class ExampleInstrumentedTest { 29 | @Test 30 | fun useAppContext() { 31 | // Context of the app under test. 32 | val appContext = InstrumentationRegistry.getTargetContext() 33 | assertEquals("promise.dbapp", appContext.packageName) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 17 | 18 | 27 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/java/promise/base/AppDatabase.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.base 15 | 16 | import promise.base.comment.Like 17 | import promise.base.comment.PostComment 18 | import promise.base.photo.Photo 19 | import promise.base.post.Post 20 | import promise.base.session.User 21 | import promise.base.todo.Todo 22 | import promise.commons.data.log.LogUtil 23 | import promise.database.DatabaseEntity 24 | import promise.db.FastDatabase 25 | import promise.db.PromiseDatabase 26 | import promise.utils.Visitor 27 | 28 | @DatabaseEntity( 29 | persistableEntities = [ 30 | PostComment::class, 31 | Photo::class, 32 | Post::class, 33 | Todo::class, 34 | Like::class, 35 | User::class 36 | ], 37 | version = 2 38 | ) 39 | abstract class AppDatabase(fastDatabase: FastDatabase) 40 | : PromiseDatabase(fastDatabase) { 41 | 42 | init { 43 | fastDatabase.setErrorHandler { 44 | LogUtil.e(TAG, "database error: ${it.path}") 45 | } 46 | fastDatabase.fallBackToDestructiveMigration() 47 | } 48 | 49 | //abstract fun getPostCommentsDao(): PostCommentDao 50 | 51 | companion object { 52 | val TAG: String = LogUtil.makeTag(AppDatabase::class.java) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/promise/base/AppTypeConverter.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.base 15 | 16 | import promise.database.TypeConverter 17 | import java.util.* 18 | 19 | @TypeConverter 20 | class AppTypeConverter { 21 | 22 | fun dateToString(date: Date?): String = (date ?: Date()).time.toString() 23 | 24 | fun stringToDate(data: String): Date = Date(data.toLong()) 25 | 26 | fun toUniqueId(data: String): ID = ID().apply { id = data } 27 | 28 | fun toString(data: ID?): String = data?.id ?: "" 29 | 30 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/base/ID.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.base 15 | 16 | import android.os.Parcel 17 | import android.os.Parcelable 18 | 19 | class ID() : Parcelable { 20 | var id: String? = "" 21 | 22 | constructor(parcel: Parcel) : this() { 23 | id = parcel.readString() 24 | } 25 | 26 | override fun writeToParcel(parcel: Parcel, flags: Int) { 27 | parcel.writeString(id) 28 | } 29 | 30 | override fun describeContents(): Int = 0 31 | 32 | companion object CREATOR : Parcelable.Creator { 33 | override fun createFromParcel(parcel: Parcel): ID = ID(parcel) 34 | override fun newArray(size: Int): Array = arrayOfNulls(size) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/promise/base/comment/PostCommentDao.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.base.comment; 15 | 16 | import java.util.List; 17 | 18 | import promise.database.DAO; 19 | import promise.db.criteria.Criteria; 20 | 21 | @DAO 22 | public interface PostCommentDao { 23 | 24 | List getPostComments(Criteria criteria); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/promise/base/comment/PostCommentToReplyRelation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.base.comment; 15 | 16 | import java.util.List; 17 | 18 | import promise.database.Child; 19 | import promise.database.Parent; 20 | import promise.database.Relation; 21 | 22 | @Relation 23 | public class PostCommentToReplyRelation { 24 | 25 | @Parent 26 | private PostComment postComment; 27 | 28 | @Child(fieldRelatedToParent = "postCommentId") 29 | private List postCommentReplies; 30 | 31 | public PostComment getPostComment() { 32 | return postComment; 33 | } 34 | 35 | public void setPostComment(PostComment postComment) { 36 | this.postComment = postComment; 37 | } 38 | 39 | public List getPostCommentReplies() { 40 | return postCommentReplies; 41 | } 42 | 43 | public void setPostCommentReplies(List postCommentReplies) { 44 | this.postCommentReplies = postCommentReplies; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/promise/base/photo/Photo.kt: -------------------------------------------------------------------------------- 1 | package promise.base.photo 2 | 3 | import android.os.Parcel 4 | import android.os.Parcelable 5 | import promise.base.post.Post 6 | import promise.database.Entity 7 | import promise.database.HasOne 8 | import promise.db.ActiveRecord 9 | 10 | @Entity 11 | class Photo() : ActiveRecord() { 12 | var albumId: Int? = null 13 | var title: String? = null 14 | var url: String? = null 15 | var thumbnailUrl: String? = null 16 | 17 | @HasOne 18 | var photoPost: Post? = null 19 | 20 | constructor(parcel: Parcel) : this() { 21 | albumId = parcel.readValue(Int::class.java.classLoader) as? Int 22 | title = parcel.readString() 23 | url = parcel.readString() 24 | thumbnailUrl = parcel.readString() 25 | photoPost = parcel.readParcelable(Post::class.java.classLoader) 26 | } 27 | 28 | override fun getEntity(): Photo = this 29 | 30 | override fun writeToParcel(parcel: Parcel, flags: Int) { 31 | super.writeToParcel(parcel, flags) 32 | parcel.writeValue(albumId) 33 | parcel.writeString(title) 34 | parcel.writeString(url) 35 | parcel.writeString(thumbnailUrl) 36 | parcel.writeParcelable(photoPost, flags) 37 | } 38 | 39 | override fun describeContents(): Int = 0 40 | 41 | companion object CREATOR : Parcelable.Creator { 42 | override fun createFromParcel(parcel: Parcel): Photo = Photo(parcel) 43 | override fun newArray(size: Int): Array = arrayOfNulls(size) 44 | } 45 | 46 | } 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/java/promise/base/post/PostRepository.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.base.post 15 | 16 | import promise.base.ID 17 | import promise.base.comment.PostComment 18 | import promise.model.IdentifiableList 19 | import javax.inject.Inject 20 | import javax.inject.Singleton 21 | 22 | interface PostRepository { 23 | 24 | fun savePost(post: Post) 25 | 26 | fun getPosts(): List 27 | 28 | fun deletePosts() 29 | } 30 | 31 | @Singleton 32 | class PostRepositoryImpl 33 | @Inject 34 | constructor( 35 | private var postRelationsDao: PostRelationsDao, 36 | private var postsTable: PostsTable) : PostRepository { 37 | init { 38 | val posts = IdentifiableList(promise.commons.model.List.generate(5) { 39 | Post().apply { 40 | uId = ID().apply { 41 | id = it.toString() 42 | } 43 | title = "post".plus(it) 44 | body = "body".plus(it) 45 | userId = it 46 | comments = promise.commons.model.List.generate(4) { 47 | PostComment().apply { 48 | name = "nm".repeat(it) 49 | uId = ID().apply { 50 | id = (it + 1).toString() 51 | } 52 | body = "hbytcvbcrxgfvbtrxt" 53 | email = "ejmail;jgfccghcfcvhbhcgvb" 54 | } 55 | } 56 | } 57 | }) 58 | 59 | postRelationsDao.saveWithComments(posts) 60 | } 61 | 62 | override fun savePost(post: Post) { 63 | postsTable.save(post) 64 | } 65 | 66 | override fun getPosts(): List = postRelationsDao.listWithComments() 67 | 68 | override fun deletePosts() { 69 | val persons = getPosts() 70 | persons.forEach { 71 | postRelationsDao.deleteComments(it) 72 | it.delete() 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/base/session/User.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.base.session 15 | 16 | import android.annotation.SuppressLint 17 | import promise.database.AddedEntity 18 | import promise.database.Entity 19 | import promise.db.ActiveRecord 20 | 21 | @SuppressLint("ParcelCreator") 22 | @Entity 23 | @AddedEntity(fromVersion = 1, toVersion = 2) 24 | class User: ActiveRecord() { 25 | 26 | var email: String = "" 27 | var likedinProfileUrl = "" 28 | var photoUrl = "" 29 | var names = "" 30 | override fun getEntity(): User = this 31 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/base/todo/Todo.java: -------------------------------------------------------------------------------- 1 | package promise.base.todo; 2 | 3 | import android.annotation.SuppressLint; 4 | 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import promise.base.photo.Photo; 8 | import promise.database.Entity; 9 | import promise.database.HasOne; 10 | import promise.db.ActiveRecord; 11 | 12 | @SuppressLint("ParcelCreator") 13 | @Entity 14 | public class Todo extends ActiveRecord { 15 | private int uid; 16 | private boolean completed; 17 | 18 | private String title; 19 | 20 | private long timeStarted; 21 | private long timeFinished; 22 | private String description; 23 | @HasOne 24 | private Photo photo; 25 | 26 | public long getTimeFinished() { 27 | return timeFinished; 28 | } 29 | 30 | public void setTimeFinished(long timeFinished) { 31 | this.timeFinished = timeFinished; 32 | } 33 | 34 | public long getTimeStarted() { 35 | return timeStarted; 36 | } 37 | 38 | public void setTimeStarted(long timeStarted) { 39 | this.timeStarted = timeStarted; 40 | } 41 | 42 | public int getUid() { 43 | return uid; 44 | } 45 | 46 | public void setUid(int uid) { 47 | this.uid = uid; 48 | } 49 | 50 | public Photo getPhoto() { 51 | return photo; 52 | } 53 | 54 | public void setPhoto(Photo photo) { 55 | this.photo = photo; 56 | } 57 | 58 | public boolean isCompleted() { 59 | return completed; 60 | } 61 | 62 | public void setCompleted(boolean completed) { 63 | this.completed = completed; 64 | } 65 | 66 | public String getTitle() { 67 | return title; 68 | } 69 | 70 | public void setTitle(String title) { 71 | this.title = title; 72 | } 73 | 74 | public String getDescription() { 75 | return description; 76 | } 77 | 78 | public void setDescription(String description) { 79 | this.description = description; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return 85 | "Todo{" + 86 | "id = '" + uid + '\'' + 87 | ",completed = '" + completed + '\'' + 88 | ",title = '" + title + '\'' + 89 | "}"; 90 | } 91 | 92 | @NotNull 93 | @Override 94 | public Todo getEntity() { 95 | return this; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/ActivityBuildersModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp 15 | 16 | import dagger.Module 17 | import dagger.android.ContributesAndroidInjector 18 | 19 | @Module 20 | abstract class ActivityBuildersModule { 21 | @ContributesAndroidInjector( 22 | modules = [ 23 | ReposModule::class 24 | ] 25 | ) 26 | abstract fun contributeMainActivity(): MainActivity 27 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/App.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp 15 | 16 | import dagger.android.AndroidInjector 17 | import dagger.android.support.DaggerApplication 18 | import promise.commons.AndroidPromise 19 | 20 | class App : DaggerApplication() { 21 | override fun onCreate() { 22 | super.onCreate() 23 | AndroidPromise.init(this, BuildConfig.DEBUG) 24 | } 25 | 26 | override fun applicationInjector(): AndroidInjector = 27 | DaggerAppComponent.factory().create(this) 28 | 29 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/AppComponent.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp 15 | 16 | import dagger.BindsInstance 17 | import dagger.Component 18 | import dagger.android.AndroidInjector 19 | import dagger.android.support.AndroidSupportInjectionModule 20 | import javax.inject.Singleton 21 | 22 | @Component( 23 | modules = [ 24 | AndroidSupportInjectionModule::class, 25 | ActivityBuildersModule::class, 26 | DatabaseDependencies::class 27 | ] 28 | ) 29 | @Singleton 30 | interface AppComponent : AndroidInjector { 31 | 32 | @Component.Factory 33 | interface Builder { 34 | fun create(@BindsInstance app: App): AppComponent 35 | } 36 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/DatabaseDependencies.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp 15 | 16 | import dagger.Module 17 | import dagger.Provides 18 | import promise.base.AppDatabaseImpl 19 | import promise.base.post.PostRelationsDao 20 | import promise.base.post.PostsTable 21 | import javax.inject.Singleton 22 | 23 | @Module 24 | object DatabaseDependencies { 25 | 26 | @Provides 27 | @Singleton 28 | @JvmStatic 29 | fun provideAppDatabase(): AppDatabaseImpl = AppDatabaseImpl.createDatabase("blog_db") 30 | 31 | @Provides 32 | @JvmStatic 33 | fun providePostRelationsDao(appDatabase: AppDatabaseImpl): PostRelationsDao = 34 | appDatabase.postRelationsDao 35 | 36 | @Provides 37 | @JvmStatic 38 | fun providePostTable(appDatabase: AppDatabaseImpl): PostsTable = 39 | appDatabase.postsTable 40 | 41 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/MainActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp 15 | 16 | import android.os.Bundle 17 | import com.google.android.material.snackbar.Snackbar 18 | import dagger.android.support.DaggerAppCompatActivity 19 | import kotlinx.android.synthetic.main.activity_main.* 20 | import kotlinx.android.synthetic.main.content_main.* 21 | import promise.base.post.PostRepository 22 | import javax.inject.Inject 23 | 24 | class MainActivity : DaggerAppCompatActivity() { 25 | 26 | @Inject 27 | lateinit var postRepository: PostRepository 28 | 29 | override fun onCreate(savedInstanceState: Bundle?) { 30 | super.onCreate(savedInstanceState) 31 | setContentView(R.layout.activity_main) 32 | setSupportActionBar(toolbar) 33 | 34 | fab.setOnClickListener { view -> 35 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 36 | .setAction("Action", null).show() 37 | } 38 | } 39 | 40 | override fun onPostCreate(savedInstanceState: Bundle?) { 41 | super.onPostCreate(savedInstanceState) 42 | showInfo() 43 | clear_button.setOnClickListener { 44 | deleteInfo() 45 | showInfo() 46 | } 47 | } 48 | 49 | private fun showInfo() { 50 | val persons = postRepository.getPosts() 51 | complex_values_textview.text = persons.toString() 52 | } 53 | 54 | private fun deleteInfo() { 55 | postRepository.deletePosts() 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/ReposModule.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp 15 | 16 | import dagger.Binds 17 | import dagger.Module 18 | import promise.base.post.PostRepository 19 | import promise.base.post.PostRepositoryImpl 20 | 21 | @Module 22 | abstract class ReposModule { 23 | 24 | @Binds 25 | abstract fun bindPostsRepository(postRepositoryImpl: PostRepositoryImpl): PostRepository 26 | } -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/test/PostCommentsDaoImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp.test; 15 | 16 | import android.database.Cursor; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import promise.base.comment.PostComment; 22 | import promise.base.comment.PostCommentDao; 23 | import promise.base.comment.PostCommentToReplyRelation; 24 | import promise.base.comment.PostCommentsTable; 25 | import promise.db.PromiseDatabase; 26 | import promise.db.criteria.Criteria; 27 | import promise.model.IdentifiableList; 28 | 29 | public class PostCommentsDaoImpl 30 | implements PostCommentDao { 31 | 32 | private PromiseDatabase promiseDatabase; 33 | 34 | public PostCommentsDaoImpl(PromiseDatabase fastDatabase) { 35 | this.promiseDatabase = fastDatabase; 36 | } 37 | 38 | private PostCommentToReplyRelation getPostCommentToReplyRelation(PostComment postComment) { 39 | return new PostCommentToReplyRelation() {{ 40 | setPostComment(postComment); 41 | setPostCommentReplies(new ArrayList<>( 42 | promiseDatabase.tableOf(PostComment.class).findAll( 43 | PostCommentsTable.postCommentIdColumn.with( 44 | postComment.getId().toString())))); 45 | }}; 46 | } 47 | 48 | @Override 49 | public List getPostComments(Criteria andCriteria) { 50 | Cursor cursor = promiseDatabase.getDatabaseInstance().query( 51 | promiseDatabase.tableOf(PostComment.class).queryBuilder() 52 | .whereAnd(andCriteria)); 53 | return getPostCommentToReplyRelationCollection(cursor); 54 | } 55 | 56 | private List getPostCommentToReplyRelationCollection(Cursor cursor) { 57 | IdentifiableList postComments = promiseDatabase.tableOf(PostComment.class).collection(cursor); 58 | return postComments.map(this::getPostCommentToReplyRelation); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/promise/dbapp/test/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017, Peter Vincent 3 | * Licensed under the Apache License, Version 2.0, Android Promise. 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * Unless required by applicable law or agreed to in writing, 8 | * software distributed under the License is distributed on an "AS IS" BASIS, 9 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | * See the License for the specific language governing permissions and 11 | * limitations under the License. 12 | */ 13 | 14 | package promise.dbapp.test; 15 | 16 | 17 | public class TestUtils { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 20 | 21 | 25 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 44 | 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/complex_layout.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 22 | 23 | 27 | 28 | 33 | 34 |