diff --git a/app/build.gradle b/app/build.gradle index 0c80acd2d7..8fe98aa880 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -203,6 +203,7 @@ dependencies { implementation project(':plugins:main') implementation project(':plugins:openhumans') implementation project(':plugins:sensitivity') + implementation project(':plugins:source') implementation project(':plugins:sync') implementation project(':implementation') implementation project(':database:entities') diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index b6b06fb5c5..a0d9cbf38f 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -48,14 +48,6 @@ import info.nightscout.plugins.general.autotune.AutotunePlugin import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin import info.nightscout.plugins.general.wear.WearPlugin import info.nightscout.plugins.general.xdripStatusline.StatusLinePlugin -import info.nightscout.plugins.source.AidexPlugin -import info.nightscout.plugins.source.DexcomPlugin -import info.nightscout.plugins.source.EversensePlugin -import info.nightscout.plugins.source.GlimpPlugin -import info.nightscout.plugins.source.GlunovoPlugin -import info.nightscout.plugins.source.IntelligoPlugin -import info.nightscout.plugins.source.PoctechPlugin -import info.nightscout.plugins.source.TomatoPlugin import info.nightscout.plugins.sync.nsclient.NSClientPlugin import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin import info.nightscout.plugins.sync.tidepool.TidepoolPlugin @@ -72,6 +64,14 @@ import info.nightscout.sensitivity.SensitivityWeightedAveragePlugin import info.nightscout.shared.SafeParse import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP +import info.nightscout.source.AidexPlugin +import info.nightscout.source.DexcomPlugin +import info.nightscout.source.EversensePlugin +import info.nightscout.source.GlimpPlugin +import info.nightscout.source.GlunovoPlugin +import info.nightscout.source.IntelligoPlugin +import info.nightscout.source.PoctechPlugin +import info.nightscout.source.TomatoPlugin import javax.inject.Inject class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChangeListener { diff --git a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt index 7ba9ed8947..229407090f 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/AppComponent.kt @@ -36,6 +36,7 @@ import info.nightscout.pump.virtual.di.VirtualPumpModule import info.nightscout.rx.di.RxModule import info.nightscout.shared.di.SharedModule import info.nightscout.shared.impl.di.SharedImplModule +import info.nightscout.source.di.SourceModule import info.nightscout.ui.di.UiModule import info.nightscout.workflow.di.WorkflowModule import javax.inject.Singleton @@ -66,6 +67,7 @@ import javax.inject.Singleton UiModule::class, ValidatorsModule::class, PluginsConstraintsModule::class, + SourceModule::class, SyncModule::class, WorkflowModule::class, diff --git a/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt b/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt index 3010832bd9..868b3b5c5a 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/PluginsListModule.kt @@ -41,17 +41,6 @@ import info.nightscout.plugins.general.wear.WearPlugin import info.nightscout.plugins.general.xdripStatusline.StatusLinePlugin import info.nightscout.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin import info.nightscout.plugins.profile.ProfilePlugin -import info.nightscout.plugins.source.AidexPlugin -import info.nightscout.plugins.source.DexcomPlugin -import info.nightscout.plugins.source.GlimpPlugin -import info.nightscout.plugins.source.GlunovoPlugin -import info.nightscout.plugins.source.IntelligoPlugin -import info.nightscout.plugins.source.MM640gPlugin -import info.nightscout.plugins.source.NSClientSourcePlugin -import info.nightscout.plugins.source.PoctechPlugin -import info.nightscout.plugins.source.RandomBgPlugin -import info.nightscout.plugins.source.TomatoPlugin -import info.nightscout.plugins.source.XdripPlugin import info.nightscout.plugins.sync.nsclient.NSClientPlugin import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin import info.nightscout.plugins.sync.tidepool.TidepoolPlugin @@ -62,6 +51,17 @@ import info.nightscout.pump.virtual.VirtualPumpPlugin import info.nightscout.sensitivity.SensitivityAAPSPlugin import info.nightscout.sensitivity.SensitivityOref1Plugin import info.nightscout.sensitivity.SensitivityWeightedAveragePlugin +import info.nightscout.source.AidexPlugin +import info.nightscout.source.DexcomPlugin +import info.nightscout.source.GlimpPlugin +import info.nightscout.source.GlunovoPlugin +import info.nightscout.source.IntelligoPlugin +import info.nightscout.source.MM640gPlugin +import info.nightscout.source.NSClientSourcePlugin +import info.nightscout.source.PoctechPlugin +import info.nightscout.source.RandomBgPlugin +import info.nightscout.source.TomatoPlugin +import info.nightscout.source.XdripPlugin import javax.inject.Qualifier @Suppress("unused") diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt index e459c0223c..1c681f7330 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt @@ -12,17 +12,17 @@ import info.nightscout.core.utils.extensions.copyString import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.interfaces.receivers.Intents import info.nightscout.plugins.general.smsCommunicator.SmsCommunicatorPlugin -import info.nightscout.plugins.source.AidexPlugin -import info.nightscout.plugins.source.DexcomPlugin -import info.nightscout.plugins.source.EversensePlugin -import info.nightscout.plugins.source.GlimpPlugin -import info.nightscout.plugins.source.MM640gPlugin -import info.nightscout.plugins.source.PoctechPlugin -import info.nightscout.plugins.source.TomatoPlugin -import info.nightscout.plugins.source.XdripPlugin import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.BundleLogger import info.nightscout.rx.logging.LTag +import info.nightscout.source.AidexPlugin +import info.nightscout.source.DexcomPlugin +import info.nightscout.source.EversensePlugin +import info.nightscout.source.GlimpPlugin +import info.nightscout.source.MM640gPlugin +import info.nightscout.source.PoctechPlugin +import info.nightscout.source.TomatoPlugin +import info.nightscout.source.XdripPlugin import javax.inject.Inject open class DataReceiver : DaggerBroadcastReceiver() { diff --git a/app/src/main/java/info/nightscout/androidaps/workflow/WorkerClassesImpl.kt b/app/src/main/java/info/nightscout/androidaps/workflow/WorkerClassesImpl.kt index b92c6549d0..80a696e6ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/workflow/WorkerClassesImpl.kt +++ b/app/src/main/java/info/nightscout/androidaps/workflow/WorkerClassesImpl.kt @@ -3,7 +3,7 @@ package info.nightscout.androidaps.workflow import info.nightscout.interfaces.workflow.WorkerClasses import info.nightscout.plugins.general.food.FoodPlugin import info.nightscout.plugins.profile.ProfilePlugin -import info.nightscout.plugins.source.NSClientSourcePlugin +import info.nightscout.source.NSClientSourcePlugin import javax.inject.Inject class WorkerClassesImpl @Inject constructor(): WorkerClasses{ diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 848cf738a2..2a64a243cb 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -37,14 +37,14 @@ import info.nightscout.plugins.constraints.ConstraintsImpl import info.nightscout.plugins.constraints.objectives.ObjectivesPlugin import info.nightscout.plugins.constraints.objectives.objectives.Objective import info.nightscout.plugins.constraints.safety.SafetyPlugin -import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin -import info.nightscout.plugins.source.GlimpPlugin import info.nightscout.pump.combo.ComboPlugin import info.nightscout.pump.combo.ruffyscripter.RuffyScripter import info.nightscout.pump.dana.DanaPump import info.nightscout.pump.dana.R import info.nightscout.pump.dana.database.DanaHistoryDatabase +import info.nightscout.pump.virtual.VirtualPumpPlugin import info.nightscout.shared.sharedPreferences.SP +import info.nightscout.source.GlimpPlugin import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt index 9fb9023c32..457d495db7 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/aps/loop/LoopPluginTest.kt @@ -21,7 +21,7 @@ import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.interfaces.ui.UiInteraction import info.nightscout.plugins.aps.loop.LoopFragment import info.nightscout.plugins.aps.loop.LoopPlugin -import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin +import info.nightscout.pump.virtual.VirtualPumpPlugin import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt index 2f121b9197..49be77219c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/safety/SafetyPluginTest.kt @@ -19,9 +19,9 @@ import info.nightscout.interfaces.utils.HardLimits import info.nightscout.plugins.aps.openAPSAMA.OpenAPSAMAPlugin import info.nightscout.plugins.aps.openAPSSMB.OpenAPSSMBPlugin import info.nightscout.plugins.constraints.safety.SafetyPlugin -import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin -import info.nightscout.plugins.source.GlimpPlugin +import info.nightscout.pump.virtual.VirtualPumpPlugin import info.nightscout.shared.sharedPreferences.SP +import info.nightscout.source.GlimpPlugin import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/source/DexcomBoyda.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/source/DexcomBoyda.kt index e786103b4a..0b4c4cb0bc 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/source/DexcomBoyda.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/source/DexcomBoyda.kt @@ -1,3 +1,8 @@ package info.nightscout.interfaces.source -interface DexcomBoyda \ No newline at end of file +interface DexcomBoyda { + + fun isEnabled(): Boolean + fun requestPermissionIfNeeded() + fun findDexcomPackageName(): String? +} \ No newline at end of file diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/source/XDrip.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/source/XDrip.kt new file mode 100644 index 0000000000..efa60ce74f --- /dev/null +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/source/XDrip.kt @@ -0,0 +1,5 @@ +package info.nightscout.interfaces.source + +interface XDrip { + fun isEnabled(): Boolean +} \ No newline at end of file diff --git a/crowdin.yml b/crowdin.yml index 42dc0118d9..a68389e204 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -21,6 +21,8 @@ files: translation: /plugins/openhumans/src/main/res/values-%android_code%/strings.xml - source: /plugins/sensitivity/src/main/res/values/strings.xml translation: /plugins/sensitivity/src/main/res/values-%android_code%/strings.xml + - source: /plugins/source/src/main/res/values/strings.xml + translation: /plugins/source/src/main/res/values-%android_code%/strings.xml - source: /plugins/insulin/src/main/res/values/strings.xml translation: /plugins/insulin/src/main/res/values-%android_code%/strings.xml - source: /plugins/configuration/src/main/res/values/strings.xml diff --git a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt index 0df16d3d8d..aaaa6657ce 100644 --- a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt @@ -85,7 +85,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { } - val injector = HasAndroidInjector { + private val injector = HasAndroidInjector { AndroidInjector { if (it is Command) { it.aapsLogger = aapsLogger diff --git a/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt b/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt index 308804fed9..1dfe6d458d 100644 --- a/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt +++ b/plugins/constraints/src/test/java/info/nightscout/plugins/constraints/bgQualityCheck/BgQualityCheckPluginTest.kt @@ -37,7 +37,7 @@ class BgQualityCheckPluginTest : TestBase() { private lateinit var plugin: BgQualityCheckPlugin private val injector = HasAndroidInjector { AndroidInjector { } } - val now = 100000000L + private val now = 100000000L //private val autosensDataStore = AutosensDataStoreObject() @BeforeEach @@ -234,6 +234,9 @@ class BgQualityCheckPluginTest : TestBase() { class DexcomPlugin : BgSource, DexcomBoyda { override fun shouldUploadToNs(glucoseValue: GlucoseValue): Boolean = true + override fun isEnabled(): Boolean = false + override fun requestPermissionIfNeeded() {} + override fun findDexcomPackageName(): String? = null } `when`(activePlugin.activeBgSource).thenReturn(DexcomPlugin()) plugin.processBgData() diff --git a/plugins/main/src/main/AndroidManifest.xml b/plugins/main/src/main/AndroidManifest.xml index 41f19bc508..aff7ae7188 100644 --- a/plugins/main/src/main/AndroidManifest.xml +++ b/plugins/main/src/main/AndroidManifest.xml @@ -19,10 +19,6 @@ - - { - if (xdripPlugin.isEnabled()) + if (xDrip.isEnabled()) openCgmApp("com.eveningoutpost.dexdrip") - else if (dexcomPlugin.isEnabled()) { - dexcomMediator.findDexcomPackageName()?.let { + else if (dexcomBoyda.isEnabled()) { + dexcomBoyda.findDexcomPackageName()?.let { openCgmApp(it) } ?: ToastUtils.infoToast(activity, rh.gs(R.string.dexcom_app_not_installed)) @@ -411,11 +410,11 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } R.id.calibration_button -> { - if (xdripPlugin.isEnabled()) { + if (xDrip.isEnabled()) { uiInteraction.runCalibrationDialog(childFragmentManager) - } else if (dexcomPlugin.isEnabled()) { + } else if (dexcomBoyda.isEnabled()) { try { - dexcomMediator.findDexcomPackageName()?.let { + dexcomBoyda.findDexcomPackageName()?.let { startActivity( Intent("com.dexcom.cgm.activities.MeterEntryActivity") .setPackage(it) @@ -577,8 +576,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList && sp.getBoolean(R.string.key_show_insulin_button, true)).toVisibility() // **** Calibration & CGM buttons **** - val xDripIsBgSource = xdripPlugin.isEnabled() - val dexcomIsSource = dexcomPlugin.isEnabled() + val xDripIsBgSource = xDrip.isEnabled() + val dexcomIsSource = dexcomBoyda.isEnabled() binding.buttonsLayout.calibrationButton.visibility = (xDripIsBgSource && actualBG != null && sp.getBoolean(R.string.key_show_calibration_button, true)).toVisibility() if (dexcomIsSource) { binding.buttonsLayout.cgmButton.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_byoda), null, null) diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index 0e61329d58..ca6256df31 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -344,48 +344,6 @@ Graph scale Graph - - dexcom_lognssensorchange - last_processed_glunovo_timestamp - last_processed_intelligo_timestamp - - NSClient BG - NS BG - Downloads BG data from Nightscout - xDrip+ - Receive BG values from xDrip+. - BYODA - BYODA - Receive BG values from the \'Build Your Own Dexcom App\'. - Eversense App (patched) - EVR - Receive BG values from the patched Eversense app. - Glimp - Receive BG values from Glimp. - MM640g - Receive BG values from the 600SeriesAndroidUploader. - Poctech - Receive BG values from Poctech app - Glunovo - Receive values from Glunovo app - Intelligo - Receive values from Intelligo app - Tomato (MiaoMiao) - Tomato - Receive BG values from Tomato app (MiaoMiao device) - GlucoRx Aidex - Aidex - Receive BG values from GlucoRx Aidex CGMS. - Random BG - Generate random BG data (Demo mode only) - BG - - Send BG data to xDrip+ - In xDrip+ select 640g/Eversense data source - BG upload settings - Log sensor change to NS - Create event \"Sensor Change\" in NS automatically on sensor start - skin diff --git a/plugins/source/.gitignore b/plugins/source/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/plugins/source/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/plugins/source/build.gradle b/plugins/source/build.gradle new file mode 100644 index 0000000000..5cbae0f81f --- /dev/null +++ b/plugins/source/build.gradle @@ -0,0 +1,28 @@ +plugins { + id 'com.android.library' + id 'kotlin-android' + id 'kotlin-kapt' + id 'kotlin-allopen' + id 'com.hiya.jacoco-android' +} + +apply from: "${project.rootDir}/core/main/android_dependencies.gradle" +apply from: "${project.rootDir}/core/main/android_module_dependencies.gradle" +apply from: "${project.rootDir}/core/main/allopen_dependencies.gradle" +apply from: "${project.rootDir}/core/main/test_dependencies.gradle" +apply from: "${project.rootDir}/core/main/jacoco_global.gradle" +android { + namespace 'info.nightscout.source' +} + + +dependencies { + implementation project(':app-wear-shared:shared') + implementation project(':database:entities') + implementation project(':database:impl') + implementation project(':core:interfaces') + implementation project(':core:main') + implementation project(':core:ns-sdk') + implementation project(':core:ui') + implementation project(':core:utils') +} \ No newline at end of file diff --git a/plugins/source/consumer-rules.pro b/plugins/source/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/source/proguard-rules.pro b/plugins/source/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/plugins/source/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 \ No newline at end of file diff --git a/plugins/source/src/main/AndroidManifest.xml b/plugins/source/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..8ab266755d --- /dev/null +++ b/plugins/source/src/main/AndroidManifest.xml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/AidexPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/AidexPlugin.kt similarity index 98% rename from plugins/main/src/main/java/info/nightscout/plugins/source/AidexPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/AidexPlugin.kt index 4a1a6f5aab..837b0ee908 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/AidexPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/AidexPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -17,7 +17,6 @@ import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.receivers.Intents import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/BGSourceFragment.kt b/plugins/source/src/main/java/info/nightscout/source/BGSourceFragment.kt similarity index 98% rename from plugins/main/src/main/java/info/nightscout/plugins/source/BGSourceFragment.kt rename to plugins/source/src/main/java/info/nightscout/source/BGSourceFragment.kt index 048bc4317c..29808634f9 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/BGSourceFragment.kt +++ b/plugins/source/src/main/java/info/nightscout/source/BGSourceFragment.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.os.Bundle import android.util.SparseArray @@ -29,9 +29,6 @@ import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.plugins.R -import info.nightscout.plugins.databinding.SourceFragmentBinding -import info.nightscout.plugins.databinding.SourceItemBinding import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventNewBG @@ -41,6 +38,8 @@ import info.nightscout.shared.extensions.toVisibility import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.T +import info.nightscout.source.databinding.SourceFragmentBinding +import info.nightscout.source.databinding.SourceItemBinding import io.reactivex.rxjava3.disposables.CompositeDisposable import io.reactivex.rxjava3.kotlin.plusAssign import java.util.concurrent.TimeUnit diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/DexcomPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/DexcomPlugin.kt similarity index 92% rename from plugins/main/src/main/java/info/nightscout/plugins/source/DexcomPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/DexcomPlugin.kt index 1217e047d5..c3471ccee7 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/DexcomPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/DexcomPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import android.content.Intent @@ -28,8 +28,6 @@ import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.source.BgSource import info.nightscout.interfaces.source.DexcomBoyda -import info.nightscout.plugins.R -import info.nightscout.plugins.source.activities.RequestDexcomPermissionActivity import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.extensions.safeGetInstalledPackages @@ -37,6 +35,7 @@ import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil import info.nightscout.shared.utils.T +import info.nightscout.source.activities.RequestDexcomPermissionActivity import javax.inject.Inject import javax.inject.Singleton import kotlin.math.abs @@ -47,7 +46,7 @@ class DexcomPlugin @Inject constructor( rh: ResourceHelper, aapsLogger: AAPSLogger, private val sp: SP, - private val dexcomMediator: DexcomMediator, + private val context: Context, config: Config ) : PluginBase( PluginDescription() @@ -77,7 +76,7 @@ class DexcomPlugin @Inject constructor( override fun onStart() { super.onStart() - dexcomMediator.requestPermissionIfNeeded() + requestPermissionIfNeeded() } // cannot be inner class because of needed injection @@ -222,6 +221,22 @@ class DexcomPlugin @Inject constructor( } } + override fun requestPermissionIfNeeded() { + if (ContextCompat.checkSelfPermission(context, PERMISSION) != PackageManager.PERMISSION_GRANTED) { + val intent = Intent(context, RequestDexcomPermissionActivity::class.java) + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + context.startActivity(intent) + } + } + + override fun findDexcomPackageName(): String? { + val packageManager = context.packageManager + for (packageInfo in packageManager.safeGetInstalledPackages(0)) { + if (PACKAGE_NAMES.contains(packageInfo.packageName)) return packageInfo.packageName + } + return null + } + companion object { private val PACKAGE_NAMES = arrayOf( @@ -232,23 +247,4 @@ class DexcomPlugin @Inject constructor( ) const val PERMISSION = "com.dexcom.cgm.EXTERNAL_PERMISSION" } - - class DexcomMediator @Inject constructor(val context: Context) { - - fun requestPermissionIfNeeded() { - if (ContextCompat.checkSelfPermission(context, PERMISSION) != PackageManager.PERMISSION_GRANTED) { - val intent = Intent(context, RequestDexcomPermissionActivity::class.java) - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - context.startActivity(intent) - } - } - - fun findDexcomPackageName(): String? { - val packageManager = context.packageManager - for (packageInfo in packageManager.safeGetInstalledPackages(0)) { - if (PACKAGE_NAMES.contains(packageInfo.packageName)) return packageInfo.packageName - } - return null - } - } } diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/EversensePlugin.kt b/plugins/source/src/main/java/info/nightscout/source/EversensePlugin.kt similarity index 99% rename from plugins/main/src/main/java/info/nightscout/plugins/source/EversensePlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/EversensePlugin.kt index ea965806fa..1d6167d0ae 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/EversensePlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/EversensePlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -17,7 +17,6 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/GlimpPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/GlimpPlugin.kt similarity index 98% rename from plugins/main/src/main/java/info/nightscout/plugins/source/GlimpPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/GlimpPlugin.kt index d529078a33..65292352f7 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/GlimpPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/GlimpPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -15,7 +15,6 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/GlunovoPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/GlunovoPlugin.kt similarity index 99% rename from plugins/main/src/main/java/info/nightscout/plugins/source/GlunovoPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/GlunovoPlugin.kt index cb283f732f..367ac7580e 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/GlunovoPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/GlunovoPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import android.net.Uri @@ -20,7 +20,6 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/IntelligoPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/IntelligoPlugin.kt similarity index 99% rename from plugins/main/src/main/java/info/nightscout/plugins/source/IntelligoPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/IntelligoPlugin.kt index e17b655aa0..25b4511871 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/IntelligoPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/IntelligoPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import android.content.pm.PackageManager @@ -22,7 +22,6 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.extensions.safeGetInstalledPackages diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/MM640gPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/MM640gPlugin.kt similarity index 98% rename from plugins/main/src/main/java/info/nightscout/plugins/source/MM640gPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/MM640gPlugin.kt index 027e6bdc67..6b7dc0d46a 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/MM640gPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/MM640gPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -15,7 +15,6 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/NSClientSourcePlugin.kt b/plugins/source/src/main/java/info/nightscout/source/NSClientSourcePlugin.kt similarity index 99% rename from plugins/main/src/main/java/info/nightscout/plugins/source/NSClientSourcePlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/NSClientSourcePlugin.kt index 0f2edb1158..7e8f9309f0 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/NSClientSourcePlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/NSClientSourcePlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -21,7 +21,6 @@ import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource import info.nightscout.interfaces.source.DoingOwnUploadSource import info.nightscout.interfaces.source.NSClientSource -import info.nightscout.plugins.R import info.nightscout.rx.bus.RxBus import info.nightscout.rx.events.EventDismissNotification import info.nightscout.rx.logging.AAPSLogger diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/PoctechPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/PoctechPlugin.kt similarity index 98% rename from plugins/main/src/main/java/info/nightscout/plugins/source/PoctechPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/PoctechPlugin.kt index 7e9de5b405..3bd3712103 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/PoctechPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/PoctechPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -16,7 +16,6 @@ import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource import info.nightscout.interfaces.utils.JsonHelper.safeGetString -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/RandomBgPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/RandomBgPlugin.kt similarity index 98% rename from plugins/main/src/main/java/info/nightscout/plugins/source/RandomBgPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/RandomBgPlugin.kt index c11fbbfe47..2aeaf1b002 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/RandomBgPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/RandomBgPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.os.Handler import android.os.HandlerThread @@ -16,7 +16,6 @@ import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.pump.VirtualPump import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/TomatoPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/TomatoPlugin.kt similarity index 98% rename from plugins/main/src/main/java/info/nightscout/plugins/source/TomatoPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/TomatoPlugin.kt index 93afb3bf50..07d56fc0f5 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/TomatoPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/TomatoPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -14,7 +14,6 @@ import info.nightscout.interfaces.plugin.PluginBase import info.nightscout.interfaces.plugin.PluginDescription import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.source.BgSource -import info.nightscout.plugins.R import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/XdripPlugin.kt b/plugins/source/src/main/java/info/nightscout/source/XdripPlugin.kt similarity index 97% rename from plugins/main/src/main/java/info/nightscout/plugins/source/XdripPlugin.kt rename to plugins/source/src/main/java/info/nightscout/source/XdripPlugin.kt index a6b8d715dd..9d2ea18dd7 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/XdripPlugin.kt +++ b/plugins/source/src/main/java/info/nightscout/source/XdripPlugin.kt @@ -1,4 +1,4 @@ -package info.nightscout.plugins.source +package info.nightscout.source import android.content.Context import androidx.work.WorkerParameters @@ -16,7 +16,7 @@ import info.nightscout.interfaces.plugin.PluginType import info.nightscout.interfaces.receivers.Intents import info.nightscout.interfaces.source.BgSource import info.nightscout.interfaces.source.DoingOwnUploadSource -import info.nightscout.plugins.R +import info.nightscout.interfaces.source.XDrip import info.nightscout.rx.logging.AAPSLogger import info.nightscout.rx.logging.LTag import info.nightscout.shared.interfaces.ResourceHelper @@ -36,7 +36,7 @@ class XdripPlugin @Inject constructor( .pluginName(R.string.xdrip) .description(R.string.description_source_xdrip), aapsLogger, rh, injector -), BgSource, DoingOwnUploadSource { +), BgSource, DoingOwnUploadSource, XDrip { private var advancedFiltering = false override var sensorBatteryLevel = -1 diff --git a/plugins/main/src/main/java/info/nightscout/plugins/source/activities/RequestDexcomPermissionActivity.kt b/plugins/source/src/main/java/info/nightscout/source/activities/RequestDexcomPermissionActivity.kt similarity index 86% rename from plugins/main/src/main/java/info/nightscout/plugins/source/activities/RequestDexcomPermissionActivity.kt rename to plugins/source/src/main/java/info/nightscout/source/activities/RequestDexcomPermissionActivity.kt index 97d2ecba8c..142601e644 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/source/activities/RequestDexcomPermissionActivity.kt +++ b/plugins/source/src/main/java/info/nightscout/source/activities/RequestDexcomPermissionActivity.kt @@ -1,8 +1,8 @@ -package info.nightscout.plugins.source.activities +package info.nightscout.source.activities import android.os.Bundle import info.nightscout.core.ui.activities.DialogAppCompatActivity -import info.nightscout.plugins.source.DexcomPlugin +import info.nightscout.source.DexcomPlugin class RequestDexcomPermissionActivity : DialogAppCompatActivity() { diff --git a/plugins/main/src/main/java/info/nightscout/plugins/di/SourceModule.kt b/plugins/source/src/main/java/info/nightscout/source/di/SourceModule.kt similarity index 65% rename from plugins/main/src/main/java/info/nightscout/plugins/di/SourceModule.kt rename to plugins/source/src/main/java/info/nightscout/source/di/SourceModule.kt index cc2fcb366a..2aec6c6d5a 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/di/SourceModule.kt +++ b/plugins/source/src/main/java/info/nightscout/source/di/SourceModule.kt @@ -1,21 +1,22 @@ -package info.nightscout.plugins.di +package info.nightscout.source.di import dagger.Binds import dagger.Module import dagger.android.ContributesAndroidInjector +import info.nightscout.interfaces.source.DexcomBoyda import info.nightscout.interfaces.source.NSClientSource -import info.nightscout.plugins.profile.ProfilePlugin -import info.nightscout.plugins.source.AidexPlugin -import info.nightscout.plugins.source.BGSourceFragment -import info.nightscout.plugins.source.DexcomPlugin -import info.nightscout.plugins.source.EversensePlugin -import info.nightscout.plugins.source.GlimpPlugin -import info.nightscout.plugins.source.MM640gPlugin -import info.nightscout.plugins.source.NSClientSourcePlugin -import info.nightscout.plugins.source.PoctechPlugin -import info.nightscout.plugins.source.TomatoPlugin -import info.nightscout.plugins.source.XdripPlugin -import info.nightscout.plugins.source.activities.RequestDexcomPermissionActivity +import info.nightscout.interfaces.source.XDrip +import info.nightscout.source.AidexPlugin +import info.nightscout.source.BGSourceFragment +import info.nightscout.source.DexcomPlugin +import info.nightscout.source.EversensePlugin +import info.nightscout.source.GlimpPlugin +import info.nightscout.source.MM640gPlugin +import info.nightscout.source.NSClientSourcePlugin +import info.nightscout.source.PoctechPlugin +import info.nightscout.source.TomatoPlugin +import info.nightscout.source.XdripPlugin +import info.nightscout.source.activities.RequestDexcomPermissionActivity @Module( includes = [ @@ -28,7 +29,6 @@ abstract class SourceModule { @ContributesAndroidInjector abstract fun contributesBGSourceFragment(): BGSourceFragment - @ContributesAndroidInjector abstract fun contributesNSProfileWorker(): ProfilePlugin.NSProfileWorker @ContributesAndroidInjector abstract fun contributesNSClientSourceWorker(): NSClientSourcePlugin.NSClientSourceWorker @ContributesAndroidInjector abstract fun contributesXdripWorker(): XdripPlugin.XdripWorker @ContributesAndroidInjector abstract fun contributesDexcomWorker(): DexcomPlugin.DexcomWorker @@ -43,6 +43,9 @@ abstract class SourceModule { @Module interface Bindings { + @Binds fun bindNSClientSource(nsClientSourcePlugin: NSClientSourcePlugin): NSClientSource + @Binds fun bindDexcomBoyda(dexcomPlugin: DexcomPlugin): DexcomBoyda + @Binds fun bindXDrip(xdripPlugin: XdripPlugin): XDrip } } \ No newline at end of file diff --git a/plugins/main/src/main/res/drawable/ic_dice.xml b/plugins/source/src/main/res/drawable/ic_dice.xml similarity index 100% rename from plugins/main/src/main/res/drawable/ic_dice.xml rename to plugins/source/src/main/res/drawable/ic_dice.xml diff --git a/plugins/main/src/main/res/layout/source_fragment.xml b/plugins/source/src/main/res/layout/source_fragment.xml similarity index 91% rename from plugins/main/src/main/res/layout/source_fragment.xml rename to plugins/source/src/main/res/layout/source_fragment.xml index f56d3e838c..e31cab2e0a 100644 --- a/plugins/main/src/main/res/layout/source_fragment.xml +++ b/plugins/source/src/main/res/layout/source_fragment.xml @@ -4,7 +4,7 @@ android:layout_height="match_parent" android:orientation="vertical" android:paddingTop="2dp" - tools:context=".source.BGSourceFragment"> + tools:context=".BGSourceFragment"> + app:srcCompat="@drawable/ic_flat" + android:contentDescription="@string/direction" /> + + + dexcom_lognssensorchange + last_processed_glunovo_timestamp + last_processed_intelligo_timestamp + + NSClient BG + NS BG + Downloads BG data from Nightscout + xDrip+ + Receive BG values from xDrip+. + BYODA + BYODA + Receive BG values from the \'Build Your Own Dexcom App\'. + Eversense App (patched) + EVR + Receive BG values from the patched Eversense app. + Glimp + Receive BG values from Glimp. + MM640g + Receive BG values from the 600SeriesAndroidUploader. + Poctech + Receive BG values from Poctech app + Glunovo + Receive values from Glunovo app + Intelligo + Receive values from Intelligo app + Tomato (MiaoMiao) + Tomato + Receive BG values from Tomato app (MiaoMiao device) + GlucoRx Aidex + Aidex + Receive BG values from GlucoRx Aidex CGMS. + Random BG + Generate random BG data (Demo mode only) + BG + + Send BG data to xDrip+ + In xDrip+ select 640g/Eversense data source + BG upload settings + Log sensor change to NS + Create event \"Sensor Change\" in NS automatically on sensor start + direction + + + \ No newline at end of file diff --git a/plugins/main/src/main/res/xml/pref_bgsource.xml b/plugins/source/src/main/res/xml/pref_bgsource.xml similarity index 100% rename from plugins/main/src/main/res/xml/pref_bgsource.xml rename to plugins/source/src/main/res/xml/pref_bgsource.xml diff --git a/plugins/main/src/main/res/xml/pref_dexcom.xml b/plugins/source/src/main/res/xml/pref_dexcom.xml similarity index 100% rename from plugins/main/src/main/res/xml/pref_dexcom.xml rename to plugins/source/src/main/res/xml/pref_dexcom.xml diff --git a/plugins/source/src/test/java/info/nightscout/androidaps/TestBase.kt b/plugins/source/src/test/java/info/nightscout/androidaps/TestBase.kt new file mode 100644 index 0000000000..4fd2aef548 --- /dev/null +++ b/plugins/source/src/test/java/info/nightscout/androidaps/TestBase.kt @@ -0,0 +1,37 @@ +package info.nightscout.androidaps + +import info.nightscout.rx.AapsSchedulers +import info.nightscout.rx.TestAapsSchedulers +import info.nightscout.rx.logging.AAPSLoggerTest +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.extension.ExtendWith +import org.mockito.Mockito +import org.mockito.junit.jupiter.MockitoExtension +import org.mockito.junit.jupiter.MockitoSettings +import org.mockito.quality.Strictness +import java.util.Locale + +@ExtendWith(MockitoExtension::class) +@MockitoSettings(strictness = Strictness.LENIENT) +open class TestBase { + + val aapsLogger = AAPSLoggerTest() + val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() + + @BeforeEach + fun setupLocale() { + Locale.setDefault(Locale.ENGLISH) + System.setProperty("disableFirebase", "true") + } + + // Workaround for Kotlin nullability. + // https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791 + // https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin + fun anyObject(): T { + Mockito.any() + return uninitialized() + } + + @Suppress("Unchecked_Cast") + fun uninitialized(): T = null as T +} \ No newline at end of file diff --git a/plugins/main/src/test/java/info/nightscout/plugins/source/GlimpPluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/GlimpPluginTest.kt similarity index 61% rename from plugins/main/src/test/java/info/nightscout/plugins/source/GlimpPluginTest.kt rename to plugins/source/src/test/java/info/nightscout/source/GlimpPluginTest.kt index 517ef7fed1..be6fc799ba 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/source/GlimpPluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/GlimpPluginTest.kt @@ -1,12 +1,10 @@ -package info.nightscout.androidaps.plugins.source +package info.nightscout.source import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.plugins.source.GlimpPlugin import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP -import org.junit.Assert +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -20,10 +18,10 @@ class GlimpPluginTest : TestBase() { @BeforeEach fun setup() { - glimpPlugin = GlimpPlugin(HasAndroidInjector { AndroidInjector { } }, rh, aapsLogger, sp) + glimpPlugin = GlimpPlugin({ AndroidInjector { } }, rh, aapsLogger, sp) } @Test fun advancedFilteringSupported() { - Assert.assertEquals(false, glimpPlugin.advancedFilteringSupported()) + Assertions.assertEquals(false, glimpPlugin.advancedFilteringSupported()) } } \ No newline at end of file diff --git a/plugins/main/src/test/java/info/nightscout/plugins/source/MM640GPluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/MM640GPluginTest.kt similarity index 61% rename from plugins/main/src/test/java/info/nightscout/plugins/source/MM640GPluginTest.kt rename to plugins/source/src/test/java/info/nightscout/source/MM640GPluginTest.kt index 5ef860f425..4d71051ef7 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/source/MM640GPluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/MM640GPluginTest.kt @@ -1,12 +1,10 @@ -package info.nightscout.androidaps.plugins.source +package info.nightscout.source import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.plugins.source.MM640gPlugin import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP -import org.junit.Assert +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -20,10 +18,10 @@ class MM640GPluginTest : TestBase() { @BeforeEach fun setup() { - mM640gPlugin = MM640gPlugin(HasAndroidInjector { AndroidInjector { } }, rh, aapsLogger, sp) + mM640gPlugin = MM640gPlugin({ AndroidInjector { } }, rh, aapsLogger, sp) } @Test fun advancedFilteringSupported() { - Assert.assertEquals(false, mM640gPlugin.advancedFilteringSupported()) + Assertions.assertEquals(false, mM640gPlugin.advancedFilteringSupported()) } } \ No newline at end of file diff --git a/plugins/main/src/test/java/info/nightscout/plugins/source/NSClientPluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/NSClientPluginTest.kt similarity index 51% rename from plugins/main/src/test/java/info/nightscout/plugins/source/NSClientPluginTest.kt rename to plugins/source/src/test/java/info/nightscout/source/NSClientPluginTest.kt index 6e74ff7be3..636520b90d 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/source/NSClientPluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/NSClientPluginTest.kt @@ -1,29 +1,27 @@ -package info.nightscout.androidaps.plugins.source +package info.nightscout.source import dagger.android.AndroidInjector import info.nightscout.androidaps.TestBase import info.nightscout.interfaces.Config import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.shared.sharedPreferences.SP -import org.junit.Assert +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock class NSClientPluginTest : TestBase() { - private lateinit var nsClientSourcePlugin: info.nightscout.plugins.source.NSClientSourcePlugin + private lateinit var nsClientSourcePlugin: NSClientSourcePlugin @Mock lateinit var rh: ResourceHelper - @Mock lateinit var sp: SP @Mock lateinit var config: Config @BeforeEach fun setup() { - nsClientSourcePlugin = info.nightscout.plugins.source.NSClientSourcePlugin({ AndroidInjector { } }, rh, aapsLogger, config) + nsClientSourcePlugin = NSClientSourcePlugin({ AndroidInjector { } }, rh, aapsLogger, config) } @Test fun advancedFilteringSupported() { - Assert.assertEquals(false, nsClientSourcePlugin.advancedFilteringSupported()) + Assertions.assertEquals(false, nsClientSourcePlugin.advancedFilteringSupported()) } } \ No newline at end of file diff --git a/plugins/main/src/test/java/info/nightscout/plugins/source/XdripPluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/XdripPluginTest.kt similarity index 57% rename from plugins/main/src/test/java/info/nightscout/plugins/source/XdripPluginTest.kt rename to plugins/source/src/test/java/info/nightscout/source/XdripPluginTest.kt index 49ac33fc0f..2524a18db6 100644 --- a/plugins/main/src/test/java/info/nightscout/plugins/source/XdripPluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/XdripPluginTest.kt @@ -1,11 +1,9 @@ -package info.nightscout.androidaps.plugins.source +package info.nightscout.source import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.plugins.source.XdripPlugin import info.nightscout.shared.interfaces.ResourceHelper -import org.junit.Assert +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock @@ -18,10 +16,10 @@ class XdripPluginTest : TestBase() { @BeforeEach fun setup() { - xdripPlugin = XdripPlugin(HasAndroidInjector { AndroidInjector { } }, rh, aapsLogger) + xdripPlugin = XdripPlugin({ AndroidInjector { } }, rh, aapsLogger) } @Test fun advancedFilteringSupported() { - Assert.assertEquals(false, xdripPlugin.advancedFilteringSupported()) + Assertions.assertEquals(false, xdripPlugin.advancedFilteringSupported()) } } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index dae8b065c8..994e5fa516 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,6 +22,7 @@ include ':plugins:insulin' include ':plugins:main' include ':plugins:openhumans' include ':plugins:sensitivity' +include ':plugins:source' include ':plugins:constraints' include ':pump:combo' include ':pump:combov2'