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); } } 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..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 @@ -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.SCREEN_DIM_WAKE_LOCK, "ConfigBuilderPlugin");; } @Override @@ -334,13 +339,27 @@ 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); - PumpEnactResult result = deliverTreatment(insulin, carbs, context); + BolusProgressDialog bolusProgressDialog = null; + if (context != null) { + bolusProgressDialog = new BolusProgressDialog(insulin); + bolusProgressDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "BolusProgress"); + } - if (Config.logCongigBuilderActions) - log.debug("deliverTreatmentFromBolusWizard insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered); + PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); + + bolusProgressDialog.bolusEnded = true; + + if (bolusProgressDialog != null && bolusProgressDialog.running) { + try { + bolusProgressDialog.dismiss(); + } catch (Exception e) { + e.printStackTrace(); // TODO: handle this better + } + } if (result.success) { Treatment t = new Treatment(); @@ -356,11 +375,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); @@ -372,8 +393,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) @@ -393,6 +420,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain t.sendToNSClient(); MainApp.bus().post(new EventTreatmentChange()); } + mWakeLock.release(); return result; } 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..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 @@ -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; @@ -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; @@ -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)); 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..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 @@ -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; } @@ -382,6 +382,7 @@ public class ExecutionService extends Service { while (!stop.stopped && !start.failed) { waitMsec(100); } + waitMsec(300); bolusingTreatment = null; getPumpStatus(); return true; 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/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 { } 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 5d25bed6e9..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,78 +131,88 @@ 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() { 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(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(); + } } bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false); pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false); - manualEnacts = settings.getInt("Objectives" + "manualEnacts", 0); + try { + manualEnacts = SafeParse.stringToInt(settings.getString("Objectives" + "manualEnacts", "0")); + } catch (Exception e) { + e.printStackTrace(); + } if (Config.logPrefsChange) log.debug("Objectives loaded"); } 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..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 @@ -30,12 +30,19 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL TextView stopPressedView; ProgressBar progressBar; - double amount; + static double amount; + public static boolean bolusEnded = false; + public static boolean running = true; boolean started = false; + public BolusProgressDialog() { + super(); + } + public BolusProgressDialog(double amount) { this.amount = amount; + bolusEnded = false; } @Override @@ -59,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 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..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; - - 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 883b1f7646..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 @@ -82,10 +82,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener { Context parentContext; - public WizardDialog(Context context) { - mHandlerThread = new HandlerThread(NewExtendedBolusDialog.class.getSimpleName()); + 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(); } } 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"); } }); 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"> + + + + + Прекъсване Презареждане 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