Explorar o código

add core* modules and release db dependencies

MrOzOn %!s(int64=5) %!d(string=hai) anos
pai
achega
30d7bec506
Modificáronse 31 ficheiros con 438 adicións e 0 borrados
  1. 1 0
      core/.gitignore
  2. 40 0
      core/build.gradle
  3. 0 0
      core/consumer-rules.pro
  4. 21 0
      core/proguard-rules.pro
  5. 24 0
      core/src/androidTest/java/com/mrozon/core/ExampleInstrumentedTest.kt
  6. 2 0
      core/src/main/AndroidManifest.xml
  7. 11 0
      core/src/main/java/com/mrozon/core/CoreProvidersFactory.kt
  8. 17 0
      core/src/test/java/com/mrozon/core/ExampleUnitTest.kt
  9. 1 0
      core_api/.gitignore
  10. 44 0
      core_api/build.gradle
  11. 0 0
      core_api/consumer-rules.pro
  12. 21 0
      core_api/proguard-rules.pro
  13. 24 0
      core_api/src/androidTest/java/com/mrozon/core_api/ExampleInstrumentedTest.kt
  14. 2 0
      core_api/src/main/AndroidManifest.xml
  15. 7 0
      core_api/src/main/java/com/mrozon/core_api/db/DatabaseProvider.kt
  16. 6 0
      core_api/src/main/java/com/mrozon/core_api/db/HealthDiaryDao.kt
  17. 5 0
      core_api/src/main/java/com/mrozon/core_api/db/HealthDiaryDatabaseContract.kt
  18. 21 0
      core_api/src/main/java/com/mrozon/core_api/db/model/UserDb.kt
  19. 8 0
      core_api/src/main/java/com/mrozon/core_api/provides/AppProvider.kt
  20. 17 0
      core_api/src/test/java/com/mrozon/core_api/ExampleUnitTest.kt
  21. 1 0
      core_impl/.gitignore
  22. 45 0
      core_impl/build.gradle
  23. 0 0
      core_impl/consumer-rules.pro
  24. 21 0
      core_impl/proguard-rules.pro
  25. 24 0
      core_impl/src/androidTest/java/com/mrozon/core_impl/ExampleInstrumentedTest.kt
  26. 2 0
      core_impl/src/main/AndroidManifest.xml
  27. 13 0
      core_impl/src/main/java/com/mrozon/core_impl/db/DatabaseComponent.kt
  28. 31 0
      core_impl/src/main/java/com/mrozon/core_impl/db/DatabaseModule.kt
  29. 9 0
      core_impl/src/main/java/com/mrozon/core_impl/db/HealthDiaryDb.kt
  30. 17 0
      core_impl/src/test/java/com/mrozon/core_impl/ExampleUnitTest.kt
  31. 3 0
      settings.gradle

+ 1 - 0
core/.gitignore

@@ -0,0 +1 @@
+/build

+ 40 - 0
core/build.gradle

@@ -0,0 +1,40 @@
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-android-extensions'
+
+android {
+    compileSdkVersion rootProject.compileSdkVersion
+    buildToolsVersion "29.0.3"
+
+    defaultConfig {
+        minSdkVersion rootProject.minSdkVersion
+        targetSdkVersion rootProject.targetSdkVersion
+        versionCode 1
+        versionName "1.0"
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles 'consumer-rules.pro'
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+
+}
+
+apply from: "$project.rootDir/scripts/deps_versions.gradle"
+
+dependencies {
+    api project(':core_api')
+    implementation project(':core_impl')
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+    implementation 'androidx.appcompat:appcompat:1.2.0'
+    implementation 'androidx.core:core-ktx:1.3.1'
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+}

+ 0 - 0
core/consumer-rules.pro


+ 21 - 0
core/proguard-rules.pro

@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 24 - 0
core/src/androidTest/java/com/mrozon/core/ExampleInstrumentedTest.kt

@@ -0,0 +1,24 @@
+package com.mrozon.core
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+    @Test
+    fun useAppContext() {
+        // Context of the app under test.
+        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+        assertEquals("com.mrozon.core.test", appContext.packageName)
+    }
+}

+ 2 - 0
core/src/main/AndroidManifest.xml

@@ -0,0 +1,2 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.mrozon.core" />

+ 11 - 0
core/src/main/java/com/mrozon/core/CoreProvidersFactory.kt

@@ -0,0 +1,11 @@
+package com.mrozon.core
+
+import com.mrozon.core_api.db.DatabaseProvider
+import com.mrozon.core_api.provides.AppProvider
+import com.mrozon.core_impl.db.DaggerDatabaseComponent
+
+object CoreProvidersFactory {
+    fun createDatabaseBuilder(appProvider: AppProvider): DatabaseProvider {
+        return DaggerDatabaseComponent.builder().appProvider(appProvider).build()
+    }
+}

