This commit is contained in:
Milos Kozak 2016-08-15 10:05:00 +02:00
commit ced974e96d
20 changed files with 171 additions and 78 deletions

View file

@ -89,7 +89,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
if (Config.DANAR) { if (Config.DANAR) {
addPreferencesFromResource(R.xml.pref_danar); addPreferencesFromResource(R.xml.pref_danar);
DanaRPlugin danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class); DanaRPlugin danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
if (danaRPlugin.isEnabled(PluginBase.PROFILE)) { if (danaRPlugin.isEnabled(PluginBase.PUMP)) {
addPreferencesFromResource(R.xml.pref_danarprofile); addPreferencesFromResource(R.xml.pref_danarprofile);
} }
} }

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -70,8 +71,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
static Date lastDeviceStatusUpload = new Date(0); static Date lastDeviceStatusUpload = new Date(0);
PowerManager.WakeLock mWakeLock;
public ConfigBuilderPlugin() { public ConfigBuilderPlugin() {
MainApp.bus().register(this); MainApp.bus().register(this);
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "ConfigBuilderPlugin");;
} }
@Override @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) { public PumpEnactResult deliverTreatmentFromBolusWizard(Context context, Double insulin, Integer carbs, Double glucose, String glucoseType, int carbTime, JSONObject boluscalc) {
mWakeLock.acquire();
insulin = applyBolusConstraints(insulin); insulin = applyBolusConstraints(insulin);
carbs = applyCarbsConstraints(carbs); 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) PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context);
log.debug("deliverTreatmentFromBolusWizard insulin: " + insulin + " carbs: " + carbs + " success: " + result.success + " enacted: " + result.enacted + " bolusDelivered: " + result.bolusDelivered);
bolusProgressDialog.bolusEnded = true;
if (bolusProgressDialog != null && bolusProgressDialog.running) {
try {
bolusProgressDialog.dismiss();
} catch (Exception e) {
e.printStackTrace(); // TODO: handle this better
}
}
if (result.success) { if (result.success) {
Treatment t = new Treatment(); Treatment t = new Treatment();
@ -356,11 +375,13 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
uploadBolusWizardRecord(t, glucose, glucoseType, carbTime, boluscalc); uploadBolusWizardRecord(t, glucose, glucoseType, carbTime, boluscalc);
MainApp.bus().post(new EventTreatmentChange()); MainApp.bus().post(new EventTreatmentChange());
} }
mWakeLock.release();
return result; return result;
} }
@Override @Override
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) { public PumpEnactResult deliverTreatment(Double insulin, Integer carbs, Context context) {
mWakeLock.acquire();
insulin = applyBolusConstraints(insulin); insulin = applyBolusConstraints(insulin);
carbs = applyCarbsConstraints(carbs); carbs = applyCarbsConstraints(carbs);
@ -372,8 +393,14 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context); PumpEnactResult result = activePump.deliverTreatment(insulin, carbs, context);
if (bolusProgressDialog != null) { bolusProgressDialog.bolusEnded = true;
bolusProgressDialog.dismiss();
if (bolusProgressDialog != null && bolusProgressDialog.running) {
try {
bolusProgressDialog.dismiss();
} catch (Exception e) {
e.printStackTrace(); // TODO: handle this better
}
} }
if (Config.logCongigBuilderActions) if (Config.logCongigBuilderActions)
@ -393,6 +420,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
t.sendToNSClient(); t.sendToNSClient();
MainApp.bus().post(new EventTreatmentChange()); MainApp.bus().post(new EventTreatmentChange());
} }
mWakeLock.release();
return result; return result;
} }

View file

