Merge remote-tracking branch 'origin/dev' into combo-scripter-v2

* origin/dev:
  fix not attached to the activity
  check for no profile
  check for no profile
  Fix namespace errors.
  Add missing ids to other overview layouts.
  Overview: make checkbox labels toggle state as well.
  minimum of 30 min for unreachable alert
This commit is contained in:
Johannes Mockenhaupt 2018-01-25 16:06:22 +01:00
commit 947203b107
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
10 changed files with 158 additions and 74 deletions

View file

@ -82,7 +82,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
Manifest.permission.WRITE_EXTERNAL_STORAGE}, CASE_STORAGE);
}
askForBatteryOptimizationPermission();
checkUpgradeToProfileTarget();
doMigrations();
if (Config.logFunctionCalls)
log.debug("onCreate");
@ -163,6 +163,19 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
}
private void doMigrations() {
checkUpgradeToProfileTarget();
// guarantee that the unreachable threshold is at least 30 and of type String
// Added in 1.57 at 21.01.2018
Integer unreachable_threshold = SP.getInt(R.string.key_pump_unreachable_threshold, 30);
SP.remove(R.string.key_pump_unreachable_threshold);
if(unreachable_threshold < 30) unreachable_threshold = 30;
SP.putString(R.string.key_pump_unreachable_threshold, unreachable_threshold.toString());
}
private void checkUpgradeToProfileTarget() { // TODO: can be removed in the future
boolean oldKeyExists = SP.contains("openapsma_min_bg");
if (oldKeyExists) {

View file

@ -103,6 +103,11 @@ public class IobCobThread extends Thread {
continue;
}
if (profile == null) {
log.debug("Aborting calculation thread (no profile): " + from);
return; // profile not set yet
}
if (profile.getIsf(bgTime) == null) {
log.debug("Aborting calculation thread (no ISF): " + from);
return; // profile not set yet

View file

@ -528,12 +528,12 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
if (calculatedTotalInsulin > 0d || calculatedCarbs > 0d) {
String insulinText = calculatedTotalInsulin > 0d ? (DecimalFormatter.to2Decimal(calculatedTotalInsulin) + "U") : "";
String carbsText = calculatedCarbs > 0d ? (DecimalFormatter.to0Decimal(calculatedCarbs) + "g") : "";
total.setText(getString(R.string.result) + ": " + insulinText + " " + carbsText);
total.setText(MainApp.gs(R.string.result) + ": " + insulinText + " " + carbsText);
okButton.setVisibility(View.VISIBLE);
} else {
// TODO this should also be run when loading the dialog as the OK button is initially visible
// but does nothing if neither carbs nor insulin is > 0
total.setText(getString(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g");
total.setText(MainApp.gs(R.string.missing) + " " + DecimalFormatter.to0Decimal(wizard.carbsEquivalent) + "g");
okButton.setVisibility(View.INVISIBLE);
}

View file

@ -149,12 +149,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
TextView sage;
TextView pbage;
CheckBox showPredictionView;
CheckBox showBasalsView;
CheckBox showIobView;
CheckBox showCobView;
CheckBox showDeviationsView;
CheckBox showRatiosView;
TextView showPredictionLabel;
CheckBox showPredictionCheckbox;
TextView showBasalsLabel;
CheckBox showBasalsCheckbox;
TextView showIobLabel;
CheckBox showIobCheckbox;
TextView showCobLabel;
CheckBox showCobCheckbox;
TextView showDeviationsLabel;
CheckBox showDeviationsCheckbox;
TextView showRatiosLabel;
CheckBox showRatiosCheckbox;
RecyclerView notificationsView;
LinearLayoutManager llm;
@ -266,24 +272,37 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
acceptTempLayout = (LinearLayout) view.findViewById(R.id.overview_accepttemplayout);
showPredictionView = (CheckBox) view.findViewById(R.id.overview_showprediction);
showBasalsView = (CheckBox) view.findViewById(R.id.overview_showbasals);
showIobView = (CheckBox) view.findViewById(R.id.overview_showiob);
showCobView = (CheckBox) view.findViewById(R.id.overview_showcob);
showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations);
showRatiosView = (CheckBox) view.findViewById(R.id.overview_showratios);
showPredictionView.setChecked(SP.getBoolean("showprediction", false));
showBasalsView.setChecked(SP.getBoolean("showbasals", true));
showIobView.setChecked(SP.getBoolean("showiob", false));
showCobView.setChecked(SP.getBoolean("showcob", false));
showDeviationsView.setChecked(SP.getBoolean("showdeviations", false));
showRatiosView.setChecked(SP.getBoolean("showratios", false));
showPredictionView.setOnCheckedChangeListener(this);
showBasalsView.setOnCheckedChangeListener(this);
showIobView.setOnCheckedChangeListener(this);
showCobView.setOnCheckedChangeListener(this);
showDeviationsView.setOnCheckedChangeListener(this);
showRatiosView.setOnCheckedChangeListener(this);
showPredictionCheckbox = (CheckBox) view.findViewById(R.id.overview_showprediction);
showBasalsCheckbox = (CheckBox) view.findViewById(R.id.overview_showbasals);
showIobCheckbox = (CheckBox) view.findViewById(R.id.overview_showiob);
showCobCheckbox = (CheckBox) view.findViewById(R.id.overview_showcob);
showDeviationsCheckbox = (CheckBox) view.findViewById(R.id.overview_showdeviations);
showRatiosCheckbox = (CheckBox) view.findViewById(R.id.overview_showratios);
showPredictionCheckbox.setChecked(SP.getBoolean("showprediction", false));
showBasalsCheckbox.setChecked(SP.getBoolean("showbasals", true));
showIobCheckbox.setChecked(SP.getBoolean("showiob", false));
showCobCheckbox.setChecked(SP.getBoolean("showcob", false));
showDeviationsCheckbox.setChecked(SP.getBoolean("showdeviations", false));
showRatiosCheckbox.setChecked(SP.getBoolean("showratios", false));
showPredictionCheckbox.setOnCheckedChangeListener(this);
showBasalsCheckbox.setOnCheckedChangeListener(this);
showIobCheckbox.setOnCheckedChangeListener(this);
showCobCheckbox.setOnCheckedChangeListener(this);
showDeviationsCheckbox.setOnCheckedChangeListener(this);
showRatiosCheckbox.setOnCheckedChangeListener(this);
showPredictionLabel = (TextView) view.findViewById(R.id.overview_showprediction_label);
showPredictionLabel.setOnClickListener(this);
showBasalsLabel = (TextView) view.findViewById(R.id.overview_showbasals_label);
showBasalsLabel.setOnClickListener(this);
showIobLabel = (TextView) view.findViewById(R.id.overview_showiob_label);
showIobLabel.setOnClickListener(this);
showCobLabel = (TextView) view.findViewById(R.id.overview_showcob_label);
showCobLabel.setOnClickListener(this);
showDeviationsLabel = (TextView) view.findViewById(R.id.overview_showdeviations_label);
showDeviationsLabel.setOnClickListener(this);
showRatiosLabel = (TextView) view.findViewById(R.id.overview_showratios_label);
showRatiosLabel.setOnClickListener(this);
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
notificationsView.setHasFixedSize(true);
@ -376,24 +395,24 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
case R.id.overview_showiob:
break;
case R.id.overview_showcob:
showDeviationsView.setOnCheckedChangeListener(null);
showDeviationsView.setChecked(false);
showDeviationsView.setOnCheckedChangeListener(this);
showDeviationsCheckbox.setOnCheckedChangeListener(null);
showDeviationsCheckbox.setChecked(false);
showDeviationsCheckbox.setOnCheckedChangeListener(this);
break;
case R.id.overview_showdeviations:
showCobView.setOnCheckedChangeListener(null);
showCobView.setChecked(false);
showCobView.setOnCheckedChangeListener(this);
showCobCheckbox.setOnCheckedChangeListener(null);
showCobCheckbox.setChecked(false);
showCobCheckbox.setOnCheckedChangeListener(this);
break;
case R.id.overview_showratios:
break;
}
SP.putBoolean("showiob", showIobView.isChecked());
SP.putBoolean("showprediction", showPredictionView.isChecked());
SP.putBoolean("showbasals", showBasalsView.isChecked());
SP.putBoolean("showcob", showCobView.isChecked());
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
SP.putBoolean("showratios", showRatiosView.isChecked());
SP.putBoolean("showiob", showIobCheckbox.isChecked());
SP.putBoolean("showprediction", showPredictionCheckbox.isChecked());
SP.putBoolean("showbasals", showBasalsCheckbox.isChecked());
SP.putBoolean("showcob", showCobCheckbox.isChecked());
SP.putBoolean("showdeviations", showDeviationsCheckbox.isChecked());
SP.putBoolean("showratios", showRatiosCheckbox.isChecked());
scheduleUpdateGUI("onGraphCheckboxesCheckedChanged");
}
@ -620,6 +639,24 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (ConfigBuilderPlugin.getActivePump().isSuspended() || !ConfigBuilderPlugin.getActivePump().isInitialized())
ConfigBuilderPlugin.getCommandQueue().readStatus("RefreshClicked", null);
break;
case R.id.overview_showprediction_label:
showPredictionCheckbox.toggle();
break;
case R.id.overview_showbasals_label:
showBasalsCheckbox.toggle();
break;
case R.id.overview_showiob_label:
showIobCheckbox.toggle();
break;
case R.id.overview_showcob_label:
showCobCheckbox.toggle();
break;
case R.id.overview_showdeviations_label:
showDeviationsCheckbox.toggle();
break;
case R.id.overview_showratios_label:
showRatiosCheckbox.toggle();
break;
}
}
@ -1246,13 +1283,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobView.setText(cobText);
}
final boolean showPrediction = showPredictionView.isChecked() && finalLastRun != null && finalLastRun.constraintsProcessed.getClass().equals(DetermineBasalResultAMA.class);
final boolean showPrediction = showPredictionCheckbox.isChecked() && finalLastRun != null && finalLastRun.constraintsProcessed.getClass().equals(DetermineBasalResultAMA.class);
if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS)) {
showPredictionView.setVisibility(View.VISIBLE);
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE);
showPredictionCheckbox.setVisibility(View.VISIBLE);
showPredictionLabel.setVisibility(View.VISIBLE);
} else {
showPredictionView.setVisibility(View.GONE);
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.GONE);
showPredictionCheckbox.setVisibility(View.GONE);
showPredictionLabel.setVisibility(View.GONE);
}
// pump status from ns
@ -1344,7 +1381,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
graphData.addTreatments(fromTime, endTime);
// add basal data
if (pump.getPumpDescription().isTempBasalCapable && showBasalsView.isChecked()) {
if (pump.getPumpDescription().isTempBasalCapable && showBasalsCheckbox.isChecked()) {
graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2d);
}
@ -1361,23 +1398,23 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
boolean useDevForScale = false;
boolean useRatioForScale = false;
if (showIobView.isChecked()) {
if (showIobCheckbox.isChecked()) {
useIobForScale = true;
} else if (showCobView.isChecked()) {
} else if (showCobCheckbox.isChecked()) {
useCobForScale = true;
} else if (showDeviationsView.isChecked()) {
} else if (showDeviationsCheckbox.isChecked()) {
useDevForScale = true;
} else if (showRatiosView.isChecked()) {
} else if (showRatiosCheckbox.isChecked()) {
useRatioForScale = true;
}
if (showIobView.isChecked())
if (showIobCheckbox.isChecked())
secondGraphData.addIob(fromTime, now, useIobForScale, 1d);
if (showCobView.isChecked())
if (showCobCheckbox.isChecked())
secondGraphData.addCob(fromTime, now, useCobForScale, useCobForScale ? 1d : 0.5d);
if (showDeviationsView.isChecked())
if (showDeviationsCheckbox.isChecked())
secondGraphData.addDeviations(fromTime, now, useDevForScale, 1d);
if (showRatiosView.isChecked())
if (showRatiosCheckbox.isChecked())
secondGraphData.addRatio(fromTime, now, useRatioForScale, 1d);
// **** NOW line ****
@ -1391,7 +1428,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
if (showIobCheckbox.isChecked() || showCobCheckbox.isChecked() || showDeviationsCheckbox.isChecked() || showRatiosCheckbox.isChecked()) {
iobGraph.setVisibility(View.VISIBLE);
} else {
iobGraph.setVisibility(View.GONE);

View file

@ -637,6 +637,11 @@ public class WatchUpdaterService extends WearableListenerService implements
private String generateBasalString(TreatmentsInterface treatmentsInterface) {
String basalStringResult;
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null)
return "";
TemporaryBasal activeTemp = treatmentsInterface.getTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp != null) {
basalStringResult = activeTemp.toStringShort();
@ -644,7 +649,7 @@ public class WatchUpdaterService extends WearableListenerService implements
if (SP.getBoolean(R.string.key_danar_visualizeextendedaspercentage, false)) {
basalStringResult = "100%";
} else {
basalStringResult = DecimalFormatter.to2Decimal(MainApp.getConfigBuilder().getProfile().getBasal()) + "U/h";
basalStringResult = DecimalFormatter.to2Decimal(profile.getBasal()) + "U/h";
}
}
return basalStringResult;

View file

@ -270,6 +270,7 @@
app:buttonTint="@color/basal" />
<TextView
android:id="@+id/overview_showbasals_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -286,6 +287,7 @@
app:buttonTint="@color/iob" />
<TextView
android:id="@+id/overview_showiob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -294,7 +296,6 @@
android:textColor="@color/iob"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showcob"
android:layout_width="wrap_content"
@ -303,6 +304,7 @@
app:buttonTint="@color/cob" />
<TextView
android:id="@+id/overview_showcob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -319,6 +321,7 @@
app:buttonTint="@color/deviations" />
<TextView
android:id="@+id/overview_showdeviations_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -334,6 +337,7 @@
android:layout_gravity="center" />
<TextView
android:id="@+id/overview_showratios_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View file

@ -479,7 +479,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/prediction" />
android:buttonTint="@color/prediction" />
<TextView
android:id="@+id/overview_showprediction_label"
@ -496,9 +496,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/basal" />
android:buttonTint="@color/basal" />
<TextView
android:id="@+id/overview_showbasals_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -512,9 +513,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/iob" />
android:buttonTint="@color/iob" />
<TextView
android:id="@+id/overview_showiob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -529,9 +531,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/cob" />
android:buttonTint="@color/cob" />
<TextView
android:id="@+id/overview_showcob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -545,9 +548,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/deviations" />
android:buttonTint="@color/deviations" />
<TextView
android:id="@+id/overview_showdeviations_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -563,6 +567,7 @@
android:layout_gravity="center" />
<TextView
android:id="@+id/overview_showratios_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View file

@ -563,7 +563,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/prediction" />
android:buttonTint="@color/prediction" />
<TextView
android:id="@+id/overview_showprediction_label"
@ -580,9 +580,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/basal" />
android:buttonTint="@color/basal" />
<TextView
android:id="@+id/overview_showbasals_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -596,9 +597,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/iob" />
android:buttonTint="@color/iob" />
<TextView
android:id="@+id/overview_showiob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -613,9 +615,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/cob" />
android:buttonTint="@color/cob" />
<TextView
android:id="@+id/overview_showcob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -629,9 +632,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/deviations" />
android:buttonTint="@color/deviations" />
<TextView
android:id="@+id/overview_showdeviations_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -647,6 +651,7 @@
android:layout_gravity="center" />
<TextView
android:id="@+id/overview_showratios_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View file

@ -245,7 +245,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/prediction" />
android:buttonTint="@color/prediction" />
<TextView
android:id="@+id/overview_showprediction_label"
@ -262,9 +262,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/basal" />
android:buttonTint="@color/basal" />
<TextView
android:id="@+id/overview_showbasals_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -278,9 +279,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/iob" />
android:buttonTint="@color/iob" />
<TextView
android:id="@+id/overview_showiob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -295,9 +297,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/cob" />
android:buttonTint="@color/cob" />
<TextView
android:id="@+id/overview_showcob_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -311,9 +314,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:buttonTint="@color/deviations" />
android:buttonTint="@color/deviations" />
<TextView
android:id="@+id/overview_showdeviations_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
@ -329,6 +333,7 @@
android:layout_gravity="center" />
<TextView
android:id="@+id/overview_showratios_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:validate="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="others"
android:title="@string/othersettings_title">
@ -76,12 +77,16 @@
android:defaultValue="true"
android:key="@string/key_enable_pump_unreachable_alert"
android:title="@string/enable_pump_unreachable_alert" />
<EditTextPreference
<com.andreabaccega.widget.ValidatingEditTextPreference
validate:testType="numericRange"
validate:minNumber="30"
validate:maxNumber="300"
android:defaultValue="30"
android:dependency="@string/key_enable_pump_unreachable_alert"
android:inputType="number"
android:key="@string/key_pump_unreachable_threshold"
android:title="@string/pump_unreachable_threshold"></EditTextPreference>
android:title="@string/pump_unreachable_threshold">
</com.andreabaccega.widget.ValidatingEditTextPreference>
</PreferenceScreen>
<SwitchPreference
android:defaultValue="false"