+ 17 - 0
core/src/test/java/com/mrozon/core/ExampleUnitTest.kt

@@ -0,0 +1,17 @@
+package com.mrozon.core
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+    @Test
+    fun addition_isCorrect() {
+        assertEquals(4, 2 + 2)
+    }
+}

+ 1 - 0
core_api/.gitignore

@@ -0,0 +1 @@
+/build

+ 44 - 0
core_api/build.gradle

@@ -0,0 +1,44 @@
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-kapt'
+
+android {
+    compileSdkVersion rootProject.compileSdkVersion
+    buildToolsVersion "29.0.3"
+
+    defaultConfig {
+        minSdkVersion rootProject.minSdkVersion
+        targetSdkVersion rootProject.targetSdkVersion
+        versionCode 1
+        versionName "1.0"
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles 'consumer-rules.pro'
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+
+}
+
+apply from: "$project.rootDir/scripts/deps_versions.gradle"
+
+dependencies {
+
+    implementation dagger
+    kapt daggerCompiler
+    implementation room
+
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+    implementation 'androidx.appcompat:appcompat:1.2.0'
+    implementation 'androidx.core:core-ktx:1.3.1'
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+}

+ 0 - 0
core_api/consumer-rules.pro


+ 21 - 0
core_api/proguard-rules.pro

@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 24 - 0
core_api/src/androidTest/java/com/mrozon/core_api/ExampleInstrumentedTest.kt

@@ -0,0 +1,24 @@
+package com.mrozon.core_api
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+    @Test
+    fun useAppContext() {
+        // Context of the app under test.
+        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+        assertEquals("com.mrozon.core_api.test", appContext.packageName)
+    }
+}

+ 2 - 0
core_api/src/main/AndroidManifest.xml

@@ -0,0 +1,2 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.mrozon.core_api" />

+ 7 - 0
core_api/src/main/java/com/mrozon/core_api/db/DatabaseProvider.kt

@@ -0,0 +1,7 @@
+package com.mrozon.core_api.db
+
+interface DatabaseProvider {
+
+    fun provideDatabase(): HealthDiaryDatabaseContract
+    fun healthDiaryDao(): HealthDiaryDao
+}

+ 6 - 0
core_api/src/main/java/com/mrozon/core_api/db/HealthDiaryDao.kt

@@ -0,0 +1,6 @@
+package com.mrozon.core_api.db
+
+import androidx.room.Dao
+
+@Dao
+interface HealthDiaryDao

+ 5 - 0
core_api/src/main/java/com/mrozon/core_api/db/HealthDiaryDatabaseContract.kt

@@ -0,0 +1,5 @@
+package com.mrozon.core_api.db
+
+interface HealthDiaryDatabaseContract {
+    fun healthDiaryDao(): HealthDiaryDao
+}

+ 21 - 0
core_api/src/main/java/com/mrozon/core_api/db/model/UserDb.kt

@@ -0,0 +1,21 @@
+package com.mrozon.core_api.db.model
+
+import androidx.room.ColumnInfo
+import androidx.room.Entity
+import androidx.room.PrimaryKey
+
+@Entity(tableName = "user_table")
+data class UserDb(
+    @PrimaryKey(autoGenerate = true)
+    @ColumnInfo(name = "user_id")
+    var id: Long = 0L,
+
+    @ColumnInfo(name = "user_email")
+    val email: String = "",
+
+    @ColumnInfo(name = "user_firstname")
+    var firstname: String = "",
+
+    @ColumnInfo(name = "user_lastname")
+    var lastname: String = ""
+)

+ 8 - 0
core_api/src/main/java/com/mrozon/core_api/provides/AppProvider.kt

@@ -0,0 +1,8 @@
+package com.mrozon.core_api.provides
+
+import android.content.Context
+
+interface AppProvider {
+
+    fun provideContext(): Context
+}

+ 17 - 0
core_api/src/test/java/com/mrozon/core_api/ExampleUnitTest.kt

@@ -0,0 +1,17 @@
+package com.mrozon.core_api
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+    @Test
+    fun addition_isCorrect() {
+        assertEquals(4, 2 + 2)
+    }
+}

+ 1 - 0
core_impl/.gitignore

@@ -0,0 +1 @@
+/build

+ 45 - 0
core_impl/build.gradle

