From 3342d9daa3b9bed877761e9638d173cbfefa502b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 19 Dec 2017 14:47:55 +0100 Subject: [PATCH 01/25] don't show single connection timeouts on the watch --- .../info/nightscout/androidaps/plugins/Wear/WearPlugin.java | 2 ++ .../main/java/info/nightscout/androidaps/queue/QueueThread.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index 00f62bd2c0..3316d68d12 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -215,6 +215,8 @@ public class WearPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { + if(ev.result == null) return; + String status; if(ev.result.success){ status = MainApp.sResources.getString(R.string.success); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 2c568cdccd..885d388db5 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -59,7 +59,7 @@ public class QueueThread extends Thread { } if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) { - MainApp.bus().post(new EventDismissBolusprogressIfRunning(new PumpEnactResult())); + MainApp.bus().post(new EventDismissBolusprogressIfRunning(null)); MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.connectiontimedout))); log.debug("QUEUE: timed out"); pump.stopConnecting(); From e11a4f6d4222949c50c416867515d6f9b2e3f107 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 19 Dec 2017 22:41:43 +0100 Subject: [PATCH 02/25] Use autosensdata for wizard instead of APSResult --- .../plugins/Overview/Dialogs/WizardDialog.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 464c422596..5e3e187d17 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -53,6 +53,8 @@ import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; +import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; @@ -439,7 +441,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com basalIobInsulin.setText(DecimalFormatter.to2Decimal(-basalIob.basaliob) + "U"); // COB only if AMA is selected - if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin && ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) { + if (ConfigBuilderPlugin.getActiveAPS() instanceof OpenAPSAMAPlugin) { cobLayout.setVisibility(View.VISIBLE); cobAvailable = true; } else { @@ -483,12 +485,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com // COB Double c_cob = 0d; if (cobAvailable && cobCheckbox.isChecked()) { - if (ConfigBuilderPlugin.getActiveAPS().getLastAPSResult() != null && ConfigBuilderPlugin.getActiveAPS().getLastAPSRun().after(new Date(System.currentTimeMillis() - 11 * 60 * 1000L))) { - try { - c_cob = SafeParse.stringToDouble(ConfigBuilderPlugin.getActiveAPS().getLastAPSResult().json().getString("COB")); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } + AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis()); + + if(autosensData != null && autosensData.time > System.currentTimeMillis() - 11 * 60 * 1000L) { + c_cob = autosensData.cob; } } From 63b0efede3d56545762b705a0e76638f5020d665 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 20 Dec 2017 20:45:21 +0100 Subject: [PATCH 03/25] allow to read status after every command --- .../nightscout/androidaps/queue/CommandQueue.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index af768e4888..b69c41e6c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -326,14 +326,14 @@ public class CommandQueue { // returns true if command is queued public boolean readStatus(String reason, Callback callback) { - if (isRunning(Command.CommandType.READSTATUS)) { - if (callback != null) - callback.result(executingNowError()).run(); - return false; - } + //if (isRunning(Command.CommandType.READSTATUS)) { + // if (callback != null) + // callback.result(executingNowError()).run(); + // return false; + //} // remove all unfinished - removeAll(Command.CommandType.READSTATUS); + //removeAll(Command.CommandType.READSTATUS); // add new command to queue add(new CommandReadStatus(reason, callback)); From adff0329dd4a47640ac3305bc92fb067a7cdc1b0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 20 Dec 2017 20:55:14 +0100 Subject: [PATCH 04/25] initialize lastCommandTime too after BT reset --- .../main/java/info/nightscout/androidaps/queue/QueueThread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index 26597144b8..dd02c5e973 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -80,7 +80,7 @@ public class QueueThread extends Thread { mBluetoothAdapter.enable(); SystemClock.sleep(1000); //start over again once after watchdog barked - connectionStartTime = System.currentTimeMillis(); + connectionStartTime = lastCommandTime = System.currentTimeMillis(); } else { queue.clear(); return; From 2bdda9af430c5b848de80bb63746e16b0d4a6e4b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 21 Dec 2017 07:45:56 +0100 Subject: [PATCH 05/25] Rv2,RS fix loading events --- .../plugins/PumpDanaRS/services/DanaRSService.java | 5 ++++- .../PumpDanaRv2/services/DanaRv2ExecutionService.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java index a30e237672..bd6f5ca690 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/services/DanaRSService.java @@ -185,7 +185,10 @@ public class DanaRSService extends Service { while (!msg.done && bleComm.isConnected()) { SystemClock.sleep(100); } - lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded - 45 * 60 * 1000L; // always load last 45 min + if (DanaRS_Packet_APS_History_Events.lastEventTimeLoaded != 0) + lastHistoryFetched = DanaRS_Packet_APS_History_Events.lastEventTimeLoaded - 45 * 60 * 1000L; // always load last 45 min + else + lastHistoryFetched = 0; log.debug("Events loaded"); return new PumpEnactResult().success(true); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 4e5b85177a..6d6ba34838 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -527,7 +527,10 @@ public class DanaRv2ExecutionService extends Service { waitMsec(100); } waitMsec(200); - lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - 45 * 60 * 1000L; //always load last 45 min; + if (MsgHistoryEvents_v2.lastEventTimeLoaded != 0) + lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - 45 * 60 * 1000L; //always load last 45 min; + else + lastHistoryFetched = 0; return new PumpEnactResult().success(true); } From 2d2bd6d77a6d85e4641c20f12fbe11ef6540d930 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 21 Dec 2017 08:26:55 +0100 Subject: [PATCH 06/25] remove string with no default translation --- app/src/main/res/values-el/strings.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index d1738abd28..c986fdba7f 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -208,7 +208,6 @@ Σύνδεση Συνδέθηκε Αποσύνδεση - Συγχρονισμός προφίλ στην αντλία Ρυθμίσεις αντλίας DanaR Nightscout Άδεια χρήσης τελικού χρήστη @@ -675,4 +674,4 @@ Τοπικές Ειδοποιήσεις Ειδοποίησε αν δεν ληφθούν δεδομένα μετρήσεων BG Απενεργοποιεί το bluetooth του τηλεφώνου για ένα δευτερόλεπτο αν δεν είναι δυνατή η σύνδεση με την αντλία.Αυτό μπορεί να βοηθήσει σε ορισμένα τηλέφωνα όπου το bluetooth παγώνει - \ No newline at end of file + From 6a3184bc39e6692352b5c49dcc58d48d40374f56 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 21 Dec 2017 11:36:25 +0100 Subject: [PATCH 07/25] ComboFragment: use history icon for history, not bolus icon. --- app/src/main/res/layout/combopump_fragment.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/layout/combopump_fragment.xml b/app/src/main/res/layout/combopump_fragment.xml index 2221d504be..ecbaf90ef6 100644 --- a/app/src/main/res/layout/combopump_fragment.xml +++ b/app/src/main/res/layout/combopump_fragment.xml @@ -402,7 +402,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:drawableTop="@drawable/icon_bolus" + android:drawableTop="@drawable/icon_danarhistory" android:paddingLeft="0dp" android:paddingRight="0dp" android:visibility="gone" From 42418d41466071de6f4c0fd31965b86e41e55e8b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Thu, 21 Dec 2017 22:43:34 +0100 Subject: [PATCH 08/25] ComboFragment: make warning/error bold for a better readability. On lower DPI devices they're already bold, but on higher DPI devices the yellow "Low" is hardly discernible from white. (cherry picked from commit 693ba73) --- .../androidaps/plugins/PumpCombo/ComboFragment.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java index 4613caf208..9d02873c21 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboFragment.java @@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.PumpCombo; import android.app.Activity; import android.app.AlertDialog; import android.graphics.Color; +import android.graphics.Typeface; import android.os.Bundle; import android.text.Spanned; import android.view.LayoutInflater; @@ -137,11 +138,14 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis if (ps.insulinState == PumpState.EMPTY || ps.batteryState == PumpState.EMPTY || ps.activeAlert != null && ps.activeAlert.errorCode != null) { stateView.setTextColor(Color.RED); + stateView.setTypeface(null, Typeface.BOLD); } else if (plugin.getPump().state.suspended || ps.activeAlert != null && ps.activeAlert.warningCode != null) { stateView.setTextColor(Color.YELLOW); + stateView.setTypeface(null, Typeface.BOLD); } else { stateView.setTextColor(Color.WHITE); + stateView.setTypeface(null, Typeface.NORMAL); } // activity @@ -171,12 +175,15 @@ public class ComboFragment extends SubscriberFragment implements View.OnClickLis if (ps.insulinState == PumpState.LOW) { reservoirView.setTextColor(Color.YELLOW); reservoirView.setText(R.string.combo_reservoir_low); + reservoirView.setTypeface(null, Typeface.BOLD); } else if (ps.insulinState == PumpState.EMPTY) { reservoirView.setTextColor(Color.RED); reservoirView.setText(R.string.combo_reservoir_empty); + reservoirView.setTypeface(null, Typeface.BOLD); } else { reservoirView.setTextColor(Color.WHITE); reservoirView.setText(R.string.combo_reservoir_normal); + reservoirView.setTypeface(null, Typeface.NORMAL); } // last connection From 771f9eac1aef8be77a8a0b87a14280b0b16cd75f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 00:12:40 +0100 Subject: [PATCH 09/25] LocalProfile TimeListEdit min, max --- .../plugins/ProfileLocal/LocalProfileFragment.java | 11 +++++++---- .../main/java/info/nightscout/utils/TimeListEdit.java | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java index 8637b863fb..ebd31e915f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java @@ -23,6 +23,7 @@ import java.text.DecimalFormat; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; +import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; @@ -84,15 +85,17 @@ public class LocalProfileFragment extends SubscriberFragment { } }; + PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); + View layout = inflater.inflate(R.layout.localprofile_fragment, container, false); diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia); diaView.setParams(localProfilePlugin.dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch); mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl); mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol); - icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", getPlugin().ic, null, 0.1d, new DecimalFormat("0.0"), save); - isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", getPlugin().isf, null, 0.1d, new DecimalFormat("0.0"), save); - basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), getPlugin().basal, null, 0.01d, new DecimalFormat("0.00"), save); - targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", getPlugin().targetLow, getPlugin().targetHigh, 0.1d, new DecimalFormat("0.0"), save); + icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save); + isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save); + basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save); + targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", getPlugin().targetLow, getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save); profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch); if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) { diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/utils/TimeListEdit.java index af3668310a..bc41ece59d 100644 --- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/utils/TimeListEdit.java @@ -52,6 +52,8 @@ public class TimeListEdit { private JSONArray data1; private JSONArray data2; private double step; + private double min; + private double max; private NumberFormat formatter; private Runnable save; private LinearLayout layout; @@ -59,7 +61,7 @@ public class TimeListEdit { private int inflatedUntil = -1; - public TimeListEdit(Context context, View view, int resLayoutId, String label, JSONArray data1, JSONArray data2, double step, NumberFormat formatter, Runnable save) { + public TimeListEdit(Context context, View view, int resLayoutId, String label, JSONArray data1, JSONArray data2, double min, double max, double step, NumberFormat formatter, Runnable save) { this.context = context; this.view = view; this.resLayoutId = resLayoutId; @@ -67,6 +69,8 @@ public class TimeListEdit { this.data1 = data1; this.data2 = data2; this.step = step; + this.min = min; + this.max = max; this.formatter = formatter; this.save = save; buildView(); @@ -239,8 +243,8 @@ public class TimeListEdit { if (i == 0) next = ONEHOURINSECONDS; fillSpinner(timeSpinner, secondFromMidnight(i), previous, next); - editText1.setParams(value1(i), 0.1d, 100d, step, formatter, false); - editText2.setParams(value2(i), 0.1d, 100d, step, formatter, false); + editText1.setParams(value1(i), min, max, step, formatter, false); + editText2.setParams(value2(i), min, max, step, formatter, false); if (data2 == null) { editText2.setVisibility(View.GONE); From a5c4495a5d8bca9c2fa3c5d35f5e5ac9e1904c5b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 00:17:46 +0100 Subject: [PATCH 10/25] BolusWizard use 0 for insulin correction if in range --- app/src/main/java/info/nightscout/utils/BolusWizard.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index a97ed233ff..5a683f1aaa 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -71,7 +71,9 @@ public class BolusWizard { targetBGLow = Profile.fromMgdlToUnits(tempTarget.low, specificProfile.getUnits()); targetBGHigh = Profile.fromMgdlToUnits(tempTarget.high, specificProfile.getUnits()); } - if (bg <= targetBGLow) { + if (bg >= targetBGLow && bg <= targetBGHigh) { + bgDiff = 0d; + } else if (bg <= targetBGLow) { bgDiff = bg - targetBGLow; } else { bgDiff = bg - targetBGHigh; From 6b23ba10bd49a59ceb29a97b8307293cc8951246 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 00:37:22 +0100 Subject: [PATCH 11/25] format output date to be displayed on iDevices correctly --- app/src/main/java/info/nightscout/utils/DateUtil.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index c406568730..68d28760d3 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -27,6 +27,8 @@ public class DateUtil { /** * The date format in iso. */ + private static String FORMAT_DATE_ISO_OUT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + private static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ssZ"; private static String FORMAT_DATE_ISO_MSEC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; private static String FORMAT_DATE_ISO_MSEC_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; @@ -79,7 +81,7 @@ public class DateUtil { * @return the iso-formatted date string */ public static String toISOString(Date date, String format, TimeZone tz) { - if (format == null) format = FORMAT_DATE_ISO; + if (format == null) format = FORMAT_DATE_ISO_OUT; if (tz == null) tz = TimeZone.getDefault(); DateFormat f = new SimpleDateFormat(format, Locale.getDefault()); f.setTimeZone(tz); @@ -87,11 +89,11 @@ public class DateUtil { } public static String toISOString(Date date) { - return toISOString(date, FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC")); + return toISOString(date, FORMAT_DATE_ISO_OUT, TimeZone.getTimeZone("UTC")); } public static String toISOString(long date) { - return toISOString(new Date(date), FORMAT_DATE_ISO, TimeZone.getTimeZone("UTC")); + return toISOString(new Date(date), FORMAT_DATE_ISO_OUT, TimeZone.getTimeZone("UTC")); } public static Date toDate(Integer seconds) { From 74abdc02712e3a4ba634d5f50456b8fa7c9e6c4f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 01:35:52 +0100 Subject: [PATCH 12/25] fix disconnecting pump --- .../androidaps/interfaces/PumpInterface.java | 2 +- .../plugins/Actions/dialogs/NewTempBasalDialog.java | 2 +- .../plugins/Overview/Dialogs/WizardDialog.java | 2 +- .../plugins/Overview/OverviewFragment.java | 13 ++++++++----- .../androidaps/plugins/PumpDanaR/DanaRPlugin.java | 6 +++--- .../plugins/PumpDanaRKorean/DanaRKoreanPlugin.java | 6 +++--- .../androidaps/plugins/PumpDanaRS/DanaRSPlugin.java | 4 ++-- .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 4 ++-- .../androidaps/plugins/PumpMDI/MDIPlugin.java | 2 +- .../plugins/PumpVirtual/VirtualPumpPlugin.java | 2 +- .../nightscout/androidaps/queue/CommandQueue.java | 4 ++-- .../queue/commands/CommandTempBasalPercent.java | 6 ++++-- 12 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java index a3ada67538..087a1dd0bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PumpInterface.java @@ -36,7 +36,7 @@ public interface PumpInterface { PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo); void stopBolusDelivering(); PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, boolean enforceNew); - PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes); + PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew); PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes); //some pumps might set a very short temp close to 100% as cancelling a temp can be noisy //when the cancel request is requested by the user (forced), the pump should always do a real cancel diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index e734cd4f96..e6c653b5ef 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -155,7 +155,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi } }; if (setAsPercent) { - ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, callback); + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(finalBasalPercent, finalDurationInMinutes, true, callback); } else { ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(finalBasal, finalDurationInMinutes, true, callback); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 464c422596..28dbf899c4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -344,7 +344,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); MainApp.bus().post(new EventRefreshOverview("WizardDialog")); } - ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 120, true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, new Callback() { @Override public void run() { if (!result.success) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 344804cf7f..088918c586 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -78,6 +78,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Careportal.CareportalFragment; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; @@ -330,6 +331,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, super.onCreateContextMenu(menu, v, menuInfo); if (v == apsModeView) { final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); + final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); if (activeloop == null) return; menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop)); @@ -340,7 +342,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h)); - menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m)); + if (pumpDescription.tempDurationStep <= 30) + menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h)); menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor3h)); @@ -479,7 +482,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) { activeloop.disconnectTo(System.currentTimeMillis() + 30L * 60 * 1000); updateGUI("suspendmenu"); - ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 30, true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 30, true, new Callback() { @Override public void run() { if (!result.success) { @@ -492,7 +495,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) { activeloop.disconnectTo(System.currentTimeMillis() + 1 * 60L * 60 * 1000); updateGUI("suspendmenu"); - ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 60, true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 60, true, new Callback() { @Override public void run() { if (!result.success) { @@ -505,7 +508,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) { activeloop.disconnectTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000); updateGUI("suspendmenu"); - ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 2 * 60, true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 2 * 60, true, new Callback() { @Override public void run() { if (!result.success) { @@ -518,7 +521,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) { activeloop.disconnectTo(System.currentTimeMillis() + 3 * 60L * 60 * 1000); updateGUI("suspendmenu"); - ConfigBuilderPlugin.getCommandQueue().tempBasalAbsolute(0d, 3 * 60, true, new Callback() { + ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 3 * 60, true, new Callback() { @Override public void run() { if (!result.success) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 167c430a6e..affa668148 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -434,7 +434,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C // Convert duration from minutes to hours if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); - return setTempBasalPercent(percentRate, durationInMinutes); + return setTempBasalPercent(percentRate, durationInMinutes, false); } if (doExtendedTemp) { // Check if some temp is already in progress @@ -499,7 +499,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C } @Override - public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) { PumpEnactResult result = new PumpEnactResult(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); percent = configBuilderPlugin.applyBasalConstraints(percent); @@ -514,7 +514,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, C if (percent > getPumpDescription().maxTempPercent) percent = getPumpDescription().maxTempPercent; TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); - if (runningTB != null && runningTB.percentRate == percent) { + if (runningTB != null && runningTB.percentRate == percent && !enforceNew) { result.enacted = false; result.success = true; result.isTempCancel = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 32c9f209ef..0caab03cc8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -436,7 +436,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf // Convert duration from minutes to hours if (Config.logPumpActions) log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); - return setTempBasalPercent(percentRate, durationInMinutes); + return setTempBasalPercent(percentRate, durationInMinutes, false); } if (doExtendedTemp) { // Check if some temp is already in progress @@ -501,7 +501,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf } @Override - public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) { PumpEnactResult result = new PumpEnactResult(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); percent = configBuilderPlugin.applyBasalConstraints(percent); @@ -516,7 +516,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, DanaRInterf if (percent > getPumpDescription().maxTempPercent) percent = getPumpDescription().maxTempPercent; TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); - if (runningTB != null && runningTB.percentRate == percent) { + if (runningTB != null && runningTB.percentRate == percent && enforceNew) { result.enacted = false; result.success = true; result.isTempCancel = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 87d8ccad5d..fcbd89cfab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -580,7 +580,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, } @Override - public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) { PumpEnactResult result = new PumpEnactResult(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); percent = configBuilderPlugin.applyBasalConstraints(percent); @@ -595,7 +595,7 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, if (percent > getPumpDescription().maxTempPercent) percent = getPumpDescription().maxTempPercent; TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); - if (runningTB != null && runningTB.percentRate == percent) { + if (runningTB != null && runningTB.percentRate == percent && !enforceNew) { result.enacted = false; result.success = true; result.isTempCancel = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 0c3ac39860..f074cb84c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -437,7 +437,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, } @Override - public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) { PumpEnactResult result = new PumpEnactResult(); ConfigBuilderPlugin configBuilderPlugin = MainApp.getConfigBuilder(); percent = configBuilderPlugin.applyBasalConstraints(percent); @@ -452,7 +452,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, DanaRInterface, if (percent > getPumpDescription().maxTempPercent) percent = getPumpDescription().maxTempPercent; TemporaryBasal runningTB = MainApp.getConfigBuilder().getRealTempBasalFromHistory(System.currentTimeMillis()); - if (runningTB != null && runningTB.percentRate == percent) { + if (runningTB != null && runningTB.percentRate == percent && !enforceNew) { result.enacted = false; result.success = true; result.isTempCancel = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index fd5d2bd270..564d29d53b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -204,7 +204,7 @@ public class MDIPlugin implements PluginBase, PumpInterface { } @Override - public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) { PumpEnactResult result = new PumpEnactResult(); result.success = false; result.comment = MainApp.instance().getString(R.string.pumperror); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index c278f7fb16..13d3f134f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -304,7 +304,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { } @Override - public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) { + public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, boolean enforceNew) { TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); PumpEnactResult result = new PumpEnactResult(); if (MainApp.getConfigBuilder().isTempBasalInProgress()) { diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index b69c41e6c4..1d5fa468a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -203,7 +203,7 @@ public class CommandQueue { } // returns true if command is queued - public boolean tempBasalPercent(int percent, int durationInMinutes, Callback callback) { + public boolean tempBasalPercent(int percent, int durationInMinutes, boolean enforceNew, Callback callback) { if (isRunning(Command.CommandType.TEMPBASAL)) { if (callback != null) callback.result(executingNowError()).run(); @@ -216,7 +216,7 @@ public class CommandQueue { Integer percentAfterConstraints = MainApp.getConfigBuilder().applyBasalConstraints(percent); // add new command to queue - add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, callback)); + add(new CommandTempBasalPercent(percentAfterConstraints, durationInMinutes, enforceNew, callback)); notifyAboutNewCommand(); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java index 663a20380d..e037f0b869 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandTempBasalPercent.java @@ -18,17 +18,19 @@ public class CommandTempBasalPercent extends Command { int durationInMinutes; int percent; + boolean enforceNew; - public CommandTempBasalPercent(int percent, int durationInMinutes, Callback callback) { + public CommandTempBasalPercent(int percent, int durationInMinutes, boolean enforceNew, Callback callback) { commandType = CommandType.TEMPBASAL; this.percent = percent; this.durationInMinutes = durationInMinutes; + this.enforceNew = enforceNew; this.callback = callback; } @Override public void execute() { - PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes); + PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setTempBasalPercent(percent, durationInMinutes, enforceNew); if (Config.logCongigBuilderActions) log.debug("setTempBasalPercent percent: " + percent + " durationInMinutes: " + durationInMinutes + " success: " + r.success + " enacted: " + r.enacted); if (callback != null) From 31975396a2f2ffaf06ef72034588df1e5d132909 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 02:55:40 +0100 Subject: [PATCH 13/25] use joda-time --- app/build.gradle | 2 + .../info/nightscout/androidaps/MainApp.java | 3 ++ .../java/info/nightscout/utils/DateUtil.java | 42 ++++--------------- .../info/nightscout/utils/DateUtilTest.java | 15 +++++-- 4 files changed, 23 insertions(+), 39 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ea54e3ac3b..00abdd64a0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -188,4 +188,6 @@ dependencies { compile 'com.google.code.gson:gson:2.7' compile 'com.google.guava:guava:20.0' + compile 'net.danlew:android.joda:2.9.9.1' + testCompile 'joda-time:joda-time:2.9.4.2' } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index bd0ba7695e..4bba16080b 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -15,6 +15,8 @@ import com.squareup.otto.Bus; import com.squareup.otto.LoggingBus; import com.squareup.otto.ThreadEnforcer; +import net.danlew.android.joda.JodaTimeAndroid; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -96,6 +98,7 @@ public class MainApp extends Application { super.onCreate(); Fabric.with(this, new Crashlytics()); Fabric.with(this, new Answers()); + JodaTimeAndroid.init(this); Crashlytics.setString("BUILDVERSION", BuildConfig.BUILDVERSION); log.info("Version: " + BuildConfig.VERSION_NAME); log.info("BuildVersion: " + BuildConfig.BUILDVERSION); diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index 68d28760d3..86965621d2 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -2,10 +2,12 @@ package info.nightscout.utils; import android.support.v4.util.LongSparseArray; import android.text.format.DateUtils; -import android.util.SparseIntArray; + +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormatter; +import org.joda.time.format.ISODateTimeFormat; import java.text.DateFormat; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -29,10 +31,6 @@ public class DateUtil { */ private static String FORMAT_DATE_ISO_OUT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - private static String FORMAT_DATE_ISO = "yyyy-MM-dd'T'HH:mm:ssZ"; - private static String FORMAT_DATE_ISO_MSEC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; - private static String FORMAT_DATE_ISO_MSEC_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; - /** * Takes in an ISO date string of the following format: * yyyy-mm-ddThh:mm:ss.ms+HoMo @@ -43,33 +41,10 @@ public class DateUtil { */ public static Date fromISODateString(String isoDateString) throws Exception { - SimpleDateFormat f = new SimpleDateFormat(FORMAT_DATE_ISO, Locale.getDefault()); - Date date; - f.setTimeZone(TimeZone.getTimeZone("UTC")); - try { - date = f.parse(isoDateString); - return date; - } catch (ParseException e) { - } - - f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC, Locale.getDefault()); - f.setTimeZone(TimeZone.getTimeZone("UTC")); - try { - date = f.parse(isoDateString); - return date; - } catch (ParseException e) { - } - - f = new SimpleDateFormat(FORMAT_DATE_ISO_MSEC_UTC, Locale.getDefault()); - f.setTimeZone(TimeZone.getTimeZone("UTC")); - try { - date = f.parse(isoDateString); - return date; - } catch (ParseException e) { - } - - throw new ParseException("Unparseable date: " + isoDateString, 0); + DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser(); + DateTime dateTime = DateTime.parse(isoDateString, parser); + return dateTime.toDate(); } /** @@ -99,11 +74,8 @@ public class DateUtil { public static Date toDate(Integer seconds) { Calendar calendar = new GregorianCalendar(); calendar.set(Calendar.HOUR_OF_DAY, seconds / 60 / 60); - String a = calendar.getTime().toString(); calendar.set(Calendar.MINUTE, (seconds / 60) % 60); - String b = calendar.getTime().toString(); calendar.set(Calendar.SECOND, 0); - String c = calendar.getTime().toString(); return calendar.getTime(); } diff --git a/app/src/test/java/info/nightscout/utils/DateUtilTest.java b/app/src/test/java/info/nightscout/utils/DateUtilTest.java index 4b48148341..d720487201 100644 --- a/app/src/test/java/info/nightscout/utils/DateUtilTest.java +++ b/app/src/test/java/info/nightscout/utils/DateUtilTest.java @@ -3,7 +3,9 @@ package info.nightscout.utils; import org.junit.Test; -import static org.junit.Assert.*; +import java.util.Date; + +import static org.junit.Assert.assertEquals; /** * Created by mike on 20.11.2017. @@ -17,10 +19,15 @@ public class DateUtilTest { @Test public void fromISODateStringTest() throws Exception { - assertEquals( 1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime()); - assertEquals( 1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+0200").getTime()); - assertEquals( 1512317365000L, DateUtil.fromISODateString("2017-12-03T16:09:25.000Z").getTime()); + assertEquals(1511124634417L, DateUtil.fromISODateString("2017-11-19T22:50:34.417+0200").getTime()); + assertEquals(1511124634000L, DateUtil.fromISODateString("2017-11-19T22:50:34+0200").getTime()); + assertEquals(1512317365000L, DateUtil.fromISODateString("2017-12-03T16:09:25.000Z").getTime()); + assertEquals(1513902750000L, DateUtil.fromISODateString("2017-12-22T00:32:30Z").getTime()); } + @Test + public void toISOStringTest() throws Exception { + assertEquals("2017-12-22T00:32:30Z", DateUtil.toISOString(new Date(1513902750000L))); + } } From 5bc6ea04c2f361a9592baf7270ca2fe22119a57b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 03:27:13 +0100 Subject: [PATCH 14/25] Double -> double --- .../info/nightscout/androidaps/interfaces/InsulinInterface.java | 2 +- .../androidaps/plugins/Insulin/InsulinFastactingPlugin.java | 2 +- .../plugins/Insulin/InsulinFastactingProlongedPlugin.java | 2 +- .../androidaps/plugins/Insulin/InsulinOrefBasePlugin.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java index 0803f65373..48efa587d8 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/InsulinInterface.java @@ -21,5 +21,5 @@ public interface InsulinInterface { String getFriendlyName(); String getComment(); double getDia(); - public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia); + public Iob iobCalcForTreatment(Treatment treatment, long time, double dia); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java index c7164ea60e..6218a2ecfe 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java @@ -107,7 +107,7 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface { } @Override - public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) { + public Iob iobCalcForTreatment(Treatment treatment, long time, double dia) { Iob result = new Iob(); double scaleFactor = 3.0 / dia; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java index 99c35a6c0b..4155a9be56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java @@ -107,7 +107,7 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte } @Override - public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) { + public Iob iobCalcForTreatment(Treatment treatment, long time, double dia) { Iob result = new Iob(); //Double scaleFactor = 3.0 / dia; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java index 6210f91c9a..cbe5f2ff64 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java @@ -64,7 +64,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf } @Override - public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) { + public Iob iobCalcForTreatment(Treatment treatment, long time, double dia) { Iob result = new Iob(); int peak = getPeak(); From 7073688920ef79315b6745e6ab4c0a9d53b60a01 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 22 Dec 2017 10:46:54 +0100 Subject: [PATCH 15/25] Update ComboPlugin to match updated PumpInterface. --- .../androidaps/plugins/PumpCombo/ComboPlugin.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index 3df159b876..d8b6268e0e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -577,9 +577,18 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf return setTempBasalPercent(roundedPercentage, durationInMinutes); } - // Note: AAPS calls this directly only for setting a temp basal issued by the user + /** + * Note: AAPS calls this directly only for setting a temp basal issued by the user + * + * @param forceNew Driver always applies the requested TBR and simply overrides whatever TBR + * is or isn't running at the moment + */ @Override - public PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes) { + public PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes, boolean forceNew) { + return setTempBasalPercent(percent, durationInMinutes); + } + + private PumpEnactResult setTempBasalPercent(Integer percent, final Integer durationInMinutes) { log.debug("setTempBasalPercent called with " + percent + "% for " + durationInMinutes + "min"); int adjustedPercent = percent; From 25667bc79eebbd16e7add958001aef4f537cd2d1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 11:57:59 +0100 Subject: [PATCH 16/25] RS fix crash when pairing is not confirmed on pump --- .../plugins/PumpDanaRS/activities/PairingProgressDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java index 00cbdb4628..a663d14245 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/activities/PairingProgressDialog.java @@ -118,7 +118,7 @@ public class PairingProgressDialog extends DialogFragment implements View.OnClic @Override public void dismiss() { - super.dismiss(); + super.dismissAllowingStateLoss(); if (helperActivity != null) { helperActivity.finish(); } From 4f46fc27adcbb3d674278b303314dafb7147f860 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Fri, 22 Dec 2017 16:12:41 +0100 Subject: [PATCH 17/25] README-Combo: clean up 'known issues section'. --- README-Combo.md | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/README-Combo.md b/README-Combo.md index 096d94e697..460e423e39 100644 --- a/README-Combo.md +++ b/README-Combo.md @@ -124,18 +124,11 @@ Usage: both of these issues can be resolved in future versions. Known issues: -- On phones with low memory (or aggressive power saving settings), Android may kill - AAPS frequently (if the buttons on the overview screen aren't displayed when opening - AAPS, the app was started again after Android killed it). - This may trigger false 'pump unreachable alarms' on start. - See the Combo tab's "last connection" field to check when the pump was last connected. - This may drain the pump's battery quicker since on startup the basal profile is read - from the pump. This may also increase the chance to hit the bug that makes the pump - reject all incoming connections until a button on the pump is pressed. -- Occasionally (every couple of days or less) AAPS might fail to automatically cancel - a TBR CANCELLED alert and needs to be dealt with (press the refresh button in AAPS - to transfer the warning to AAPS or confirm the alert on the pump). Similarly, the - 'pump unreachable' bug may occur from time to time. +- Occasionally (every couple of days or so) AAPS might fail to automatically cancel + a TBR CANCELLED alert the user then needs to deal with (press the refresh button in AAPS + to transfer the warning to AAPS or confirm the alert on the pump). +- Similarly, the 'pump unreachable' bug may occur from time to time, which requires confirming + the alert on the pump to get the pump to accept connections again. - Overall the integration seems rather robust, but there are limits to the way the pump is controlled and how stable BT is, so there will be minor issues like the above from time to time, though they're small compared to what works well. From 600e2ade1c9eabb8bf361940d8d08ca2e3588a13 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Dec 2017 19:50:16 +0100 Subject: [PATCH 18/25] SingleClickButton --- .../plugins/Actions/ActionsFragment.java | 30 ++++----- .../plugins/Actions/dialogs/FillDialog.java | 2 + .../dialogs/NewExtendedBolusDialog.java | 9 +-- .../Actions/dialogs/NewTempBasalDialog.java | 2 + .../Dialogs/NewNSTreatmentDialog.java | 1 + .../Overview/Dialogs/CalibrationDialog.java | 1 + .../Overview/Dialogs/NewTreatmentDialog.java | 1 + .../Overview/Dialogs/WizardDialog.java | 1 + .../plugins/Overview/OverviewFragment.java | 23 ++++--- .../nightscout/utils/SingleClickButton.java | 67 +++++++++++++++++++ app/src/main/res/layout/actions_fragment.xml | 14 ++-- .../main/res/layout/careportal_fragment.xml | 40 +++++------ app/src/main/res/layout/overview_fragment.xml | 10 +-- .../res/layout/overview_fragment_nsclient.xml | 6 +- .../overview_fragment_nsclient_tablet.xml | 8 +-- .../layout/overview_fragment_smallheight.xml | 8 +-- .../overview_newextendedbolus_dialog.xml | 8 +++ 17 files changed, 155 insertions(+), 76 deletions(-) create mode 100644 app/src/main/java/info/nightscout/utils/SingleClickButton.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index 910f032fc5..d6f56e501b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -8,7 +8,6 @@ import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import com.crashlytics.android.Crashlytics; import com.crashlytics.android.answers.Answers; @@ -33,6 +32,7 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.utils.SingleClickButton; /** * A simple {@link Fragment} subclass. @@ -45,13 +45,13 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL return actionsPlugin; } - Button profileSwitch; - Button tempTarget; - Button extendedBolus; - Button extendedBolusCancel; - Button tempBasal; - Button tempBasalCancel; - Button fill; + SingleClickButton profileSwitch; + SingleClickButton tempTarget; + SingleClickButton extendedBolus; + SingleClickButton extendedBolusCancel; + SingleClickButton tempBasal; + SingleClickButton tempBasalCancel; + SingleClickButton fill; public ActionsFragment() { super(); @@ -64,13 +64,13 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL try { View view = inflater.inflate(R.layout.actions_fragment, container, false); - profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch); - tempTarget = (Button) view.findViewById(R.id.actions_temptarget); - extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus); - extendedBolusCancel = (Button) view.findViewById(R.id.actions_extendedbolus_cancel); - tempBasal = (Button) view.findViewById(R.id.actions_settempbasal); - tempBasalCancel = (Button) view.findViewById(R.id.actions_canceltempbasal); - fill = (Button) view.findViewById(R.id.actions_fill); + profileSwitch = (SingleClickButton) view.findViewById(R.id.actions_profileswitch); + tempTarget = (SingleClickButton) view.findViewById(R.id.actions_temptarget); + extendedBolus = (SingleClickButton) view.findViewById(R.id.actions_extendedbolus); + extendedBolusCancel = (SingleClickButton) view.findViewById(R.id.actions_extendedbolus_cancel); + tempBasal = (SingleClickButton) view.findViewById(R.id.actions_settempbasal); + tempBasalCancel = (SingleClickButton) view.findViewById(R.id.actions_canceltempbasal); + fill = (SingleClickButton) view.findViewById(R.id.actions_fill); profileSwitch.setOnClickListener(this); tempTarget.setOnClickListener(this); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index 8391f93492..2901ad862f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -100,6 +100,8 @@ public class FillDialog extends DialogFragment implements OnClickListener { if (button1.getVisibility() == View.GONE && button2.getVisibility() == View.GONE && button3.getVisibility() == View.GONE) { divider.setVisibility(View.GONE); } + + setCancelable(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java index fbb9fafd9b..aea4f4f4aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewExtendedBolusDialog.java @@ -54,14 +54,9 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli view.findViewById(R.id.ok).setOnClickListener(this); view.findViewById(R.id.cancel).setOnClickListener(this); - return view; - } - @Override - public void onResume() { - super.onResume(); - if (getDialog() != null) - getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + setCancelable(false); + return view; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java index e6c653b5ef..0337166fd6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/NewTempBasalDialog.java @@ -102,6 +102,8 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi view.findViewById(R.id.ok).setOnClickListener(this); view.findViewById(R.id.cancel).setOnClickListener(this); basalTypeRadioGroup.setOnCheckedChangeListener(this); + + setCancelable(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index b284acff91..92c287f888 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -360,6 +360,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_reuse_layout), options.profile && ps != null && ps.isCPP); showOrHide((ViewGroup) view.findViewById(R.id.careportal_newnstreatment_temptarget_layout), options.tempTarget); + setCancelable(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java index fdc58e92f4..32b34b6f85 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java @@ -76,6 +76,7 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis unitsView = (TextView) view.findViewById(R.id.overview_calibration_units); unitsView.setText(units); + setCancelable(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java index 3b50ae9950..55dc39fc11 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewTreatmentDialog.java @@ -102,6 +102,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene editCarbs.setParams(0d, 0d, (double) maxCarbs, 1d, new DecimalFormat("0"), false, textWatcher); editInsulin.setParams(0d, 0d, maxInsulin, ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep, new DecimalFormat("0.00"), false, textWatcher); + setCancelable(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index 28dbf899c4..4869300742 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -251,6 +251,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com editCarbTime.setParams(0d, -60d, 60d, 5d, new DecimalFormat("0"), false); initDialog(); + setCancelable(false); return view; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index 088918c586..c531b080c0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -52,7 +52,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; @@ -113,6 +112,7 @@ import info.nightscout.utils.NSUpload; import info.nightscout.utils.OKDialog; import info.nightscout.utils.Profiler; import info.nightscout.utils.SP; +import info.nightscout.utils.SingleClickButton; import info.nightscout.utils.ToastUtils; public class OverviewFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener { @@ -156,11 +156,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, LinearLayoutManager llm; LinearLayout acceptTempLayout; - Button treatmentButton; - Button wizardButton; - Button calibrationButton; - Button acceptTempButton; - Button quickWizardButton; + SingleClickButton treatmentButton; + SingleClickButton wizardButton; + SingleClickButton calibrationButton; + SingleClickButton acceptTempButton; + SingleClickButton quickWizardButton; CheckBox lockScreen; @@ -244,16 +244,16 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph); iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph); - treatmentButton = (Button) view.findViewById(R.id.overview_treatmentbutton); + treatmentButton = (SingleClickButton) view.findViewById(R.id.overview_treatmentbutton); treatmentButton.setOnClickListener(this); - wizardButton = (Button) view.findViewById(R.id.overview_wizardbutton); + wizardButton = (SingleClickButton) view.findViewById(R.id.overview_wizardbutton); wizardButton.setOnClickListener(this); - acceptTempButton = (Button) view.findViewById(R.id.overview_accepttempbutton); + acceptTempButton = (SingleClickButton) view.findViewById(R.id.overview_accepttempbutton); if (acceptTempButton != null) acceptTempButton.setOnClickListener(this); - quickWizardButton = (Button) view.findViewById(R.id.overview_quickwizardbutton); + quickWizardButton = (SingleClickButton) view.findViewById(R.id.overview_quickwizardbutton); quickWizardButton.setOnClickListener(this); - calibrationButton = (Button) view.findViewById(R.id.overview_calibrationbutton); + calibrationButton = (SingleClickButton) view.findViewById(R.id.overview_calibrationbutton); if (calibrationButton != null) calibrationButton.setOnClickListener(this); @@ -320,6 +320,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return view; } catch (Exception e) { Crashlytics.logException(e); + log.debug("Runtime Exception", e); } return null; diff --git a/app/src/main/java/info/nightscout/utils/SingleClickButton.java b/app/src/main/java/info/nightscout/utils/SingleClickButton.java new file mode 100644 index 0000000000..ef0d4d3aec --- /dev/null +++ b/app/src/main/java/info/nightscout/utils/SingleClickButton.java @@ -0,0 +1,67 @@ +package info.nightscout.utils; + +import android.app.Activity; +import android.content.Context; +import android.os.SystemClock; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.view.View; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Created by mike on 22.12.2017. + */ + +public class SingleClickButton extends android.support.v7.widget.AppCompatButton implements View.OnClickListener { + private static Logger log = LoggerFactory.getLogger(SingleClickButton.class); + + Context context; + OnClickListener listener = null; + + public SingleClickButton(Context context) { + super(context); + this.context = context; + super.setOnClickListener(this); + } + + public SingleClickButton(Context context, AttributeSet attrs) { + super(context, attrs); + this.context = context; + super.setOnClickListener(this); + } + + public SingleClickButton(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + this.context = context; + super.setOnClickListener(this); + } + + @Override + public void setOnClickListener(@Nullable OnClickListener l) { + listener = l; + } + + @Override + public void onClick(final View v) { + setEnabled(false); + new Thread(new Runnable() { + @Override + public void run() { + SystemClock.sleep(3000); + Activity activity = (Activity) context; + if (activity != null) + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + setEnabled(true); + log.debug("Button enabled"); + } + }); + } + }).start(); + if (listener != null) + listener.onClick(v); + } +} diff --git a/app/src/main/res/layout/actions_fragment.xml b/app/src/main/res/layout/actions_fragment.xml index bc8f416770..6673099110 100644 --- a/app/src/main/res/layout/actions_fragment.xml +++ b/app/src/main/res/layout/actions_fragment.xml @@ -13,7 +13,7 @@ android:layout_height="wrap_content" android:orientation="vertical"> -