@ -119,7 +119,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public boolean isEnabled(int type) { 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.PUMP) return fragmentPumpEnabled;
else if (type == PluginBase.CONSTRAINTS) return fragmentPumpEnabled; else if (type == PluginBase.CONSTRAINTS) return fragmentPumpEnabled;
return false; return false;
@ -240,7 +240,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
if (insulin > 0 || carbs > 0) { if (insulin > 0 || carbs > 0) {
Treatment t = new Treatment(); Treatment t = new Treatment();
boolean connectionOK = false; 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(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
@ -576,6 +576,9 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public JSONObject getJSONStatus() { public JSONObject getJSONStatus() {
if (getDanaRPump().lastConnection.getTime() + 5 * 60 * 1000L < new Date().getTime()) {
return null;
}
JSONObject pump = new JSONObject(); JSONObject pump = new JSONObject();
JSONObject battery = new JSONObject(); JSONObject battery = new JSONObject();
JSONObject status = new JSONObject(); JSONObject status = new JSONObject();
@ -583,7 +586,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
try { try {
battery.put("percent", getDanaRPump().batteryRemaining); battery.put("percent", getDanaRPump().batteryRemaining);
status.put("status", "normal"); status.put("status", "normal");
status.put("timestamp", DateUtil.toISOString(new Date())); status.put("timestamp", DateUtil.toISOString(getDanaRPump().lastConnection));
if (isTempBasalInProgress()) { if (isTempBasalInProgress()) {
extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate()); extended.put("TempBasalAbsoluteRate", getTempBasalAbsoluteRate());
extended.put("TempBasalStart", DateUtil.toISOString(getTempBasal().timeStart)); extended.put("TempBasalStart", DateUtil.toISOString(getTempBasal().timeStart));

View file

@ -139,7 +139,7 @@ public class DanaRPump {
} else { } else {
time = df.format(h) + ":00"; 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); profile.put("basal", basals);
@ -149,6 +149,8 @@ public class DanaRPump {
store.put("" + (activeProfile + 1), profile); store.put("" + (activeProfile + 1), profile);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) {
return null;
} }
return new NSProfile(json, "" + (activeProfile + 1)); return new NSProfile(json, "" + (activeProfile + 1));
} }

View file

@ -175,7 +175,7 @@ public class ExecutionService extends Service {
} }
public void connect(String from) { 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); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.wrongpumppassword), R.raw.error);
return; return;
} }
@ -382,6 +382,7 @@ public class ExecutionService extends Service {
while (!stop.stopped && !start.failed) { while (!stop.stopped && !start.failed) {
waitMsec(100); waitMsec(100);
} }
waitMsec(300);
bolusingTreatment = null; bolusingTreatment = null;
getPumpStatus(); getPumpStatus();
return true; return true;

View file

@ -29,7 +29,6 @@ public class MsgInitConnStatusOption extends MessageBase {
int i = intFromBuff(bytes, 8, 1); int i = intFromBuff(bytes, 8, 1);
if (bytes.length >= 21) { if (bytes.length >= 21) {
DanaRPlugin.getDanaRPump().password = intFromBuff(bytes, 9, 2) ^ 0x3463; DanaRPlugin.getDanaRPump().password = intFromBuff(bytes, 9, 2) ^ 0x3463;
DanaRPlugin.getDanaRPump().isNewPump = true;
if (Config.logDanaMessageDetail) if (Config.logDanaMessageDetail)
log.debug("Pump password: " + DanaRPlugin.getDanaRPump().password); log.debug("Pump password: " + DanaRPlugin.getDanaRPump().password);
} }

View file

@ -3,6 +3,8 @@ package info.nightscout.androidaps.plugins.DanaR.comm;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin; 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().serialNumber = stringFromBuff(bytes, 0, 10);
DanaRPlugin.getDanaRPump().shippingDate = dateFromBuff(bytes, 10); DanaRPlugin.getDanaRPump().shippingDate = dateFromBuff(bytes, 10);
DanaRPlugin.getDanaRPump().shippingCountry = asciiStringFromBuff(bytes, 13, 3); 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) { if (Config.logDanaMessageDetail) {
log.debug("Serial number: " + DanaRPlugin.getDanaRPump().serialNumber); log.debug("Serial number: " + DanaRPlugin.getDanaRPump().serialNumber);
log.debug("Shipping date: " + DanaRPlugin.getDanaRPump().shippingDate); log.debug("Shipping date: " + DanaRPlugin.getDanaRPump().shippingDate);

View file

@ -13,7 +13,7 @@ import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.FragmentBase; 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; import info.nightscout.utils.DecimalFormatter;
public class NSProfileViewerFragment extends Fragment implements FragmentBase { public class NSProfileViewerFragment extends Fragment implements FragmentBase {
@ -63,7 +63,7 @@ public class NSProfileViewerFragment extends Fragment implements FragmentBase {
} }
@Subscribe @Subscribe
public void onStatusEvent(final EventNSProfileViewerUpdateGui ev) { public void onStatusEvent(final EventNSProfileViewerUpdateGUI ev) {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) if (activity != null)
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface; 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; import info.nightscout.client.data.NSProfile;
/** /**
@ -83,7 +83,7 @@ public class NSProfileViewerPlugin implements PluginBase, ProfileInterface {
public void onStatusEvent(final EventNewBasalProfile ev) { public void onStatusEvent(final EventNewBasalProfile ev) {
profile = new NSProfile(ev.newNSProfile.getData(), ev.newNSProfile.getActiveProfile()); profile = new NSProfile(ev.newNSProfile.getData(), ev.newNSProfile.getActiveProfile());
storeNSProfile(); storeNSProfile();
MainApp.bus().post(new EventNSProfileViewerUpdateGui()); MainApp.bus().post(new EventNSProfileViewerUpdateGUI());
} }
private void storeNSProfile() { private void storeNSProfile() {

View file

@ -3,5 +3,5 @@ package info.nightscout.androidaps.plugins.NSProfileViewer.events;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class EventNSProfileViewerUpdateGui { public class EventNSProfileViewerUpdateGUI {
} }

View file

@ -7,6 +7,7 @@ import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Layout;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -37,6 +38,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
RecyclerView recyclerView; RecyclerView recyclerView;
LinearLayoutManager llm; LinearLayoutManager llm;
CheckBox enableFake; CheckBox enableFake;
LinearLayout fake_layout;
TextView reset;
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -82,7 +85,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag(); ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag();
o.started = new Date(); o.started = new Date();
updateGUI(); updateGUI();
objectivesPlugin.saveProgress(); ObjectivesPlugin.saveProgress();
} }
}); });
holder.verifyButton.setOnClickListener(new View.OnClickListener() { 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()) { if (objectivesPlugin.requirementsMet(o.num).done || enableFake.isChecked()) {
o.accomplished = new Date(); o.accomplished = new Date();
updateGUI(); updateGUI();
objectivesPlugin.saveProgress(); ObjectivesPlugin.saveProgress();
} }
} }
}); });
@ -185,11 +188,20 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
llm = new LinearLayoutManager(view.getContext()); llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm); recyclerView.setLayoutManager(llm);
enableFake = (CheckBox) view.findViewById(R.id.objectives_fake); 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() { enableFake.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
updateGUI(); 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 // Add correct translations to array after app is initialized
objectivesPlugin.objectives.get(0).objective = MainApp.sResources.getString(R.string.objectives_0_objective); 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() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
RecyclerViewAdapter adapter = new RecyclerViewAdapter(objectivesPlugin.objectives); RecyclerViewAdapter adapter = new RecyclerViewAdapter(ObjectivesPlugin.objectives);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
} }
}); });

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.utils.SafeParse;
/** /**
* Created by mike on 05.08.2016. * 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 = new ArrayList<>();
objectives.add(new Objective(0, objectives.add(new Objective(0,
MainApp.sResources.getString(R.string.objectives_0_objective), MainApp.sResources.getString(R.string.objectives_0_objective),
MainApp.sResources.getString(R.string.objectives_0_gate), MainApp.sResources.getString(R.string.objectives_0_gate),
new Date(0, 0, 0), new Date(0),
1, // 1 day 1, // 1 day
new Date(0, 0, 0))); new Date(0)));
objectives.add(new Objective(1, objectives.add(new Objective(1,
MainApp.sResources.getString(R.string.objectives_1_objective), MainApp.sResources.getString(R.string.objectives_1_objective),
MainApp.sResources.getString(R.string.objectives_1_gate), MainApp.sResources.getString(R.string.objectives_1_gate),
new Date(0, 0, 0), new Date(0),
7, // 7 days 7, // 7 days
new Date(0, 0, 0))); new Date(0)));
objectives.add(new Objective(2, objectives.add(new Objective(2,
MainApp.sResources.getString(R.string.objectives_2_objective), MainApp.sResources.getString(R.string.objectives_2_objective),
MainApp.sResources.getString(R.string.objectives_2_gate), MainApp.sResources.getString(R.string.objectives_2_gate),
new Date(0, 0, 0), new Date(0),
0, // 0 days 0, // 0 days
new Date(0, 0, 0))); new Date(0)));
objectives.add(new Objective(3, objectives.add(new Objective(3,
MainApp.sResources.getString(R.string.objectives_3_objective), MainApp.sResources.getString(R.string.objectives_3_objective),
MainApp.sResources.getString(R.string.objectives_3_gate), MainApp.sResources.getString(R.string.objectives_3_gate),
new Date(0, 0, 0), new Date(0),
5, // 5 days 5, // 5 days
new Date(0, 0, 0))); new Date(0)));
objectives.add(new Objective(4, objectives.add(new Objective(4,
MainApp.sResources.getString(R.string.objectives_4_objective), MainApp.sResources.getString(R.string.objectives_4_objective),
MainApp.sResources.getString(R.string.objectives_4_gate), MainApp.sResources.getString(R.string.objectives_4_gate),
new Date(0, 0, 0), new Date(0),
1, 1,
new Date(0, 0, 0))); new Date(0)));
objectives.add(new Objective(5, objectives.add(new Objective(5,
MainApp.sResources.getString(R.string.objectives_5_objective), MainApp.sResources.getString(R.string.objectives_5_objective),
MainApp.sResources.getString(R.string.objectives_5_gate), MainApp.sResources.getString(R.string.objectives_5_gate),
new Date(0, 0, 0), new Date(0),
7, 7,
new Date(0, 0, 0))); new Date(0)));
objectives.add(new Objective(6, objectives.add(new Objective(6,
MainApp.sResources.getString(R.string.objectives_6_objective), MainApp.sResources.getString(R.string.objectives_6_objective),
"", "",
new Date(0, 0, 0), new Date(0),
1, 1,
new Date(0, 0, 0))); new Date(0)));
} }
public static void saveProgress() { public static void saveProgress() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); if (objectives != null) {
SharedPreferences.Editor editor = settings.edit(); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
for (int num = 0; num < objectives.size(); num++) { SharedPreferences.Editor editor = settings.edit();
Objective o = objectives.get(num); for (int num = 0; num < objectives.size(); num++) {
editor.putLong("Objectives" + num + "started", o.started.getTime()); Objective o = objectives.get(num);
editor.putLong("Objectives" + num + "accomplished", o.accomplished.getTime()); 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() { void loadProgress() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
for (int num = 0; num < objectives.size(); num++) { for (int num = 0; num < objectives.size(); num++) {
Objective o = objectives.get(num); Objective o = objectives.get(num);
o.started = new Date(settings.getLong("Objectives" + num + "started", 0)); try {
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();
}
} }
bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false); bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false);
pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", 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) if (Config.logPrefsChange)
log.debug("Objectives loaded"); log.debug("Objectives loaded");
} }

View file

@ -30,12 +30,19 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
TextView stopPressedView; TextView stopPressedView;
ProgressBar progressBar; ProgressBar progressBar;
double amount; static double amount;
public static boolean bolusEnded = false;
public static boolean running = true;
boolean started = false; boolean started = false;
public BolusProgressDialog() {
super();
}
public BolusProgressDialog(double amount) { public BolusProgressDialog(double amount) {
this.amount = amount; this.amount = amount;
bolusEnded = false;
} }
@Override @Override
@ -59,12 +66,15 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
MainApp.bus().register(this); MainApp.bus().register(this);
running = true;
if (bolusEnded) dismiss();
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
MainApp.bus().unregister(this); MainApp.bus().unregister(this);
running = false;
} }
@Override @Override

View file

@ -38,13 +38,10 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
Handler mHandler; Handler mHandler;
public static HandlerThread mHandlerThread; public static HandlerThread mHandlerThread;
Context parentContext; public NewTreatmentDialog() {
public NewTreatmentDialog(Context context) {
mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName()); mHandlerThread = new HandlerThread(NewTreatmentDialog.class.getSimpleName());
mHandlerThread.start(); mHandlerThread.start();
this.mHandler = new Handler(mHandlerThread.getLooper()); this.mHandler = new Handler(mHandlerThread.getLooper());
parentContext = context;
} }
@Override @Override
@ -91,7 +88,9 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
final Double finalInsulinAfterConstraints = insulinAfterConstraints; final Double finalInsulinAfterConstraints = insulinAfterConstraints;
final Integer finalCarbsAfterConstraints = carbsAfterConstraints; 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.setTitle(this.getContext().getString(R.string.confirmation));
builder.setMessage(confirmMessage); builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@ -101,9 +100,9 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, parentContext); PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints, context);
if (!result.success) { 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.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
builder.setMessage(result.comment); builder.setMessage(result.comment);
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);

View file

@ -82,10 +82,15 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
Context parentContext; Context parentContext;
public WizardDialog(Context context) { public WizardDialog() {
mHandlerThread = new HandlerThread(NewExtendedBolusDialog.class.getSimpleName()); mHandlerThread = new HandlerThread(WizardDialog.class.getSimpleName());
mHandlerThread.start(); mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper()); mHandler = new Handler(mHandlerThread.getLooper());
}
public WizardDialog(Context context) {
this();
parentContext = context; parentContext = context;
} }
@ -120,7 +125,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
@Override @Override
public void onNothingSelected(AdapterView<?> parent) { 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); wizardDialogDeliverButton.setVisibility(View.GONE);
} }
}; };
@ -192,10 +197,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g"; confirmMessage += "\n" + getString(R.string.carbs) + ": " + carbsAfterConstraints + "g";
if (insulinAfterConstraints - calculatedTotalInsulin != 0 || carbsAfterConstraints != calculatedCarbs) { if (insulinAfterConstraints - calculatedTotalInsulin != 0 || carbsAfterConstraints != calculatedCarbs) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror)); builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput)); 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(); builder.show();
return; return;
} }
@ -203,8 +208,8 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
final Double finalInsulinAfterConstraints = insulinAfterConstraints; final Double finalInsulinAfterConstraints = insulinAfterConstraints;
final Integer finalCarbsAfterConstraints = carbsAfterConstraints; final Integer finalCarbsAfterConstraints = carbsAfterConstraints;
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
builder.setTitle(getContext().getString(R.string.confirmation)); builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
builder.setMessage(confirmMessage); builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
@ -223,10 +228,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
boluscalcJSON boluscalcJSON
); );
if (!result.success) { if (!result.success) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(parentContext);
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror)); builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror));
builder.setMessage(result.comment); builder.setMessage(result.comment);
builder.setPositiveButton(getContext().getString(R.string.ok), null); builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null);
builder.show(); builder.show();
} }
} }

View file

@ -137,7 +137,7 @@ public class OverviewFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog(getContext()); NewTreatmentDialog treatmentDialogFragment = new NewTreatmentDialog();
treatmentDialogFragment.show(manager, "TreatmentDialog"); treatmentDialogFragment.show(manager, "TreatmentDialog");
} }
}); });

View file

@ -9,11 +9,29 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<CheckBox <LinearLayout
android:layout_width="wrap_content" android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Enable fake time and progress" android:id="@+id/objectives_fake_layout"
android:id="@+id/objectives_fake" /> android:visibility="gone">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable fake time and progress"
android:id="@+id/objectives_fake" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:id="@+id/objectives_reset"
android:textColor="#fef900"
android:gravity="right"
android:layout_weight="0.5"
android:layout_marginRight="10dp" />
</LinearLayout>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/objectives_recyclerview" android:id="@+id/objectives_recyclerview"

View file

@ -277,7 +277,7 @@
<string name="danar_history_syspend">Прекъсване</string> <string name="danar_history_syspend">Прекъсване</string>
<string name="danar_historyreload">Презареждане</string> <string name="danar_historyreload">Презареждане</string>
<string name="danar_iob_label">IOB на помпата</string> <string name="danar_iob_label">IOB на помпата</string>
<string name="danar_password">Парола за помпа след 2016г</string> <string name="danar_password">Парола за помпа</string>
<string name="danar_refill">пълнене</string> <string name="danar_refill">пълнене</string>
<string name="danar_totaluploaded" formatted="false">Общо %d записа са изпратени</string> <string name="danar_totaluploaded" formatted="false">Общо %d записа са изпратени</string>
<string name="enacted">Приложено</string> <string name="enacted">Приложено</string>

View file

@ -278,7 +278,7 @@
<string name="pumpbusy">Pumpa je zaneprázdněna</string> <string name="pumpbusy">Pumpa je zaneprázdněna</string>
<string name="wrongpumppassword">Špatné heslo k pumpě</string> <string name="wrongpumppassword">Špatné heslo k pumpě</string>
<string name="mm640g">MM 640g</string> <string name="mm640g">MM 640g</string>
<string name="danar_password">Heslo k pumpě (pouze verze 2016)</string> <string name="danar_password">Heslo k pumpě</string>
<string name="overview_bolusiprogress_occlusion">Okluze</string> <string name="overview_bolusiprogress_occlusion">Okluze</string>
<string name="overview_bolusprogress_delivered">Podáno</string> <string name="overview_bolusprogress_delivered">Podáno</string>
<string name="overview_bolusprogress_stop">Stop</string> <string name="overview_bolusprogress_stop">Stop</string>

View file

@ -279,7 +279,7 @@
<string name="danar_history_refill">Refill</string> <string name="danar_history_refill">Refill</string>
<string name="danar_history_syspend">Suspend</string> <string name="danar_history_syspend">Suspend</string>
<string name="danar_history_connectingfor" formatted="false">Connecting for %d s</string> <string name="danar_history_connectingfor" formatted="false">Connecting for %d s</string>
<string name="danar_password">Pump password (2016 pump only)</string> <string name="danar_password">Pump password</string>
<string name="wrongpumppassword">Wrong pump password!</string> <string name="wrongpumppassword">Wrong pump password!</string>
<string name="pumpbusy">Pump is busy</string> <string name="pumpbusy">Pump is busy</string>
<string name="overview_bolusprogress_delivered">Delivered</string> <string name="overview_bolusprogress_delivered">Delivered</string>
@ -304,6 +304,6 @@
<string name="objectives_6_objective">Enabling additional features for daytime use, such as advanced meal assist</string> <string name="objectives_6_objective">Enabling additional features for daytime use, such as advanced meal assist</string>
<string name="youareonallowedlimit">You reached allowed limit</string> <string name="youareonallowedlimit">You reached allowed limit</string>
<string name="openapsma_target_bg">Target value for calculations</string> <string name="openapsma_target_bg">Target value for calculations</string>
<string name="noprofileselected">No profile seselcted</string> <string name="noprofileselected">No profile selected</string>
</resources> </resources>