@@ -0,0 +1,45 @@
+apply plugin: 'com.android.library'
+apply plugin: 'kotlin-android'
+apply plugin: 'kotlin-android-extensions'
+apply plugin: 'kotlin-kapt'
+
+android {
+    compileSdkVersion rootProject.compileSdkVersion
+    buildToolsVersion "29.0.3"
+
+    defaultConfig {
+        minSdkVersion rootProject.minSdkVersion
+        targetSdkVersion rootProject.targetSdkVersion
+        versionCode 1
+        versionName "1.0"
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles 'consumer-rules.pro'
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+
+}
+
+apply from: "$project.rootDir/scripts/deps_versions.gradle"
+
+dependencies {
+    api project(':core_api')
+
+    implementation dagger
+    kapt daggerCompiler
+    implementation room
+
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+    implementation 'androidx.appcompat:appcompat:1.2.0'
+    implementation 'androidx.core:core-ktx:1.3.1'
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+}

+ 0 - 0
core_impl/consumer-rules.pro


+ 21 - 0
core_impl/proguard-rules.pro

@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile

+ 24 - 0
core_impl/src/androidTest/java/com/mrozon/core_impl/ExampleInstrumentedTest.kt

@@ -0,0 +1,24 @@
+package com.mrozon.core_impl
+
+import androidx.test.platform.app.InstrumentationRegistry
+import androidx.test.ext.junit.runners.AndroidJUnit4
+
+import org.junit.Test
+import org.junit.runner.RunWith
+
+import org.junit.Assert.*
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+@RunWith(AndroidJUnit4::class)
+class ExampleInstrumentedTest {
+    @Test
+    fun useAppContext() {
+        // Context of the app under test.
+        val appContext = InstrumentationRegistry.getInstrumentation().targetContext
+        assertEquals("com.mrozon.core_impl.test", appContext.packageName)
+    }
+}

+ 2 - 0
core_impl/src/main/AndroidManifest.xml

@@ -0,0 +1,2 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.mrozon.core_impl" />

+ 13 - 0
core_impl/src/main/java/com/mrozon/core_impl/db/DatabaseComponent.kt

@@ -0,0 +1,13 @@
+package com.mrozon.core_impl.db
+
+import com.mrozon.core_api.db.DatabaseProvider
+import com.mrozon.core_api.provides.AppProvider
+import dagger.Component
+import javax.inject.Singleton
+
+@Singleton
+@Component(
+    dependencies = [AppProvider::class],
+    modules = [DatabaseModule::class]
+)
+interface DatabaseComponent : DatabaseProvider

+ 31 - 0
core_impl/src/main/java/com/mrozon/core_impl/db/DatabaseModule.kt

@@ -0,0 +1,31 @@
+package com.mrozon.core_impl.db
+
+import android.content.Context
+import androidx.room.Room
+import com.mrozon.core_api.db.HealthDiaryDao
+import com.mrozon.core_api.db.HealthDiaryDatabaseContract
+import dagger.Module
+import dagger.Provides
+import dagger.Reusable
+import javax.inject.Singleton
+
+private const val DATABASE_NAME = "HealthDiaryDB"
+
+@Module
+class DatabaseModule {
+
+    @Provides
+    @Reusable
+    fun provideHabitsDao(healthDiaryDatabaseContract: HealthDiaryDatabaseContract): HealthDiaryDao {
+        return healthDiaryDatabaseContract.healthDiaryDao()
+    }
+
+    @Provides
+    @Singleton
+    fun provideHabitsDatabase(context: Context): HealthDiaryDatabaseContract {
+        return Room.databaseBuilder(
+            context,
+            HabitsDatabase::class.java, DATABASE_NAME
+        ).build()
+    }
+}

+ 9 - 0
core_impl/src/main/java/com/mrozon/core_impl/db/HealthDiaryDb.kt

@@ -0,0 +1,9 @@
+package com.mrozon.core_impl.db
+
+import androidx.room.Database
+import androidx.room.RoomDatabase
+import com.mrozon.core_api.db.HealthDiaryDatabaseContract
+import com.mrozon.core_api.db.model.UserDb
+
+@Database(entities = [UserDb::class], version = 1)
+abstract class HabitsDatabase : RoomDatabase(), HealthDiaryDatabaseContract

+ 17 - 0
core_impl/src/test/java/com/mrozon/core_impl/ExampleUnitTest.kt

@@ -0,0 +1,17 @@
+package com.mrozon.core_impl
+
+import org.junit.Test
+
+import org.junit.Assert.*
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * See [testing documentation](http://d.android.com/tools/testing).
+ */
+class ExampleUnitTest {
+    @Test
+    fun addition_isCorrect() {
+        assertEquals(4, 2 + 2)
+    }
+}

+ 3 - 0
settings.gradle

@@ -1,3 +1,6 @@
 rootProject.name='HealthDiary'
 include ':app'
 include ':utils'
+include ':core_api'
+include ':core_impl'
+include ':core'