diff --git a/app/build.gradle b/app/build.gradle index fe6ce65442..6f613d0f64 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -242,6 +242,8 @@ allprojects { dependencies { wearApp project(':wear') + implementation project(':core') + implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.google.android.gms:play-services-wearable:17.0.0' implementation "com.google.android.gms:play-services-location:17.0.0" diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt index 91153bd867..1bb1595863 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppComponent.kt @@ -5,6 +5,7 @@ import dagger.Component import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjector import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.core.dependencyInjection.CoreModule import info.nightscout.androidaps.data.Profile import info.nightscout.androidaps.data.ProfileStore import info.nightscout.androidaps.data.PumpEnactResult @@ -53,6 +54,7 @@ import javax.inject.Singleton @Component( modules = [ AndroidInjectionModule::class, + CoreModule::class, ActivitiesModule::class, FragmentsModule::class, AppModule::class, diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt index 871f88a503..4bfabbdfed 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/AppModule.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.dependencyInjection +import android.app.Application import android.content.Context import androidx.preference.PreferenceManager import dagger.Binds @@ -89,12 +90,6 @@ open class AppModule { return ProfileFunctionImplementation(injector, aapsLogger, sp, resourceHelper, activePlugin, fabricPrivacy) } - @Provides - @Singleton - fun provideResources(mainApp: MainApp): ResourceHelper { - return ResourceHelperImplementation(mainApp) - } - @Provides @Singleton fun provideAAPSLogger(): AAPSLogger { @@ -132,6 +127,7 @@ open class AppModule { interface AppBindings { @Binds fun bindContext(mainApp: MainApp): Context + @Binds fun bindApplication(mainApp: MainApp): Application @Binds fun bindInjector(mainApp: MainApp): HasAndroidInjector @Binds diff --git a/build.gradle b/build.gradle index 579db1fcbf..23ca45ba11 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,16 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.71' + ext { + kotlin_version = '1.3.71' + android_ktx_version = '1.2.0' + rxjava_version = '2.2.19' + rxandroid_version = '2.1.1' + rxkotlin_version = '2.4.0' + room_version = '2.2.5' + lifecycle_version = '2.2.0' + dagger_version = '2.27' + } repositories { google() jcenter() diff --git a/core/.gitignore b/core/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/core/.gitignore @@ -0,0 +1 @@ +/build diff --git a/core/build.gradle b/core/build.gradle new file mode 100644 index 0000000000..19c024a1de --- /dev/null +++ b/core/build.gradle @@ -0,0 +1,45 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + minSdkVersion 23 + targetSdkVersion 29 + 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' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + + implementation "com.google.dagger:dagger-android:$dagger_version" + implementation "com.google.dagger:dagger-android-support:$dagger_version" + annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" + annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-android-processor:$dagger_version" + kapt "com.google.dagger:dagger-compiler:$dagger_version" + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/core/consumer-rules.pro b/core/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core/proguard-rules.pro b/core/proguard-rules.pro new file mode 100644 index 0000000000..f1b424510d --- /dev/null +++ b/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 diff --git a/core/src/androidTest/java/info/nightscout/androidaps/core/ExampleInstrumentedTest.kt b/core/src/androidTest/java/info/nightscout/androidaps/core/ExampleInstrumentedTest.kt new file mode 100644 index 0000000000..f0f2aec62c --- /dev/null +++ b/core/src/androidTest/java/info/nightscout/androidaps/core/ExampleInstrumentedTest.kt @@ -0,0 +1,25 @@ +package info.nightscout.androidaps.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("info.nightscout.androidaps.core.test", appContext.packageName) + } +} diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..46d6d492d4 --- /dev/null +++ b/core/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt new file mode 100644 index 0000000000..3d022dfd6f --- /dev/null +++ b/core/src/main/java/info/nightscout/androidaps/core/dependencyInjection/CoreModule.kt @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.core.dependencyInjection + +import android.content.Context +import dagger.Module +import dagger.Provides +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation +import javax.inject.Singleton + +@Module +open class CoreModule { + + @Provides + @Singleton + fun provideResources(context: Context): ResourceHelper { + return ResourceHelperImplementation(context) + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt b/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelper.kt similarity index 100% rename from app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelper.kt rename to core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelper.kt diff --git a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt b/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt similarity index 96% rename from app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt rename to core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt index 3cd72d5f4a..573f19f065 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/resources/ResourceHelperImplementation.kt +++ b/core/src/main/java/info/nightscout/androidaps/core/resources/ResourceHelperImplementation.kt @@ -12,8 +12,7 @@ import androidx.annotation.ColorRes import androidx.annotation.PluralsRes import androidx.annotation.StringRes import androidx.core.content.ContextCompat -import info.nightscout.androidaps.Config -import info.nightscout.androidaps.R +import info.nightscout.androidaps.core.R import javax.inject.Inject /** diff --git a/app/src/main/res/values-sw600dp/layout.xml b/core/src/main/res/values-sw600dp/layout.xml similarity index 100% rename from app/src/main/res/values-sw600dp/layout.xml rename to core/src/main/res/values-sw600dp/layout.xml diff --git a/app/src/main/res/values/layout.xml b/core/src/main/res/values/layout.xml similarity index 100% rename from app/src/main/res/values/layout.xml rename to core/src/main/res/values/layout.xml diff --git a/core/src/test/java/info/nightscout/androidaps/core/ExampleUnitTest.kt b/core/src/test/java/info/nightscout/androidaps/core/ExampleUnitTest.kt new file mode 100644 index 0000000000..35bc1a6629 --- /dev/null +++ b/core/src/test/java/info/nightscout/androidaps/core/ExampleUnitTest.kt @@ -0,0 +1,18 @@ +package info.nightscout.androidaps.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) + } +} diff --git a/settings.gradle b/settings.gradle index 9ccfb61915..f7c8a5fc0a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':wear' +include ':app', ':wear', ':core' \ No newline at end of file