Wear plugin Move prediction setting from Phone to Watch

This commit is contained in:
Philoul 2023-09-05 19:14:38 +02:00
parent 06c1ab0ec3
commit 343045ca9b
7 changed files with 28 additions and 34 deletions

View file

@ -89,8 +89,7 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
override fun onBindViewHolder(holder: CwfFileViewHolder, position: Int) { override fun onBindViewHolder(holder: CwfFileViewHolder, position: Int) {
val customWatchfaceFile = customWatchfaceFileList[position] val customWatchfaceFile = customWatchfaceFileList[position]
val metadata = customWatchfaceFile.metadata val metadata = customWatchfaceFile.metadata
val drawable = customWatchfaceFile.resDatas[ResFileMap val drawable = customWatchfaceFile.resDatas[ResFileMap.CUSTOM_WATCHFACE]?.toDrawable(resources)
.CUSTOM_WATCHFACE]?.toDrawable(resources)
with(holder.customWatchfaceImportListItemBinding) { with(holder.customWatchfaceImportListItemBinding) {
filelistName.text = rh.gs(info.nightscout.shared.R.string.metadata_wear_import_filename, metadata[CWF_FILENAME]) filelistName.text = rh.gs(info.nightscout.shared.R.string.metadata_wear_import_filename, metadata[CWF_FILENAME])
filelistName.tag = customWatchfaceFile filelistName.tag = customWatchfaceFile

View file

@ -873,7 +873,7 @@ class DataHandlerMobile @Inject constructor(
repository.getCarbsDataFromTimeExpanded(startTimeWindow, true).blockingGet() repository.getCarbsDataFromTimeExpanded(startTimeWindow, true).blockingGet()
.forEach { (_, _, _, isValid, _, _, timestamp, _, _, amount) -> boluses.add(EventData.TreatmentData.Treatment(timestamp, 0.0, amount, false, isValid)) } .forEach { (_, _, _, isValid, _, _, timestamp, _, _, amount) -> boluses.add(EventData.TreatmentData.Treatment(timestamp, 0.0, amount, false, isValid)) }
val finalLastRun = loop.lastRun 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 val predArray = finalLastRun.constraintsProcessed!!.predictions
.stream().map { bg: GlucoseValue -> GlucoseValueDataPoint(bg, profileFunction, rh) } .stream().map { bg: GlucoseValue -> GlucoseValueDataPoint(bg, profileFunction, rh) }
.collect(Collectors.toList()) .collect(Collectors.toList())

View file

@ -353,12 +353,9 @@
<string name="wearcontrol_title">Controls from Watch</string> <string name="wearcontrol_title">Controls from Watch</string>
<string name="wearcontrol_summary">Set Temp-Targets and enter Treatments from the watch.</string> <string name="wearcontrol_summary">Set Temp-Targets and enter Treatments from the watch.</string>
<string name="wear_wizard_settings_summary">Calculations included in the Wizard result:</string> <string name="wear_wizard_settings_summary">Calculations included in the Wizard result:</string>
<string name="wear_display_settings">Display Settings</string>
<string name="wear_general_settings">General Settings</string> <string name="wear_general_settings">General Settings</string>
<string name="wear_notifysmb_title">Notify on SMB</string> <string name="wear_notifysmb_title">Notify on SMB</string>
<string name="wear_notifysmb_summary">Show SMB on the watch like a standard bolus.</string> <string name="wear_notifysmb_summary">Show SMB on the watch like a standard bolus.</string>
<string name="wear_predictions_summary">Show the predictions on the watchface.</string>
<string name="wear_predictions_title">Predictions</string>
<string name="wear_custom_watchface_settings">Custom Watchface Settings</string> <string name="wear_custom_watchface_settings">Custom Watchface Settings</string>
<string name="wear_custom_watchface_authorization_title">Custom Watchface Authorization</string> <string name="wear_custom_watchface_authorization_title">Custom Watchface Authorization</string>
<string name="wear_custom_watchface_authorization_summary">Authorize loaded custom watchface to change and lock some watch display settings to suit watchface design</string> <string name="wear_custom_watchface_authorization_summary">Authorize loaded custom watchface to change and lock some watch display settings to suit watchface design</string>
@ -384,7 +381,6 @@
<string name="hour_short">h</string> <string name="hour_short">h</string>
<string name="no_active_profile">No active profile switch!</string> <string name="no_active_profile">No active profile switch!</string>
<string name="profile_message">Profile:\n\nTimeshift: %1$d\nPercentage: %2$d%%\"</string> <string name="profile_message">Profile:\n\nTimeshift: %1$d\nPercentage: %2$d%%\"</string>
<string name="key_wear_predictions" translatable="false">wear_predictions</string>
<string name="tdd_line">%1$.2fU %1$.0f%%</string> <string name="tdd_line">%1$.2fU %1$.0f%%</string>
<string name="no_profile">No profile loaded</string> <string name="no_profile">No profile loaded</string>
<string name="aps_only">Only apply in APS mode!</string> <string name="aps_only">Only apply in APS mode!</string>

View file

@ -50,17 +50,6 @@
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory
android:title="@string/wear_display_settings">
<SwitchPreference
android:defaultValue="true"
android:key="wear_predictions"
android:summary="@string/wear_predictions_summary"
android:title="@string/wear_predictions_title" />
</PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:title="@string/wear_custom_watchface_settings"> android:title="@string/wear_custom_watchface_settings">

View file

@ -39,7 +39,6 @@ class BgGraphBuilder(
private val timeSpan: Int private val timeSpan: Int
) { ) {
private val predictionEndTime: Long
private var endingTime: Long = System.currentTimeMillis() + 1000L * 60 * 6 * timeSpan private var endingTime: Long = System.currentTimeMillis() + 1000L * 60 * 6 * timeSpan
private var startingTime: Long = System.currentTimeMillis() - 1000L * 60 * 60 * timeSpan private var startingTime: Long = System.currentTimeMillis() - 1000L * 60 * 60 * timeSpan
private var fuzzyTimeDiv = (1000 * 60 * 1).toDouble() private var fuzzyTimeDiv = (1000 * 60 * 1).toDouble()
@ -49,8 +48,19 @@ class BgGraphBuilder(
private val highValues: MutableList<PointValue> = ArrayList() private val highValues: MutableList<PointValue> = ArrayList()
private val lowValues: MutableList<PointValue> = ArrayList() private val lowValues: MutableList<PointValue> = 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 { init {
predictionEndTime = getPredictionEndTime() if (sp.getBoolean(R.string.key_prediction_lines, true))
endingTime = max(predictionEndTime, endingTime) endingTime = max(predictionEndTime, endingTime)
} }
@ -109,6 +119,7 @@ class BgGraphBuilder(
if (highlight) lines.add(tempValuesLine(twd, minChart.toFloat(), factor, true, 1)) if (highlight) lines.add(tempValuesLine(twd, minChart.toFloat(), factor, true, 1))
} }
} }
if (sp.getBoolean(R.string.key_prediction_lines, true))
addPredictionLines(lines) addPredictionLines(lines)
lines.add(basalLine(minChart.toFloat(), factor, highlight)) lines.add(basalLine(minChart.toFloat(), factor, highlight))
lines.add(bolusLine(minChart.toFloat())) lines.add(bolusLine(minChart.toFloat()))
@ -197,9 +208,8 @@ class BgGraphBuilder(
private fun addPredictionLines(lines: MutableList<Line>) { private fun addPredictionLines(lines: MutableList<Line>) {
val values: MutableMap<Int, MutableList<PointValue>> = HashMap() val values: MutableMap<Int, MutableList<PointValue>> = HashMap()
val endTime = getPredictionEndTime()
for ((timeStamp, _, _, _, _, _, _, _, _, sgv, _, _, color) in predictionsList) { for ((timeStamp, _, _, _, _, _, _, _, _, sgv, _, _, color) in predictionsList) {
if (timeStamp <= endTime) { if (timeStamp <= predictionEndTime) {
val value = min(sgv, UPPER_CUTOFF_SGV) val value = min(sgv, UPPER_CUTOFF_SGV)
if (!values.containsKey(color)) { if (!values.containsKey(color)) {
values[color] = ArrayList() values[color] = ArrayList()
@ -346,16 +356,6 @@ class BgGraphBuilder(
return xAxis 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 { private fun fuzz(value: Long): Float {
return (value / fuzzyTimeDiv).roundToLong().toFloat() return (value / fuzzyTimeDiv).roundToLong().toFloat()
} }

View file

@ -41,6 +41,7 @@
<string name="pref_show_ago">Show Ago</string> <string name="pref_show_ago">Show Ago</string>
<string name="pref_dark" comment="Enables dark visual theme">Dark</string> <string name="pref_dark" comment="Enables dark visual theme">Dark</string>
<string name="pref_highlight_basals">Highlight Basals</string> <string name="pref_highlight_basals">Highlight Basals</string>
<string name="pref_prediction_lines">Show predictions</string>
<string name="pref_matching_divider" comment="To make divider match its background with background of whole watchface">Matching divider</string> <string name="pref_matching_divider" comment="To make divider match its background with background of whole watchface">Matching divider</string>
<string name="pref_chart_timeframe">Chart Timeframe</string> <string name="pref_chart_timeframe">Chart Timeframe</string>
<string name="pref_1_hour">1 hour</string> <string name="pref_1_hour">1 hour</string>
@ -186,6 +187,7 @@
<string name="key_single_target" translatable="false">singletarget</string> <string name="key_single_target" translatable="false">singletarget</string>
<string name="key_wizard_percentage" translatable="false">wizardpercentage</string> <string name="key_wizard_percentage" translatable="false">wizardpercentage</string>
<string name="key_highlight_basals" translatable="false">highlight_basals</string> <string name="key_highlight_basals" translatable="false">highlight_basals</string>
<string name="key_prediction_lines" translatable="false">prediction_lines</string>
<string name="key_chart_time_frame" translatable="false">chart_time_frame</string> <string name="key_chart_time_frame" translatable="false">chart_time_frame</string>
<string name="key_show_week_number" translatable="false">show_week_number</string> <string name="key_show_week_number" translatable="false">show_week_number</string>
<string name="key_show_date" translatable="false">show_date</string> <string name="key_show_date" translatable="false">show_date</string>

View file

@ -118,6 +118,14 @@
app:wear_iconOff="@drawable/settings_off" app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" /> app:wear_iconOn="@drawable/settings_on" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/key_prediction_lines"
android:summary="show prediction lines"
android:title="@string/pref_prediction_lines"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on" />
<ListPreference <ListPreference
android:defaultValue="3" android:defaultValue="3"
android:entries="@array/chart_timeframe" android:entries="@array/chart_timeframe"