Merge pull request #131 from AdrianLxM/tempt-pill

Tempt pill
This commit is contained in:
Milos Kozak 2017-01-21 00:11:07 +01:00 committed by GitHub
commit ea37d9eaa8
13 changed files with 123 additions and 48 deletions

View file

@ -43,6 +43,14 @@ public class Constants {
public static final int CPP_MIN_PERCENTAGE = 50; public static final int CPP_MIN_PERCENTAGE = 50;
public static final int CPP_MAX_PERCENTAGE = 200; public static final int CPP_MAX_PERCENTAGE = 200;
public static final String MAX_BG_DEFAULT_MGDL = "180";
public static final String MAX_BG_DEFAULT_MMOL = "10";
public static final String MIN_BG_DEFAULT_MGDL = "100";
public static final String MIN_BG_DEFAULT_MMOL = "5";
public static final String TARGET_BG_DEFAULT_MGDL = "150";
public static final String TARGET_BG_DEFAULT_MMOL = "7";
// Very Hard Limits Ranges // Very Hard Limits Ranges
// First value is the Lowest and second value is the Highest a Limit can define // First value is the Lowest and second value is the Highest a Limit can define
public static final int[] VERY_HARD_LIMIT_MIN_BG = {72,180}; public static final int[] VERY_HARD_LIMIT_MIN_BG = {72,180};

View file

@ -370,6 +370,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
String enteredBy = SP.getString("careportal_enteredby", ""); String enteredBy = SP.getString("careportal_enteredby", "");
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
try { try {
boolean allowZeroDuration = false;
data.put("created_at", DateUtil.toISOString(eventTime)); data.put("created_at", DateUtil.toISOString(eventTime));
switch (options.eventType) { switch (options.eventType) {
case R.id.careportal_bgcheck: case R.id.careportal_bgcheck:
@ -431,6 +432,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
break; break;
case R.id.careportal_temptarget: case R.id.careportal_temptarget:
data.put("eventType", "Temporary Target"); data.put("eventType", "Temporary Target");
allowZeroDuration = true;
break; break;
} }
if (SafeParse.stringToDouble(bgInputEdit.getText().toString()) != 0d) { if (SafeParse.stringToDouble(bgInputEdit.getText().toString()) != 0d) {
@ -443,7 +445,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
data.put("carbs", SafeParse.stringToDouble(carbsEdit.getText().toString())); data.put("carbs", SafeParse.stringToDouble(carbsEdit.getText().toString()));
if (SafeParse.stringToDouble(insulinEdit.getText().toString()) != 0d) if (SafeParse.stringToDouble(insulinEdit.getText().toString()) != 0d)
data.put("insulin", SafeParse.stringToDouble(insulinEdit.getText().toString())); data.put("insulin", SafeParse.stringToDouble(insulinEdit.getText().toString()));
if (SafeParse.stringToDouble(durationeEdit.getText().toString()) != 0d) if (allowZeroDuration || SafeParse.stringToDouble(durationeEdit.getText().toString()) != 0d)
data.put("duration", SafeParse.stringToDouble(durationeEdit.getText().toString())); data.put("duration", SafeParse.stringToDouble(durationeEdit.getText().toString()));
if (layoutPercent.getVisibility() != View.GONE) if (layoutPercent.getVisibility() != View.GONE)
data.put("percent", SafeParse.stringToDouble(percentEdit.getText().toString())); data.put("percent", SafeParse.stringToDouble(percentEdit.getText().toString()));
@ -607,30 +609,41 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
ConfigBuilderPlugin.uploadCareportalEntryToNS(data); ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
} }
if (options.executeTempTarget) { if (options.executeTempTarget) {
if (data.has("targetBottom") && data.has("targetTop")) {
sHandler.post(new Runnable() {
@Override try {
public void run() { if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration")&& data.getInt("duration") == 0)) {
try { sHandler.post(new Runnable() {
TempTarget tempTarget = new TempTarget(); @Override
tempTarget.timeStart = eventTime; public void run() {
tempTarget.duration = data.getInt("duration"); try {
tempTarget.reason = data.getString("reason"); TempTarget tempTarget = new TempTarget();
tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits()); tempTarget.timeStart = eventTime;
tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits()); tempTarget.duration = data.getInt("duration");
tempTarget.setTimeIndex(tempTarget.getTimeIndex()); tempTarget.reason = data.getString("reason");
Dao<TempTarget, Long> dao = MainApp.getDbHelper().getDaoTempTargets(); if(tempTarget.duration != 0) {
log.debug("Creating new TempTarget db record: " + tempTarget.log()); tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits());
dao.createIfNotExists(tempTarget); tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), MainApp.getConfigBuilder().getActiveProfile().getProfile().getUnits());
MainApp.bus().post(new EventTempTargetRangeChange()); } else {
ConfigBuilderPlugin.uploadCareportalEntryToNS(data); tempTarget.low = 0;
} catch (JSONException e) { tempTarget.high = 0;
e.printStackTrace(); }
} catch (SQLException e) { tempTarget.setTimeIndex(tempTarget.getTimeIndex());
e.printStackTrace(); Dao<TempTarget, Long> dao = MainApp.getDbHelper().getDaoTempTargets();
log.debug("Creating new TempTarget db record: " + tempTarget.log());
dao.createIfNotExists(tempTarget);
MainApp.bus().post(new EventTempTargetRangeChange());
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
} catch (JSONException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
} }
} });
}); }
} catch (JSONException e) {
e.printStackTrace();
} }
} else { } else {
ConfigBuilderPlugin.uploadCareportalEntryToNS(data); ConfigBuilderPlugin.uploadCareportalEntryToNS(data);

View file

@ -147,13 +147,13 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
String units = profile.getUnits(); String units = profile.getUnits();
String maxBgDefault = "180"; String maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
String minBgDefault = "100"; String minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
String targetBgDefault = "150"; String targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
if (!units.equals(Constants.MGDL)) { if (!units.equals(Constants.MGDL)) {
maxBgDefault = "10"; maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = "5"; minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
targetBgDefault = "7"; targetBgDefault = Constants.TARGET_BG_DEFAULT_MMOL;
} }
Date now = new Date(); Date now = new Date();

View file

@ -148,13 +148,13 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
String units = profile.getUnits(); String units = profile.getUnits();
String maxBgDefault = "180"; String maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
String minBgDefault = "100"; String minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
String targetBgDefault = "150"; String targetBgDefault = Constants.TARGET_BG_DEFAULT_MGDL;
if (!units.equals(Constants.MGDL)) { if (!units.equals(Constants.MGDL)) {
maxBgDefault = "10"; maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = "5"; minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
targetBgDefault = "7"; targetBgDefault = Constants.TARGET_BG_DEFAULT_MMOL;
} }
Date now = new Date(); Date now = new Date();

View file

@ -81,7 +81,9 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter; import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsPlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin; import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.androidaps.plugins.TempTargetRange.events.EventTempTargetRangeChange;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.BolusWizard; import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
@ -430,6 +432,9 @@ public class OverviewFragment extends Fragment {
@Subscribe @Subscribe
public void onStatusEvent(final EventNewBasalProfile ev) { updateGUIIfVisible(); } public void onStatusEvent(final EventNewBasalProfile ev) { updateGUIIfVisible(); }
@Subscribe
public void onStatusEvent(final EventTempTargetRangeChange ev) {updateGUIIfVisible();}
@Subscribe @Subscribe
public void onStatusEvent(final EventNewNotification n) { updateNotifications(); } public void onStatusEvent(final EventNewNotification n) { updateNotifications(); }
@ -531,11 +536,25 @@ public class OverviewFragment extends Fragment {
if (tempTargetRangePlugin != null && tempTargetRangePlugin.isEnabled(PluginBase.GENERAL)) { if (tempTargetRangePlugin != null && tempTargetRangePlugin.isEnabled(PluginBase.GENERAL)) {
TempTarget tempTarget = tempTargetRangePlugin.getTempTargetInProgress(new Date().getTime()); TempTarget tempTarget = tempTargetRangePlugin.getTempTargetInProgress(new Date().getTime());
if (tempTarget != null) { if (tempTarget != null) {
tempTargetView.setTextColor(Color.BLACK);
tempTargetView.setBackgroundResource(R.drawable.temptargetborder);
tempTargetView.setVisibility(View.VISIBLE); tempTargetView.setVisibility(View.VISIBLE);
tempTargetView.setText(NSProfile.toUnitsString(tempTarget.low, NSProfile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits()) + " - " + NSProfile.toUnitsString(tempTarget.high, NSProfile.fromMgdlToUnits(tempTarget.high, profile.getUnits()), profile.getUnits())); tempTargetView.setText(NSProfile.toUnitsString(tempTarget.low, NSProfile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits()) + " - " + NSProfile.toUnitsString(tempTarget.high, NSProfile.fromMgdlToUnits(tempTarget.high, profile.getUnits()), profile.getUnits()));
} else { } else {
tempTargetView.setVisibility(View.GONE);
String maxBgDefault = Constants.MAX_BG_DEFAULT_MGDL;
String minBgDefault = Constants.MIN_BG_DEFAULT_MGDL;
if (!profile.getUnits().equals(Constants.MGDL)) {
maxBgDefault = Constants.MAX_BG_DEFAULT_MMOL;
minBgDefault = Constants.MIN_BG_DEFAULT_MMOL;
}
tempTargetView.setTextColor(Color.WHITE);
tempTargetView.setBackgroundResource(R.drawable.temptargetborderdisabled);
tempTargetView.setText(prefs.getString("openapsma_min_bg", minBgDefault) + " - " + prefs.getString("openapsma_max_bg", maxBgDefault));
tempTargetView.setVisibility(View.VISIBLE);
} }
} else {
tempTargetView.setVisibility(View.GONE);
} }
// **** Temp button **** // **** Temp button ****
@ -588,6 +607,21 @@ public class OverviewFragment extends Fragment {
}); });
activeProfileView.setLongClickable(true); activeProfileView.setLongClickable(true);
tempTargetView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
final OptionsToShow temptarget = new OptionsToShow(R.id.careportal_temptarget, R.string.careportal_temptarget, false, false, false, false, true, false, false, false, false, true);
temptarget.executeTempTarget = true;
newTTDialog.setOptions(temptarget);
newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
return true;
}
});
tempTargetView.setLongClickable(true);
// QuickWizard button // QuickWizard button
QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive(); QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive();
if (quickWizardEntry != null && lastBG != null && pump.isInitialized()) { if (quickWizardEntry != null && lastBG != null && pump.isInitialized()) {

View file

@ -83,6 +83,12 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
holder.reason.setText(tempTarget.reason); holder.reason.setText(tempTarget.reason);
if (tempTarget.isInProgress()) if (tempTarget.isInProgress())
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorInProgress)); holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.colorInProgress));
else if (tempTarget.duration == 0){
holder.low.setText("");
holder.high.setText("");
holder.duration.setText(R.string.cancel);
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.notificationUrgent));
}
else else
holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground)); holder.dateLinearLayout.setBackgroundColor(MainApp.instance().getResources().getColor(R.color.cardColorBackground));
holder.remove.setTag(tempTarget); holder.remove.setTag(tempTarget);

