From 40aada0eb4a7af369686531016772dd59c579d09 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 12 Aug 2016 20:22:44 +0200 Subject: [PATCH 01/15] ajdust some danar pump comm params --- .../androidaps/plugins/DanaR/DanaRPump.java | 4 +++- .../plugins/DanaR/Services/ExecutionService.java | 2 +- .../DanaR/comm/MsgInitConnStatusOption.java | 1 - .../plugins/DanaR/comm/MsgSettingShippingInfo.java | 5 +++++ .../plugins/Objectives/ObjectivesPlugin.java | 14 +++++++++++--- app/src/main/res/values-bg/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values/strings.xml | 4 ++-- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java index ea692eb25c..579407e365 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java @@ -139,7 +139,7 @@ public class DanaRPump { } else { time = df.format(h) + ":00"; } - basals.put(new JSONObject().put("time", time).put("timeAsSeconds", h * basalIncrement).put("value", pumpProfiles[activeProfile][h])); + basals.put(new JSONObject().put("time", time).put("timeAsSeconds", h * basalIncrement).put("value", pumpProfiles[activeProfile][h])); } profile.put("basal", basals); @@ -149,6 +149,8 @@ public class DanaRPump { store.put("" + (activeProfile + 1), profile); } catch (JSONException e) { e.printStackTrace(); + } catch (Exception e) { + return null; } return new NSProfile(json, "" + (activeProfile + 1)); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java index cb90f25935..2b78538634 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java @@ -175,7 +175,7 @@ public class ExecutionService extends Service { } public void connect(String from) { - if (danaRPump.isNewPump && danaRPump.password != SafeParse.stringToInt(SP.getString("danar_password", "-1"))) { + if (danaRPump.password != -1 && danaRPump.password != SafeParse.stringToInt(SP.getString("danar_password", "-1"))) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error); return; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusOption.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusOption.java index 1b2ca4bd11..b8049c23ee 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusOption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgInitConnStatusOption.java @@ -29,7 +29,6 @@ public class MsgInitConnStatusOption extends MessageBase { int i = intFromBuff(bytes, 8, 1); if (bytes.length >= 21) { DanaRPlugin.getDanaRPump().password = intFromBuff(bytes, 9, 2) ^ 0x3463; - DanaRPlugin.getDanaRPump().isNewPump = true; if (Config.logDanaMessageDetail) log.debug("Pump password: " + DanaRPlugin.getDanaRPump().password); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java index fbc786af6f..ccecfbbd6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingShippingInfo.java @@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.DanaR.comm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.Date; + import info.nightscout.androidaps.Config; import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; @@ -20,6 +22,9 @@ public class MsgSettingShippingInfo extends MessageBase { DanaRPlugin.getDanaRPump().serialNumber = stringFromBuff(bytes, 0, 10); DanaRPlugin.getDanaRPump().shippingDate = dateFromBuff(bytes, 10); DanaRPlugin.getDanaRPump().shippingCountry = asciiStringFromBuff(bytes, 13, 3); + if (DanaRPlugin.getDanaRPump().shippingDate.getTime() > new Date(116, 4, 1).getTime()) { + DanaRPlugin.getDanaRPump().isNewPump = true; + } if (Config.logDanaMessageDetail) { log.debug("Serial number: " + DanaRPlugin.getDanaRPump().serialNumber); log.debug("Shipping date: " + DanaRPlugin.getDanaRPump().shippingDate); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java index 5d25bed6e9..31014b99e9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java @@ -196,12 +196,20 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); for (int num = 0; num < objectives.size(); num++) { Objective o = objectives.get(num); - o.started = new Date(settings.getLong("Objectives" + num + "started", 0)); - o.accomplished = new Date(settings.getLong("Objectives" + num + "accomplished", 0)); + try { + o.started = new Date(settings.getLong("Objectives" + num + "started", 0)); + o.accomplished = new Date(settings.getLong("Objectives" + num + "accomplished", 0)); + } catch (Exception e) { + e.printStackTrace(); + } } bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false); pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false); - manualEnacts = settings.getInt("Objectives" + "manualEnacts", 0); + try { + manualEnacts = settings.getInt("Objectives" + "manualEnacts", 0); + } catch (Exception e) { + e.printStackTrace(); + } if (Config.logPrefsChange) log.debug("Objectives loaded"); } diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index e2c4dc4cb7..fd2ba0a138 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -277,7 +277,7 @@ Прекъсване Презареждане IOB на помпата - Парола за помпа след 2016г + Парола за помпа пълнене Общо %d записа са изпратени Приложено diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index ee18270954..d551bd3c86 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -278,7 +278,7 @@ Pumpa je zaneprázdněna Špatné heslo k pumpě MM 640g - Heslo k pumpě (pouze verze 2016) + Heslo k pumpě Okluze Podáno Stop diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa28b5bfb6..84dbc46616 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -279,7 +279,7 @@ Refill Suspend Connecting for %d s - Pump password (2016 pump only) + Pump password Wrong pump password! Pump is busy Delivered @@ -304,6 +304,6 @@ Enabling additional features for daytime use, such as advanced meal assist You reached allowed limit Target value for calculations - No profile seselcted + No profile selected From 3fb84636db1fc4bbb3a81cd08d8c65a2e5d33b0a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 11:30:43 +0200 Subject: [PATCH 02/15] fix objectives import/export --- .../Objectives/ObjectivesFragment.java | 18 +++++- .../plugins/Objectives/ObjectivesPlugin.java | 63 ++++++++++--------- .../main/res/layout/objectives_fragment.xml | 26 ++++++-- 3 files changed, 70 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java index c1f7e673e0..131c022ae6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java @@ -7,6 +7,7 @@ import android.support.v4.app.Fragment; import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.text.Layout; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -37,6 +38,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener RecyclerView recyclerView; LinearLayoutManager llm; CheckBox enableFake; + LinearLayout fake_layout; + TextView reset; @Override public void onClick(View v) { @@ -82,7 +85,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag(); o.started = new Date(); updateGUI(); - objectivesPlugin.saveProgress(); + ObjectivesPlugin.saveProgress(); } }); holder.verifyButton.setOnClickListener(new View.OnClickListener() { @@ -91,7 +94,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener if (objectivesPlugin.requirementsMet(o.num).done || enableFake.isChecked()) { o.accomplished = new Date(); updateGUI(); - objectivesPlugin.saveProgress(); + ObjectivesPlugin.saveProgress(); } } }); @@ -185,11 +188,20 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener llm = new LinearLayoutManager(view.getContext()); recyclerView.setLayoutManager(llm); enableFake = (CheckBox) view.findViewById(R.id.objectives_fake); + fake_layout = (LinearLayout) view.findViewById(R.id.objectives_fake_layout); + reset = (TextView) view.findViewById(R.id.objectives_reset); enableFake.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { updateGUI(); } }); + reset.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + objectivesPlugin.initializeData(); + objectivesPlugin.saveProgress(); + updateGUI(); + } + }); // Add correct translations to array after app is initialized objectivesPlugin.objectives.get(0).objective = MainApp.sResources.getString(R.string.objectives_0_objective); @@ -216,7 +228,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener activity.runOnUiThread(new Runnable() { @Override public void run() { - RecyclerViewAdapter adapter = new RecyclerViewAdapter(objectivesPlugin.objectives); + RecyclerViewAdapter adapter = new RecyclerViewAdapter(ObjectivesPlugin.objectives); recyclerView.setAdapter(adapter); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java index 31014b99e9..3aeb44125a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesPlugin.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.utils.SafeParse; /** * Created by mike on 05.08.2016. @@ -130,66 +131,68 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { } - private void initializeData() { + public void initializeData() { objectives = new ArrayList<>(); objectives.add(new Objective(0, MainApp.sResources.getString(R.string.objectives_0_objective), MainApp.sResources.getString(R.string.objectives_0_gate), - new Date(0, 0, 0), + new Date(0), 1, // 1 day - new Date(0, 0, 0))); + new Date(0))); objectives.add(new Objective(1, MainApp.sResources.getString(R.string.objectives_1_objective), MainApp.sResources.getString(R.string.objectives_1_gate), - new Date(0, 0, 0), + new Date(0), 7, // 7 days - new Date(0, 0, 0))); + new Date(0))); objectives.add(new Objective(2, MainApp.sResources.getString(R.string.objectives_2_objective), MainApp.sResources.getString(R.string.objectives_2_gate), - new Date(0, 0, 0), + new Date(0), 0, // 0 days - new Date(0, 0, 0))); + new Date(0))); objectives.add(new Objective(3, MainApp.sResources.getString(R.string.objectives_3_objective), MainApp.sResources.getString(R.string.objectives_3_gate), - new Date(0, 0, 0), + new Date(0), 5, // 5 days - new Date(0, 0, 0))); + new Date(0))); objectives.add(new Objective(4, MainApp.sResources.getString(R.string.objectives_4_objective), MainApp.sResources.getString(R.string.objectives_4_gate), - new Date(0, 0, 0), + new Date(0), 1, - new Date(0, 0, 0))); + new Date(0))); objectives.add(new Objective(5, MainApp.sResources.getString(R.string.objectives_5_objective), MainApp.sResources.getString(R.string.objectives_5_gate), - new Date(0, 0, 0), + new Date(0), 7, - new Date(0, 0, 0))); + new Date(0))); objectives.add(new Objective(6, MainApp.sResources.getString(R.string.objectives_6_objective), "", - new Date(0, 0, 0), + new Date(0), 1, - new Date(0, 0, 0))); + new Date(0))); } public static void saveProgress() { - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - SharedPreferences.Editor editor = settings.edit(); - for (int num = 0; num < objectives.size(); num++) { - Objective o = objectives.get(num); - editor.putLong("Objectives" + num + "started", o.started.getTime()); - editor.putLong("Objectives" + num + "accomplished", o.accomplished.getTime()); + if (objectives != null) { + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + SharedPreferences.Editor editor = settings.edit(); + for (int num = 0; num < objectives.size(); num++) { + Objective o = objectives.get(num); + editor.putString("Objectives" + num + "started", Long.toString(o.started.getTime())); + editor.putString("Objectives" + num + "accomplished", Long.toString(o.accomplished.getTime())); + } + editor.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS); + editor.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS); + editor.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts)); + editor.apply(); + if (Config.logPrefsChange) + log.debug("Objectives stored"); } - editor.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS); - editor.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS); - editor.putInt("Objectives" + "manualEnacts", manualEnacts); - editor.apply(); - if (Config.logPrefsChange) - log.debug("Objectives stored"); } void loadProgress() { @@ -197,8 +200,8 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { for (int num = 0; num < objectives.size(); num++) { Objective o = objectives.get(num); try { - o.started = new Date(settings.getLong("Objectives" + num + "started", 0)); - o.accomplished = new Date(settings.getLong("Objectives" + num + "accomplished", 0)); + o.started = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "started", "0"))); + o.accomplished = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "accomplished", "0"))); } catch (Exception e) { e.printStackTrace(); } @@ -206,7 +209,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false); pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false); try { - manualEnacts = settings.getInt("Objectives" + "manualEnacts", 0); + manualEnacts = SafeParse.stringToInt(settings.getString("Objectives" + "manualEnacts", "0")); } catch (Exception e) { e.printStackTrace(); } diff --git a/app/src/main/res/layout/objectives_fragment.xml b/app/src/main/res/layout/objectives_fragment.xml index c28805aac8..75fa19eaf1 100644 --- a/app/src/main/res/layout/objectives_fragment.xml +++ b/app/src/main/res/layout/objectives_fragment.xml @@ -9,11 +9,29 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:id="@+id/objectives_fake_layout" + android:visibility="gone"> + + + + + Date: Sat, 13 Aug 2016 12:30:10 +0200 Subject: [PATCH 03/15] upload only fresh pump status --- .../nightscout/androidaps/plugins/DanaR/DanaRPlugin.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index 994a41d515..cc1f9a0fc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -576,6 +576,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public JSONObject getJSONStatus() { + if (getDanaRPump().lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) { + return null; + } JSONObject pump = new JSONObject(); JSONObject battery = new JSONObject(); JSONObject status = new JSONObject(); @@ -583,7 +586,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf try { battery.put("percent", getDanaRPump().batteryRemaining); status.put("status", "normal"); - status.put("timestamp", DateUtil.toISOString(new Date())); + status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection)); if (isTempBasalInProgress()) { extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalStart", DateUtil.toISOString(getTempBasal().timeStart)); From 609f99dc1c97751be55b4ad1f6129ec7f9f40435 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 12:33:20 +0200 Subject: [PATCH 04/15] fix danar show in prefs --- .../java/info/nightscout/androidaps/PreferencesActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index 9afa7be945..65ea26394c 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -89,7 +89,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre if (Config.DANAR) { addPreferencesFromResource(R.xml.pref_danar); DanaRPlugin danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); - if (danaRPlugin.isEnabled(PluginBase.PROFILE)) { + if (danaRPlugin.isEnabled(PluginBase.PUMP)) { addPreferencesFromResource(R.xml.pref_danarprofile); } } From 6c9c0d8223b5ea3e75847d9a6af92edd823629bc Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 12:36:33 +0200 Subject: [PATCH 05/15] hide danar profile option when pump disabled --- .../info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index cc1f9a0fc1..715430dc8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -119,7 +119,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public boolean isEnabled(int type) { - if (type == PluginBase.PROFILE) return fragmentProfileEnabled; + if (type == PluginBase.PROFILE) return fragmentProfileEnabled && fragmentPumpEnabled; else if (type == PluginBase.PUMP) return fragmentPumpEnabled; else if (type == PluginBase.CONSTRAINTS) return fragmentPumpEnabled; return false; From d85bb7db4dfaf36ff213ac50281e253f45a496ce Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 12:47:15 +0200 Subject: [PATCH 06/15] fix double treatment upload from wizard --- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 12 +++++++++++- .../plugins/Overview/Dialogs/WizardDialog.java | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 9b999a4cf0..9bf0fa8ea8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -337,7 +337,17 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain insulin = applyBolusConstraints(insulin); carbs = applyCarbsConstraints(carbs); - PumpEnactResult result = deliverTreatment(insulin, carbs, context); + BolusProgressDialog bolusProgressDialog = null; + if (context != null) { + bolusProgressDialog = new BolusProgressDialog(insulin); + bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress"); + } + + PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); + + if (bolusProgressDialog != null) { + bolusProgressDialog.dismiss(); + } if (Config.logCongigBuilderActions) log.debug("deliverTreatmentFromBolusWizard insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered); 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 883b1f7646..1fdfd2a454 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 @@ -83,7 +83,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { Context parentContext; public WizardDialog(Context context) { - mHandlerThread = new HandlerThread(NewExtendedBolusDialog.class.getSimpleName()); + mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName()); mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); parentContext = context; From 129c88478fe207fce70ba03f61eae51777ded4ef Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 15:07:57 +0200 Subject: [PATCH 07/15] empty constructor in progressdialog --- .../plugins/Overview/Dialogs/BolusProgressDialog.java | 6 +++++- .../plugins/Overview/Dialogs/NewTreatmentDialog.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index 4952adec79..a03f7f0b2f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -30,10 +30,14 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL TextView stopPressedView; ProgressBar progressBar; - double amount; + static double amount; boolean started = false; + public BolusProgressDialog() { + super(); + } + public BolusProgressDialog(double amount) { this.amount = amount; } 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 ef1f9ab0d7..199419a485 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 @@ -38,7 +38,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Handler mHandler; public static HandlerThread mHandlerThread; - Context parentContext; + Context parentContext = null; public NewTreatmentDialog(Context context) { mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName()); From 4793561f7c43186cadc04596ba5a38486e851328 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 13 Aug 2016 20:02:54 +0200 Subject: [PATCH 08/15] Align class name with file name to fix error on case-sensitive filesystems/OSs. --- .../plugins/NSProfileViewer/NSProfileViewerFragment.java | 4 ++-- .../plugins/NSProfileViewer/NSProfileViewerPlugin.java | 4 ++-- .../NSProfileViewer/events/EventNSProfileViewerUpdateGUI.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java index fcf3a14c81..5ef13866d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java @@ -13,7 +13,7 @@ import com.squareup.otto.Subscribe; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.FragmentBase; -import info.nightscout.androidaps.plugins.NSProfileViewer.events.EventNSProfileViewerUpdateGui; +import info.nightscout.androidaps.plugins.NSProfileViewer.events.EventNSProfileViewerUpdateGUI; import info.nightscout.utils.DecimalFormatter; public class NSProfileViewerFragment extends Fragment implements FragmentBase { @@ -63,7 +63,7 @@ public class NSProfileViewerFragment extends Fragment implements FragmentBase { } @Subscribe - public void onStatusEvent(final EventNSProfileViewerUpdateGui ev) { + public void onStatusEvent(final EventNSProfileViewerUpdateGUI ev) { Activity activity = getActivity(); if (activity != null) activity.runOnUiThread(new Runnable() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerPlugin.java index 5314805d47..f957b46fce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerPlugin.java @@ -19,7 +19,7 @@ import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.ProfileInterface; -import info.nightscout.androidaps.plugins.NSProfileViewer.events.EventNSProfileViewerUpdateGui; +import info.nightscout.androidaps.plugins.NSProfileViewer.events.EventNSProfileViewerUpdateGUI; import info.nightscout.client.data.NSProfile; /** @@ -83,7 +83,7 @@ public class NSProfileViewerPlugin implements PluginBase, ProfileInterface { public void onStatusEvent(final EventNewBasalProfile ev) { profile = new NSProfile(ev.newNSProfile.getData(), ev.newNSProfile.getActiveProfile()); storeNSProfile(); - MainApp.bus().post(new EventNSProfileViewerUpdateGui()); + MainApp.bus().post(new EventNSProfileViewerUpdateGUI()); } private void storeNSProfile() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/events/EventNSProfileViewerUpdateGUI.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/events/EventNSProfileViewerUpdateGUI.java index 734dd696c6..f84515eb56 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/events/EventNSProfileViewerUpdateGUI.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/events/EventNSProfileViewerUpdateGUI.java @@ -3,5 +3,5 @@ package info.nightscout.androidaps.plugins.NSProfileViewer.events; /** * Created by mike on 05.08.2016. */ -public class EventNSProfileViewerUpdateGui { +public class EventNSProfileViewerUpdateGUI { } From d11f0b1ea1876ac25fb51a81b9625d3b5d1c22d9 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 22:16:04 +0200 Subject: [PATCH 09/15] wakelock on bolusing --- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 9bf0fa8ea8..a6056b2d13 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.PowerManager; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; @@ -70,8 +71,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain static Date lastDeviceStatusUpload = new Date(0); + PowerManager.WakeLock mWakeLock; + public ConfigBuilderPlugin() { MainApp.bus().register(this); + PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); + mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaConnection");; } @Override @@ -334,6 +339,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain } public PumpEnactResult deliverTreatmentFromBolusWizard(Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) { + mWakeLock.acquire(); insulin = applyBolusConstraints(insulin); carbs = applyCarbsConstraints(carbs); @@ -366,11 +372,13 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain uploadBolusWizardRecord(t, glucose, glucoseType, carbTime, boluscalc); MainApp.bus().post(new EventTreatmentChange()); } + mWakeLock.release(); return result; } @Override public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) { + mWakeLock.acquire(); insulin = applyBolusConstraints(insulin); carbs = applyCarbsConstraints(carbs); @@ -403,6 +411,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain t.sendToNSClient(); MainApp.bus().post(new EventTreatmentChange()); } + mWakeLock.release(); return result; } From b77bbd5bc6f4a6b009757f33b63310e5e90005dd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 22:16:36 +0200 Subject: [PATCH 10/15] static options in careportal dialog --- .../plugins/Careportal/Dialogs/NewNSTreatmentDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fa6d71366d..9e5361841a 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 @@ -62,7 +62,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick private FragmentActivity context; - private CareportalFragment.OptionsToShow options; + private static CareportalFragment.OptionsToShow options; NSProfile profile; String units; From 9c3b8dc2b9515c7f8cc9c0036da3f3857e1bb361 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 13 Aug 2016 23:00:10 +0200 Subject: [PATCH 11/15] typo --- .../androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index a6056b2d13..5bd54a5353 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -76,7 +76,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain public ConfigBuilderPlugin() { MainApp.bus().register(this); PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); - mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DanaConnection");; + mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ConfigBuilderPlugin");; } @Override From be8c1c2a832769a2105418ccc95adb6313939017 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 14 Aug 2016 10:13:26 +0200 Subject: [PATCH 12/15] change to screen lock, better context handling --- .../ConfigBuilder/ConfigBuilderPlugin.java | 2 +- .../androidaps/plugins/DanaR/DanaRPlugin.java | 2 +- .../Overview/Dialogs/WizardDialog.java | 27 +++++++++++-------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 5bd54a5353..df452796cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -76,7 +76,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain public ConfigBuilderPlugin() { MainApp.bus().register(this); PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE); - mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ConfigBuilderPlugin");; + mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "ConfigBuilderPlugin");; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java index 715430dc8c..6541671974 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPlugin.java @@ -240,7 +240,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (insulin > 0 || carbs > 0) { Treatment t = new Treatment(); boolean connectionOK = false; - if (insulin > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t); + if (insulin > 0 || carbs > 0) connectionOK = sExecutionService.bolus(insulin, carbs, t); PumpEnactResult result = new PumpEnactResult(); result.success = connectionOK; result.bolusDelivered = t.insulin; 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 1fdfd2a454..3e845e8419 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 @@ -82,10 +82,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener { Context parentContext; - public WizardDialog(Context context) { + public WizardDialog() { mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName()); mHandlerThread.start(); mHandler = new Handler(mHandlerThread.getLooper()); + } + + + public WizardDialog(Context context) { + this(); parentContext = context; } @@ -120,7 +125,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { @Override public void onNothingSelected(AdapterView parent) { - ToastUtils.showToastInUiThread(getContext(), MainApp.sResources.getString(R.string.noprofileselected)); + ToastUtils.showToastInUiThread(parentContext, MainApp.sResources.getString(R.string.noprofileselected)); wizardDialogDeliverButton.setVisibility(View.GONE); } }; @@ -192,10 +197,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener { confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; if (insulinAfterConstraints - calculatedTotalInsulin != 0 || carbsAfterConstraints != calculatedCarbs) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror)); + AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput)); - builder.setPositiveButton(getContext().getString(R.string.ok), null); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); builder.show(); return; } @@ -203,8 +208,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener { final Double finalInsulinAfterConstraints = insulinAfterConstraints; final Integer finalCarbsAfterConstraints = carbsAfterConstraints; - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(getContext().getString(R.string.confirmation)); + AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); builder.setMessage(confirmMessage); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -223,10 +228,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener { boluscalcJSON ); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); - builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror)); + AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); builder.setMessage(result.comment); - builder.setPositiveButton(getContext().getString(R.string.ok), null); + builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); builder.show(); } } @@ -253,7 +258,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { ArrayList profileList; profileList = profile.getProfileList(); - ArrayAdapter adapter = new ArrayAdapter(getContext(), + ArrayAdapter adapter = new ArrayAdapter(parentContext, android.R.layout.simple_spinner_item, profileList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); profileSpinner.setAdapter(adapter); From bb041b1c06f5ef8adb7296a4aec69d2be66ba839 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 14 Aug 2016 20:19:47 +0200 Subject: [PATCH 13/15] more progress dialog tweaking --- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 10 ++++++++-- .../plugins/Overview/Dialogs/BolusProgressDialog.java | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index df452796cf..411e50d05f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -390,8 +390,14 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); - if (bolusProgressDialog != null) { - bolusProgressDialog.dismiss(); + bolusProgressDialog.bolusEnded = true; + + if (bolusProgressDialog != null && bolusProgressDialog.running) { + try { + bolusProgressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); // TODO: handle this better + } } if (Config.logCongigBuilderActions) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index a03f7f0b2f..6984397f4f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -31,6 +31,8 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL ProgressBar progressBar; static double amount; + public static boolean bolusEnded = false; + public static boolean running = true; boolean started = false; @@ -40,6 +42,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL public BolusProgressDialog(double amount) { this.amount = amount; + bolusEnded = false; } @Override @@ -63,12 +66,15 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL public void onResume() { super.onResume(); MainApp.bus().register(this); + running = true; + if (bolusEnded) dismiss(); } @Override public void onPause() { super.onPause(); MainApp.bus().unregister(this); + running = false; } @Override From 8864886702d811c3d319f193e07d9cfa3e484bb6 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 14 Aug 2016 20:33:29 +0200 Subject: [PATCH 14/15] more dialogs tweaking --- .../plugins/ConfigBuilder/ConfigBuilderPlugin.java | 13 ++++++++----- .../Overview/Dialogs/NewTreatmentDialog.java | 13 ++++++------- .../plugins/Overview/Dialogs/WizardDialog.java | 2 +- .../plugins/Overview/OverviewFragment.java | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 411e50d05f..e3caaf81ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -351,12 +351,15 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); - if (bolusProgressDialog != null) { - bolusProgressDialog.dismiss(); - } + bolusProgressDialog.bolusEnded = true; - if (Config.logCongigBuilderActions) - log.debug("deliverTreatmentFromBolusWizard insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered); + if (bolusProgressDialog != null && bolusProgressDialog.running) { + try { + bolusProgressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); // TODO: handle this better + } + } if (result.success) { Treatment t = new Treatment(); 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 199419a485..a105d07536 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 @@ -38,13 +38,10 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene Handler mHandler; public static HandlerThread mHandlerThread; - Context parentContext = null; - - public NewTreatmentDialog(Context context) { + public NewTreatmentDialog() { mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName()); mHandlerThread.start(); this.mHandler = new Handler(mHandlerThread.getLooper()); - parentContext = context; } @Override @@ -91,7 +88,9 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene final Double finalInsulinAfterConstraints = insulinAfterConstraints; final Integer finalCarbsAfterConstraints = carbsAfterConstraints; - AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); + final Context context = getContext(); + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(this.getContext().getString(R.string.confirmation)); builder.setMessage(confirmMessage); builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @@ -101,9 +100,9 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene mHandler.post(new Runnable() { @Override public void run() { - PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, parentContext); + PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, context); if (!result.success) { - AlertDialog.Builder builder = new AlertDialog.Builder(parentContext); + AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); builder.setMessage(result.comment); builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); 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 3e845e8419..b9db84bd22 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 @@ -258,7 +258,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener { ArrayList profileList; profileList = profile.getProfileList(); - ArrayAdapter adapter = new ArrayAdapter(parentContext, + ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item, profileList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); profileSpinner.setAdapter(adapter); 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 1c225fc73a..e5235028d6 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 @@ -137,7 +137,7 @@ public class OverviewFragment extends Fragment { @Override public void onClick(View view) { FragmentManager manager = getFragmentManager(); - NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(getContext()); + NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(); treatmentDialogFragment.show(manager, "TreatmentDialog"); } }); From 451a455d3d8447aa16fafade49f8e8b77c759c24 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 14 Aug 2016 20:35:00 +0200 Subject: [PATCH 15/15] longer wait in comm after bolus --- .../androidaps/plugins/DanaR/Services/ExecutionService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java index 2b78538634..e9151a53c3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Services/ExecutionService.java @@ -382,6 +382,7 @@ public class ExecutionService extends Service { while (!stop.stopped && !start.failed) { waitMsec(100); } + waitMsec(300); bolusingTreatment = null; getPumpStatus(); return true;