From 343045ca9b1f801a1ff3d38fd30f2fe531ce78f2 Mon Sep 17 00:00:00 2001 From: Philoul Date: Tue, 5 Sep 2023 19:14:38 +0200 Subject: [PATCH] Wear plugin Move prediction setting from Phone to Watch --- .../CustomWatchfaceImportListActivity.kt | 3 +- .../wear/wearintegration/DataHandlerMobile.kt | 2 +- plugins/main/src/main/res/values/strings.xml | 4 --- plugins/main/src/main/res/xml/pref_wear.xml | 11 ------- .../watchfaces/utils/BgGraphBuilder.kt | 32 +++++++++---------- wear/src/main/res/values/strings.xml | 2 ++ wear/src/main/res/xml/preferences.xml | 8 +++++ 7 files changed, 28 insertions(+), 34 deletions(-) diff --git a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt index 5fa86127b9..5c6ad810e5 100644 --- a/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt +++ b/plugins/configuration/src/main/java/info/nightscout/configuration/maintenance/activities/CustomWatchfaceImportListActivity.kt @@ -89,8 +89,7 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() { override fun onBindViewHolder(holder: CwfFileViewHolder, position: Int) { val customWatchfaceFile = customWatchfaceFileList[position] val metadata = customWatchfaceFile.metadata - val drawable = customWatchfaceFile.resDatas[ResFileMap - .CUSTOM_WATCHFACE]?.toDrawable(resources) + val drawable = customWatchfaceFile.resDatas[ResFileMap.CUSTOM_WATCHFACE]?.toDrawable(resources) with(holder.customWatchfaceImportListItemBinding) { filelistName.text = rh.gs(info.nightscout.shared.R.string.metadata_wear_import_filename, metadata[CWF_FILENAME]) filelistName.tag = customWatchfaceFile diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt index 1795f86514..dd75d51ed5 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/wearintegration/DataHandlerMobile.kt @@ -873,7 +873,7 @@ class DataHandlerMobile @Inject constructor( repository.getCarbsDataFromTimeExpanded(startTimeWindow, true).blockingGet() .forEach { (_, _, _, isValid, _, _, timestamp, _, _, amount) -> boluses.add(EventData.TreatmentData.Treatment(timestamp, 0.0, amount, false, isValid)) } val finalLastRun = loop.lastRun - if (sp.getBoolean(rh.gs(R.string.key_wear_predictions), true) && finalLastRun?.request?.hasPredictions == true && finalLastRun.constraintsProcessed != null) { + if (finalLastRun?.request?.hasPredictions == true && finalLastRun.constraintsProcessed != null) { val predArray = finalLastRun.constraintsProcessed!!.predictions .stream().map { bg: GlucoseValue -> GlucoseValueDataPoint(bg, profileFunction, rh) } .collect(Collectors.toList()) diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index d7b1619138..9f1b4c6556 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -353,12 +353,9 @@ Controls from Watch Set Temp-Targets and enter Treatments from the watch. Calculations included in the Wizard result: - Display Settings General Settings Notify on SMB Show SMB on the watch like a standard bolus. - Show the predictions on the watchface. - Predictions Custom Watchface Settings Custom Watchface Authorization Authorize loaded custom watchface to change and lock some watch display settings to suit watchface design @@ -384,7 +381,6 @@ h No active profile switch! Profile:\n\nTimeshift: %1$d\nPercentage: %2$d%%\" - wear_predictions %1$.2fU %1$.0f%% No profile loaded Only apply in APS mode! diff --git a/plugins/main/src/main/res/xml/pref_wear.xml b/plugins/main/src/main/res/xml/pref_wear.xml index 3d0378db49..2e4e682094 100644 --- a/plugins/main/src/main/res/xml/pref_wear.xml +++ b/plugins/main/src/main/res/xml/pref_wear.xml @@ -50,17 +50,6 @@ - - - - - - diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt index 02578086c3..0af955c525 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt @@ -39,7 +39,6 @@ class BgGraphBuilder( private val timeSpan: Int ) { - private val predictionEndTime: Long private var endingTime: Long = System.currentTimeMillis() + 1000L * 60 * 6 * timeSpan private var startingTime: Long = System.currentTimeMillis() - 1000L * 60 * 60 * timeSpan private var fuzzyTimeDiv = (1000 * 60 * 1).toDouble() @@ -49,9 +48,20 @@ class BgGraphBuilder( private val highValues: MutableList = ArrayList() private val lowValues: MutableList = ArrayList() + private val predictionEndTime: Long + get() { + var maxPredictionDate = System.currentTimeMillis() + for ((timeStamp) in predictionsList) { + if (maxPredictionDate < timeStamp) { + maxPredictionDate = timeStamp + } + } + return min(maxPredictionDate.toDouble(), System.currentTimeMillis() + MAX_PREDICTION__TIME_RATIO * timeSpan * 1000 * 60 * 60).toLong() + } + init { - predictionEndTime = getPredictionEndTime() - endingTime = max(predictionEndTime, endingTime) + if (sp.getBoolean(R.string.key_prediction_lines, true)) + endingTime = max(predictionEndTime, endingTime) } //used for low resolution screen. @@ -109,7 +119,8 @@ class BgGraphBuilder( if (highlight) lines.add(tempValuesLine(twd, minChart.toFloat(), factor, true, 1)) } } - addPredictionLines(lines) + if (sp.getBoolean(R.string.key_prediction_lines, true)) + addPredictionLines(lines) lines.add(basalLine(minChart.toFloat(), factor, highlight)) lines.add(bolusLine(minChart.toFloat())) lines.add(bolusInvalidLine(minChart.toFloat())) @@ -197,9 +208,8 @@ class BgGraphBuilder( private fun addPredictionLines(lines: MutableList) { val values: MutableMap> = HashMap() - val endTime = getPredictionEndTime() for ((timeStamp, _, _, _, _, _, _, _, _, sgv, _, _, color) in predictionsList) { - if (timeStamp <= endTime) { + if (timeStamp <= predictionEndTime) { val value = min(sgv, UPPER_CUTOFF_SGV) if (!values.containsKey(color)) { values[color] = ArrayList() @@ -346,16 +356,6 @@ class BgGraphBuilder( return xAxis } - private fun getPredictionEndTime(): Long { - var maxPredictionDate = System.currentTimeMillis() - for ((timeStamp) in predictionsList) { - if (maxPredictionDate < timeStamp) { - maxPredictionDate = timeStamp - } - } - return min(maxPredictionDate.toDouble(), System.currentTimeMillis() + MAX_PREDICTION__TIME_RATIO * timeSpan * 1000 * 60 * 60).toLong() - } - private fun fuzz(value: Long): Float { return (value / fuzzyTimeDiv).roundToLong().toFloat() } diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index 6011568759..02d4feb90a 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -41,6 +41,7 @@ Show Ago Dark Highlight Basals + Show predictions Matching divider Chart Timeframe 1 hour @@ -186,6 +187,7 @@ singletarget wizardpercentage highlight_basals + prediction_lines chart_time_frame show_week_number show_date diff --git a/wear/src/main/res/xml/preferences.xml b/wear/src/main/res/xml/preferences.xml index 47f0122a3b..cd6bfbb80b 100644 --- a/wear/src/main/res/xml/preferences.xml +++ b/wear/src/main/res/xml/preferences.xml @@ -118,6 +118,14 @@ app:wear_iconOff="@drawable/settings_off" app:wear_iconOn="@drawable/settings_on" /> + +