From 9dc85d4e14227117206163af00193618a67ee09a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 1 Jun 2022 08:02:50 +0200 Subject: [PATCH 1/7] Gradle: enable build cache --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index 489d41472f..9e4747695e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,3 +21,4 @@ org.gradle.jvmargs=-Xmx2g android.enableJetifier=true android.useAndroidX=true +org.gradle.unsafe.configuration-cache=true From 06feba5fe9705a58851dda5d74e79bcb523e3f81 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 4 Jun 2022 21:34:52 +0200 Subject: [PATCH 2/7] Fix Autotune UserEntry with Automation --- .../androidaps/plugins/general/autotune/AutotunePlugin.kt | 7 ++++--- .../general/automation/actions/ActionRunAutotune.kt | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt index 9a7839f600..320a0d212b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotunePlugin.kt @@ -161,7 +161,8 @@ class AutotunePlugin @Inject constructor( updateProfile(tunedP) uel.log( UserEntry.Action.STORE_PROFILE, - UserEntry.Sources.Autotune, + UserEntry.Sources.Automation, + rh.gs(R.string.autotune), ValueWithUnit.SimpleString(tunedP.profilename) ) updateButtonVisibility = View.GONE @@ -178,8 +179,8 @@ class AutotunePlugin @Inject constructor( log("Profile Switch succeed ${tunedP.profilename}") uel.log( UserEntry.Action.PROFILE_SWITCH, - UserEntry.Sources.Autotune, - "Autotune AutoSwitch", + UserEntry.Sources.Automation, + rh.gs(R.string.autotune), ValueWithUnit.SimpleString(tunedP.profilename)) } rxBus.send(EventLocalProfileChanged()) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionRunAutotune.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionRunAutotune.kt index 27b26108f0..c2687fffed 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionRunAutotune.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionRunAutotune.kt @@ -28,7 +28,6 @@ class ActionRunAutotune(injector: HasAndroidInjector) : Action(injector) { @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var activePlugin: ActivePlugin @Inject lateinit var sp: SP - @Inject lateinit var uel: UserEntryLogger var defaultValue = 0 private var inputProfileName = InputProfileName(rh, activePlugin, "", true) From d9916c3d50b15397dd0f96ecc91a8950c4d4c54d Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 4 Jun 2022 21:45:38 +0200 Subject: [PATCH 3/7] Hide Autotune detailed log setting --- .../androidaps/plugins/general/autotune/AutotuneFragment.kt | 1 + app/src/main/res/xml/pref_autotune.xml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneFragment.kt index b968c7fc88..a3c6fa80c5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/autotune/AutotuneFragment.kt @@ -79,6 +79,7 @@ class AutotuneFragment : DaggerFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) sp.putBoolean(R.string.key_autotune_tune_insulin_curve, false) // put to false tune insulin curve + sp.putBoolean(R.string.key_autotune_additional_log, false) // put to false additional log autotunePlugin.lastRun = sp.getLong(R.string.key_autotune_last_run, 0) if (autotunePlugin.lastNbDays.isEmpty()) autotunePlugin.lastNbDays = sp.getInt(R.string.key_autotune_default_tune_days, 5).toString() diff --git a/app/src/main/res/xml/pref_autotune.xml b/app/src/main/res/xml/pref_autotune.xml index 35abef7d12..fc5f6dbc72 100644 --- a/app/src/main/res/xml/pref_autotune.xml +++ b/app/src/main/res/xml/pref_autotune.xml @@ -36,11 +36,12 @@ android:key="@string/key_autotune_circadian_ic_isf" android:summary="@string/autotune_circadian_ic_isf_summary" android:title="@string/autotune_circadian_ic_isf_title" /> - + \ No newline at end of file From 46a56809034eaf9f5a9a40f67333cf7a17cfce32 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 6 Jun 2022 10:25:08 +0200 Subject: [PATCH 4/7] gradle update --- app/build.gradle | 2 ++ app/src/main/AndroidManifest.xml | 3 +-- automation/build.gradle | 3 +++ automation/src/main/AndroidManifest.xml | 3 +-- build.gradle | 2 +- combo/build.gradle | 3 +++ combo/src/main/AndroidManifest.xml | 3 +-- core/build.gradle | 4 ++++ core/src/main/AndroidManifest.xml | 3 +-- dana/build.gradle | 2 ++ dana/src/main/AndroidManifest.xml | 3 +-- danar/build.gradle | 3 +++ danar/src/main/AndroidManifest.xml | 3 +-- danars/build.gradle | 1 + danars/src/main/AndroidManifest.xml | 3 +-- database/build.gradle | 2 ++ database/src/main/AndroidManifest.xml | 3 +-- diaconn/build.gradle | 2 ++ diaconn/src/main/AndroidManifest.xml | 3 +-- insight/build.gradle | 2 ++ insight/src/main/AndroidManifest.xml | 3 +-- medtronic/build.gradle | 3 +++ medtronic/src/main/AndroidManifest.xml | 3 +-- omnipod-common/build.gradle | 3 +++ omnipod-common/src/main/AndroidManifest.xml | 3 +-- omnipod-dash/build.gradle | 2 ++ omnipod-dash/src/main/AndroidManifest.xml | 3 +-- omnipod-eros/build.gradle | 2 ++ omnipod-eros/src/main/AndroidManifest.xml | 3 +-- openhumans/build.gradle | 3 +++ openhumans/src/main/AndroidManifest.xml | 3 +-- pump-common/build.gradle | 3 +++ pump-common/src/main/AndroidManifest.xml | 2 +- rileylink/build.gradle | 3 +++ rileylink/src/main/AndroidManifest.xml | 3 +-- shared/build.gradle | 2 ++ shared/src/main/AndroidManifest.xml | 3 +-- wear/build.gradle | 1 + wear/src/main/AndroidManifest.xml | 3 +-- 39 files changed, 66 insertions(+), 38 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f125a9e74c..c37650c720 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -104,6 +104,8 @@ tasks.matching { it instanceof Test }.all { } android { + + namespace 'info.nightscout.androidaps' ndkVersion "21.1.6352462" defaultConfig { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index aaa245f3bf..8cb2f771fb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> diff --git a/automation/build.gradle b/automation/build.gradle index 79564845d5..e1107c676f 100644 --- a/automation/build.gradle +++ b/automation/build.gradle @@ -8,6 +8,9 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" +android { + namespace 'info.nightscout.androidaps.automation' +} dependencies { diff --git a/automation/src/main/AndroidManifest.xml b/automation/src/main/AndroidManifest.xml index 3396187ca4..94da5bcfde 100644 --- a/automation/src/main/AndroidManifest.xml +++ b/automation/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/build.gradle b/build.gradle index 46c6aa6926..e33b5b9e46 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } // jacoco 0.2 } dependencies { - classpath 'com.android.tools.build:gradle:7.2.1' + classpath 'com.android.tools.build:gradle:7.2.0' classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0' diff --git a/combo/build.gradle b/combo/build.gradle index 7605e4667d..a3faa431e6 100644 --- a/combo/build.gradle +++ b/combo/build.gradle @@ -8,6 +8,9 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" +android { + namespace 'info.nightscout.androidaps.combo' +} dependencies { implementation project(':core') diff --git a/combo/src/main/AndroidManifest.xml b/combo/src/main/AndroidManifest.xml index a5aa9f0e8e..11b940a009 100644 --- a/combo/src/main/AndroidManifest.xml +++ b/combo/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/core/build.gradle b/core/build.gradle index b3fef255db..f1b51650c2 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -15,3 +15,7 @@ dependencies { implementation project(':shared') implementation project(':database') } + +android { + namespace 'info.nightscout.androidaps.core' +} diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 9f170d4340..6cd58651e5 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/dana/build.gradle b/dana/build.gradle index 64bc021517..f03521d269 100644 --- a/dana/build.gradle +++ b/dana/build.gradle @@ -10,6 +10,8 @@ apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" android { + + namespace 'info.nightscout.androidaps.dana' defaultConfig { kapt { arguments { diff --git a/dana/src/main/AndroidManifest.xml b/dana/src/main/AndroidManifest.xml index dda39a96f5..af4b1f4b1e 100644 --- a/dana/src/main/AndroidManifest.xml +++ b/dana/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/danar/build.gradle b/danar/build.gradle index 6a273260c5..7fe1ba8c55 100644 --- a/danar/build.gradle +++ b/danar/build.gradle @@ -8,6 +8,9 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" +android { + namespace 'info.nightscout.androidaps.danar' +} dependencies { implementation project(':core') diff --git a/danar/src/main/AndroidManifest.xml b/danar/src/main/AndroidManifest.xml index afa0e2ef98..df2a5d9b43 100644 --- a/danar/src/main/AndroidManifest.xml +++ b/danar/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/danars/build.gradle b/danars/build.gradle index 96b60d2931..2f0b2a46a4 100644 --- a/danars/build.gradle +++ b/danars/build.gradle @@ -11,6 +11,7 @@ apply from: "${project.rootDir}/core/jacoco_global.gradle" android { ndkVersion "21.1.6352462" + namespace 'info.nightscout.androidaps.danars' defaultConfig { diff --git a/danars/src/main/AndroidManifest.xml b/danars/src/main/AndroidManifest.xml index 9588230a7d..c0a4377e25 100644 --- a/danars/src/main/AndroidManifest.xml +++ b/danars/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/database/build.gradle b/database/build.gradle index b990da9e89..d67b86c464 100644 --- a/database/build.gradle +++ b/database/build.gradle @@ -7,6 +7,8 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" android { + + namespace 'info.nightscout.androidaps.database' defaultConfig { kapt { arguments { diff --git a/database/src/main/AndroidManifest.xml b/database/src/main/AndroidManifest.xml index fa796cae8a..94cbbcfc39 100644 --- a/database/src/main/AndroidManifest.xml +++ b/database/src/main/AndroidManifest.xml @@ -1,2 +1 @@ - + diff --git a/diaconn/build.gradle b/diaconn/build.gradle index 64bc021517..84034c07ae 100644 --- a/diaconn/build.gradle +++ b/diaconn/build.gradle @@ -10,6 +10,8 @@ apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" android { + + namespace 'info.nightscout.androidaps.diaconn' defaultConfig { kapt { arguments { diff --git a/diaconn/src/main/AndroidManifest.xml b/diaconn/src/main/AndroidManifest.xml index 290eecf25f..b4487ffda6 100644 --- a/diaconn/src/main/AndroidManifest.xml +++ b/diaconn/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/insight/build.gradle b/insight/build.gradle index 64bc021517..623c52532a 100644 --- a/insight/build.gradle +++ b/insight/build.gradle @@ -10,6 +10,8 @@ apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" android { + + namespace 'info.nightscout.androidaps.insight' defaultConfig { kapt { arguments { diff --git a/insight/src/main/AndroidManifest.xml b/insight/src/main/AndroidManifest.xml index 7e05839276..d8d973e0b3 100644 --- a/insight/src/main/AndroidManifest.xml +++ b/insight/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/medtronic/build.gradle b/medtronic/build.gradle index 7b00d238c8..89b2f37c51 100644 --- a/medtronic/build.gradle +++ b/medtronic/build.gradle @@ -8,6 +8,9 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" +android { + namespace 'info.nightscout.androidaps.plugins.pump.medtronic' +} dependencies { implementation project(':core') diff --git a/medtronic/src/main/AndroidManifest.xml b/medtronic/src/main/AndroidManifest.xml index 9738faa19c..6c2ac78309 100644 --- a/medtronic/src/main/AndroidManifest.xml +++ b/medtronic/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/omnipod-common/build.gradle b/omnipod-common/build.gradle index 5a2e5bfac4..3d4aab407b 100644 --- a/omnipod-common/build.gradle +++ b/omnipod-common/build.gradle @@ -9,6 +9,9 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" +android { + namespace 'info.nightscout.androidaps.plugins.pump.omnipod.common' +} dependencies { implementation project(':core') diff --git a/omnipod-common/src/main/AndroidManifest.xml b/omnipod-common/src/main/AndroidManifest.xml index 5f59d2c48f..9d6e11f691 100644 --- a/omnipod-common/src/main/AndroidManifest.xml +++ b/omnipod-common/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/omnipod-dash/build.gradle b/omnipod-dash/build.gradle index c6c5734f70..631dec2207 100644 --- a/omnipod-dash/build.gradle +++ b/omnipod-dash/build.gradle @@ -17,6 +17,8 @@ detekt { // TODO move to `subprojects` section in global build.gradle } android { + + namespace 'info.nightscout.androidaps.plugins.pump.omnipod.dash' defaultConfig { kapt { arguments { diff --git a/omnipod-dash/src/main/AndroidManifest.xml b/omnipod-dash/src/main/AndroidManifest.xml index 68a2f71c0b..ee32e26eea 100644 --- a/omnipod-dash/src/main/AndroidManifest.xml +++ b/omnipod-dash/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + diff --git a/omnipod-eros/build.gradle b/omnipod-eros/build.gradle index 9bc119cef9..a748715b9d 100644 --- a/omnipod-eros/build.gradle +++ b/omnipod-eros/build.gradle @@ -10,6 +10,8 @@ apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" android { + + namespace 'info.nightscout.androidaps.plugins.pump.omnipod.eros' defaultConfig { kapt { arguments { diff --git a/omnipod-eros/src/main/AndroidManifest.xml b/omnipod-eros/src/main/AndroidManifest.xml index 68957b8696..02eb4fc2fa 100644 --- a/omnipod-eros/src/main/AndroidManifest.xml +++ b/omnipod-eros/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/openhumans/build.gradle b/openhumans/build.gradle index 79564845d5..ead419045a 100644 --- a/openhumans/build.gradle +++ b/openhumans/build.gradle @@ -8,6 +8,9 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" +android { + namespace 'info.nightscout.androidaps.plugin.general.openhumans' +} dependencies { diff --git a/openhumans/src/main/AndroidManifest.xml b/openhumans/src/main/AndroidManifest.xml index ed6ea8dc06..11cb7d1764 100644 --- a/openhumans/src/main/AndroidManifest.xml +++ b/openhumans/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + + diff --git a/rileylink/build.gradle b/rileylink/build.gradle index 0647e1d938..24ac3125e8 100644 --- a/rileylink/build.gradle +++ b/rileylink/build.gradle @@ -8,6 +8,9 @@ apply from: "${project.rootDir}/core/android_dependencies.gradle" apply from: "${project.rootDir}/core/android_module_dependencies.gradle" apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" +android { + namespace 'info.nightscout.androidaps.plugins.pump.common.hw.rileylink' +} dependencies { implementation project(':core') diff --git a/rileylink/src/main/AndroidManifest.xml b/rileylink/src/main/AndroidManifest.xml index 2efb9aa635..17c2a20a5e 100644 --- a/rileylink/src/main/AndroidManifest.xml +++ b/rileylink/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/shared/build.gradle b/shared/build.gradle index 381cfdc40e..3a6a62902e 100644 --- a/shared/build.gradle +++ b/shared/build.gradle @@ -11,6 +11,8 @@ apply from: "${project.rootDir}/core/test_dependencies.gradle" apply from: "${project.rootDir}/core/jacoco_global.gradle" android { + + namespace 'info.nightscout.shared' defaultConfig { minSdkVersion 23 // for wear } diff --git a/shared/src/main/AndroidManifest.xml b/shared/src/main/AndroidManifest.xml index c299e9eece..a5918e68ab 100644 --- a/shared/src/main/AndroidManifest.xml +++ b/shared/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + \ No newline at end of file diff --git a/wear/build.gradle b/wear/build.gradle index 9bfdcf3e1f..ddcfcbfa2f 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -76,6 +76,7 @@ android { versionName version + "-nsclient" } } + namespace 'info.nightscout.androidaps' } allprojects { diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 1b75866fe8..88b52fc779 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> From 15a9cef6fd750b081a04de3ca07518b68364c44e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 6 Jun 2022 10:27:18 +0200 Subject: [PATCH 5/7] fix warnings --- .../androidaps/interaction/menus/FillMenuActivity.kt | 4 ++-- .../androidaps/interaction/menus/MainMenuActivity.kt | 4 ++-- .../androidaps/interaction/menus/StatusMenuActivity.kt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.kt index 20ac94ad81..552f26f391 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/FillMenuActivity.kt @@ -23,8 +23,8 @@ class FillMenuActivity : MenuListActivity() { add(MenuItem(R.drawable.ic_canula, getString(R.string.action_free_amount))) } - override fun doAction(action: String) { - when (action) { + override fun doAction(position: String) { + when (position) { getString(R.string.action_preset_1) -> rxBus.send(EventWearToMobile(EventData.ActionFillPresetPreCheck(1))) getString(R.string.action_preset_2) -> rxBus.send(EventWearToMobile(EventData.ActionFillPresetPreCheck(2))) getString(R.string.action_preset_3) -> rxBus.send(EventWearToMobile(EventData.ActionFillPresetPreCheck(3))) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.kt index 5b24ece99c..68ea46c780 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/MainMenuActivity.kt @@ -40,8 +40,8 @@ class MainMenuActivity : MenuListActivity() { } } - override fun doAction(action: String) { - when (action) { + override fun doAction(position: String) { + when (position) { getString(R.string.menu_settings) -> startActivity(Intent(this, WatchfaceConfigurationActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) }) getString(R.string.menu_resync) -> rxBus.send(EventWearToMobile(ActionResendData("Re-Sync"))) getString(R.string.status_profile_switch) -> rxBus.send(EventWearToMobile(EventData.ActionProfileSwitchSendInitialData(System.currentTimeMillis()))) diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.kt index f7abab22cc..c6705cedf3 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/menus/StatusMenuActivity.kt @@ -22,8 +22,8 @@ class StatusMenuActivity : MenuListActivity() { add(MenuItem(R.drawable.ic_tdd, getString(R.string.status_tdd))) } - override fun doAction(action: String) { - when (action) { + override fun doAction(position: String) { + when (position) { getString(R.string.status_pump) -> rxBus.send(EventWearToMobile(ActionPumpStatus(System.currentTimeMillis()))) getString(R.string.status_loop) -> rxBus.send(EventWearToMobile(ActionLoopStatus(System.currentTimeMillis()))) getString(R.string.status_tdd) -> rxBus.send(EventWearToMobile(ActionTddStatus(System.currentTimeMillis()))) From c2889710089f2a4e9c2a5619709b085696b3e3c8 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 6 Jun 2022 10:41:45 +0200 Subject: [PATCH 6/7] gradle update --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e33b5b9e46..46c6aa6926 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } // jacoco 0.2 } dependencies { - classpath 'com.android.tools.build:gradle:7.2.0' + classpath 'com.android.tools.build:gradle:7.2.1' classpath 'com.google.gms:google-services:4.3.10' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0' From 43cec5bf6216d29620468b6dbbe7a0ff2b98f33d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 7 Jun 2022 18:05:54 +0200 Subject: [PATCH 7/7] move more calculations to io thread --- .../general/overview/OverviewFragment.kt | 579 +++++++++--------- 1 file changed, 305 insertions(+), 274 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 426b197249..e0fbf0c088 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -224,7 +224,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList disposable += activePlugin.activeOverview.overviewBus .toObservable(EventUpdateOverviewIobCob::class.java) .debounce(1L, TimeUnit.SECONDS) - .observeOn(aapsSchedulers.main) + .observeOn(aapsSchedulers.io) .subscribe({ updateIobCob() }, fabricPrivacy::logException) disposable += activePlugin.activeOverview.overviewBus .toObservable(EventUpdateOverviewSensitivity::class.java) @@ -256,7 +256,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList disposable += rxBus .toObservable(EventNewBG::class.java) .debounce(1L, TimeUnit.SECONDS) - .observeOn(aapsSchedulers.main) + .observeOn(aapsSchedulers.io) .subscribe({ updateBg() }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventRefreshOverview::class.java) @@ -287,19 +287,19 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventEffectiveProfileSwitchChanged::class.java) - .observeOn(aapsSchedulers.main) + .observeOn(aapsSchedulers.io) .subscribe({ updateProfile() }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventTempTargetChange::class.java) - .observeOn(aapsSchedulers.main) + .observeOn(aapsSchedulers.io) .subscribe({ updateTemporaryTarget() }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventExtendedBolusChange::class.java) - .observeOn(aapsSchedulers.main) + .observeOn(aapsSchedulers.io) .subscribe({ updateExtendedBolus() }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventTempBasalChange::class.java) - .observeOn(aapsSchedulers.main) + .observeOn(aapsSchedulers.io) .subscribe({ updateTemporaryBasal() }, fabricPrivacy::logException) refreshLoop = Runnable { @@ -316,17 +316,19 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList fun refreshAll() { runOnUiThread { _binding ?: return@runOnUiThread - updateBg() updateTime() - updateProfile() - updateTemporaryBasal() - updateExtendedBolus() - updateTemporaryTarget() - updateIobCob() updateSensitivity() updateGraph() updateNotification() } + updateBg() + updateTemporaryBasal() + updateExtendedBolus() + updateIobCob() + processButtonsVisibility() + processAps() + updateProfile() + updateTemporaryTarget() } @Synchronized @@ -513,13 +515,16 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // QuickWizard button val quickWizardEntry = quickWizard.getActive() - if (quickWizardEntry != null && lastBG != null && profile != null && pump.isInitialized() && !pump.isSuspended() && !loop.isDisconnected) { - binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE - val wizard = quickWizardEntry.doCalc(profile, profileName, lastBG, false) - binding.buttonsLayout.quickWizardButton.text = quickWizardEntry.buttonText() + "\n" + rh.gs(R.string.format_carbs, quickWizardEntry.carbs()) + - " " + rh.gs(R.string.formatinsulinunits, wizard.calculatedTotalInsulin) - if (wizard.calculatedTotalInsulin <= 0) binding.buttonsLayout.quickWizardButton.visibility = View.GONE - } else binding.buttonsLayout.quickWizardButton.visibility = View.GONE + runOnUiThread { + _binding ?: return@runOnUiThread + if (quickWizardEntry != null && lastBG != null && profile != null && pump.isInitialized() && !pump.isSuspended() && !loop.isDisconnected) { + binding.buttonsLayout.quickWizardButton.visibility = View.VISIBLE + val wizard = quickWizardEntry.doCalc(profile, profileName, lastBG, false) + binding.buttonsLayout.quickWizardButton.text = quickWizardEntry.buttonText() + "\n" + rh.gs(R.string.format_carbs, quickWizardEntry.carbs()) + + " " + rh.gs(R.string.formatinsulinunits, wizard.calculatedTotalInsulin) + if (wizard.calculatedTotalInsulin <= 0) binding.buttonsLayout.quickWizardButton.visibility = View.GONE + } else binding.buttonsLayout.quickWizardButton.visibility = View.GONE + } // **** Temp button **** val lastRun = loop.lastRun @@ -530,72 +535,76 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList (lastRun.lastOpenModeAccept == 0L || lastRun.lastOpenModeAccept < lastRun.lastAPSRun) &&// never accepted or before last result lastRun.constraintsProcessed?.isChangeRequested == true // change is requested - if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && (loop as PluginBase).isEnabled()) { - binding.buttonsLayout.acceptTempButton.visibility = View.VISIBLE - binding.buttonsLayout.acceptTempButton.text = "${rh.gs(R.string.setbasalquestion)}\n${lastRun!!.constraintsProcessed}" - } else { - binding.buttonsLayout.acceptTempButton.visibility = View.GONE - } - - // **** Various treatment buttons **** - binding.buttonsLayout.carbsButton.visibility = - ((!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized() && !pump.isSuspended()) && profile != null - && sp.getBoolean(R.string.key_show_carbs_button, true)).toVisibility() - binding.buttonsLayout.treatmentButton.visibility = (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null - && sp.getBoolean(R.string.key_show_treatment_button, false)).toVisibility() - binding.buttonsLayout.wizardButton.visibility = (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null - && sp.getBoolean(R.string.key_show_wizard_button, true)).toVisibility() - binding.buttonsLayout.insulinButton.visibility = (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null - && sp.getBoolean(R.string.key_show_insulin_button, true)).toVisibility() - - // **** Calibration & CGM buttons **** - val xDripIsBgSource = xdripPlugin.isEnabled() - val dexcomIsSource = dexcomPlugin.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) - for (drawable in binding.buttonsLayout.cgmButton.compoundDrawables) { - drawable?.mutate() - drawable?.colorFilter = PorterDuffColorFilter(rh.gac(context, R.attr.cgmDexColor), PorterDuff.Mode.SRC_IN) + runOnUiThread { + _binding ?: return@runOnUiThread + if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && (loop as PluginBase).isEnabled()) { + binding.buttonsLayout.acceptTempButton.visibility = View.VISIBLE + binding.buttonsLayout.acceptTempButton.text = "${rh.gs(R.string.setbasalquestion)}\n${lastRun!!.constraintsProcessed}" + } else { + binding.buttonsLayout.acceptTempButton.visibility = View.GONE } - binding.buttonsLayout.cgmButton.setTextColor(rh.gac(context, R.attr.cgmDexColor)) - } else if (xDripIsBgSource) { - binding.buttonsLayout.cgmButton.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_xdrip), null, null) - for (drawable in binding.buttonsLayout.cgmButton.compoundDrawables) { - drawable?.mutate() - drawable?.colorFilter = PorterDuffColorFilter(rh.gac(context, R.attr.cgmXdripColor), PorterDuff.Mode.SRC_IN) + + // **** Various treatment buttons **** + binding.buttonsLayout.carbsButton.visibility = + ((!activePlugin.activePump.pumpDescription.storesCarbInfo || pump.isInitialized() && !pump.isSuspended()) && profile != null + && sp.getBoolean(R.string.key_show_carbs_button, true)).toVisibility() + binding.buttonsLayout.treatmentButton.visibility = (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null + && sp.getBoolean(R.string.key_show_treatment_button, false)).toVisibility() + binding.buttonsLayout.wizardButton.visibility = (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null + && sp.getBoolean(R.string.key_show_wizard_button, true)).toVisibility() + binding.buttonsLayout.insulinButton.visibility = (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null + && sp.getBoolean(R.string.key_show_insulin_button, true)).toVisibility() + + // **** Calibration & CGM buttons **** + val xDripIsBgSource = xdripPlugin.isEnabled() + val dexcomIsSource = dexcomPlugin.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) + for (drawable in binding.buttonsLayout.cgmButton.compoundDrawables) { + drawable?.mutate() + drawable?.colorFilter = PorterDuffColorFilter(rh.gac(context, R.attr.cgmDexColor), PorterDuff.Mode.SRC_IN) + } + binding.buttonsLayout.cgmButton.setTextColor(rh.gac(context, R.attr.cgmDexColor)) + } else if (xDripIsBgSource) { + binding.buttonsLayout.cgmButton.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_xdrip), null, null) + for (drawable in binding.buttonsLayout.cgmButton.compoundDrawables) { + drawable?.mutate() + drawable?.colorFilter = PorterDuffColorFilter(rh.gac(context, R.attr.cgmXdripColor), PorterDuff.Mode.SRC_IN) + } + binding.buttonsLayout.cgmButton.setTextColor(rh.gac(context, R.attr.cgmXdripColor)) } - binding.buttonsLayout.cgmButton.setTextColor(rh.gac(context, R.attr.cgmXdripColor)) - } - binding.buttonsLayout.cgmButton.visibility = (sp.getBoolean(R.string.key_show_cgm_button, false) && (xDripIsBgSource || dexcomIsSource)).toVisibility() + binding.buttonsLayout.cgmButton.visibility = (sp.getBoolean(R.string.key_show_cgm_button, false) && (xDripIsBgSource || dexcomIsSource)).toVisibility() - // Automation buttons - binding.buttonsLayout.userButtonsLayout.removeAllViews() - val events = automationPlugin.userEvents() - if (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null) - for (event in events) - if (event.isEnabled && event.trigger.shouldRun()) - context?.let { context -> - SingleClickButton(context).also { - it.setTextColor(rh.gac(context, R.attr.treatmentButton)) - it.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10f) - it.layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 0.5f).also { l -> - l.setMargins(0, 0, rh.dpToPx(-4), 0) - } - it.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_danar_useropt), null, null) - it.text = event.title + // Automation buttons + binding.buttonsLayout.userButtonsLayout.removeAllViews() + val events = automationPlugin.userEvents() + if (!loop.isDisconnected && pump.isInitialized() && !pump.isSuspended() && profile != null) + for (event in events) + if (event.isEnabled && event.trigger.shouldRun()) + context?.let { context -> + SingleClickButton(context).also { + it.setTextColor(rh.gac(context, R.attr.treatmentButton)) + it.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10f) + it.layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 0.5f).also { l -> + l.setMargins(0, 0, rh.dpToPx(-4), 0) + } + it.setCompoundDrawablesWithIntrinsicBounds(null, rh.gd(R.drawable.ic_danar_useropt), null, null) + it.text = event.title - it.setOnClickListener { - OKDialog.showConfirmation(context, rh.gs(R.string.run_question, event.title), { handler.post { automationPlugin.processEvent(event) } }) + it.setOnClickListener { + OKDialog.showConfirmation(context, rh.gs(R.string.run_question, event.title), { handler.post { automationPlugin.processEvent(event) } }) + } + binding.buttonsLayout.userButtonsLayout.addView(it) } - binding.buttonsLayout.userButtonsLayout.addView(it) } - } - binding.buttonsLayout.userButtonsLayout.visibility = events.isNotEmpty().toVisibility() + binding.buttonsLayout.userButtonsLayout.visibility = events.isNotEmpty().toVisibility() + } } private fun processAps() { val pump = activePlugin.activePump + val profile = profileFunction.getProfile() // aps mode val closedLoopEnabled = constraintChecker.isClosedLoopAllowed() @@ -608,103 +617,106 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } } - if (config.APS && pump.pumpDescription.isTempBasalCapable) { - binding.infoLayout.apsMode.visibility = View.VISIBLE - binding.infoLayout.timeLayout.visibility = View.GONE - when { - (loop as PluginBase).isEnabled() && loop.isSuperBolus -> { - binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_superbolus) - apsModeSetA11yLabel(R.string.superbolus) - binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) - binding.infoLayout.apsModeText.visibility = View.VISIBLE - } + runOnUiThread { + _binding ?: return@runOnUiThread + if (config.APS && pump.pumpDescription.isTempBasalCapable) { + binding.infoLayout.apsMode.visibility = View.VISIBLE + binding.infoLayout.timeLayout.visibility = View.GONE + when { + (loop as PluginBase).isEnabled() && loop.isSuperBolus -> { + binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_superbolus) + apsModeSetA11yLabel(R.string.superbolus) + binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) + binding.infoLayout.apsModeText.visibility = View.VISIBLE + } - loop.isDisconnected -> { - binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_disconnected) - apsModeSetA11yLabel(R.string.disconnected) - binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) - binding.infoLayout.apsModeText.visibility = View.VISIBLE - } + loop.isDisconnected -> { + binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_disconnected) + apsModeSetA11yLabel(R.string.disconnected) + binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) + binding.infoLayout.apsModeText.visibility = View.VISIBLE + } - (loop as PluginBase).isEnabled() && loop.isSuspended -> { - binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_paused) - apsModeSetA11yLabel(R.string.suspendloop_label) - binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) - binding.infoLayout.apsModeText.visibility = View.VISIBLE - } + (loop as PluginBase).isEnabled() && loop.isSuspended -> { + binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_paused) + apsModeSetA11yLabel(R.string.suspendloop_label) + binding.infoLayout.apsModeText.text = dateUtil.age(loop.minutesToEndOfSuspend() * 60000L, true, rh) + binding.infoLayout.apsModeText.visibility = View.VISIBLE + } - pump.isSuspended() -> { - binding.infoLayout.apsMode.setImageResource( - if (pump.model() == PumpType.OMNIPOD_EROS || pump.model() == PumpType.OMNIPOD_DASH) { - // For Omnipod, indicate the pump as disconnected when it's suspended. - // The only way to 'reconnect' it, is through the Omnipod tab - apsModeSetA11yLabel(R.string.disconnected) - R.drawable.ic_loop_disconnected - } else { - apsModeSetA11yLabel(R.string.pump_paused) - R.drawable.ic_loop_paused - } - ) - binding.infoLayout.apsModeText.visibility = View.GONE - } - - (loop as PluginBase).isEnabled() && closedLoopEnabled.value() && loop.isLGS -> { - binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_lgs) - apsModeSetA11yLabel(R.string.uel_lgs_loop_mode) - binding.infoLayout.apsModeText.visibility = View.GONE - } - - (loop as PluginBase).isEnabled() && closedLoopEnabled.value() -> { - binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_closed) - apsModeSetA11yLabel(R.string.closedloop) - binding.infoLayout.apsModeText.visibility = View.GONE - } - - (loop as PluginBase).isEnabled() && !closedLoopEnabled.value() -> { - binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_open) - apsModeSetA11yLabel(R.string.openloop) - binding.infoLayout.apsModeText.visibility = View.GONE - } - - else -> { - binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_disabled) - apsModeSetA11yLabel(R.string.disabledloop) - binding.infoLayout.apsModeText.visibility = View.GONE - } - } - // Show variable sensitivity - val request = loop.lastRun?.request - if (request is DetermineBasalResultSMB) { - val isfMgdl = profileFunction.getProfile()?.getIsfMgdl() - val variableSens = request.variableSens - if (variableSens != isfMgdl && variableSens != null && isfMgdl != null) { - binding.infoLayout.variableSensitivity.text = - String.format( - Locale.getDefault(), "%1$.1f→%2$.1f", - Profile.toUnits(isfMgdl, isfMgdl * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()), - Profile.toUnits(variableSens, variableSens * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()) + pump.isSuspended() -> { + binding.infoLayout.apsMode.setImageResource( + if (pump.model() == PumpType.OMNIPOD_EROS || pump.model() == PumpType.OMNIPOD_DASH) { + // For Omnipod, indicate the pump as disconnected when it's suspended. + // The only way to 'reconnect' it, is through the Omnipod tab + apsModeSetA11yLabel(R.string.disconnected) + R.drawable.ic_loop_disconnected + } else { + apsModeSetA11yLabel(R.string.pump_paused) + R.drawable.ic_loop_paused + } ) - binding.infoLayout.variableSensitivity.visibility = View.VISIBLE + binding.infoLayout.apsModeText.visibility = View.GONE + } + + (loop as PluginBase).isEnabled() && closedLoopEnabled.value() && loop.isLGS -> { + binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_lgs) + apsModeSetA11yLabel(R.string.uel_lgs_loop_mode) + binding.infoLayout.apsModeText.visibility = View.GONE + } + + (loop as PluginBase).isEnabled() && closedLoopEnabled.value() -> { + binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_closed) + apsModeSetA11yLabel(R.string.closedloop) + binding.infoLayout.apsModeText.visibility = View.GONE + } + + (loop as PluginBase).isEnabled() && !closedLoopEnabled.value() -> { + binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_open) + apsModeSetA11yLabel(R.string.openloop) + binding.infoLayout.apsModeText.visibility = View.GONE + } + + else -> { + binding.infoLayout.apsMode.setImageResource(R.drawable.ic_loop_disabled) + apsModeSetA11yLabel(R.string.disabledloop) + binding.infoLayout.apsModeText.visibility = View.GONE + } + } + // Show variable sensitivity + val request = loop.lastRun?.request + if (request is DetermineBasalResultSMB) { + val isfMgdl = profile?.getIsfMgdl() + val variableSens = request.variableSens + if (variableSens != isfMgdl && variableSens != null && isfMgdl != null) { + binding.infoLayout.variableSensitivity.text = + String.format( + Locale.getDefault(), "%1$.1f→%2$.1f", + Profile.toUnits(isfMgdl, isfMgdl * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()), + Profile.toUnits(variableSens, variableSens * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()) + ) + binding.infoLayout.variableSensitivity.visibility = View.VISIBLE + } else binding.infoLayout.variableSensitivity.visibility = View.GONE } else binding.infoLayout.variableSensitivity.visibility = View.GONE - } else binding.infoLayout.variableSensitivity.visibility = View.GONE - } else { - //nsclient - binding.infoLayout.apsMode.visibility = View.GONE - binding.infoLayout.apsModeText.visibility = View.GONE - binding.infoLayout.timeLayout.visibility = View.VISIBLE + } else { + //nsclient + binding.infoLayout.apsMode.visibility = View.GONE + binding.infoLayout.apsModeText.visibility = View.GONE + binding.infoLayout.timeLayout.visibility = View.VISIBLE + } + + // pump status from ns + binding.pump.text = nsDeviceStatus.pumpStatus + binding.pump.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.pump), nsDeviceStatus.extendedPumpStatus) } } + + // OpenAPS status from ns + binding.openaps.text = nsDeviceStatus.openApsStatus + binding.openaps.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.openaps), nsDeviceStatus.extendedOpenApsStatus) } } + + // Uploader status from ns + binding.uploader.text = nsDeviceStatus.uploaderStatusSpanned + binding.uploader.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.uploader), nsDeviceStatus.extendedUploaderStatus) } } } - - // pump status from ns - binding.pump.text = nsDeviceStatus.pumpStatus - binding.pump.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.pump), nsDeviceStatus.extendedPumpStatus) } } - - // OpenAPS status from ns - binding.openaps.text = nsDeviceStatus.openApsStatus - binding.openaps.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.openaps), nsDeviceStatus.extendedOpenApsStatus) } } - - // Uploader status from ns - binding.uploader.text = nsDeviceStatus.uploaderStatusSpanned - binding.uploader.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.uploader), nsDeviceStatus.extendedUploaderStatus) } } } private fun prepareGraphsIfNeeded(numOfGraphs: Int) { @@ -760,59 +772,67 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList @SuppressLint("SetTextI18n") fun updateBg() { - _binding ?: return val units = profileFunction.getUnits() - binding.infoLayout.bg.text = overviewData.lastBg?.valueToUnitsString(units) - ?: rh.gs(R.string.notavailable) - binding.infoLayout.bg.setTextColor(overviewData.lastBgColor(context)) - binding.infoLayout.arrow.setImageResource(trendCalculator.getTrendArrow(overviewData.lastBg).directionToIcon()) - binding.infoLayout.arrow.setColorFilter(overviewData.lastBgColor(context)) - binding.infoLayout.arrow.contentDescription = overviewData.lastBgDescription + " " + rh.gs(R.string.and) + " " + trendCalculator.getTrendDescription(overviewData.lastBg) - + val lastBg = overviewData.lastBg + val lastBgColor = overviewData.lastBgColor(context) + val isActualBg = overviewData.isActualBg val glucoseStatus = glucoseStatusProvider.glucoseStatusData - if (glucoseStatus != null) { - binding.infoLayout.deltaLarge.text = Profile.toSignedUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) - binding.infoLayout.deltaLarge.setTextColor(overviewData.lastBgColor(context)) - binding.infoLayout.delta.text = Profile.toSignedUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) - binding.infoLayout.avgDelta.text = Profile.toSignedUnitsString(glucoseStatus.shortAvgDelta, glucoseStatus.shortAvgDelta * Constants.MGDL_TO_MMOLL, units) - binding.infoLayout.longAvgDelta.text = Profile.toSignedUnitsString(glucoseStatus.longAvgDelta, glucoseStatus.longAvgDelta * Constants.MGDL_TO_MMOLL, units) - } else { - binding.infoLayout.deltaLarge.text = "" - binding.infoLayout.delta.text = "Δ " + rh.gs(R.string.notavailable) - binding.infoLayout.avgDelta.text = "" - binding.infoLayout.longAvgDelta.text = "" - } + val trendDescription = trendCalculator.getTrendDescription(lastBg) + val trendArrow = trendCalculator.getTrendArrow(lastBg) + val lastBgDescription = overviewData.lastBgDescription + runOnUiThread { + _binding ?: return@runOnUiThread + binding.infoLayout.bg.text = lastBg?.valueToUnitsString(units) + ?: rh.gs(R.string.notavailable) + binding.infoLayout.bg.setTextColor(lastBgColor) + binding.infoLayout.arrow.setImageResource(trendArrow.directionToIcon()) + binding.infoLayout.arrow.setColorFilter(lastBgColor) + binding.infoLayout.arrow.contentDescription = lastBgDescription + " " + rh.gs(R.string.and) + " " + trendDescription - // strike through if BG is old - binding.infoLayout.bg.paintFlags = - if (!overviewData.isActualBg) binding.infoLayout.bg.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG - else binding.infoLayout.bg.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() - - val outDate = (if (!overviewData.isActualBg) rh.gs(R.string.a11y_bg_outdated) else "") - binding.infoLayout.bg.contentDescription = - rh.gs(R.string.a11y_blood_glucose) + " " + binding.infoLayout.bg.text.toString() + " " + overviewData.lastBgDescription + " " + outDate - - binding.infoLayout.timeAgo.text = dateUtil.minAgo(rh, overviewData.lastBg?.timestamp) - binding.infoLayout.timeAgo.contentDescription = dateUtil.minAgoLong(rh, overviewData.lastBg?.timestamp) - binding.infoLayout.timeAgoShort.text = "(" + dateUtil.minAgoShort(overviewData.lastBg?.timestamp) + ")" - - val qualityIcon = bgQualityCheckPlugin.icon() - if (qualityIcon != 0) { - binding.infoLayout.bgQuality.visibility = View.VISIBLE - binding.infoLayout.bgQuality.setImageResource(qualityIcon) - binding.infoLayout.bgQuality.contentDescription = rh.gs(R.string.a11y_bg_quality) + " " + bgQualityCheckPlugin.stateDescription() - binding.infoLayout.bgQuality.setOnClickListener { - context?.let { context -> OKDialog.show(context, rh.gs(R.string.data_status), bgQualityCheckPlugin.message) } + if (glucoseStatus != null) { + binding.infoLayout.deltaLarge.text = Profile.toSignedUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + binding.infoLayout.deltaLarge.setTextColor(lastBgColor) + binding.infoLayout.delta.text = Profile.toSignedUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + binding.infoLayout.avgDelta.text = Profile.toSignedUnitsString(glucoseStatus.shortAvgDelta, glucoseStatus.shortAvgDelta * Constants.MGDL_TO_MMOLL, units) + binding.infoLayout.longAvgDelta.text = Profile.toSignedUnitsString(glucoseStatus.longAvgDelta, glucoseStatus.longAvgDelta * Constants.MGDL_TO_MMOLL, units) + } else { + binding.infoLayout.deltaLarge.text = "" + binding.infoLayout.delta.text = "Δ " + rh.gs(R.string.notavailable) + binding.infoLayout.avgDelta.text = "" + binding.infoLayout.longAvgDelta.text = "" + } + + // strike through if BG is old + binding.infoLayout.bg.paintFlags = + if (!isActualBg) binding.infoLayout.bg.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG + else binding.infoLayout.bg.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() + + val outDate = (if (!isActualBg) rh.gs(R.string.a11y_bg_outdated) else "") + binding.infoLayout.bg.contentDescription = rh.gs(R.string.a11y_blood_glucose) + " " + binding.infoLayout.bg.text.toString() + " " + lastBgDescription + " " + outDate + + binding.infoLayout.timeAgo.text = dateUtil.minAgo(rh, lastBg?.timestamp) + binding.infoLayout.timeAgo.contentDescription = dateUtil.minAgoLong(rh, lastBg?.timestamp) + binding.infoLayout.timeAgoShort.text = "(" + dateUtil.minAgoShort(lastBg?.timestamp) + ")" + + val qualityIcon = bgQualityCheckPlugin.icon() + if (qualityIcon != 0) { + binding.infoLayout.bgQuality.visibility = View.VISIBLE + binding.infoLayout.bgQuality.setImageResource(qualityIcon) + binding.infoLayout.bgQuality.contentDescription = rh.gs(R.string.a11y_bg_quality) + " " + bgQualityCheckPlugin.stateDescription() + binding.infoLayout.bgQuality.setOnClickListener { + context?.let { context -> OKDialog.show(context, rh.gs(R.string.data_status), bgQualityCheckPlugin.message) } + } + } else { + binding.infoLayout.bgQuality.visibility = View.GONE } - } else { - binding.infoLayout.bgQuality.visibility = View.GONE } } fun updateProfile() { - _binding ?: return - val profileBackgroundColor = - profileFunction.getProfile()?.let { + val profile = profileFunction.getProfile() + runOnUiThread { + _binding ?: return@runOnUiThread + val profileBackgroundColor = profile?.let { if (it is ProfileSealed.EPS) { if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L) R.attr.ribbonWarningColor @@ -824,8 +844,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } } ?: R.attr.ribbonCriticalColor - val profileTextColor = - profileFunction.getProfile()?.let { + val profileTextColor = profile?.let { if (it is ProfileSealed.EPS) { if (it.value.originalPercentage != 100 || it.value.originalTimeshift != 0L || it.value.originalDuration != 0L) R.attr.ribbonTextWarningColor @@ -836,27 +855,35 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList R.attr.ribbonTextDefaultColor } } ?: R.attr.ribbonTextDefaultColor - setRibbon(binding.activeProfile, profileTextColor, profileBackgroundColor, profileFunction.getProfileNameWithRemainingTime()) + setRibbon(binding.activeProfile, profileTextColor, profileBackgroundColor, profileFunction.getProfileNameWithRemainingTime()) + } } private fun updateTemporaryBasal() { - _binding ?: return - binding.infoLayout.baseBasal.text = overviewData.temporaryBasalText(iobCobCalculator) - binding.infoLayout.baseBasal.setTextColor(overviewData.temporaryBasalColor(context, iobCobCalculator)) - binding.infoLayout.baseBasalIcon.setImageResource(overviewData.temporaryBasalIcon(iobCobCalculator)) - binding.infoLayout.basalLayout.setOnClickListener { - activity?.let { OKDialog.show(it, rh.gs(R.string.basal), overviewData.temporaryBasalDialogText(iobCobCalculator)) } + val temporaryBasalText = overviewData.temporaryBasalText(iobCobCalculator) + val temporaryBasalColor = overviewData.temporaryBasalColor(context, iobCobCalculator) + val temporaryBasalIcon = overviewData.temporaryBasalIcon(iobCobCalculator) + val temporaryBasalDialogText = overviewData.temporaryBasalDialogText(iobCobCalculator) + runOnUiThread { + _binding ?: return@runOnUiThread + binding.infoLayout.baseBasal.text = temporaryBasalText + binding.infoLayout.baseBasal.setTextColor(temporaryBasalColor) + binding.infoLayout.baseBasalIcon.setImageResource(temporaryBasalIcon) + binding.infoLayout.basalLayout.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.basal), temporaryBasalDialogText) } } } } private fun updateExtendedBolus() { - _binding ?: return val pump = activePlugin.activePump - binding.infoLayout.extendedBolus.text = overviewData.extendedBolusText(iobCobCalculator) - binding.infoLayout.extendedLayout.setOnClickListener { - activity?.let { OKDialog.show(it, rh.gs(R.string.extended_bolus), overviewData.extendedBolusDialogText(iobCobCalculator)) } + val extendedBolus = iobCobCalculator.getExtendedBolus(dateUtil.now()) + val extendedBolusText = overviewData.extendedBolusText(iobCobCalculator) + val extendedBolusDialogText = overviewData.extendedBolusDialogText(iobCobCalculator) + runOnUiThread { + _binding ?: return@runOnUiThread + binding.infoLayout.extendedBolus.text = extendedBolusText + binding.infoLayout.extendedLayout.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.extended_bolus), extendedBolusDialogText) } } + binding.infoLayout.extendedLayout.visibility = (extendedBolus != null && !pump.isFakingTempsByExtendedBoluses).toVisibility() } - binding.infoLayout.extendedLayout.visibility = (iobCobCalculator.getExtendedBolus(dateUtil.now()) != null && !pump.isFakingTempsByExtendedBoluses).toVisibility() } fun updateTime() { @@ -887,69 +914,73 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList binding.statusLightsLayout.pbAge, binding.statusLightsLayout.batteryLevel ) - processButtonsVisibility() - processAps() } fun updateIobCob() { - _binding ?: return - binding.infoLayout.iob.text = overviewData.iobText(iobCobCalculator) - binding.infoLayout.iobLayout.setOnClickListener { - activity?.let { OKDialog.show(it, rh.gs(R.string.iob), overviewData.iobDialogText(iobCobCalculator)) } - } - // cob - var cobText = overviewData.cobInfo(iobCobCalculator).displayText(rh, dateUtil, buildHelper.isEngineeringMode()) ?: rh.gs(R.string.value_unavailable_short) + val iobText = overviewData.iobText(iobCobCalculator) + val iobDialogText = overviewData.iobDialogText(iobCobCalculator) + val displayText = overviewData.cobInfo(iobCobCalculator).displayText(rh, dateUtil, buildHelper.isEngineeringMode()) + val lastCarbsTime = overviewData.lastCarbsTime + runOnUiThread { + _binding ?: return@runOnUiThread + binding.infoLayout.iob.text = iobText + binding.infoLayout.iobLayout.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(R.string.iob), iobDialogText) } } + // cob + var cobText = displayText ?: rh.gs(R.string.value_unavailable_short) - val constraintsProcessed = loop.lastRun?.constraintsProcessed - val lastRun = loop.lastRun - if (config.APS && constraintsProcessed != null && lastRun != null) { - if (constraintsProcessed.carbsReq > 0) { - //only display carbsreq when carbs have not been entered recently - if (overviewData.lastCarbsTime < lastRun.lastAPSRun) { - cobText += " | " + constraintsProcessed.carbsReq + " " + rh.gs(R.string.required) + val constraintsProcessed = loop.lastRun?.constraintsProcessed + val lastRun = loop.lastRun + if (config.APS && constraintsProcessed != null && lastRun != null) { + if (constraintsProcessed.carbsReq > 0) { + //only display carbsreq when carbs have not been entered recently + if (lastCarbsTime < lastRun.lastAPSRun) { + cobText += " | " + constraintsProcessed.carbsReq + " " + rh.gs(R.string.required) + } + if (carbAnimation?.isRunning == false) + carbAnimation?.start() + } else { + carbAnimation?.stop() + carbAnimation?.selectDrawable(0) } - if (carbAnimation?.isRunning == false) - carbAnimation?.start() - } else { - carbAnimation?.stop() - carbAnimation?.selectDrawable(0) } + binding.infoLayout.cob.text = cobText } - binding.infoLayout.cob.text = cobText } @SuppressLint("SetTextI18n") fun updateTemporaryTarget() { - _binding ?: return val units = profileFunction.getUnits() val tempTarget = overviewData.temporaryTarget - if (tempTarget != null) { - setRibbon( - binding.tempTarget, - R.attr.ribbonTextWarningColor, - R.attr.ribbonWarningColor, - Profile.toTargetRangeString(tempTarget.lowTarget, tempTarget.highTarget, GlucoseUnit.MGDL, units) + " " + dateUtil.untilString(tempTarget.end, rh) - ) - } else { - // If the target is not the same as set in the profile then oref has overridden it - profileFunction.getProfile()?.let { profile -> - val targetUsed = loop.lastRun?.constraintsProcessed?.targetBG ?: 0.0 + runOnUiThread { + _binding ?: return@runOnUiThread + if (tempTarget != null) { + setRibbon( + binding.tempTarget, + R.attr.ribbonTextWarningColor, + R.attr.ribbonWarningColor, + Profile.toTargetRangeString(tempTarget.lowTarget, tempTarget.highTarget, GlucoseUnit.MGDL, units) + " " + dateUtil.untilString(tempTarget.end, rh) + ) + } else { + // If the target is not the same as set in the profile then oref has overridden it + profileFunction.getProfile()?.let { profile -> + val targetUsed = loop.lastRun?.constraintsProcessed?.targetBG ?: 0.0 - if (targetUsed != 0.0 && abs(profile.getTargetMgdl() - targetUsed) > 0.01) { - aapsLogger.debug("Adjusted target. Profile: ${profile.getTargetMgdl()} APS: $targetUsed") - setRibbon( - binding.tempTarget, - R.attr.ribbonTextWarningColor, - R.attr.tempTargetBackgroundColor, - Profile.toTargetRangeString(targetUsed, targetUsed, GlucoseUnit.MGDL, units) - ) - } else { - setRibbon( - binding.tempTarget, - R.attr.ribbonTextDefaultColor, - R.attr.ribbonDefaultColor, - Profile.toTargetRangeString(profile.getTargetLowMgdl(), profile.getTargetHighMgdl(), GlucoseUnit.MGDL, units) - ) + if (targetUsed != 0.0 && abs(profile.getTargetMgdl() - targetUsed) > 0.01) { + aapsLogger.debug("Adjusted target. Profile: ${profile.getTargetMgdl()} APS: $targetUsed") + setRibbon( + binding.tempTarget, + R.attr.ribbonTextWarningColor, + R.attr.tempTargetBackgroundColor, + Profile.toTargetRangeString(targetUsed, targetUsed, GlucoseUnit.MGDL, units) + ) + } else { + setRibbon( + binding.tempTarget, + R.attr.ribbonTextDefaultColor, + R.attr.ribbonDefaultColor, + Profile.toTargetRangeString(profile.getTargetLowMgdl(), profile.getTargetHighMgdl(), GlucoseUnit.MGDL, units) + ) + } } } }