From 1dd579fd1934d1241566992a45b0267d4b2d663f Mon Sep 17 00:00:00 2001 From: Philoul Date: Fri, 15 May 2020 11:37:09 +0200 Subject: [PATCH 01/16] Add disable vibration in insight settings (local_full only) Build works but as it related to pump communication, I prefer to not test it on my pump before Tebbe confirmation... (code is very simple, so it should work!) --- .../plugins/pump/insight/LocalInsightPlugin.java | 2 ++ .../app_layer/remote_control/DeliverBolusMessage.java | 9 ++++++++- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_insight_local_full.xml | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index f8d1cf1ce5..51c6337df1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -597,6 +597,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, bolusMessage.setDuration(0); bolusMessage.setExtendedAmount(0); bolusMessage.setImmediateAmount(insulin); + bolusMessage.setVibration(sp.getBoolean("insight_disable_vibration",false)); bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); bolusCancelled = false; } @@ -820,6 +821,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, bolusMessage.setDuration(durationInMinutes); bolusMessage.setExtendedAmount(insulin); bolusMessage.setImmediateAmount(0); + bolusMessage.setVibration(sp.getBoolean("insight_disable_vibration",false)); int bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); InsightBolusID insightBolusID = new InsightBolusID(); insightBolusID.bolusID = bolusID; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java index e0d0f2461a..6a4973b42b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/app_layer/remote_control/DeliverBolusMessage.java @@ -14,6 +14,7 @@ public class DeliverBolusMessage extends AppLayerMessage { private double extendedAmount; private int duration; private int bolusId; + private boolean disableVibration = false; public DeliverBolusMessage() { super(MessagePriority.NORMAL, true, true, Service.REMOTE_CONTROL); @@ -22,7 +23,11 @@ public class DeliverBolusMessage extends AppLayerMessage { @Override protected ByteBuf getData() { ByteBuf byteBuf = new ByteBuf(22); - byteBuf.putUInt16LE(252); + // 805 => Old value with vibration (2.6.1 and earlier), 252 => new value without vibrations for firmware 3.x + if (disableVibration) + byteBuf.putUInt16LE(252); + else + byteBuf.putUInt16LE(805); byteBuf.putUInt16LE(BolusTypeIDs.IDS.getID(bolusType)); byteBuf.putUInt16LE(31); byteBuf.putUInt16LE(0); @@ -57,6 +62,8 @@ public class DeliverBolusMessage extends AppLayerMessage { this.duration = duration; } + public void setVibration(boolean disableVibration) { this.disableVibration = disableVibration;} + public int getBolusId() { return bolusId; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4a4595fab4..8033c82057 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1016,6 +1016,8 @@ Log alerts Enable TBR emulation Use extended boluses instead of TBRs to bypass the 250%% limit + Disable vibrations on bolus delivery + This setting is only available with Insight firmware 3.x Disconnect delay [s] Serial number Release software version diff --git a/app/src/main/res/xml/pref_insight_local_full.xml b/app/src/main/res/xml/pref_insight_local_full.xml index ceaba15e38..761016b287 100644 --- a/app/src/main/res/xml/pref_insight_local_full.xml +++ b/app/src/main/res/xml/pref_insight_local_full.xml @@ -48,6 +48,12 @@ android:summary="@string/enable_tbr_emulation_summary" android:title="@string/enable_tbr_emulation" /> + + Date: Thu, 21 May 2020 00:09:31 +1200 Subject: [PATCH 02/16] Add required functions --- .../info/nightscout/androidaps/data/Profile.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/src/main/java/info/nightscout/androidaps/data/Profile.java b/core/src/main/java/info/nightscout/androidaps/data/Profile.java index 4aaa5848fb..972730ca3d 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/core/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -523,13 +523,28 @@ public class Profile { return ret; } + public double getTargetUnits() { + if (units.equals(Constants.MGDL)) { + return getTargetMgdl(secondsFromMidnight()); + } else { + return getTargetMmol(secondsFromMidnight()); + } + } + public double getTargetMgdl() { return getTargetMgdl(secondsFromMidnight()); } + public double getTargetMmol() { + return getTargetMmol(secondsFromMidnight()); + } + public double getTargetMgdl(int timeAsSeconds) { return toMgdl((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); } + public double getTargetMmol(int timeAsSeconds) { + return toMmol((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); + } public double getTargetLowMgdl() { return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight()), units); From 3c2d5ff3d6d67676a7a6fef22268be1609be51be Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 00:10:16 +1200 Subject: [PATCH 03/16] Add targetBG --- app/src/main/assets/OpenAPSSMB/determine-basal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/OpenAPSSMB/determine-basal.js b/app/src/main/assets/OpenAPSSMB/determine-basal.js index 00a9c1d0a2..fbc0a4de9f 100644 --- a/app/src/main/assets/OpenAPSSMB/determine-basal.js +++ b/app/src/main/assets/OpenAPSSMB/determine-basal.js @@ -407,6 +407,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ , 'bg': bg , 'tick': tick , 'eventualBG': eventualBG + , 'targetBG': target_bg , 'insulinReq': 0 , 'reservoir' : reservoir_data // The expected reservoir volume at which to deliver the microbolus (the reservoir volume from right before the last pumphistory run) , 'deliverAt' : deliverAt // The time at which the microbolus should be delivered From a20008c0dbb6035c025808257ad80fdd9bfed83c Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 00:10:51 +1200 Subject: [PATCH 04/16] Add TargetBG --- .../plugins/aps/openAPSSMB/DetermineBasalResultSMB.java | 3 +++ .../info/nightscout/androidaps/plugins/aps/loop/APSResult.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java index dae170d5d9..f8f72c6c87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java @@ -51,6 +51,9 @@ public class DetermineBasalResultSMB extends APSResult { } else { smb = 0d; } + if (result.has("targetBG")) { + targetBG = result.getDouble("targetBG"); + } if (result.has("deliverAt")) { String date = result.getString("deliverAt"); diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java b/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java index 84ab8e5661..359ed88560 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java +++ b/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java @@ -62,6 +62,7 @@ public class APSResult { public boolean hasPredictions = false; public double smb = 0d; // super micro bolus in units public long deliverAt = 0; + public double targetBG = 0d; public Constraint inputConstraints; @@ -184,6 +185,7 @@ public class APSResult { newResult.smbConstraint = smbConstraint; newResult.percent = percent; newResult.usePercent = usePercent; + newResult.targetBG = targetBG; } From 77a5af75e22f5115b637404606057b926361a16c Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 00:11:36 +1200 Subject: [PATCH 05/16] Display when Target BG is overidden --- .../general/overview/OverviewFragment.kt | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 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 93c112f745..d3038090b6 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 @@ -646,6 +646,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } else { overview_apsmode_text?.visibility = View.GONE } + val lastRun = loopPlugin.lastRun // temp target val tempTarget = treatmentsPlugin.tempTargetFromHistory @@ -654,9 +655,27 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning)) overview_temptarget?.text = Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end(), resourceHelper) } else { - overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) - overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) - overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) + //If the target is not the same as set in the profile then oref has overridden it + //show this change to the user if it exists + if (lastRun != null){ + var targetused = lastRun!!.constraintsProcessed!!.targetBG + if (units == Constants.MMOL) + targetused *= Constants.MGDL_TO_MMOLL + + if (profile.targetUnits != targetused) { + overview_temptarget?.text = targetused.toString() + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) + }else{ + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) + overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) + } + }else { + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) + overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) + } } // Basal, TBR @@ -741,7 +760,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } overview_cob?.text = cobText - val lastRun = loopPlugin.lastRun val predictionsAvailable = if (config.APS) lastRun?.request?.hasPredictions == true else config.NSCLIENT // pump status from ns From 723c0292289ee4c441ec5d9b94ac245cdb57ef1a Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 02:20:38 +1200 Subject: [PATCH 06/16] Deal with 0.0 if AMA is used --- .../plugins/general/overview/OverviewFragment.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 d3038090b6..547dc3d85b 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 @@ -657,8 +657,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } else { //If the target is not the same as set in the profile then oref has overridden it //show this change to the user if it exists - if (lastRun != null){ - var targetused = lastRun!!.constraintsProcessed!!.targetBG + var targetused = lastRun?.constraintsProcessed?.targetBG + if (targetused != null && targetused != 0.0) { if (units == Constants.MMOL) targetused *= Constants.MGDL_TO_MMOLL @@ -666,12 +666,12 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_temptarget?.text = targetused.toString() overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) - }else{ + } else { overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) } - }else { + } else { overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) @@ -696,7 +696,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList if (activeTemp != null) overview_basebasal_icon.setImageResource(if (activeTemp.tempBasalConvertedToPercent(System.currentTimeMillis(), profile) > 100) R.drawable.icon_cp_basal_tbr_high else R.drawable.icon_cp_basal_tbr_low) else - overview_basebasal_icon.setImageResource( R.drawable.icon_cp_basal_no_tbr ) + overview_basebasal_icon.setImageResource(R.drawable.icon_cp_basal_no_tbr) // Extended bolus val extendedBolus = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) @@ -777,7 +777,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // Sensitivity if (sp.getBoolean(R.string.key_openapsama_useautosens, false) && constraintChecker.isAutosensModeEnabled().value()) { overview_sensitivity_icon.setImageResource(R.drawable.ic_swap_vert_black_48dp_green) - }else { + } else { overview_sensitivity_icon.setImageResource(R.drawable.ic_x_swap_vert_48px_green) } From bf412ea798c85488fe28d62c7b69a312f3fae2a6 Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 04:19:22 +1200 Subject: [PATCH 07/16] refractor --- .../androidaps/plugins/general/overview/OverviewFragment.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 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 547dc3d85b..3891ba6b7e 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 @@ -659,11 +659,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList //show this change to the user if it exists var targetused = lastRun?.constraintsProcessed?.targetBG if (targetused != null && targetused != 0.0) { - if (units == Constants.MMOL) - targetused *= Constants.MGDL_TO_MMOLL - if (profile.targetUnits != targetused) { - overview_temptarget?.text = targetused.toString() + if (((profile.targetLowMgdl+profile.targetHighMgdl)/2)!= targetused) { + overview_temptarget?.text = Profile.toTargetRangeString(targetused, targetused, Constants.MGDL, units) overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) } else { From 06e97400f7fe07ddfbe327c0cef93316c0826d8f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 20 May 2020 22:34:09 +0200 Subject: [PATCH 08/16] Simplify show-targets view logic --- .../general/overview/OverviewFragment.kt | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 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 3891ba6b7e..c9ea872345 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 @@ -655,20 +655,13 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning)) overview_temptarget?.text = Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end(), resourceHelper) } else { - //If the target is not the same as set in the profile then oref has overridden it - //show this change to the user if it exists - var targetused = lastRun?.constraintsProcessed?.targetBG - if (targetused != null && targetused != 0.0) { + // If the target is not the same as set in the profile then oref has overridden it + val targetUsed = lastRun?.constraintsProcessed?.targetBG ?: 0.0 - if (((profile.targetLowMgdl+profile.targetHighMgdl)/2)!= targetused) { - overview_temptarget?.text = Profile.toTargetRangeString(targetused, targetused, Constants.MGDL, units) - overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) - overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) - } else { - overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) - overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) - overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) - } + if (targetUsed != 0.0 && profile.targetMgdl != targetUsed) { + overview_temptarget?.text = Profile.toTargetRangeString(targetUsed, targetUsed, Constants.MGDL, units) + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) } else { overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) @@ -899,4 +892,4 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } } } -} \ No newline at end of file +} From 87782377a58f4b0f98d8e060e2deab31f4d2e930 Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 10:21:37 +1200 Subject: [PATCH 09/16] Remove not needed functions --- .../info/nightscout/androidaps/data/Profile.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/data/Profile.java b/core/src/main/java/info/nightscout/androidaps/data/Profile.java index 972730ca3d..21eb288c09 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/core/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -523,29 +523,13 @@ public class Profile { return ret; } - public double getTargetUnits() { - if (units.equals(Constants.MGDL)) { - return getTargetMgdl(secondsFromMidnight()); - } else { - return getTargetMmol(secondsFromMidnight()); - } - } - public double getTargetMgdl() { return getTargetMgdl(secondsFromMidnight()); } - public double getTargetMmol() { - return getTargetMmol(secondsFromMidnight()); - } - public double getTargetMgdl(int timeAsSeconds) { return toMgdl((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); } - public double getTargetMmol(int timeAsSeconds) { - return toMmol((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); - } - public double getTargetLowMgdl() { return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight()), units); } From 72943a5236fd6e7ffdb93f7ac235df7c385076a9 Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Fri, 22 May 2020 11:08:01 +1200 Subject: [PATCH 10/16] Add back setting adjustment --- .../plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java index 6b5f5363b0..8b894e8579 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalAdapterSMBJS.java @@ -259,8 +259,8 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("low_temptarget_lowers_sensitivity", false); - mProfile.put("sensitivity_raises_target", SMBDefaults.sensitivity_raises_target); - mProfile.put("resistance_lowers_target", SMBDefaults.resistance_lowers_target); + mProfile.put("sensitivity_raises_target", sp.getBoolean(resourceHelper.gs(R.string.key_sensitivity_raises_target),SMBDefaults.sensitivity_raises_target)); + mProfile.put("resistance_lowers_target", sp.getBoolean(resourceHelper.gs(R.string.key_resistance_lowers_target),SMBDefaults.resistance_lowers_target)); mProfile.put("adv_target_adjustments", SMBDefaults.adv_target_adjustments); mProfile.put("exercise_mode", SMBDefaults.exercise_mode); mProfile.put("half_basal_exercise_target", SMBDefaults.half_basal_exercise_target); From d40188f04e429283e17b2653ab2b2c363b53805d Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 23 May 2020 15:39:05 +0200 Subject: [PATCH 11/16] Default language option --- .../nightscout/androidaps/MainActivity.kt | 2 +- .../info/nightscout/androidaps/MainApp.java | 2 +- .../activities/PreferencesActivity.kt | 2 +- .../activities/SingleFragmentActivity.kt | 2 +- .../activities/PrefImportListActivity.kt | 2 +- .../androidaps/setupwizard/SWDefinition.kt | 2 +- .../setupwizard/SetupWizardActivity.kt | 2 +- .../androidaps/utils/JSONFormatter.java | 25 ++++--------- app/src/main/res/values/arrays.xml | 2 + app/src/main/res/values/strings.xml | 1 + .../activities/DialogAppCompatActivity.kt | 2 +- .../activities/NoSplashAppCompatActivity.kt | 2 +- .../androidaps/events/EventRebuildTabs.kt | 2 +- .../nightscout/androidaps/utils/HtmlHelper.kt | 7 +--- .../androidaps/utils/locale/LocaleHelper.kt | 37 ++++++++++--------- 15 files changed, 40 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt index c78aaedaf5..f25cf49fc9 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.kt @@ -49,7 +49,7 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicato import info.nightscout.androidaps.setupwizard.SetupWizardActivity import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.LocaleHelper +import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.alertDialogs.OKDialog import info.nightscout.androidaps.utils.buildHelper.BuildHelper import info.nightscout.androidaps.utils.extensions.isRunningRealPumpTest diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 126ba47d22..6b78a50599 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -37,7 +37,7 @@ import info.nightscout.androidaps.receivers.NetworkChangeReceiver; import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver; import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.utils.ActivityMonitor; -import info.nightscout.androidaps.utils.LocaleHelper; +import info.nightscout.androidaps.utils.locale.LocaleHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; public class MainApp extends DaggerApplication { diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt index ad3961c883..ea90f4b250 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.kt @@ -5,7 +5,7 @@ import android.os.Bundle import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceScreen import info.nightscout.androidaps.R -import info.nightscout.androidaps.utils.LocaleHelper +import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject diff --git a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt index 9e62f16c97..0193b690a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/SingleFragmentActivity.kt @@ -9,7 +9,7 @@ import dagger.android.support.DaggerAppCompatActivity import info.nightscout.androidaps.R import info.nightscout.androidaps.interfaces.PluginBase import info.nightscout.androidaps.plugins.configBuilder.PluginStore -import info.nightscout.androidaps.utils.LocaleHelper +import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.protection.ProtectionCheck import javax.inject.Inject diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt index 7703166d04..6be8b5e020 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/activities/PrefImportListActivity.kt @@ -19,7 +19,7 @@ import info.nightscout.androidaps.plugins.general.maintenance.PrefsFileContract import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefsFormatsHandler import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefsMetadataKey import info.nightscout.androidaps.plugins.general.maintenance.formats.PrefsStatus -import info.nightscout.androidaps.utils.LocaleHelper +import info.nightscout.androidaps.utils.locale.LocaleHelper import info.nightscout.androidaps.utils.resources.ResourceHelper import kotlinx.android.synthetic.main.maintenance_importlist_activity.* import javax.inject.Inject diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index c8e406881b..d0f8c29138 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -34,7 +34,7 @@ import info.nightscout.androidaps.setupwizard.elements.* import info.nightscout.androidaps.setupwizard.events.EventSWUpdate import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.CryptoUtil -import info.nightscout.androidaps.utils.LocaleHelper.update +import info.nightscout.androidaps.utils.locale.LocaleHelper.update import info.nightscout.androidaps.utils.extensions.isRunningTest import info.nightscout.androidaps.utils.protection.ProtectionCheck import info.nightscout.androidaps.utils.resources.ResourceHelper diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt index b265af0d4c..44af0e1312 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SetupWizardActivity.kt @@ -20,7 +20,7 @@ import info.nightscout.androidaps.setupwizard.elements.SWItem import info.nightscout.androidaps.setupwizard.events.EventSWUpdate import info.nightscout.androidaps.utils.AndroidPermission import info.nightscout.androidaps.utils.FabricPrivacy -import info.nightscout.androidaps.utils.LocaleHelper.update +import info.nightscout.androidaps.utils.locale.LocaleHelper.update import info.nightscout.androidaps.utils.alertDialogs.OKDialog.show import info.nightscout.androidaps.utils.alertDialogs.OKDialog.showConfirmation import info.nightscout.androidaps.utils.resources.ResourceHelper diff --git a/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.java b/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.java index 9b754ac47a..db1f6af239 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/JSONFormatter.java @@ -1,6 +1,5 @@ package info.nightscout.androidaps.utils; -import android.os.Build; import android.text.Html; import android.text.Spanned; @@ -8,7 +7,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Iterator; @@ -24,33 +22,24 @@ public class JSONFormatter { final JsonVisitor visitor = new JsonVisitor(1, '\t'); try { if (jsonString.equals("undefined")) - return Html.fromHtml("undefined"); + return HtmlHelper.INSTANCE.fromHtml("undefined"); else if (jsonString.getBytes()[0] == '[') - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return Html.fromHtml(visitor.visit(new JSONArray(jsonString), 0), Html.FROM_HTML_MODE_COMPACT); - } else { - return Html.fromHtml(visitor.visit(new JSONArray(jsonString), 0)); - } - else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0), Html.FROM_HTML_MODE_COMPACT); - } else { - return Html.fromHtml(visitor.visit(new JSONObject(jsonString), 0)); - } - } + return HtmlHelper.INSTANCE.fromHtml(visitor.visit(new JSONArray(jsonString), 0)); + else + return HtmlHelper.INSTANCE.fromHtml(visitor.visit(new JSONObject(jsonString), 0)); } catch (JSONException e) { log.error("Unhandled exception", e); - return Html.fromHtml(""); + return HtmlHelper.INSTANCE.fromHtml(""); } } public static Spanned format(final JSONObject object) { final JsonVisitor visitor = new JsonVisitor(1, '\t'); try { - return Html.fromHtml(visitor.visit(object, 0)); + return HtmlHelper.INSTANCE.fromHtml(visitor.visit(object, 0)); } catch (JSONException e) { log.error("Unhandled exception", e); - return Html.fromHtml(""); + return HtmlHelper.INSTANCE.fromHtml(""); } } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 7ca80a7af9..0d8f4134a1 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -22,6 +22,7 @@ + @string/default_lang @string/en_lang @string/af_lang @string/bg_lang @@ -45,6 +46,7 @@ @string/zh_lang + default en af bg diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4a4595fab4..140c3310cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ + System default English Czech Afrikaans diff --git a/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt index e2aa70d960..14f941a422 100644 --- a/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt +++ b/core/src/main/java/info/nightscout/androidaps/activities/DialogAppCompatActivity.kt @@ -2,7 +2,7 @@ package info.nightscout.androidaps.activities import android.content.Context import dagger.android.support.DaggerAppCompatActivity -import info.nightscout.androidaps.utils.LocaleHelper +import info.nightscout.androidaps.utils.locale.LocaleHelper open class DialogAppCompatActivity : DaggerAppCompatActivity() { public override fun attachBaseContext(newBase: Context) { diff --git a/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt b/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt index 060f1a8c2e..6ded8b95b5 100644 --- a/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt +++ b/core/src/main/java/info/nightscout/androidaps/activities/NoSplashAppCompatActivity.kt @@ -4,7 +4,7 @@ import android.content.Context import android.os.Bundle import dagger.android.support.DaggerAppCompatActivity import info.nightscout.androidaps.core.R -import info.nightscout.androidaps.utils.LocaleHelper +import info.nightscout.androidaps.utils.locale.LocaleHelper //@Suppress("registered") open class NoSplashAppCompatActivity : DaggerAppCompatActivity() { diff --git a/core/src/main/java/info/nightscout/androidaps/events/EventRebuildTabs.kt b/core/src/main/java/info/nightscout/androidaps/events/EventRebuildTabs.kt index aa0db3467a..3d4180f29f 100644 --- a/core/src/main/java/info/nightscout/androidaps/events/EventRebuildTabs.kt +++ b/core/src/main/java/info/nightscout/androidaps/events/EventRebuildTabs.kt @@ -1,3 +1,3 @@ package info.nightscout.androidaps.events -class EventRebuildTabs @JvmOverloads constructor(var recreate: Boolean = false) : Event() +class EventRebuildTabs constructor(var recreate: Boolean = false) : Event() diff --git a/core/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.kt index b79fe884b4..dd0da3b72f 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/HtmlHelper.kt @@ -6,11 +6,6 @@ import android.text.Spanned object HtmlHelper { fun fromHtml(source: String): Spanned { - // API level 24 to replace call - @Suppress("DEPRECATION") - return when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY) - else -> Html.fromHtml(source) - } + return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY) } } \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/utils/locale/LocaleHelper.kt b/core/src/main/java/info/nightscout/androidaps/utils/locale/LocaleHelper.kt index 7180bf7927..d7bc0a8ce5 100644 --- a/core/src/main/java/info/nightscout/androidaps/utils/locale/LocaleHelper.kt +++ b/core/src/main/java/info/nightscout/androidaps/utils/locale/LocaleHelper.kt @@ -1,22 +1,23 @@ -package info.nightscout.androidaps.utils +package info.nightscout.androidaps.utils.locale import android.content.Context import android.content.ContextWrapper -import android.os.Build import android.os.LocaleList import androidx.preference.PreferenceManager import info.nightscout.androidaps.core.R import java.util.* object LocaleHelper { - private fun currentLanguage(context: Context): String = - PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.key_language), "en") - ?: "en" + private fun selectedLanguage(context: Context): String = + PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.key_language), "default") + ?: "default" // injection not possible because of use in attachBaseContext //SP.getString(R.string.key_language, Locale.getDefault().language) private fun currentLocale(context: Context): Locale { - val language = currentLanguage(context) + val language = selectedLanguage(context) + if (language == "default") return Locale.getDefault() + var locale = Locale(language) if (language.contains("_")) { // language with country like pt_BR defined in arrays.xml @@ -27,8 +28,10 @@ object LocaleHelper { return locale } - @Suppress("DEPRECATION") fun update(context: Context) { + // no action for system default language + if (selectedLanguage(context) == "default") return + val locale = currentLocale(context) Locale.setDefault(locale) val resources = context.resources @@ -39,20 +42,18 @@ object LocaleHelper { resources.updateConfiguration(configuration, resources.displayMetrics) } - fun wrap(ctx: Context): ContextWrapper { + fun wrap(ctx: Context): Context { + // no action for system default language + if (selectedLanguage(ctx) == "default") return ctx + val res = ctx.resources val configuration = res.configuration val newLocale = currentLocale(ctx) - val context = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - configuration.setLocale(newLocale) - val localeList = LocaleList(newLocale) - LocaleList.setDefault(localeList) - configuration.locales = localeList - ctx.createConfigurationContext(configuration) - } else { - configuration.setLocale(newLocale) - ctx.createConfigurationContext(configuration) - } + configuration.setLocale(newLocale) + val localeList = LocaleList(newLocale) + LocaleList.setDefault(localeList) + configuration.locales = localeList + val context = ctx.createConfigurationContext(configuration) return ContextWrapper(context) } } \ No newline at end of file From 4f41890add4b00dca59abffee5edad8068840c78 Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 23 May 2020 16:30:03 +0200 Subject: [PATCH 12/16] Add additionnal setting for automated deliveries and add both in pumpcontrol pref - previous setting is for manual bolus and extended bolus - This new setting is for SMB and temp basal with TBR emulation You can change settings name and summary if you find better... --- .../plugins/pump/insight/LocalInsightPlugin.java | 11 ++++++----- app/src/main/res/values/strings.xml | 8 ++++++-- app/src/main/res/xml/pref_insight_local_full.xml | 8 +++++++- .../main/res/xml/pref_insight_local_pumpcontrol.xml | 12 ++++++++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index 51c6337df1..1b4e537f0c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -597,7 +597,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, bolusMessage.setDuration(0); bolusMessage.setExtendedAmount(0); bolusMessage.setImmediateAmount(insulin); - bolusMessage.setVibration(sp.getBoolean("insight_disable_vibration",false)); + bolusMessage.setVibration(sp.getBoolean(detailedBolusInfo.isSMB ? R.string.key_disable_vibration_auto : R.string.key_disable_vibration ,false)); bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); bolusCancelled = false; } @@ -721,7 +721,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, PumpEnactResult cancelTBRResult = cancelTempBasalOnly(); if (cancelTBRResult.success) { PumpEnactResult ebResult = setExtendedBolusOnly((absoluteRate - getBaseBasalRate()) / 60D - * ((double) durationInMinutes), durationInMinutes); + * ((double) durationInMinutes), durationInMinutes, + sp.getBoolean(R.string.key_disable_vibration_auto,false)); if (ebResult.success) { result.success = true; result.enacted = true; @@ -799,7 +800,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, @NonNull @Override public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) { PumpEnactResult result = cancelExtendedBolusOnly(); - if (result.success) result = setExtendedBolusOnly(insulin, durationInMinutes); + if (result.success) result = setExtendedBolusOnly(insulin, durationInMinutes, sp.getBoolean(R.string.key_disable_vibration,false)); try { fetchStatus(); readHistory(); @@ -813,7 +814,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, return result; } - public PumpEnactResult setExtendedBolusOnly(Double insulin, Integer durationInMinutes) { + public PumpEnactResult setExtendedBolusOnly(Double insulin, Integer durationInMinutes, boolean disableVibration) { PumpEnactResult result = new PumpEnactResult(getInjector()); try { DeliverBolusMessage bolusMessage = new DeliverBolusMessage(); @@ -821,7 +822,7 @@ public class LocalInsightPlugin extends PumpPluginBase implements PumpInterface, bolusMessage.setDuration(durationInMinutes); bolusMessage.setExtendedAmount(insulin); bolusMessage.setImmediateAmount(0); - bolusMessage.setVibration(sp.getBoolean("insight_disable_vibration",false)); + bolusMessage.setVibration(disableVibration); int bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); InsightBolusID insightBolusID = new InsightBolusID(); insightBolusID.bolusID = bolusID; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8033c82057..c9530266e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1016,8 +1016,12 @@ Log alerts Enable TBR emulation Use extended boluses instead of TBRs to bypass the 250%% limit - Disable vibrations on bolus delivery - This setting is only available with Insight firmware 3.x + insight_disable_vibration + Disable vibrations on manual bolus delivery + For bolus and extended bolus (only available with Insight firmware 3.x) + insight_disable_vibration_auto + Disable vibrations on automated bolus delivery + For SMB and Temp Basal with TBR emulation (only available with Insight firmware 3.x) Disconnect delay [s] Serial number Release software version diff --git a/app/src/main/res/xml/pref_insight_local_full.xml b/app/src/main/res/xml/pref_insight_local_full.xml index 761016b287..820c12d422 100644 --- a/app/src/main/res/xml/pref_insight_local_full.xml +++ b/app/src/main/res/xml/pref_insight_local_full.xml @@ -50,10 +50,16 @@ + + + + + + Date: Sat, 23 May 2020 17:49:49 +0200 Subject: [PATCH 13/16] Update pref_insight_local_pumpcontrol.xml --- app/src/main/res/xml/pref_insight_local_pumpcontrol.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/src/main/res/xml/pref_insight_local_pumpcontrol.xml b/app/src/main/res/xml/pref_insight_local_pumpcontrol.xml index d40a48e1d0..a863e56757 100644 --- a/app/src/main/res/xml/pref_insight_local_pumpcontrol.xml +++ b/app/src/main/res/xml/pref_insight_local_pumpcontrol.xml @@ -54,12 +54,6 @@ android:summary="@string/disable_vibration_summary" android:title="@string/disable_vibration" /> - - Date: Sat, 23 May 2020 21:54:01 +0200 Subject: [PATCH 14/16] nsalarm notifications fix --- .../general/nsclient/data/NSDeviceStatus.java | 2 +- .../nsclient/services/NSClientService.java | 47 +++++++++++-------- .../notifications/NotificationWithAction.kt | 7 +-- app/src/main/res/values/strings.xml | 16 ++----- .../main/res/xml/pref_nsclientinternal.xml | 30 ++---------- 5 files changed, 39 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java index 7195435515..757692e655 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.java @@ -331,7 +331,7 @@ public class NSDeviceStatus { // test warning level int level = Levels.INFO; long now = System.currentTimeMillis(); - if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_urgent_staledatavalue, 16) * 60 * 1000L < now) + if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_urgent_staledatavalue, 31) * 60 * 1000L < now) level = Levels.URGENT; else if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_staledatavalue, 16) * 60 * 1000L < now) level = Levels.WARN; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index cc5057f7eb..7c4d41ca86 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -842,33 +842,42 @@ public class NSClientService extends DaggerService { } private void handleAnnouncement(JSONObject announcement) { - NSAlarm nsAlarm = new NSAlarm(announcement); - Notification notification = new NotificationWithAction(injector, nsAlarm); - rxBus.send(new EventNewNotification(notification)); - rxBus.send(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(announcement, "message", "received"))); - aapsLogger.debug(LTag.NSCLIENT, announcement.toString()); + boolean defaultVal = config.getNSCLIENT(); + if (sp.getBoolean(R.string.key_ns_announcements, defaultVal)) { + NSAlarm nsAlarm = new NSAlarm(announcement); + Notification notification = new NotificationWithAction(injector, nsAlarm); + rxBus.send(new EventNewNotification(notification)); + rxBus.send(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(announcement, "message", "received"))); + aapsLogger.debug(LTag.NSCLIENT, announcement.toString()); + } } private void handleAlarm(JSONObject alarm) { - long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); - if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { - NSAlarm nsAlarm = new NSAlarm(alarm); - Notification notification = new NotificationWithAction(injector, nsAlarm); - rxBus.send(new EventNewNotification(notification)); + boolean defaultVal = config.getNSCLIENT(); + if (sp.getBoolean(R.string.key_ns_alarms, defaultVal)) { + long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); + if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { + NSAlarm nsAlarm = new NSAlarm(alarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); + rxBus.send(new EventNewNotification(notification)); + } + rxBus.send(new EventNSClientNewLog("ALARM", JsonHelper.safeGetString(alarm, "message", "received"))); + aapsLogger.debug(LTag.NSCLIENT, alarm.toString()); } - rxBus.send(new EventNSClientNewLog("ALARM", JsonHelper.safeGetString(alarm, "message", "received"))); - aapsLogger.debug(LTag.NSCLIENT, alarm.toString()); } private void handleUrgentAlarm(JSONObject alarm) { - long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); - if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { - NSAlarm nsAlarm = new NSAlarm(alarm); - Notification notification = new NotificationWithAction(injector, nsAlarm); - rxBus.send(new EventNewNotification(notification)); + boolean defaultVal = config.getNSCLIENT(); + if (sp.getBoolean(R.string.key_ns_alarms, defaultVal)) { + long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L); + if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) { + NSAlarm nsAlarm = new NSAlarm(alarm); + Notification notification = new NotificationWithAction(injector, nsAlarm); + rxBus.send(new EventNewNotification(notification)); + } + rxBus.send(new EventNSClientNewLog("URGENTALARM", JsonHelper.safeGetString(alarm, "message", "received"))); + aapsLogger.debug(LTag.NSCLIENT, alarm.toString()); } - rxBus.send(new EventNSClientNewLog("URGENTALARM", JsonHelper.safeGetString(alarm, "message", "received"))); - aapsLogger.debug(LTag.NSCLIENT, alarm.toString()); } public void handleNewCal(JSONArray cals, boolean isDelta) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt index f492196b29..4e85b03b5c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationWithAction.kt @@ -22,8 +22,6 @@ class NotificationWithAction constructor( @Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var nsClientPlugin: NSClientPlugin - private var nsAlarm: NSAlarm? = null - init { injector.androidInjector().inject(this) } @@ -36,7 +34,6 @@ class NotificationWithAction constructor( } constructor (injector: HasAndroidInjector, nsAlarm: NSAlarm) : this(injector) { - this.nsAlarm = nsAlarm date = System.currentTimeMillis() when (nsAlarm.level()) { 0 -> { @@ -50,14 +47,14 @@ class NotificationWithAction constructor( id = NSALARM level = NORMAL text = nsAlarm.title() - if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.alarm + soundId = R.raw.alarm } 2 -> { id = NSURGENTALARM level = URGENT text = nsAlarm.title() - if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_urgent_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_urgent_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.urgentalarm + soundId = R.raw.urgentalarm } } buttonText = R.string.snooze diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index de9f03587e..4908f7d04f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -549,20 +549,12 @@ Do Profile Switch Pump battery age Alarm options - nsalarm_urgent_high - nsalarm_high - nsalarm_low - nsalarm_urgent_low - nsalarm_staledata - nsalarm_urgent_staledata + ns_announcements + ns_alarms nsalarm_staledatavalue nsalarm_urgent_staledatavalue - Urgent high - High - Low - Urgent low - Stale data - Urgent stale data + Create notifications from NS alarms + Create notifications from NS announcements Stale data threshold [min] Urgent stale data threshold [min] Interval for autosens [h] diff --git a/app/src/main/res/xml/pref_nsclientinternal.xml b/app/src/main/res/xml/pref_nsclientinternal.xml index 6f68d77a7b..a25aeebd2f 100644 --- a/app/src/main/res/xml/pref_nsclientinternal.xml +++ b/app/src/main/res/xml/pref_nsclientinternal.xml @@ -42,29 +42,12 @@ android:title="@string/ns_alarmoptions"> + android:key="@string/key_ns_alarms" + android:title="@string/ns_alarms" /> - - - - - - + android:key="@string/key_ns_announcements" + android:title="@string/ns_announcements" /> - - Date: Sat, 23 May 2020 22:16:55 +0200 Subject: [PATCH 15/16] fix ProfileSwitch loading --- .../info/nightscout/androidaps/db/DatabaseHelper.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 50a7d3ed47..4b8d637c47 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -1531,7 +1531,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { //add last one without duration ProfileSwitch last = getLastProfileSwitchWithoutDuration(); if (last != null) { - if (!profileSwitches.contains(last)) + if (!isInList(profileSwitches, last)) profileSwitches.add(last); } return profileSwitches; @@ -1541,6 +1541,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } + boolean isInList(List profileSwitches, ProfileSwitch last) { + for (ProfileSwitch ps : profileSwitches) { + if (ps.isEqual(last)) return true; + } + return false; + } + @Nullable private ProfileSwitch getLastProfileSwitchWithoutDuration() { try { From 87eb8021de430adf18b313dd095c6f0a2ea6137a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 23 May 2020 22:49:05 +0200 Subject: [PATCH 16/16] configbuilder fix --- .../nightscout/androidaps/plugins/configBuilder/PluginStore.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt index 5166248e7d..3958f17d78 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/configBuilder/PluginStore.kt @@ -108,7 +108,7 @@ class PluginStore @Inject constructor( (activeProfile as PluginBase).setPluginEnabled(PluginType.PROFILE, true) aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting ProfileInterface") } - setFragmentVisiblities((activeSensitivity as PluginBase).name, pluginsInCategory, PluginType.PROFILE) + setFragmentVisiblities((activeProfile as PluginBase).name, pluginsInCategory, PluginType.PROFILE) // PluginType.BGSOURCE pluginsInCategory = getSpecificPluginsList(PluginType.BGSOURCE)