View file

@ -91,7 +91,10 @@ public class TempTargetRangePlugin implements PluginBase {
@Nullable @Nullable
public TempTarget getTempTargetInProgress(long time) { public TempTarget getTempTargetInProgress(long time) {
for (int i = tempTargets.size() - 1; i >= 0; i--) { for (int i = 0; i < tempTargets.size(); i++) {
// a zero-duration temp target will cancel all prior targets
if (tempTargets.get(i).duration == 0) return null;
if (tempTargets.get(i).timeStart.getTime() > time) continue; if (tempTargets.get(i).timeStart.getTime() > time) continue;
if (tempTargets.get(i).getPlannedTimeEnd().getTime() >= time) return tempTargets.get(i); if (tempTargets.get(i).getPlannedTimeEnd().getTime() >= time) return tempTargets.get(i);
} }

View file

@ -0,0 +1,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="@color/colorPrimaryDark" />
<stroke android:width="1dip" android:color="@android:color/white"/>
<corners
android:radius="2dp" >
</corners>
</shape>

View file

@ -32,8 +32,8 @@
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginTop="3dp" android:layout_marginTop="3dp"
android:layout_weight="0.5" android:layout_weight="0.5"
android:text="@string/careportal_temptarget" android:text="@string/careportal_temporarytarget"
android:textColor="@color/colorTempTargetButton" /> android:textColor="@color/colorWizardButton" />
<Button <Button
android:id="@+id/actions_settempbasal" android:id="@+id/actions_settempbasal"

View file

@ -30,14 +30,16 @@
android:id="@+id/overview_apsmode" android:id="@+id/overview_apsmode"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_weight="0.2"
android:background="@drawable/loopmodeborder" android:background="@drawable/loopmodeborder"
android:gravity="center_vertical|center_horizontal" android:gravity="center_vertical|center_horizontal"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
android:text="Open Loop" android:text="Open Loop"
android:textAppearance="?android:attr/textAppearanceSmall" /> android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="0.1" />
<TextView <TextView
android:id="@+id/overview_activeprofile" android:id="@+id/overview_activeprofile"
@ -59,13 +61,15 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="right" android:layout_gravity="right"
android:layout_weight="0.2" android:layout_marginRight="10dp"
android:background="@drawable/temptargetborder" android:background="@drawable/temptargetborder"
android:gravity="center_vertical|center_horizontal" android:gravity="center_vertical|center_horizontal"
android:paddingLeft="10dp"
android:text="TempTarget" android:text="TempTarget"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/mdtp_white" /> android:textColor="@color/mdtp_white"
android:layout_weight="0.2" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
@ -88,7 +92,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal"
android:gravity="center_horizontal">
<TextView <TextView
android:id="@+id/overview_bg" android:id="@+id/overview_bg"

View file

@ -387,7 +387,6 @@
<string name="localprofile">Místní profil</string> <string name="localprofile">Místní profil</string>
<string name="activity">Aktivita</string> <string name="activity">Aktivita</string>
<string name="array_of_elements">Pole %d prvků. Aktuální hodnota:</string> <string name="array_of_elements">Pole %d prvků. Aktuální hodnota:</string>
<string name="careportal_temptarget"></string>
<string name="eatingsoon">Před jídlem</string> <string name="eatingsoon">Před jídlem</string>
<string name="el_lang">Řečtina</string> <string name="el_lang">Řečtina</string>
<string name="initializing">Inicializuji ...</string> <string name="initializing">Inicializuji ...</string>

View file

@ -312,5 +312,4 @@
<string name="absorption_rate">Absorptionsrate:</string> <string name="absorption_rate">Absorptionsrate:</string>
<string name="configbuilder">Config Builder</string> <string name="configbuilder">Config Builder</string>
<string name="minago">vor %d min</string> <string name="minago">vor %d min</string>
<string name="el_lang"></string>
</resources> </resources>

View file

@ -427,4 +427,5 @@
<string name="danar_stats_tbb">Total Base Basal</string> <string name="danar_stats_tbb">Total Base Basal</string>
<string name="danar_stats_tbb2">Total Base Basal ²</string> <string name="danar_stats_tbb2">Total Base Basal ²</string>
<string name="initializing">Initializing ...</string> <string name="initializing">Initializing ...</string>
<string name="careportal_temptarget">Temporary Target</string>
</resources> </resources>