Merge remote-tracking branch 'origin/dev' into carbs-gen-pr

* origin/dev:
  Overview: fix rendering zero-temp covering entire displayed range.
  cleanup
  remove duplicate upload
  upload temptargets to NS properly
  fix NPE
  log profile conditional
  adding device name to AndroidAPS started note
  show tests in travis
  gradle 3.1.1
  Remove CB.getActiveLoop(), use LoopPlugin.getPlugin().
  added phone Manufacturer and model note to NS
  dummy-edit to re-trigger travis
  Fix for black number and labels on black background (aaps wear)
  Fix re-enabling the loop plugin from overview. Fixes #861.
  int to double in the isOlderThan()
  Get thresholds from NS

# Conflicts:
#	app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/NewCarbsDialog.java
This commit is contained in:
Johannes Mockenhaupt 2018-04-12 21:18:04 +02:00
commit 7e19aff121
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
29 changed files with 282 additions and 254 deletions

View file

@ -50,7 +50,7 @@ def generateGitBuild = { ->
}
tasks.matching {it instanceof Test}.all {
testLogging.events = ["failed", "skipped"]
testLogging.events = ["failed", "skipped", "started"]
testLogging.exceptionFormat = "full"
}

View file

@ -37,6 +37,7 @@ public class Config {
public static final boolean logCongigBuilderActions = true;
public static final boolean logAutosensData = false;
public static final boolean logEvents = false;
public static final boolean logProfile = false;
// DanaR specific
public static final boolean logDanaBTComm = true;

View file

@ -12,6 +12,7 @@ import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.TimeZone;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
@ -275,7 +276,7 @@ public class Profile {
Integer getShitfTimeSecs(Integer originalTime) {
Integer shiftedTime = originalTime + timeshift * 60 * 60;
shiftedTime = (shiftedTime + 24 * 60 * 60) % (24 * 60 * 60);
if (timeshift != 0)
if (timeshift != 0 && Config.logProfile)
log.debug("(Sec) Original time: " + originalTime + " ShiftedTime: " + shiftedTime);
return shiftedTime;
}

View file

@ -11,7 +11,6 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
@ -119,8 +118,8 @@ public class QuickWizardEntry {
if (useSuperBolus() == YES && SP.getBoolean(R.string.key_usesuperbolus, false)) {
superBolus = true;
}
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus())
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (loopPlugin.isEnabled(loopPlugin.getType()) && loopPlugin.isSuperBolus())
superBolus = false;
// Trend

View file

@ -55,6 +55,7 @@ public interface TreatmentsInterface {
TempTarget getTempTargetFromHistory();
TempTarget getTempTargetFromHistory(long time);
Intervals<TempTarget> getTempTargetsFromHistory();
void addToHistoryTempTarget(TempTarget tempTarget);
ProfileSwitch getProfileSwitchFromHistory(long time);
ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory();

View file

@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.HardLimits;
import info.nightscout.utils.JsonHelper;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.NumberPicker;
import info.nightscout.utils.SP;
@ -694,26 +695,24 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
}
}
} else if (options.executeTempTarget) {
try {
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) {
TempTarget tempTarget = new TempTarget()
.date(eventTime.getTime())
.duration(data.getInt("duration"))
.reason(data.getString("reason"))
.source(Source.USER);
if (tempTarget.durationInMinutes != 0) {
tempTarget.low(Profile.toMgdl(data.getDouble("targetBottom"), profile.getUnits()))
.high(Profile.toMgdl(data.getDouble("targetTop"), profile.getUnits()));
} else {
tempTarget.low(0).high(0);
}
log.debug("Creating new TempTarget db record: " + tempTarget.toString());
MainApp.getDbHelper().createOrUpdate(tempTarget);
NSUpload.uploadCareportalEntryToNS(data);
FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget"));
final int duration = JsonHelper.safeGetInt(data, "duration");
final double targetBottom = JsonHelper.safeGetDouble(data, "targetBottom");
final double targetTop = JsonHelper.safeGetDouble(data, "targetTop");
final String reason = JsonHelper.safeGetString(data, "reason", "");
if ((targetBottom != 0d && targetTop != 0d) || duration == 0) {
TempTarget tempTarget = new TempTarget()
.date(eventTime.getTime())
.duration(duration)
.reason(reason)
.source(Source.USER);
if (tempTarget.durationInMinutes != 0) {
tempTarget.low(Profile.toMgdl(targetBottom, profile.getUnits()))
.high(Profile.toMgdl(targetTop, profile.getUnits()));
} else {
tempTarget.low(0).high(0);
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget"));
}
} else {
NSUpload.uploadCareportalEntryToNS(data);

View file

@ -264,10 +264,6 @@ public class ConfigBuilderPlugin extends PluginBase {
return activeAPS;
}
public static LoopPlugin getActiveLoop() {
return activeLoop;
}
public static PumpInterface getActivePump() {
return activePump;
}
@ -621,7 +617,7 @@ public class ConfigBuilderPlugin extends PluginBase {
}
public void disconnectPump(int durationInMinutes, Profile profile) {
getActiveLoop().disconnectTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000L);
LoopPlugin.getPlugin().disconnectTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000L);
getCommandQueue().tempBasalPercent(0, durationInMinutes, true, profile, new Callback() {
@Override
public void run() {
@ -644,7 +640,7 @@ public class ConfigBuilderPlugin extends PluginBase {
}
public void suspendLoop(int durationInMinutes) {
getActiveLoop().suspendTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000);
LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + durationInMinutes * 60 * 1000);
getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {

View file

@ -9,6 +9,7 @@ import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.app.NotificationCompat;
import com.crashlytics.android.answers.CustomEvent;
@ -56,6 +57,7 @@ public class LoopPlugin extends PluginBase {
protected static LoopPlugin loopPlugin;
@NonNull
public static LoopPlugin getPlugin() {
if (loopPlugin == null) {
loopPlugin = new LoopPlugin();

View file

@ -357,34 +357,34 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C
}
accepted = true;
if (startActivityTTCheckbox.isChecked()) {
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
.duration(finalActivityTTDuration)
.reason(MainApp.gs(R.string.activity))
.source(Source.USER)
.low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()))
.high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()));
MainApp.getDbHelper().createOrUpdate(tempTarget);
} else if (startEatingSoonTTCheckbox.isChecked()) {
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
.duration(finalEatingSoonTTDuration)
.reason(MainApp.gs(R.string.eatingsoon))
.source(Source.USER)
.low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()))
.high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()));
MainApp.getDbHelper().createOrUpdate(tempTarget);
} else if (startHypoTTCheckbox.isChecked()) {
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
.duration(finalHypoTTDuration)
.reason(MainApp.gs(R.string.hypo))
.source(Source.USER)
.low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()))
.high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()));
MainApp.getDbHelper().createOrUpdate(tempTarget);
}
if (startActivityTTCheckbox.isChecked()) {
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
.duration(finalActivityTTDuration)
.reason(MainApp.gs(R.string.activity))
.source(Source.USER)
.low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()))
.high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()));
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
} else if (startEatingSoonTTCheckbox.isChecked()) {
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
.duration(finalEatingSoonTTDuration)
.reason(MainApp.gs(R.string.eatingsoon))
.source(Source.USER)
.low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()))
.high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()));
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
} else if (startHypoTTCheckbox.isChecked()) {
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
.duration(finalHypoTTDuration)
.reason(MainApp.gs(R.string.hypo))
.source(Source.USER)
.low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()))
.high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()));
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
}
if (carbsAfterConstraints > 0) {
if (duration == 0) {

View file

@ -288,7 +288,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
.source(Source.USER)
.low((int) finalTT)
.high((int) finalTT);
MainApp.getDbHelper().createOrUpdate(tempTarget);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
}
if (finalInsulinAfterConstraints <= 0.01) {

View file

@ -53,6 +53,7 @@ import info.nightscout.androidaps.events.EventFeatureRunning;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
@ -334,9 +335,9 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
accepted = true;
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
if (useSuperBolus) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null) {
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
}
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() {

View file

@ -457,14 +457,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v == apsModeView) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation"))
if (loopPlugin == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation"))
return;
menu.setHeaderTitle(MainApp.gs(R.string.loop));
if (activeloop.isEnabled(PluginType.LOOP)) {
if (loopPlugin.isEnabled(PluginType.LOOP)) {
menu.add(MainApp.gs(R.string.disableloop));
if (!activeloop.isSuspended()) {
if (!loopPlugin.isSuspended()) {
menu.add(MainApp.gs(R.string.suspendloopfor1h));
menu.add(MainApp.gs(R.string.suspendloopfor2h));
menu.add(MainApp.gs(R.string.suspendloopfor3h));
@ -480,7 +480,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
menu.add(MainApp.gs(R.string.resume));
}
}
if (!activeloop.isEnabled(PluginType.LOOP))
if (!loopPlugin.isEnabled(PluginType.LOOP))
menu.add(MainApp.gs(R.string.enableloop));
} else if (v == activeProfileView) {
menu.setHeaderTitle(MainApp.gs(R.string.profile));
@ -496,13 +496,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null)
return true;
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (item.getTitle().equals(MainApp.gs(R.string.disableloop))) {
activeloop.setPluginEnabled(PluginType.LOOP, false);
activeloop.setFragmentVisible(PluginType.LOOP, false);
loopPlugin.setPluginEnabled(PluginType.LOOP, false);
loopPlugin.setFragmentVisible(PluginType.LOOP, false);
MainApp.getConfigBuilder().storeSettings("DisablingLoop");
updateGUI("suspendmenu");
MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() {
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
@ -513,16 +513,16 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration
return true;
} else if (item.getTitle().equals(MainApp.gs(R.string.enableloop))) {
activeloop.setPluginEnabled(PluginType.LOOP, true);
activeloop.setFragmentVisible(PluginType.LOOP, true);
loopPlugin.setPluginEnabled(PluginType.LOOP, true);
loopPlugin.setFragmentVisible(PluginType.LOOP, true);
MainApp.getConfigBuilder().storeSettings("EnablingLoop");
updateGUI("suspendmenu");
NSUpload.uploadOpenAPSOffline(0);
return true;
} else if (item.getTitle().equals(MainApp.gs(R.string.resume))) {
activeloop.suspendTo(0L);
loopPlugin.suspendTo(0L);
updateGUI("suspendmenu");
MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() {
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override
public void run() {
if (!result.success) {
@ -673,36 +673,34 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
private void onClickAcceptTemp() {
Profile profile = MainApp.getConfigBuilder().getProfile();
if (ConfigBuilderPlugin.getActiveLoop() != null && profile != null) {
ConfigBuilderPlugin.getActiveLoop().invoke("Accept temp button", false);
if (LoopPlugin.getPlugin().isEnabled(PluginType.LOOP) && profile != null) {
LoopPlugin.getPlugin().invoke("Accept temp button", false);
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.isChangeRequested()) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getContext().getString(R.string.confirmation));
builder.setMessage(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
hideTempRecommendation();
clearNotification();
MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() {
@Override
public void run() {
if (result.enacted) {
finalLastRun.tbrSetByPump = result;
finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus();
ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class);
if (objectivesPlugin != null) {
ObjectivesPlugin.manualEnacts++;
ObjectivesPlugin.saveProgress();
}
builder.setPositiveButton(getContext().getString(R.string.ok), (dialog, id) -> {
hideTempRecommendation();
clearNotification();
MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() {
@Override
public void run() {
if (result.enacted) {
finalLastRun.tbrSetByPump = result;
finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus();
ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class);
if (objectivesPlugin != null) {
ObjectivesPlugin.manualEnacts++;
ObjectivesPlugin.saveProgress();
}
scheduleUpdateGUI("onClickAcceptTemp");
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp"));
}
scheduleUpdateGUI("onClickAcceptTemp");
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp"));
});
builder.setNegativeButton(getContext().getString(R.string.cancel), null);
builder.show();
@ -768,57 +766,55 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
accepted = false;
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
synchronized (builder) {
if (accepted) {
log.debug("guarding: already accepted");
return;
}
accepted = true;
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
if (wizard.superBolus) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null) {
activeloop.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
}
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() {
@Override
public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
}
});
builder.setPositiveButton(getString(R.string.ok), (dialog, id) -> {
synchronized (builder) {
if (accepted) {
log.debug("guarding: already accepted");
return;
}
accepted = true;
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
if (wizard.superBolus) {
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.superBolusTo(System.currentTimeMillis() + 2 * 60L * 60 * 1000);
MainApp.bus().post(new EventRefreshOverview("WizardDialog"));
}
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
detailedBolusInfo.context = context;
detailedBolusInfo.boluscalc = boluscalcJSON;
detailedBolusInfo.source = Source.USER;
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
ConfigBuilderPlugin.getCommandQueue().tempBasalPercent(0, 120, true, profile, new Callback() {
@Override
public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("QuickWizard"));
}
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.eventType = CareportalEvent.BOLUSWIZARD;
detailedBolusInfo.insulin = finalInsulinAfterConstraints;
detailedBolusInfo.carbs = finalCarbsAfterConstraints;
detailedBolusInfo.context = context;
detailedBolusInfo.boluscalc = boluscalcJSON;
detailedBolusInfo.source = Source.USER;
ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() {
@Override
public void run() {
if (!result.success) {
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
}
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("QuickWizard"));
}
}
});
@ -1024,24 +1020,24 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
apsModeView.setVisibility(View.VISIBLE);
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopenabled));
apsModeView.setTextColor(Color.BLACK);
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus()) {
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuperBolus()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(String.format(MainApp.gs(R.string.loopsuperbolusfor), activeloop.minutesToEndOfSuspend()));
apsModeView.setText(String.format(MainApp.gs(R.string.loopsuperbolusfor), loopPlugin.minutesToEndOfSuspend()));
apsModeView.setTextColor(Color.WHITE);
} else if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isDisconnected()) {
} else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isDisconnected()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(String.format(MainApp.gs(R.string.loopdisconnectedfor), activeloop.minutesToEndOfSuspend()));
apsModeView.setText(String.format(MainApp.gs(R.string.loopdisconnectedfor), loopPlugin.minutesToEndOfSuspend()));
apsModeView.setTextColor(Color.WHITE);
} else if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuspended()) {
} else if (loopPlugin.isEnabled(PluginType.LOOP) && loopPlugin.isSuspended()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(String.format(MainApp.gs(R.string.loopsuspendedfor), activeloop.minutesToEndOfSuspend()));
apsModeView.setText(String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()));
apsModeView.setTextColor(Color.WHITE);
} else if (pump.isSuspended()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(MainApp.gs(R.string.pumpsuspended));
apsModeView.setTextColor(Color.WHITE);
} else if (activeloop != null && activeloop.isEnabled(activeloop.getType())) {
} else if (loopPlugin.isEnabled(PluginType.LOOP)) {
if (closedLoopEnabled.value()) {
apsModeView.setText(MainApp.gs(R.string.closedloop));
} else {
@ -1077,7 +1073,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result
showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.isChangeRequested(); // change is requested
if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && ConfigBuilderPlugin.getActiveLoop() != null) {
if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) {
acceptTempLayout.setVisibility(View.VISIBLE);
acceptTempButton.setText(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
} else {

View file

@ -172,7 +172,7 @@ public class GraphData {
lastAbsoluteLineBasal = absoluteLineValue;
lastLineBasal = baseBasalValue;
lastTempBasal = tempBasalValue;
maxBasalValueFound = Math.max(maxBasalValueFound, basal);
maxBasalValueFound = Math.max(maxBasalValueFound, Math.max(tempBasalValue, baseBasalValue));
}
basalLineArray.add(new ScaledDataPoint(toTime, lastLineBasal, basalScale));

View file

@ -279,8 +279,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
FabricPrivacy.getInstance().logCustom(new CustomEvent("SMS_Loop_Status"));
break;
case "RESUME":
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
activeloop.suspendTo(0);
LoopPlugin.getPlugin().suspendTo(0);
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_RESUME"));
NSUpload.uploadOpenAPSOffline(0);
reply = MainApp.sResources.getString(R.string.smscommunicator_loopresumed);
@ -517,8 +516,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
@Override
public void run() {
if (result.success) {
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
activeloop.suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000);
LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + suspendWaitingForConfirmation.duration * 60L * 1000);
NSUpload.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60);
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_SUSPENDED"));
String reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended) + " " +

View file

@ -505,6 +505,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
}
}
@Override
public void addToHistoryTempTarget(TempTarget tempTarget) {
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
MainApp.getDbHelper().createOrUpdate(tempTarget);
NSUpload.uploadTempTarget(tempTarget);
}
// Profile Switch
@Subscribe
@SuppressWarnings("unused")

View file

@ -441,21 +441,21 @@ public class ActionStringHandler {
private static String getLoopStatus() {
String ret = "";
// decide if enabled/disabled closed/open; what Plugin as APS?
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
if (activeloop != null && activeloop.isEnabled(activeloop.getType())) {
final LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (loopPlugin.isEnabled(loopPlugin.getType())) {
if (MainApp.getConstraintChecker().isClosedLoopAllowed().value()) {
ret += "CLOSED LOOP\n";
} else {
ret += "OPEN LOOP\n";
}
final APSInterface aps = MainApp.getConfigBuilder().getActiveAPS();
final APSInterface aps = ConfigBuilderPlugin.getActiveAPS();
ret += "APS: " + ((aps == null) ? "NO APS SELECTED!" : ((PluginBase) aps).getName());
if (activeloop.lastRun != null) {
if (activeloop.lastRun.lastAPSRun != null)
ret += "\nLast Run: " + DateUtil.timeString(activeloop.lastRun.lastAPSRun);
if (LoopPlugin.lastRun != null) {
if (LoopPlugin.lastRun.lastAPSRun != null)
ret += "\nLast Run: " + DateUtil.timeString(LoopPlugin.lastRun.lastAPSRun);
if (activeloop.lastRun.lastEnact != null)
ret += "\nLast Enact: " + DateUtil.timeString(activeloop.lastRun.lastEnact);
if (LoopPlugin.lastRun.lastEnact != null)
ret += "\nLast Enact: " + DateUtil.timeString(LoopPlugin.lastRun.lastEnact);
}
@ -502,7 +502,7 @@ public class ActionStringHandler {
return "No profile set :(";
}
APSInterface usedAPS = MainApp.getConfigBuilder().getActiveAPS();
APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS();
if (usedAPS == null) {
return "No active APS :(!";
}
@ -622,10 +622,7 @@ public class ActionStringHandler {
} else {
tempTarget.low(0).high(0);
}
MainApp.getDbHelper().createOrUpdate(tempTarget);
//TODO: Nightscout-Treatment for Temp-Target!
//ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
}
private static void doFillBolus(final Double amount) {

View file

@ -140,11 +140,7 @@ public class WearPlugin extends PluginBase {
@Subscribe
public void onStatusEvent(final EventRefreshOverview ev) {
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
if (activeloop == null) return;
if (WatchUpdaterService.shouldReportLoopStatus(activeloop.isEnabled(PluginType.LOOP))) {
if (WatchUpdaterService.shouldReportLoopStatus(LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))) {
sendDataToWatch(true, false, false);
}
}

View file

@ -666,12 +666,12 @@ public class WatchUpdaterService extends WearableListenerService implements
return status;
}
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
LoopPlugin activeloop = LoopPlugin.getPlugin();
if (activeloop != null && !activeloop.isEnabled(PluginType.LOOP)) {
if (!activeloop.isEnabled(PluginType.LOOP)) {
status += getString(R.string.disabledloop) + "\n";
lastLoopStatus = false;
} else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) {
} else {
lastLoopStatus = true;
}

View file

@ -108,12 +108,12 @@ public class StatuslinePlugin extends PluginBase {
@NonNull
private String buildStatusString(Profile profile) {
String status = "";
LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (activeloop != null && !activeloop.isEnabled(PluginType.LOOP)) {
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
status += ctx.getString(R.string.disabledloop) + "\n";
lastLoopStatus = false;
} else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) {
} else if (loopPlugin.isEnabled(PluginType.LOOP)) {
lastLoopStatus = true;
}
@ -179,13 +179,8 @@ public class StatuslinePlugin extends PluginBase {
@Subscribe
public void onStatusEvent(final EventRefreshOverview ev) {
//Filter events where loop is (de)activated
LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop == null) return;
if ((lastLoopStatus != activeloop.isEnabled(PluginType.LOOP))) {
if ((lastLoopStatus != LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))) {
sendStatus();
}
}

View file

@ -53,6 +53,12 @@ public class QueueThread extends Thread {
try {
while (true) {
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (pump == null) {
log.debug("QUEUE: pump == null");
MainApp.bus().post(new EventPumpStatusChanged(MainApp.sResources.getString(R.string.pumpNotInitialized)));
SystemClock.sleep(1000);
continue;
}
long secondsElapsed = (System.currentTimeMillis() - connectionStartTime) / 1000;
if (!pump.isConnected() && secondsElapsed > Constants.PUMP_MAX_CONNECTION_TIME_IN_SECONDS) {

View file

@ -13,6 +13,7 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
@ -38,7 +39,7 @@ public class LocalAlertUtils {
boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0L) < System.currentTimeMillis();
if (Config.APS && SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), true)
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !ConfigBuilderPlugin.getActiveLoop().isDisconnected()) {
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached && !LoopPlugin.getPlugin().isDisconnected()) {
log.debug("Generating pump unreachable alarm. lastConnection: " + DateUtil.dateAndTimeString(lastConnection) + " isStatusOutdated: " + isStatusOutdated);
Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.sResources.getString(R.string.pump_unreachable), Notification.URGENT);
n.soundId = R.raw.alarm;

View file

@ -28,6 +28,7 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult;
@ -302,6 +303,22 @@ public class NSUpload {
}
}
public static void uploadTempTarget(TempTarget tempTarget) {
try {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.TEMPORARYTARGET);
data.put("duration", tempTarget.durationInMinutes);
data.put("reason", tempTarget.reason);
data.put("targetBottom", tempTarget.low);
data.put("targetTop", tempTarget.high);
data.put("created_at", DateUtil.toISOString(tempTarget.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
uploadCareportalEntryToNS(data);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
}
public static void updateProfileSwitch(ProfileSwitch profileSwitch) {
try {
JSONObject data = new JSONObject();
@ -466,7 +483,7 @@ public class NSUpload {
try {
data.put("eventType", "Note");
data.put("created_at", DateUtil.toISOString(new Date()));
data.put("notes", MainApp.sResources.getString(R.string.androidaps_start));
data.put("notes", MainApp.sResources.getString(R.string.androidaps_start)+" - "+ Build.MANUFACTURER + " "+ Build.MODEL);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
@ -476,7 +493,7 @@ public class NSUpload {
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
}
}
}
public static void uploadEvent(String careportalEvent, long time) {

View file

@ -7,7 +7,7 @@ buildscript {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.android.tools.build:gradle:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View file

@ -26,28 +26,31 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<EditText
android:id="@+id/amountfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="numberDecimal"
android:minWidth="50dp"
android:padding="10dp"
android:text="112"
android:textSize="45sp"
android:cursorVisible="false"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"
android:textSize="25sp" />
<EditText
android:id="@+id/amountfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cursorVisible="false"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:minWidth="50dp"
android:padding="10dp"
android:text="112"
android:textColor="@color/white"
android:textSize="45sp" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textSize="25sp" />
</LinearLayout>
<ImageView
android:id="@+id/plusbutton"

View file

@ -16,21 +16,23 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cursorVisible="false"
android:gravity="center"
android:inputType="numberDecimal"
android:minWidth="50dp"
android:text="112"
android:textSize="45sp"
android:cursorVisible="false"
android:gravity="center" />
android:textColor="@color/white"
android:textSize="45sp" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp" />
<LinearLayout

View file

@ -27,28 +27,31 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center">
<EditText
android:id="@+id/amountfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="numberDecimal"
android:minWidth="100dp"
android:paddingTop="10dp"
android:text="112"
android:textSize="45sp"
android:cursorVisible="false"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"
android:textSize="25sp" />
<EditText
android:id="@+id/amountfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cursorVisible="false"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:minWidth="100dp"
android:paddingTop="10dp"
android:text="112"
android:textColor="@color/white"
android:textSize="45sp" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textSize="25sp" />
<ImageView
android:id="@+id/minusbutton"

View file

@ -17,28 +17,31 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center">
<EditText
android:id="@+id/amountfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="numberDecimal"
android:minWidth="100dp"
android:paddingTop="10dp"
android:text="112"
android:textSize="45sp"
android:cursorVisible="false"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"
android:textSize="25sp" />
<EditText
android:id="@+id/amountfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:cursorVisible="false"
android:gravity="center_horizontal"
android:inputType="numberDecimal"
android:minWidth="100dp"
android:paddingTop="10dp"
android:text="112"
android:textColor="@color/white"
android:textSize="45sp" />
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textSize="25sp" />
<ImageView
android:id="@+id/minusbutton"

View file

@ -22,8 +22,9 @@
android:layout_gravity="left|center_vertical"
android:gravity="center"
android:rotation="90"
android:text="label"
android:text="labelx"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/white"
android:textSize="25sp" />
<LinearLayout
@ -53,6 +54,7 @@
android:minWidth="50dp"
android:padding="10dp"
android:text="112"
android:textColor="@color/white"
android:textSize="45sp" />
<ImageView
@ -66,4 +68,4 @@
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>

View file

@ -10,14 +10,16 @@
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="label"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center"/>
android:textColor="@color/white" />
<ImageView
android:id="@+id/togglebutton"
android:layout_width="wrap_content"