From 7502824a1b68ce10c5ee9a3d3a49c05f47f5f178 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 5 Mar 2022 22:27:16 +0000 Subject: [PATCH 01/14] - added Aidex implementation (doesn't work yet) --- app/src/main/AndroidManifest.xml | 4 + .../activities/MyPreferenceFragment.kt | 9 +- .../nightscout/androidaps/di/PluginsModule.kt | 6 ++ .../androidaps/plugins/source/AidexPlugin.kt | 101 ++++++++++++++++++ .../androidaps/receivers/DataReceiver.kt | 3 + .../nightscout/androidaps/services/Intents.kt | 23 ++++ app/src/main/res/values/strings.xml | 6 ++ .../database/entities/GlucoseValue.kt | 1 + 8 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a163b3729c..b8b5d99d97 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,6 +34,10 @@ + + + + () + glucoseValues += CgmSourceTransaction.TransactionGlucoseValue( + timestamp = bundle.getLong(Intents.AIDEX_TIMESTAMP, 0), + value = if (bundle.getString(Intents.AIDEX_BG_TYPE, "mg/dl").equals("mg/dl")) bundle.getDouble(Intents.AIDEX_BG_VALUE, 0.0) else bundle.getDouble(Intents.AIDEX_BG_VALUE, 0.0) * Constants.MMOLL_TO_MGDL, + raw = null, + noise = null, + trendArrow = GlucoseValue.TrendArrow.fromString(bundle.getString(Intents.AIDEX_BG_SLOPE_NAME)), + sourceSensor = GlucoseValue.SourceSensor.AIDEX + ) + repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null)) + .doOnError { + aapsLogger.error(LTag.DATABASE, "Error while saving values from Xdrip", it) + ret = Result.failure(workDataOf("Error" to it.toString())) + } + .blockingGet() + .also { savedValues -> + savedValues.all().forEach { + aapsLogger.debug(LTag.DATABASE, "Inserted bg $it") + } + } + return ret + } + } +} 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 6be6a5ad2e..a65c77a569 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt +++ b/app/src/main/java/info/nightscout/androidaps/receivers/DataReceiver.kt @@ -67,6 +67,9 @@ open class DataReceiver : DaggerBroadcastReceiver() { Intents.DEXCOM_BG -> OneTimeWorkRequest.Builder(DexcomPlugin.DexcomWorker::class.java) .setInputData(dataWorker.storeInputData(bundle, intent)).build() + Intents.AIDEX_NEW_BG_ESTIMATE -> + OneTimeWorkRequest.Builder(AidexPlugin.AidexWorker::class.java) + .setInputData(dataWorker.storeInputData(bundle, intent)).build() else -> null }?.let { request -> dataWorker.enqueue(request) } } diff --git a/app/src/main/java/info/nightscout/androidaps/services/Intents.kt b/app/src/main/java/info/nightscout/androidaps/services/Intents.kt index bf3a8d3695..87c74bcb47 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/Intents.kt +++ b/app/src/main/java/info/nightscout/androidaps/services/Intents.kt @@ -31,6 +31,29 @@ interface Intents { const val POCTECH_BG = "com.china.poctech.data" const val TOMATO_BG = "com.fanqies.tomatofn.BgEstimate" + // Aidex -> AAPS + var AIDEX_NEW_BG_ESTIMATE = "com.microtechmd.cgms.aidex.BgEstimate" + + // DATA + // DATA + /** + * BG Type: Can be either mmol/l or mg/dl + */ + var AIDEX_BG_TYPE = "com.microtechmd.cgms.aidex.BgType" + var AIDEX_BG_VALUE = "com.microtechmd.cgms.aidex.BgValue" + + /** + * BG Slope Name: following values are valid: + * "DoubleUp", "SingleUp", "FortyFiveUp", "Flat", "FortyFiveDown", "SingleDown", + * "DoubleDown", "NotComputable", "RateOutOfRange" + */ + var AIDEX_BG_SLOPE_NAME = "com.microtechmd.cgms.aidex.BgSlopeName" + var AIDEX_TIMESTAMP = "com.microtechmd.cgms.aidex.Time" // epoch in ms + + var AIDEX_TRANSMITTER_SN = "com.microtechmd.cgms.aidex.TransmitterSerialNumber" + var AIDEX_SENSOR_ID = "com.microtechmd.cgms.aidex.SensorId" + + // Broadcast status const val AAPS_BROADCAST = "info.nightscout.androidaps.status" } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 07bf55f635..438ab04f7f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1222,4 +1222,10 @@ Hide loop Show loop %1$d selected + + GlucoRx Aidex + Aidex + Receive BG values from GlucoRx Aidex CGMS. + + diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt index 241485a254..00979a554c 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt @@ -111,6 +111,7 @@ data class GlucoseValue( GLUNOVO_NATIVE("Glunovo"), MM_600_SERIES("MM600Series"), EVERSENSE("Eversense"), + AIDEX("GlucoRx Aidex"), RANDOM("Random"), UNKNOWN("Unknown"), From 5c05a31030271778ef92ce6854f82aaaa4b9500c Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Thu, 17 Mar 2022 19:05:38 +0000 Subject: [PATCH 02/14] - support for Aidex plugins --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 2 ++ .../nightscout/androidaps/di/WorkersModule.kt | 1 + .../androidaps/plugins/source/AidexPlugin.kt | 16 +++++++++++++--- .../nightscout/androidaps/services/Intents.kt | 16 +--------------- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 427013fd1a..9d7b945424 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -109,7 +109,7 @@ android { defaultConfig { multiDexEnabled true versionCode 1500 - version "3.0.0.1-dev-e" + version "3.0.0.1-dev-aidex" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b8b5d99d97..3badcdbfaf 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -109,6 +109,8 @@ + + diff --git a/app/src/main/java/info/nightscout/androidaps/di/WorkersModule.kt b/app/src/main/java/info/nightscout/androidaps/di/WorkersModule.kt index 92c84687b7..78991d111f 100644 --- a/app/src/main/java/info/nightscout/androidaps/di/WorkersModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/di/WorkersModule.kt @@ -32,4 +32,5 @@ abstract class WorkersModule { @ContributesAndroidInjector abstract fun contributesNSClientMbgWorker(): NSClientMbgWorker @ContributesAndroidInjector abstract fun contributesFoodWorker(): FoodPlugin.FoodWorker @ContributesAndroidInjector abstract fun contributesCsvExportWorker(): ImportExportPrefsImpl.CsvExportWorker + @ContributesAndroidInjector abstract fun contributesAidexWorker(): AidexPlugin.AidexWorker } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt index 5c91d6f278..05e795cfcb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt @@ -21,6 +21,7 @@ import info.nightscout.androidaps.services.Intents import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject import javax.inject.Singleton +import kotlin.math.log @Singleton class AidexPlugin @Inject constructor( @@ -32,7 +33,7 @@ class AidexPlugin @Inject constructor( .fragmentClass(BGSourceFragment::class.java.name) .pluginIcon((R.drawable.ic_blooddrop_48)) .pluginName(R.string.aidex) - .shortName(R.string.randombg_short) + .shortName(R.string.aidex_short) .description(R.string.description_source_aidex), aapsLogger, rh, injector ), BgSource { @@ -76,9 +77,18 @@ class AidexPlugin @Inject constructor( if (bundle.containsKey(Intents.AIDEX_SENSOR_ID)) aapsLogger.debug(LTag.BGSOURCE, "sensorId: " + bundle.getString(Intents.AIDEX_SENSOR_ID)) val glucoseValues = mutableListOf() + + val timestamp = bundle.getLong(Intents.AIDEX_TIMESTAMP, 0) + val bgType = bundle.getString(Intents.AIDEX_BG_TYPE, "mg/dl") + val bgValue = bundle.getDouble(Intents.AIDEX_BG_VALUE, 0.0) + + val bgValueTarget = if (bgType.equals("mg/dl")) bgValue else bgValue * Constants.MMOLL_TO_MGDL + + aapsLogger.debug(LTag.BGSOURCE, "Received Aidex broadcast [time=$timestamp, bgType=$bgType, value=$bgValue, targetValue=$bgValueTarget") + glucoseValues += CgmSourceTransaction.TransactionGlucoseValue( - timestamp = bundle.getLong(Intents.AIDEX_TIMESTAMP, 0), - value = if (bundle.getString(Intents.AIDEX_BG_TYPE, "mg/dl").equals("mg/dl")) bundle.getDouble(Intents.AIDEX_BG_VALUE, 0.0) else bundle.getDouble(Intents.AIDEX_BG_VALUE, 0.0) * Constants.MMOLL_TO_MGDL, + timestamp = timestamp, + value = bgValueTarget, raw = null, noise = null, trendArrow = GlucoseValue.TrendArrow.fromString(bundle.getString(Intents.AIDEX_BG_SLOPE_NAME)), diff --git a/app/src/main/java/info/nightscout/androidaps/services/Intents.kt b/app/src/main/java/info/nightscout/androidaps/services/Intents.kt index 87c74bcb47..925c74eff8 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/Intents.kt +++ b/app/src/main/java/info/nightscout/androidaps/services/Intents.kt @@ -32,28 +32,14 @@ interface Intents { const val TOMATO_BG = "com.fanqies.tomatofn.BgEstimate" // Aidex -> AAPS - var AIDEX_NEW_BG_ESTIMATE = "com.microtechmd.cgms.aidex.BgEstimate" - - // DATA - // DATA - /** - * BG Type: Can be either mmol/l or mg/dl - */ + var AIDEX_NEW_BG_ESTIMATE = "com.microtechmd.cgms.aidex.action.BgEstimate" var AIDEX_BG_TYPE = "com.microtechmd.cgms.aidex.BgType" var AIDEX_BG_VALUE = "com.microtechmd.cgms.aidex.BgValue" - - /** - * BG Slope Name: following values are valid: - * "DoubleUp", "SingleUp", "FortyFiveUp", "Flat", "FortyFiveDown", "SingleDown", - * "DoubleDown", "NotComputable", "RateOutOfRange" - */ var AIDEX_BG_SLOPE_NAME = "com.microtechmd.cgms.aidex.BgSlopeName" var AIDEX_TIMESTAMP = "com.microtechmd.cgms.aidex.Time" // epoch in ms - var AIDEX_TRANSMITTER_SN = "com.microtechmd.cgms.aidex.TransmitterSerialNumber" var AIDEX_SENSOR_ID = "com.microtechmd.cgms.aidex.SensorId" - // Broadcast status const val AAPS_BROADCAST = "info.nightscout.androidaps.status" } From 10d1170d9c0250eca462ff581bdc79c556f0ca82 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 29 Mar 2022 23:22:39 +0100 Subject: [PATCH 03/14] Add Aidex --- .idea/dictionaries/project_dictionary.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.idea/dictionaries/project_dictionary.xml b/.idea/dictionaries/project_dictionary.xml index 49af19275e..d167564b60 100644 --- a/.idea/dictionaries/project_dictionary.xml +++ b/.idea/dictionaries/project_dictionary.xml @@ -5,6 +5,7 @@ abcdef acked actionstring + aidex allowednumbers androidaps autosens @@ -105,4 +106,4 @@ ypsopump - \ No newline at end of file + From 499cdd06831d99e680566a8d13818edfd233904a Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 29 Mar 2022 23:23:50 +0100 Subject: [PATCH 04/14] Add Aidex --- .../nightscout/androidaps/plugins/source/BGSourceFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index d285db5f0a..00f3c57c25 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -153,6 +153,7 @@ class BGSourceFragment : DaggerFragment() { R.string.poctech -> Sources.PocTech R.string.tomato -> Sources.Tomato R.string.glunovo -> Sources.Glunovo + R.string.aidex -> Sources.Aidex R.string.xdrip -> Sources.Xdrip else -> Sources.Unknown } From 4364c11160e9aec78181f0ea4136915967598478 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 29 Mar 2022 23:25:37 +0100 Subject: [PATCH 05/14] Add Aidex --- .../main/java/info/nightscout/androidaps/utils/Translator.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt b/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt index d680f5e3f3..c386e0703c 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/Translator.kt @@ -255,6 +255,7 @@ class Translator @Inject internal constructor( Sources.MM640g -> TODO() Sources.NSClientSource -> TODO() Sources.PocTech -> TODO() + Sources.Aidex -> TODO() Sources.Tomato -> TODO() Sources.Xdrip -> TODO() Sources.LocalProfile -> TODO() @@ -293,4 +294,4 @@ class Translator @Inject internal constructor( else -> source.name } -} \ No newline at end of file +} From ec25aba8eba8053958f19869f87c37cab0359cd2 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 29 Mar 2022 23:27:40 +0100 Subject: [PATCH 06/14] Add Aidex --- .../nightscout/androidaps/utils/userEntry/UserEntryMapper.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt index fb667823e4..9f2333fbd9 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryMapper.kt @@ -109,6 +109,7 @@ class UserEntryMapper { Actions (UserEntry.Sources.Actions), Automation (UserEntry.Sources.Automation), BG (UserEntry.Sources.BG), + Aidex (UserEntry.Sources.Aidex), Dexcom (UserEntry.Sources.Dexcom), Eversense (UserEntry.Sources.Eversense), Glimp (UserEntry.Sources.Glimp), @@ -150,4 +151,4 @@ class UserEntryMapper { Unknown(UserEntry.Sources.Unknown) ; } -} \ No newline at end of file +} From 8d98e7005f0c02d718fb2569794042e884a7d209 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 29 Mar 2022 23:29:09 +0100 Subject: [PATCH 07/14] Add temp Aidex icon, will need updated --- .../androidaps/utils/userEntry/UserEntryPresentationHelper.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt index 0b1ac8a3a4..076a6626b6 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/userEntry/UserEntryPresentationHelper.kt @@ -63,6 +63,7 @@ class UserEntryPresentationHelper @Inject constructor( Sources.Actions -> R.drawable.ic_action Sources.Automation -> R.drawable.ic_automation Sources.BG -> R.drawable.ic_generic_cgm + Sources.Aidex -> R.drawable.ic_blooddrop_48 Sources.Dexcom -> R.drawable.ic_dexcom_g6 Sources.Eversense -> R.drawable.ic_eversense Sources.Glimp -> R.drawable.ic_glimp @@ -226,4 +227,4 @@ class UserEntryPresentationHelper @Inject constructor( private fun String.addWithSeparator(add: Any) = this + (if (this.isBlank()) "" else " / ") + add.toString() -} \ No newline at end of file +} From 831820275591c3cc382842e4f389735c580b993c Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 29 Mar 2022 23:30:30 +0100 Subject: [PATCH 08/14] Add Aidex --- .../info/nightscout/androidaps/database/entities/UserEntry.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt index 0b0db5bf82..f6c3d39234 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/UserEntry.kt @@ -139,6 +139,7 @@ data class UserEntry( Actions, //From Actions plugin Automation, //From Automation plugin BG, //From BG plugin => Add One Source per BG Source for Calibration or Sensor Change + Aidex, Dexcom, Eversense, Glimp, @@ -197,4 +198,4 @@ data class UserEntry( Pump, Aaps } -} \ No newline at end of file +} From 5ca545811775abec4f01f6ee91a04f281579e633 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Tue, 12 Apr 2022 23:24:35 +0100 Subject: [PATCH 09/14] - small text change --- .../info/nightscout/androidaps/plugins/source/AidexPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt index 05e795cfcb..d4cb82ce83 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/AidexPlugin.kt @@ -96,7 +96,7 @@ class AidexPlugin @Inject constructor( ) repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, emptyList(), null)) .doOnError { - aapsLogger.error(LTag.DATABASE, "Error while saving values from Xdrip", it) + aapsLogger.error(LTag.DATABASE, "Error while saving values from Aidex", it) ret = Result.failure(workDataOf("Error" to it.toString())) } .blockingGet() From b86a81bdffb36f5396dfce8691a4f6c7ab5b8e35 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 19 Apr 2022 01:19:54 +0100 Subject: [PATCH 10/14] merge upstream changes --- .../plugins/source/BGSourceFragment.kt | 128 ++++++++++++------ 1 file changed, 85 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index 00f3c57c25..ad6e0f867d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -1,10 +1,9 @@ package info.nightscout.androidaps.plugins.source -import android.graphics.Paint import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup +import android.util.SparseArray +import android.view.* +import androidx.core.util.forEach import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import dagger.android.support.DaggerFragment @@ -26,6 +25,7 @@ import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.utils.ActionModeHelper import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.T @@ -54,11 +54,10 @@ class BGSourceFragment : DaggerFragment() { private val disposable = CompositeDisposable() private val millsToThePast = T.hours(36).msecs() - + private lateinit var actionHelper: ActionModeHelper private var _binding: BgsourceFragmentBinding? = null - // This property is only valid between onCreateView and - // onDestroyView. + // This property is only valid between onCreateView and onDestroyView. private val binding get() = _binding!! override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = @@ -66,6 +65,10 @@ class BGSourceFragment : DaggerFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + actionHelper = ActionModeHelper(rh, activity) + actionHelper.setUpdateListHandler { binding.recyclerview.adapter?.notifyDataSetChanged() } + actionHelper.setOnRemoveHandler { removeSelected(it) } + setHasOptionsMenu(actionHelper.inMenu) binding.recyclerview.setHasFixedSize(true) binding.recyclerview.layoutManager = LinearLayoutManager(view.context) @@ -94,10 +97,21 @@ class BGSourceFragment : DaggerFragment() { @Synchronized override fun onPause() { + actionHelper.finish() disposable.clear() super.onPause() } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + super.onCreateOptionsMenu(menu, inflater) + actionHelper.onCreateOptionsMenu(menu, inflater) + } + + override fun onPrepareOptionsMenu(menu: Menu) { + super.onPrepareOptionsMenu(menu) + actionHelper.onPrepareOptionsMenu(menu) + } + @Synchronized override fun onDestroyView() { super.onDestroyView() @@ -105,6 +119,9 @@ class BGSourceFragment : DaggerFragment() { _binding = null } + override fun onOptionsItemSelected(item: MenuItem) = + actionHelper.onOptionsItemSelected(item) + inner class RecyclerViewAdapter internal constructor(private var glucoseValues: List) : RecyclerView.Adapter() { override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): GlucoseValuesViewHolder { @@ -116,59 +133,84 @@ class BGSourceFragment : DaggerFragment() { val glucoseValue = glucoseValues[position] holder.binding.ns.visibility = (glucoseValue.interfaceIDs.nightscoutId != null).toVisibility() holder.binding.invalid.visibility = (!glucoseValue.isValid).toVisibility() - val sameDayPrevious = position > 0 && dateUtil.isSameDay(glucoseValue.timestamp, glucoseValues[position-1].timestamp) - holder.binding.date.visibility = sameDayPrevious.not().toVisibility() - holder.binding.date.text = dateUtil.dateString(glucoseValue.timestamp) + val newDay = position == 0 || !dateUtil.isSameDay(glucoseValue.timestamp, glucoseValues[position - 1].timestamp) + holder.binding.date.visibility = newDay.toVisibility() + holder.binding.date.text = if (newDay) dateUtil.dateStringRelative(glucoseValue.timestamp, rh) else "" holder.binding.time.text = dateUtil.timeString(glucoseValue.timestamp) holder.binding.value.text = glucoseValue.valueToUnitsString(profileFunction.getUnits()) holder.binding.direction.setImageResource(glucoseValue.trendArrow.directionToIcon()) - holder.binding.remove.tag = glucoseValue if (position > 0) { val previous = glucoseValues[position - 1] val diff = previous.timestamp - glucoseValue.timestamp if (diff < T.secs(20).msecs()) - holder.binding.root.setBackgroundColor(rh.gc(R.color.errorAlertBackground)) + holder.binding.root.setBackgroundColor(rh.gac(context, R.attr.bgsourceError)) } + + holder.binding.root.setOnLongClickListener { + if (actionHelper.startRemove()) { + holder.binding.cbRemove.toggle() + actionHelper.updateSelection(position, glucoseValue, holder.binding.cbRemove.isChecked) + return@setOnLongClickListener true + } + false + } + holder.binding.root.setOnClickListener { + if (actionHelper.isRemoving) { + holder.binding.cbRemove.toggle() + actionHelper.updateSelection(position, glucoseValue, holder.binding.cbRemove.isChecked) + } + } + holder.binding.cbRemove.setOnCheckedChangeListener { _, value -> + actionHelper.updateSelection(position, glucoseValue, value) + } + holder.binding.cbRemove.isChecked = actionHelper.isSelected(position) + holder.binding.cbRemove.visibility = actionHelper.isRemoving.toVisibility() } - override fun getItemCount(): Int = glucoseValues.size + override fun getItemCount() = glucoseValues.size inner class GlucoseValuesViewHolder(view: View) : RecyclerView.ViewHolder(view) { val binding = BgsourceItemBinding.bind(view) + } + } - init { - binding.remove.paintFlags = binding.remove.paintFlags or Paint.UNDERLINE_TEXT_FLAG - binding.remove.setOnClickListener { v: View -> - val glucoseValue = v.tag as GlucoseValue - activity?.let { activity -> - val text = dateUtil.dateAndTimeString(glucoseValue.timestamp) + "\n" + glucoseValue.valueToUnitsString(profileFunction.getUnits()) - OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), text, Runnable { - val source = when ((activePlugin.activeBgSource as PluginBase).pluginDescription.pluginName) { - R.string.dexcom_app_patched -> Sources.Dexcom - R.string.eversense -> Sources.Eversense - R.string.Glimp -> Sources.Glimp - R.string.MM640g -> Sources.MM640g - R.string.nsclientbg -> Sources.NSClientSource - R.string.poctech -> Sources.PocTech - R.string.tomato -> Sources.Tomato - R.string.glunovo -> Sources.Glunovo - R.string.aidex -> Sources.Aidex - R.string.xdrip -> Sources.Xdrip - else -> Sources.Unknown - } - uel.log( - Action.BG_REMOVED, source, - ValueWithUnit.Timestamp(glucoseValue.timestamp) - ) - repository.runTransactionForResult(InvalidateGlucoseValueTransaction(glucoseValue.id)) - .doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating BG value", it) } - .blockingGet() - .also { result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated bg $it") } } - }) + private fun getConfirmationText(selectedItems: SparseArray): String { + if (selectedItems.size() == 1) { + val glucoseValue = selectedItems.valueAt(0) + return dateUtil.dateAndTimeString(glucoseValue.timestamp) + "\n" + glucoseValue.valueToUnitsString(profileFunction.getUnits()) + } + return rh.gs(R.string.confirm_remove_multiple_items, selectedItems.size()) + } + + private fun removeSelected(selectedItems: SparseArray) { + activity?.let { activity -> + OKDialog.showConfirmation(activity, rh.gs(R.string.removerecord), getConfirmationText(selectedItems), Runnable { + selectedItems.forEach { _, glucoseValue -> + val source = when ((activePlugin.activeBgSource as PluginBase).pluginDescription.pluginName) { + R.string.dexcom_app_patched -> Sources.Dexcom + R.string.eversense -> Sources.Eversense + R.string.Glimp -> Sources.Glimp + R.string.MM640g -> Sources.MM640g + R.string.nsclientbg -> Sources.NSClientSource + R.string.poctech -> Sources.PocTech + R.string.tomato -> Sources.Tomato + R.string.glunovo -> Sources.Glunovo + R.string.xdrip -> Sources.Xdrip + R.string.aidex -> Sources.Aidex + else -> Sources.Unknown } + uel.log( + Action.BG_REMOVED, source, + ValueWithUnit.Timestamp(glucoseValue.timestamp) + ) + repository.runTransactionForResult(InvalidateGlucoseValueTransaction(glucoseValue.id)) + .doOnError { aapsLogger.error(LTag.DATABASE, "Error while invalidating BG value", it) } + .blockingGet() + .also { result -> result.invalidated.forEach { aapsLogger.debug(LTag.DATABASE, "Invalidated bg $it") } } } - } + actionHelper.finish() + }) } } } From 6cdf242cd3e368c891aa5f8e77686cc815333a57 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 19 Apr 2022 01:29:31 +0100 Subject: [PATCH 11/14] Update BGSourceFragment.kt --- .../nightscout/androidaps/plugins/source/BGSourceFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index ad6e0f867d..264a999eb8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -197,7 +197,6 @@ class BGSourceFragment : DaggerFragment() { R.string.tomato -> Sources.Tomato R.string.glunovo -> Sources.Glunovo R.string.xdrip -> Sources.Xdrip - R.string.aidex -> Sources.Aidex else -> Sources.Unknown } uel.log( From 4b4f347463de1236890a01f06b9847cf40a7b8b2 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 19 Apr 2022 01:32:44 +0100 Subject: [PATCH 12/14] add aidex --- .../nightscout/androidaps/plugins/source/BGSourceFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index 264a999eb8..ad6e0f867d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -197,6 +197,7 @@ class BGSourceFragment : DaggerFragment() { R.string.tomato -> Sources.Tomato R.string.glunovo -> Sources.Glunovo R.string.xdrip -> Sources.Xdrip + R.string.aidex -> Sources.Aidex else -> Sources.Unknown } uel.log( From 5d052afc64d9f7f97863ece5faf5d1ac417472d7 Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 19 Apr 2022 01:38:19 +0100 Subject: [PATCH 13/14] Update BGSourceFragment.kt --- .../nightscout/androidaps/plugins/source/BGSourceFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index ad6e0f867d..264a999eb8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -197,7 +197,6 @@ class BGSourceFragment : DaggerFragment() { R.string.tomato -> Sources.Tomato R.string.glunovo -> Sources.Glunovo R.string.xdrip -> Sources.Xdrip - R.string.aidex -> Sources.Aidex else -> Sources.Unknown } uel.log( From 682e370eb68790056d864f6e45d467f7ea0aca4d Mon Sep 17 00:00:00 2001 From: Mark Breen Date: Tue, 19 Apr 2022 01:40:46 +0100 Subject: [PATCH 14/14] re-add aidex --- .../nightscout/androidaps/plugins/source/BGSourceFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt index 264a999eb8..ad6e0f867d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/BGSourceFragment.kt @@ -197,6 +197,7 @@ class BGSourceFragment : DaggerFragment() { R.string.tomato -> Sources.Tomato R.string.glunovo -> Sources.Glunovo R.string.xdrip -> Sources.Xdrip + R.string.aidex -> Sources.Aidex else -> Sources.Unknown } uel.log(