Fix bugs, refactor code and add preferences

This commit is contained in:
Nico Schmitz 2018-06-14 20:49:58 +02:00
parent d7db19bf2d
commit 1604b53327
7 changed files with 110 additions and 61 deletions

View file

@ -86,8 +86,8 @@ public class CareportalEvent implements DataPointWithLabelInterface {
return System.currentTimeMillis() - date;
}
public long getHoursFromStart() {
return (System.currentTimeMillis() - date) / (60 * 60 * 1000);
public double getHoursFromStart() {
return (System.currentTimeMillis() - date) / (60 * 60 * 1000.0);
}
public String age() {

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Overview;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.NotificationManager;
import android.arch.core.util.Function;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
@ -159,7 +160,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
TextView cageView;
TextView reservoirView;
TextView sageView;
TextView pbageView;
TextView batteryView;
LinearLayout statuslightsLayout;
RecyclerView notificationsView;
LinearLayoutManager llm;
@ -263,7 +265,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cageView = (TextView) view.findViewById(R.id.overview_canulaage);
reservoirView = (TextView) view.findViewById(R.id.overview_reservoirlevel);
sageView = (TextView) view.findViewById(R.id.overview_sensorage);
pbageView = (TextView) view.findViewById(R.id.overview_pbage);
batteryView = (TextView) view.findViewById(R.id.overview_batterylevel);
statuslightsLayout = (LinearLayout) view.findViewById(R.id.overview_statuslights);
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
@ -1321,44 +1324,54 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobView.setText(cobText);
}
CareportalEvent careportalEvent;
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
if (statuslightsLayout != null) {
if (SP.getBoolean(R.string.key_show_statuslights, false)) {
CareportalEvent careportalEvent;
NSSettingsStatus nsSettings = new NSSettingsStatus().getInstance();
double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 96);
double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 72);
double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 72);
double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 48);
double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 166);
double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 164);
//double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 360);
//double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 240);
double batUrgent = SP.getDouble(R.string.key_statuslights_bat_critical, 5.0);
double batWarn = SP.getDouble(R.string.key_statuslights_bat_warning, 25.0);
double resUrgent = SP.getDouble(R.string.key_statuslights_res_critical, 10.0);
double resWarn = SP.getDouble(R.string.key_statuslights_res_warning, 80.0);
double iageUrgent = nsSettings.getExtendedWarnValue("iage", "urgent", 120);
double iageWarn = nsSettings.getExtendedWarnValue("iage", "warn", 96);
double cageUrgent = nsSettings.getExtendedWarnValue("cage", "urgent", 48);
double cageWarn = nsSettings.getExtendedWarnValue("cage", "warn", 24);
double sageUrgent = nsSettings.getExtendedWarnValue("sage", "urgent", 504);
double sageWarn = nsSettings.getExtendedWarnValue("sage", "warn", 336);
double pbageUrgent = nsSettings.getExtendedWarnValue("pgage", "urgent", 672);
double pbageWarn = nsSettings.getExtendedWarnValue("pgage", "warn", 504);
if (cageView != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
applyRibbonView(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE, true);
}
if (cageView != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
double canAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
applyRibbonView(cageView, "CAN", canAge, cageWarn, cageUrgent, Double.MAX_VALUE);
}
if (iageView != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
applyRibbonView(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE, true);
}
if (iageView != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
double insulinAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
applyRibbonView(iageView, "INS", insulinAge, iageWarn, iageUrgent, Double.MAX_VALUE);
}
if (reservoirView != null) {
double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
applyRibbonView(reservoirView, "RES", reservoirLevel, resWarn, resUrgent, -1, false);
}
if (reservoirView != null) {
double reservoirLevel = pump.isInitialized() ? pump.getReservoirLevel() : -1;
applyRibbonView(reservoirView, "RES", reservoirLevel, 80, 10, -1);
}
if (sageView != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
applyRibbonView(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE, true);
}
if (sageView != null) {
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
double sensorAge = careportalEvent != null ? careportalEvent.getHoursFromStart() : Double.MAX_VALUE;
applyRibbonView(sageView, "SEN", sensorAge, sageWarn, sageUrgent, Double.MAX_VALUE);
}
if (pbageView != null) {
double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
applyRibbonView(pbageView, "BAT", batteryLevel, 25, 5, -1);
if (batteryView != null) {
double batteryLevel = pump.isInitialized() ? pump.getBatteryLevel() : -1;
applyRibbonView(batteryView, "BAT", batteryLevel, batWarn, batUrgent, -1, false);
}
statuslightsLayout.setVisibility(View.VISIBLE);
} else {
statuslightsLayout.setVisibility(View.GONE);
}
}
final boolean predictionsAvailable = finalLastRun != null && finalLastRun.request.hasPredictions;
@ -1523,13 +1536,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
}
public static void applyRibbonView(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid) {
public static void applyRibbonView(TextView view, String text, double value, double warnThreshold, double urgentThreshold, double invalid, boolean checkAscending) {
Function<Double, Boolean> check = checkAscending ? (Double threshold) -> value >= threshold : (Double threshold) -> value <= threshold;
if (value != invalid) {
view.setText(text);
if (value <= urgentThreshold) {
if (check.apply(urgentThreshold)) {
view.setTextColor(MainApp.gc(R.color.ribbonTextCritical));
view.setBackgroundColor(MainApp.gc(R.color.ribbonBgCritical));
} else if (value <= warnThreshold) {
} else if (check.apply(warnThreshold)) {
view.setTextColor(MainApp.gc(R.color.ribbonTextWarning));
view.setBackgroundColor(MainApp.gc(R.color.ribbonBgWarning));
} else {

View file

@ -432,7 +432,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
public int getBatteryLevel() {
switch (pump.state.batteryState) {
case PumpState.EMPTY:
return 0;
return 5;
case PumpState.LOW:
return 25;
default:

View file

@ -184,6 +184,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/overview_statuslights"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
@ -232,7 +233,7 @@
android:textSize="14sp" />
<TextView
android:id="@+id/overview_pbage"
android:id="@+id/overview_batterylevel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="5dp"

View file

@ -625,8 +625,12 @@
<string name="tempbasal">TBR</string>
<string name="danar_history">Pumpen-Speicher</string>
<string name="enablesuperbolus_summary">Aktiviere die SuperBolus-Funktion im Wizard. Nicht aktivieren, wenn du nicht weißt, welche Auswirkungen dieser Bolus hat! ES KANN ZU EINER ÜBERDOSIERUNG AN INSULIN KOMMEN!</string>
<string name="show_reservoirview">Zeige Reservoir-Füllstand in Übersicht</string>
<string name="show_reservoirview_summary">Zeigt den Füllstand des Reservoirs in der Übersicht an.</string>
<string name="show_statuslights">Zeige Status-Ampeln in der Übersicht</string>
<string name="show_statuslights_summary">Aktiviert die Statusanzeige für CAGE, IAGE, SAGE, Reservoir- und Batteriestand auf dem Startbildschirm.</string>
<string name="statuslights_res_warning">Reservoirfüllstand Warnung [IE]</string>
<string name="statuslights_res_critical">Reservoirfüllstand Alarm [IE]</string>
<string name="statuslights_bat_warning">Batterieladung Warnung [%]</string>
<string name="statuslights_bat_critical">Batterieladung Alarm [%]</string>
<string name="gettingbolusstatus">Status des Bolus wird ermittelt</string>
<string name="pairing">PAIRING</string>
<string name="startingbolus">Bolus-Abgabe gestartet</string>

View file

@ -607,13 +607,17 @@
<string name="key_usesuperbolus" translatable="false">key_usersuperbolus</string>
<string name="enablesuperbolus">Enable superbolus in wizard</string>
<string name="enablesuperbolus_summary">Enable superbolus functionality in wizard. Do not enable until you learn what it really does. IT MAY CAUSE INSULIN OVERDOSE IF USED BLINDLY!</string>
<string name="key_show_reservoirview" translatable="false">key_show_reservoirview</string>
<string name="show_reservoirview">Show reservoir level in overview</string>
<string name="show_reservoirview_summary">Show the reservoir level on the overview page.</string>
<string name="key_reservoirview_levelwarning" translatable="false">key_reservoirview_levelwarning</string>
<string name="reservoirview_levelwarning">Level warning</string>
<string name="key_reservoirview_levelcritical" translatable="false">key_reservoirview_levelcritical</string>
<string name="reservoirview_levelcritical">Level critical</string>
<string name="key_show_statuslights" translatable="false">key_show_statuslights</string>
<string name="show_statuslights">Show status lights on home screen</string>
<string name="show_statuslights_summary">Enable status lights for cage, iage, sage, reservoir and battery level on home screen.</string>
<string name="key_statuslights_res_warning" translatable="false">key_statuslights_res_warning</string>
<string name="statuslights_res_warning">Threshold warning reservoir level [U]</string>
<string name="key_statuslights_res_critical" translatable="false">key_statuslights_res_critical</string>
<string name="statuslights_res_critical">Threshold critical reservoir level [U]</string>
<string name="key_statuslights_bat_warning" translatable="false">key_statuslights_bat_warning</string>
<string name="statuslights_bat_warning">Threshold warning battery level [%]</string>
<string name="key_statuslights_bat_critical" translatable="false">key_statuslights_bat_critical</string>
<string name="statuslights_bat_critical">Threshold critical battery level [%]</string>
<string name="iob">IOB</string>
<string name="cob">COB</string>
<string name="virtualpump_firmware_label">Firmware</string>

View file

@ -145,36 +145,62 @@
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_show_reservoirview"
android:summary="@string/show_reservoirview_summary"
android:title="@string/show_reservoirview" />
android:key="@string/key_show_statuslights"
android:summary="@string/show_statuslights_summary"
android:title="@string/show_statuslights" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="80"
android:dependency="@string/key_show_reservoirview"
android:dependency="@string/key_show_statuslights"
android:inputType="numberSigned"
android:key="@string/key_reservoirview_levelwarning"
android:key="@string/key_statuslights_res_warning"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/reservoirview_levelwarning"
android:title="@string/statuslights_res_warning"
validate:maxNumber="300"
validate:minNumber="0"
validate:testType="numericRange" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="5"
android:dependency="@string/key_show_reservoirview"
android:defaultValue="10"
android:dependency="@string/key_show_statuslights"
android:inputType="numberSigned"
android:key="@string/key_reservoirview_levelcritical"
android:key="@string/key_statuslights_res_critical"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/reservoirview_levelcritical"
android:title="@string/statuslights_res_critical"
validate:maxNumber="300"
validate:minNumber="0"
validate:testType="numericRange" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="25"
android:dependency="@string/key_show_statuslights"
android:inputType="numberSigned"
android:key="@string/key_statuslights_bat_warning"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/statuslights_bat_warning"
validate:maxNumber="100"
validate:minNumber="0"
validate:testType="numericRange" />
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="5"
android:dependency="@string/key_show_statuslights"
android:inputType="numberSigned"
android:key="@string/key_statuslights_bat_critical"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/statuslights_bat_critical"
validate:maxNumber="100"
validate:minNumber="0"
validate:testType="numericRange" />
</PreferenceScreen>
</PreferenceCategory>