Merge branch 'dev' into oref1

This commit is contained in:
Milos Kozak 2018-06-22 17:55:38 +02:00
commit 9360151100
20 changed files with 465 additions and 219 deletions

View file

@ -176,13 +176,19 @@ public class HistoryBrowseActivity extends AppCompatActivity {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateGUI("EventAutosensCalculationFinished");
synchronized (HistoryBrowseActivity.this) {
updateGUI("EventAutosensCalculationFinished");
}
}
});
}
}
void updateGUI(String from) {
if (noProfile == null || buttonDate == null || buttonZoom == null || bgGraph == null || iobGraph == null || seekBar == null)
return;
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
final Profile profile = MainApp.getConfigBuilder().getProfile();

View file

@ -10,6 +10,7 @@ import java.util.Date;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
/**
* Created by mike on 29.05.2017.
@ -17,6 +18,7 @@ import info.nightscout.androidaps.db.Source;
public class DetailedBolusInfo {
public long date = System.currentTimeMillis();
public long lastKnownBolusTime;
public String eventType = CareportalEvent.MEALBOLUS;
public double insulin = 0;
public double carbs = 0;

View file

@ -1470,14 +1470,19 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
profileSwitch.profileJson = trJson.getString("profileJson");
else {
ProfileStore store = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile();
Profile profile = store.getSpecificProfile(profileSwitch.profileName);
if (profile != null) {
profileSwitch.profileJson = profile.getData().toString();
log.debug("Profile switch prefilled with JSON from local store");
// Update data in NS
NSUpload.updateProfileSwitch(profileSwitch);
if (store != null) {
Profile profile = store.getSpecificProfile(profileSwitch.profileName);
if (profile != null) {
profileSwitch.profileJson = profile.getData().toString();
log.debug("Profile switch prefilled with JSON from local store");
// Update data in NS
NSUpload.updateProfileSwitch(profileSwitch);
} else {
log.debug("JSON for profile switch doesn't exist. Ignoring: " + trJson.toString());
return;
}
} else {
log.debug("JSON for profile switch doesn't exist. Ignoring: " + trJson.toString());
log.debug("Store for profile switch doesn't exist. Ignoring: " + trJson.toString());
return;
}
}

View file

@ -22,9 +22,7 @@ import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import butterknife.Optional;
import butterknife.Unbinder;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.PreferencesActivity;
@ -51,7 +49,7 @@ import info.nightscout.utils.PasswordProtection;
public class ConfigBuilderFragment extends SubscriberFragment {
private List<PluginView> pluginViews = new ArrayList<>();
private List<PluginViewHolder> pluginViewHolders = new ArrayList<>();
@BindView(R.id.profile_plugins)
LinearLayout profilePlugins;
@ -111,33 +109,33 @@ public class ConfigBuilderFragment extends SubscriberFragment {
@Override
public void onDestroyView() {
super.onDestroyView();
for (PluginView pluginView : pluginViews) pluginView.unbind();
pluginViews.clear();
for (PluginViewHolder pluginViewHolder : pluginViewHolders) pluginViewHolder.unbind();
pluginViewHolders.clear();
}
@Override
protected void updateGUI() {
for (PluginView pluginView : pluginViews) pluginView.update();
for (PluginViewHolder pluginViewHolder : pluginViewHolders) pluginViewHolder.update();
}
private void createViews() {
createViewsForPlugins(profilePlugins, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginType.PROFILE));
createViewsForPlugins(insulinPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginType.INSULIN));
createViewsForPlugins(bgSourcePlugins, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginType.BGSOURCE));
createViewsForPlugins(pumpPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP));
createViewsForPlugins(sensitivityPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginType.SENSITIVITY));
createViewsForPlugins(apsPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.APS));
createViewsForPlugins(loopPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP));
createViewsForPlugins(constraintsPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginType.CONSTRAINTS));
createViewsForPlugins(treatmentsPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT));
createViewsForPlugins(generalPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.GENERAL));
createViewsForPlugins(profilePlugins, PluginType.PROFILE, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginType.PROFILE));
createViewsForPlugins(insulinPlugins, PluginType.INSULIN, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginType.INSULIN));
createViewsForPlugins(bgSourcePlugins, PluginType.BGSOURCE, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginType.BGSOURCE));
createViewsForPlugins(pumpPlugins, PluginType.PUMP, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP));
createViewsForPlugins(sensitivityPlugins, PluginType.SENSITIVITY, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginType.SENSITIVITY));
createViewsForPlugins(apsPlugins, PluginType.APS, MainApp.getSpecificPluginsVisibleInList(PluginType.APS));
createViewsForPlugins(loopPlugins, PluginType.LOOP, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP));
createViewsForPlugins(constraintsPlugins, PluginType.CONSTRAINTS, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginType.CONSTRAINTS));
createViewsForPlugins(treatmentsPlugins, PluginType.TREATMENT, MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT));
createViewsForPlugins(generalPlugins, PluginType.GENERAL, MainApp.getSpecificPluginsVisibleInList(PluginType.GENERAL));
}
private void createViewsForPlugins(LinearLayout parent, List<PluginBase> plugins) {
private void createViewsForPlugins(LinearLayout parent, PluginType pluginType, List<PluginBase> plugins) {
for (PluginBase plugin: plugins) {
PluginView pluginView = new PluginView(plugin);
parent.addView(pluginView.getBaseView());
pluginViews.add(pluginView);
PluginViewHolder pluginViewHolder = new PluginViewHolder(pluginType, plugin);
parent.addView(pluginViewHolder.getBaseView());
pluginViewHolders.add(pluginViewHolder);
}
}
@ -200,9 +198,10 @@ public class ConfigBuilderFragment extends SubscriberFragment {
}
}
class PluginView {
class PluginViewHolder {
private Unbinder unbinder;
private PluginType pluginType;
private PluginBase plugin;
LinearLayout baseView;
@ -219,7 +218,8 @@ public class ConfigBuilderFragment extends SubscriberFragment {
@BindView(R.id.plugin_visibility)
CheckBox pluginVisibility;
public PluginView(PluginBase plugin) {
public PluginViewHolder(PluginType pluginType, PluginBase plugin) {
this.pluginType = pluginType;
this.plugin = plugin;
baseView = (LinearLayout) getLayoutInflater().inflate(R.layout.configbuilder_single_plugin, null);
unbinder = ButterKnife.bind(this, baseView);
@ -231,10 +231,10 @@ public class ConfigBuilderFragment extends SubscriberFragment {
}
public void update() {
enabledExclusive.setVisibility(areMultipleSelectionsAllowed(plugin.getType()) ? View.GONE : View.VISIBLE);
enabledInclusive.setVisibility(areMultipleSelectionsAllowed(plugin.getType()) ? View.VISIBLE : View.GONE);
enabledExclusive.setChecked(plugin.isEnabled(plugin.getType()));
enabledInclusive.setChecked(plugin.isEnabled(plugin.getType()));
enabledExclusive.setVisibility(areMultipleSelectionsAllowed(pluginType) ? View.GONE : View.VISIBLE);
enabledInclusive.setVisibility(areMultipleSelectionsAllowed(pluginType) ? View.VISIBLE : View.GONE);
enabledExclusive.setChecked(plugin.isEnabled(pluginType));
enabledInclusive.setChecked(plugin.isEnabled(pluginType));
enabledInclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled);
enabledExclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled);
pluginName.setText(plugin.getName());
@ -243,15 +243,15 @@ public class ConfigBuilderFragment extends SubscriberFragment {
pluginDescription.setVisibility(View.VISIBLE);
pluginDescription.setText(plugin.getDescription());
}
pluginPreferences.setVisibility(plugin.getPreferencesId() == -1 || !plugin.isEnabled(plugin.getType()) ? View.INVISIBLE : View.VISIBLE);
pluginPreferences.setVisibility(plugin.getPreferencesId() == -1 || !plugin.isEnabled(pluginType) ? View.INVISIBLE : View.VISIBLE);
pluginVisibility.setVisibility(plugin.hasFragment() ? View.VISIBLE : View.INVISIBLE);
pluginVisibility.setEnabled(!(plugin.pluginDescription.neverVisible || plugin.pluginDescription.alwayVisible) && plugin.isEnabled(plugin.getType()));
pluginVisibility.setEnabled(!(plugin.pluginDescription.neverVisible || plugin.pluginDescription.alwayVisible) && plugin.isEnabled(pluginType));
pluginVisibility.setChecked(plugin.isFragmentVisible());
}
@OnClick(R.id.plugin_visibility)
void onVisibilityChanged() {
plugin.setFragmentVisible(plugin.getType(), pluginVisibility.isChecked());
plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked());
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible");
MainApp.bus().post(new EventRefreshGui());
ConfigBuilderPlugin.getPlugin().logPluginStatus();
@ -260,9 +260,9 @@ public class ConfigBuilderFragment extends SubscriberFragment {
@OnClick({R.id.plugin_enabled_exclusive, R.id.plugin_enabled_inclusive})
void onEnabledChanged() {
boolean enabled = enabledExclusive.getVisibility() == View.VISIBLE ? enabledExclusive.isChecked() : enabledInclusive.isChecked();
plugin.setPluginEnabled(plugin.getType(), enabled);
plugin.setFragmentVisible(plugin.getType(), enabled);
processOnEnabledCategoryChanged(plugin, plugin.getType());
plugin.setPluginEnabled(pluginType, enabled);
plugin.setFragmentVisible(pluginType, enabled);
processOnEnabledCategoryChanged(plugin, pluginType);
updateGUI();
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled");
MainApp.bus().post(new EventRefreshGui());

View file

@ -520,6 +520,7 @@ public class ConfigBuilderPlugin extends PluginBase {
// deliver SMB
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.lastKnownBolusTime = activeTreatments.getLastBolusTime();
detailedBolusInfo.eventType = CareportalEvent.CORRECTIONBOLUS;
detailedBolusInfo.insulin = request.smb;
detailedBolusInfo.isSMB = true;

View file

@ -80,7 +80,7 @@ public class LoopFragment extends SubscriberFragment {
clearGUI();
final Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> lastRunView.setText(ev.text));
activity.runOnUiThread(() -> { synchronized (LoopFragment.this) { if (lastRunView != null) lastRunView.setText(ev.text); } });
}
@ -89,26 +89,29 @@ public class LoopFragment extends SubscriberFragment {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
if (lastRun != null) {
requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : "");
constraintsProcessedView.setText(lastRun.constraintsProcessed != null ? lastRun.constraintsProcessed.toSpanned() : "");
sourceView.setText(lastRun.source != null ? lastRun.source : "");
lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : "");
lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : "");
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? Html.fromHtml(lastRun.tbrSetByPump.toHtml()) : "");
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? Html.fromHtml(lastRun.smbSetByPump.toHtml()) : "");
synchronized (LoopFragment.this) {
if (!isBound()) return;
LoopPlugin.LastRun lastRun = LoopPlugin.lastRun;
if (lastRun != null) {
requestView.setText(lastRun.request != null ? lastRun.request.toSpanned() : "");
constraintsProcessedView.setText(lastRun.constraintsProcessed != null ? lastRun.constraintsProcessed.toSpanned() : "");
sourceView.setText(lastRun.source != null ? lastRun.source : "");
lastRunView.setText(lastRun.lastAPSRun != null && lastRun.lastAPSRun.getTime() != 0 ? lastRun.lastAPSRun.toLocaleString() : "");
lastEnactView.setText(lastRun.lastEnact != null && lastRun.lastEnact.getTime() != 0 ? lastRun.lastEnact.toLocaleString() : "");
tbrSetByPumpView.setText(lastRun.tbrSetByPump != null ? Html.fromHtml(lastRun.tbrSetByPump.toHtml()) : "");
smbSetByPumpView.setText(lastRun.smbSetByPump != null ? Html.fromHtml(lastRun.smbSetByPump.toHtml()) : "");
String constraints = "";
if (lastRun.constraintsProcessed != null) {
Constraint<Double> allConstraints = new Constraint<>(0d);
if (lastRun.constraintsProcessed.rateConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.rateConstraint);
if (lastRun.constraintsProcessed.smbConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.smbConstraint);
constraints = allConstraints.getMostLimitedReasons();
String constraints = "";
if (lastRun.constraintsProcessed != null) {
Constraint<Double> allConstraints = new Constraint<>(0d);
if (lastRun.constraintsProcessed.rateConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.rateConstraint);
if (lastRun.constraintsProcessed.smbConstraint != null)
allConstraints.copyReasons(lastRun.constraintsProcessed.smbConstraint);
constraints = allConstraints.getMostLimitedReasons();
}
constraintsView.setText(constraints);
}
constraintsView.setText(constraints);
}
});
}
@ -117,13 +120,29 @@ public class LoopFragment extends SubscriberFragment {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> {
requestView.setText("");
constraintsProcessedView.setText("");
sourceView.setText("");
lastRunView.setText("");
lastEnactView.setText("");
tbrSetByPumpView.setText("");
smbSetByPumpView.setText("");
synchronized (LoopFragment.this) {
if (isBound()) {
requestView.setText("");
constraintsProcessedView.setText("");
sourceView.setText("");
lastRunView.setText("");
lastEnactView.setText("");
tbrSetByPumpView.setText("");
smbSetByPumpView.setText("");
}
}
});
}
boolean isBound() {
return requestView != null
&& constraintsProcessedView != null
&& sourceView != null
&& lastRunView != null
&& lastEnactView != null
&& tbrSetByPumpView != null
&& smbSetByPumpView != null
&& constraintsView != null
&& runNowButton != null;
}
}

View file

@ -46,6 +46,7 @@ import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
@ -332,7 +333,9 @@ public class LoopPlugin extends PluginBase {
Constraint<Boolean> closedLoopEnabled = MainApp.getConstraintChecker().isClosedLoopAllowed();
if (closedLoopEnabled.value()) {
if (result.isChangeRequested()) {
if (result.isChangeRequested()
&& !ConfigBuilderPlugin.getCommandQueue().bolusInQueue()
&& !ConfigBuilderPlugin.getCommandQueue().isRunning(Command.CommandType.BOLUS)) {
final PumpEnactResult waiting = new PumpEnactResult();
waiting.queued = true;
if (resultAfterConstraints.tempBasalRequested)

View file

@ -87,34 +87,37 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
if (determineBasalAdapterSMBJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException see log for details");
synchronized (OpenAPSSMBFragment.this) {
if (!isBound()) return;
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
if (lastAPSResult != null) {
resultView.setText(JSONFormatter.format(lastAPSResult.json));
requestView.setText(lastAPSResult.toSpanned());
}
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
if (determineBasalAdapterSMBJS != null) {
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
try {
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
} catch (JSONException e) {
log.error("Unhandled exception", e);
iobDataView.setText("JSONException see log for details");
}
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
}
if (plugin.lastAPSRun != null) {
lastRunView.setText(plugin.lastAPSRun.toLocaleString().trim());
}
if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
}
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
}
if (plugin.lastAPSRun != null) {
lastRunView.setText(plugin.lastAPSRun.toLocaleString().trim());
}
if (plugin.lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
}
}
});
@ -126,17 +129,36 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
resultView.setText(text);
glucoseStatusView.setText("");
currentTempView.setText("");
iobDataView.setText("");
profileView.setText("");
mealDataView.setText("");
autosensDataView.setText("");
scriptdebugView.setText("");
requestView.setText("");
lastRunView.setText("");
synchronized (OpenAPSSMBFragment.this) {
if (isBound()) {
resultView.setText(text);
glucoseStatusView.setText("");
currentTempView.setText("");
iobDataView.setText("");
profileView.setText("");
mealDataView.setText("");
autosensDataView.setText("");
scriptdebugView.setText("");
requestView.setText("");
lastRunView.setText("");
}
}
}
});
}
private boolean isBound() {
return run != null
&& lastRunView != null
&& constraintsView != null
&& glucoseStatusView != null
&& currentTempView != null
&& iobDataView != null
&& profileView != null
&& mealDataView != null
&& autosensDataView != null
&& resultView != null
&& scriptdebugView != null
&& requestView != null;
}
}

View file

@ -114,6 +114,7 @@ import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.DefaultValueHelper;
import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.OKDialog;
@ -122,6 +123,8 @@ import info.nightscout.utils.SP;
import info.nightscout.utils.SingleClickButton;
import info.nightscout.utils.ToastUtils;
import static info.nightscout.utils.DateUtil.now;
public class OverviewFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener {
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
@ -488,6 +491,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() != null) {
menu.add(MainApp.gs(R.string.careportal_profileswitch));
}
} else if (v == tempTargetView) {
menu.setHeaderTitle(MainApp.gs(R.string.careportal_temporarytarget));
menu.add(MainApp.gs(R.string.custom));
menu.add(MainApp.gs(R.string.eatingsoon));
menu.add(MainApp.gs(R.string.activity));
menu.add(MainApp.gs(R.string.hypo));
if (TreatmentsPlugin.getPlugin().getTempTargetFromHistory() != null) {
menu.add(MainApp.gs(R.string.cancel));
}
}
}
@ -578,6 +590,53 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(System.currentTimeMillis());
FragmentManager manager = getFragmentManager();
pvd.show(manager, "ProfileViewDialog");
} else if (item.getTitle().equals(MainApp.gs(R.string.eatingsoon))) {
DefaultValueHelper defHelper = new DefaultValueHelper();
double target = defHelper.determineEatingSoonTT(profile.getUnits());
TempTarget tempTarget = new TempTarget()
.date(System.currentTimeMillis())
.duration(defHelper.determineEatingSoonTTDuration())
.reason(MainApp.gs(R.string.eatingsoon))
.source(Source.USER)
.low(target)
.high(target);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
} else if (item.getTitle().equals(MainApp.gs(R.string.activity))) {
DefaultValueHelper defHelper = new DefaultValueHelper();
double target = defHelper.determineActivityTT(profile.getUnits());
TempTarget tempTarget = new TempTarget()
.date(now())
.duration(defHelper.determineActivityTTDuration())
.reason(MainApp.gs(R.string.activity))
.source(Source.USER)
.low(target)
.high(target);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
} else if (item.getTitle().equals(MainApp.gs(R.string.hypo))) {
DefaultValueHelper defHelper = new DefaultValueHelper();
double target = defHelper.determineHypoTT(profile.getUnits());
TempTarget tempTarget = new TempTarget()
.date(now())
.duration(defHelper.determineHypoTTDuration())
.reason(MainApp.gs(R.string.activity))
.source(Source.USER)
.low(target)
.high(target);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
} else if (item.getTitle().equals(MainApp.gs(R.string.custom))) {
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
final OptionsToShow temptarget = CareportalFragment.TEMPTARGET;
temptarget.executeTempTarget = true;
newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget);
newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
} else if (item.getTitle().equals(MainApp.gs(R.string.cancel))) {
TempTarget tempTarget = new TempTarget()
.source(Source.USER)
.date(now())
.duration(0)
.low(0)
.high(0);
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
}
return super.onContextItemSelected(item);
@ -843,6 +902,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
sLoopHandler.removeCallbacksAndMessages(null);
unregisterForContextMenu(apsModeView);
unregisterForContextMenu(activeProfileView);
unregisterForContextMenu(tempTargetView);
}
@Override
@ -856,6 +916,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
registerForContextMenu(apsModeView);
registerForContextMenu(activeProfileView);
registerForContextMenu(tempTargetView);
updateGUI("onResume");
}
@ -1196,17 +1257,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
activeProfileView.setText(MainApp.getConfigBuilder().getProfileName());
activeProfileView.setBackgroundColor(Color.GRAY);
tempTargetView.setOnLongClickListener(view -> {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
final OptionsToShow temptarget = CareportalFragment.TEMPTARGET;
temptarget.executeTempTarget = true;
newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget);
newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
return true;
});
tempTargetView.setLongClickable(true);
// QuickWizard button
QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
@ -1422,7 +1472,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
secondGraphData.addDeviations(fromTime, now, useDevForScale, 1d);
if (SP.getBoolean("showratios", false))
secondGraphData.addRatio(fromTime, now, useRatioForScale, 1d);
if (SP.getBoolean("showdevslope", false))
if (SP.getBoolean("showdevslope", false) && MainApp.devBranch)
secondGraphData.addDeviationSlope(fromTime, now, useDSForScale, 1d);
// **** NOW line ****

View file

@ -79,11 +79,14 @@ public class NSProfileFragment extends SubscriberFragment {
public void onStatusEvent(final EventNSProfileUpdateGUI ev) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(() -> updateGUI());
activity.runOnUiThread(() -> { synchronized (NSProfileFragment.this) { updateGUI(); } });
}
@Override
protected void updateGUI() {
if (noProfile == null || profileSpinner == null)
return;
ProfileStore profileStore = NSProfilePlugin.getPlugin().getProfile();
if (profileStore != null) {
ArrayList<CharSequence> profileList = profileStore.getProfileList();

View file

@ -354,6 +354,11 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint
// trigger a connect, which will update state and check history
CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState);
if (stateResult.invalidSetup) {
MainApp.bus().post(new EventNewNotification(
new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_invalid_setup), Notification.URGENT)));
return;
}
if (!stateResult.success) {
return;
}

View file

@ -5,10 +5,11 @@ import android.support.annotation.Nullable;
import java.util.LinkedList;
import java.util.List;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.PumpHistory;
public class CommandResult {
/** True if a condition indicating a broken pump setup/configuration is detected */
public boolean invalidSetup;
/** Whether the command was executed successfully. */
public boolean success;
/** State of the pump *after* command execution. */

View file

@ -281,10 +281,10 @@ public class RuffyScripter implements RuffyCommands {
log.debug("Executing " + cmd + " took " + (cmdEndTime - cmdStartTime) + "ms");
} catch (CommandException e) {
log.error("CommandException running command", e);
activeCmd.getResult().success = false;
cmd.getResult().success = false;
} catch (Exception e) {
log.error("Unexpected exception running cmd", e);
activeCmd.getResult().success = false;
cmd.getResult().success = false;
}
}, cmd.getClass().getSimpleName());
long executionStart = System.currentTimeMillis();
@ -328,6 +328,7 @@ public class RuffyScripter implements RuffyCommands {
if (unparsableMenuEncountered) {
log.error("UnparsableMenuEncountered flagged, aborting command");
cmdThread.interrupt();
activeCmd.getResult().invalidSetup = true;
activeCmd.getResult().success = false;
}

View file

@ -39,17 +39,19 @@ public class ReadQuickInfoCommand extends BaseCommand {
// read bolus records
int totalRecords = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.TOTAL_RECORD);
int record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
while (true) {
bolusHistory.add(readBolusRecord());
if (bolusHistory.size() == numberOfBolusRecordsToRetrieve || record == totalRecords) {
break;
if (record > 0) {
while (true) {
bolusHistory.add(readBolusRecord());
if (bolusHistory.size() == numberOfBolusRecordsToRetrieve || record == totalRecords) {
break;
}
// advance to next record
scripter.pressDownKey();
while (record == (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD)) {
scripter.waitForScreenUpdate();
}
record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
}
// advance to next record
scripter.pressDownKey();
while (record == (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD)) {
scripter.waitForScreenUpdate();
}
record = (int) scripter.getCurrentMenu().getAttribute(MenuAttribute.CURRENT_RECORD);
}
if (log.isDebugEnabled()) {
if (!result.history.bolusHistory.isEmpty()) {

View file

@ -216,74 +216,96 @@ public class DanaRFragment extends SubscriberFragment {
@SuppressLint("SetTextI18n")
@Override
public void run() {
DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;
int agoMin = (int) (agoMsec / 60d / 1000d);
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")");
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
}
if (pump.lastBolusTime.getTime() != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
double agoHours = agoMsec / 60d / 60d / 1000d;
if (agoHours < 6) // max 6h back
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
else lastBolusView.setText("");
}
synchronized(DanaRFragment.this) {
if (!isBound()) return;
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h");
// DanaRPlugin, DanaRKoreanPlugin
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
DanaRPump pump = DanaRPump.getInstance();
if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;
int agoMin = (int) (agoMsec / 60d / 1000d);
lastConnectionView.setText(DateUtil.timeString(pump.lastConnection) + " (" + String.format(MainApp.gs(R.string.minago), agoMin) + ")");
SetWarnColor.setColor(lastConnectionView, agoMin, 16d, 31d);
}
} else {
// v2 plugin
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
if (pump.lastBolusTime.getTime() != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastBolusTime.getTime();
double agoHours = agoMsec / 60d / 60d / 1000d;
if (agoHours < 6) // max 6h back
lastBolusView.setText(DateUtil.timeString(pump.lastBolusTime) + " " + DateUtil.sinceString(pump.lastBolusTime.getTime()) + " " + DecimalFormatter.to2Decimal(DanaRPump.getInstance().lastBolusAmount) + " U");
else lastBolusView.setText("");
}
}
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
if (activeExtendedBolus != null) {
extendedBolusView.setText(activeExtendedBolus.toString());
} else {
extendedBolusView.setText("");
}
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U");
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");
SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d);
iobView.setText(pump.iob + " U");
if (pump.model != 0 || pump.protocol != 0 || pump.productCode != 0) {
firmwareView.setText(String.format(MainApp.gs(R.string.danar_model), pump.model, pump.protocol, pump.productCode));
} else {
firmwareView.setText("OLD");
}
basalStepView.setText("" + pump.basalStep);
bolusStepView.setText("" + pump.bolusStep);
serialNumberView.setText("" + pump.serialNumber);
if (queueView != null) {
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
if (status.toString().equals("")) {
queueView.setVisibility(View.GONE);
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(ConfigBuilderPlugin.getActivePump().getBaseBasalRate()) + " U/h");
// DanaRPlugin, DanaRKoreanPlugin
if (ConfigBuilderPlugin.getActivePump().isFakingTempsByExtendedBoluses()) {
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
} else {
queueView.setVisibility(View.VISIBLE);
queueView.setText(status);
// v2 plugin
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
tempBasalView.setText(TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis()).toStringFull());
} else {
tempBasalView.setText("");
}
}
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
if (activeExtendedBolus != null) {
extendedBolusView.setText(activeExtendedBolus.toString());
} else {
extendedBolusView.setText("");
}
reservoirView.setText(DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + " / 300 U");
SetWarnColor.setColorInverse(reservoirView, pump.reservoirRemainingUnits, 50d, 20d);
batteryView.setText("{fa-battery-" + (pump.batteryRemaining / 25) + "}");
SetWarnColor.setColorInverse(batteryView, pump.batteryRemaining, 51d, 26d);
iobView.setText(pump.iob + " U");
if (pump.model != 0 || pump.protocol != 0 || pump.productCode != 0) {
firmwareView.setText(String.format(MainApp.gs(R.string.danar_model), pump.model, pump.protocol, pump.productCode));
} else {
firmwareView.setText("OLD");
}
basalStepView.setText("" + pump.basalStep);
bolusStepView.setText("" + pump.bolusStep);
serialNumberView.setText("" + pump.serialNumber);
if (queueView != null) {
Spanned status = ConfigBuilderPlugin.getCommandQueue().spannedStatus();
if (status.toString().equals("")) {
queueView.setVisibility(View.GONE);
} else {
queueView.setVisibility(View.VISIBLE);
queueView.setText(status);
}
}
//hide user options button if not an RS pump
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
if (isKorean) {
danar_user_options.setVisibility(View.GONE);
}
}
//hide user options button if not an RS pump
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
if (isKorean ) {
danar_user_options.setVisibility(View.GONE);
}
}
});
}
private boolean isBound() {
return lastConnectionView != null
&& lastBolusView != null
&& dailyUnitsView != null
&& basaBasalRateView != null
&& tempBasalView != null
&& extendedBolusView != null
&& reservoirView != null
&& batteryView != null
&& iobView != null
&& firmwareView != null
&& basalStepView != null
&& bolusStepView != null
&& serialNumberView != null
&& danar_user_options != null
&& queueView != null;
}
}

View file

@ -43,6 +43,8 @@ import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
import static info.nightscout.utils.DateUtil.now;
public class TreatmentsBolusFragment extends SubscriberFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(TreatmentsBolusFragment.class);
@ -52,6 +54,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
TextView iobTotal;
TextView activityTotal;
Button refreshFromNS;
Button deleteFutureTreatments;
Context context;
@ -89,7 +92,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
holder.iob.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorActive));
else
holder.iob.setTextColor(holder.carbs.getCurrentTextColor());
if (t.date > DateUtil.now())
if (t.date > now())
holder.date.setTextColor(ContextCompat.getColor(MainApp.instance(), R.color.colorScheduled));
else
holder.date.setTextColor(holder.carbs.getCurrentTextColor());
@ -189,6 +192,9 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
refreshFromNS = (Button) view.findViewById(R.id.treatments_reshreshfromnightscout);
refreshFromNS.setOnClickListener(this);
deleteFutureTreatments = (Button) view.findViewById(R.id.treatments_delete_future_treatments);
deleteFutureTreatments.setOnClickListener(this);
boolean nsUploadOnly = SP.getBoolean(R.string.key_ns_upload_only, false);
if (nsUploadOnly)
refreshFromNS.setVisibility(View.GONE);
@ -201,17 +207,37 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
@Override
public void onClick(View view) {
AlertDialog.Builder builder;
switch (view.getId()) {
case R.id.treatments_reshreshfromnightscout:
AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext());
builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.refresheventsfromnightscout) + "?");
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
TreatmentsPlugin.getPlugin().getService().resetTreatments();
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
TreatmentsPlugin.getPlugin().getService().resetTreatments();
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
break;
case R.id.treatments_delete_future_treatments:
builder = new AlertDialog.Builder(this.getContext());
builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.deletefuturetreatments) + "?");
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
final List<Treatment> futureTreatments = TreatmentsPlugin.getPlugin().getService()
.getTreatmentDataFromTime(now() + 1000, true);
for (Treatment treatment : futureTreatments) {
final String _id = treatment._id;
if (NSUpload.isIdValid(_id)) {
NSUpload.removeCareportalEntryFromNS(_id);
} else {
UploadQueue.removeID("dbAdd", _id);
}
TreatmentsPlugin.getPlugin().getService().delete(treatment);
}
updateGUI();
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
@ -233,14 +259,16 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
protected void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTreatmentsFromHistory()), false);
if (TreatmentsPlugin.getPlugin().getLastCalculationTreatments() != null) {
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().iob) + " U");
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().activity) + " U");
}
activity.runOnUiThread(() -> {
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTreatmentsFromHistory()), false);
if (TreatmentsPlugin.getPlugin().getLastCalculationTreatments() != null) {
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().iob) + " " + MainApp.gs(R.string.insulin_unit_shortname));
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().activity) + " " + MainApp.gs(R.string.insulin_unit_shortname));
}
if (!TreatmentsPlugin.getPlugin().getService().getTreatmentDataFromTime(now() + 1000, true).isEmpty()) {
deleteFutureTreatments.setVisibility(View.VISIBLE);
} else {
deleteFutureTreatments.setVisibility(View.GONE);
}
});
}

View file

@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressHelperAc
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.androidaps.queue.commands.CommandBolus;
import info.nightscout.androidaps.queue.commands.CommandCancelExtendedBolus;
@ -177,6 +178,18 @@ public class CommandQueue {
public synchronized boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
Command.CommandType type = detailedBolusInfo.isSMB ? Command.CommandType.SMB_BOLUS : Command.CommandType.BOLUS;
if (type == Command.CommandType.SMB_BOLUS) {
if (isRunning(Command.CommandType.BOLUS) || bolusInQueue()) {
log.debug("Rejecting SMB since a bolus is queue/running");
return false;
}
if (detailedBolusInfo.lastKnownBolusTime < TreatmentsPlugin.getPlugin().getLastBolusTime()) {
log.debug("Rejecting bolus, another bolus was issued since request time");
return false;
}
}
if(type.equals(Command.CommandType.BOLUS) && detailedBolusInfo.carbs > 0 && detailedBolusInfo.insulin == 0){
type = Command.CommandType.CARBS_ONLY_TREATMENT;
//Carbs only can be added in parallel as they can be "in the future".

View file

@ -50,13 +50,28 @@
</LinearLayout>
<Button
android:id="@+id/treatments_reshreshfromnightscout"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/nav_refreshtreatments" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/treatments_reshreshfromnightscout"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/nav_refreshtreatments"/>
<Button
android:id="@+id/treatments_delete_future_treatments"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/deletefuturetreatments" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/treatments_recyclerview"

View file

@ -438,6 +438,7 @@
<string name="openapsma_scriptdebugdata_label">Script debug</string>
<string name="openapsama_useautosens">Use AMA autosens feature</string>
<string name="refresheventsfromnightscout">Refresh events from NS</string>
<string name="deletefuturetreatments">Delete treatments in the future</string>
<string name="eatingsoon">Eating Soon</string>
<string name="hypo">Hypo</string>
<string name="activity">Activity</string>
@ -1168,6 +1169,8 @@
<string translatable="false" name="key_low_temptarget_lowers_sensitivity">low_temptarget_lowers_sensitivity</string>
<string name="high_temptarget_raises_sensitivity_summary"><![CDATA[Raise sensitivity for temptargets >= 100]]></string>
<string name="low_temptarget_lowers_sensitivity_summary"><![CDATA[Lower sensitivity for temptargets < 100]]></string>
<string name="combo_invalid_setup">Invalid pump setup, check the docs and verify that the Quick Info menu is named "QUICK INFO" using the 360 configuration software.</string>
<string name="custom">Custom</string>
<plurals name="objective_days">
<item quantity="one">%d day</item>

View file

@ -15,6 +15,8 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.ConstraintChecker;
@ -24,9 +26,11 @@ import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpMDI.MDIPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.utils.ToastUtils;
import static info.nightscout.utils.DateUtil.now;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -36,7 +40,7 @@ import static org.mockito.Mockito.when;
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class})
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, TreatmentsPlugin.class})
public class CommandQueueTest extends CommandQueue {
String validProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}";
@ -142,6 +146,11 @@ public class CommandQueueTest extends CommandQueue {
when(MainApp.bus()).thenReturn(bus);
when(MainApp.gs(0)).thenReturn("");
PowerMockito.mockStatic(TreatmentsPlugin.class);
TreatmentsPlugin treatmentsPlugin = mock(TreatmentsPlugin.class);
when(TreatmentsPlugin.getPlugin()).thenReturn(treatmentsPlugin);
when(treatmentsPlugin.getLastBolusTime()).thenReturn(new Date(100, 0,1 ).getTime());
}
@Override
@ -159,21 +168,57 @@ public class CommandQueueTest extends CommandQueue {
@Test
public void callingCancelAllBolusesClearsQueue() throws Exception {
// given
prepareMock(0d, 0);
// add normal and SMB-bolus to queue
Assert.assertEquals(0, size());
DetailedBolusInfo smb = new DetailedBolusInfo();
smb.lastKnownBolusTime = now();
smb.isSMB = true;
bolus(smb, null);
bolus(new DetailedBolusInfo(), null);
Assert.assertEquals(2, size());
// when
cancelAllBoluses();
// then
Assert.assertEquals(0, size());
}
@Test
public void smbIsRejectedIfABolusIsQueued() throws Exception {
// given
prepareMock(0d, 0);
Assert.assertEquals(0, size());
// when
bolus(new DetailedBolusInfo(), null);
DetailedBolusInfo smb = new DetailedBolusInfo();
smb.isSMB = true;
bolus(smb, null);
boolean queued = bolus(smb, null);
Assert.assertEquals(2, size());
// then
Assert.assertFalse(queued);
Assert.assertEquals(size(), 1);
}
// cancelling all boluses clear all boluses from the queue
cancelAllBoluses();
@Test
public void smbIsRejectedIfLastKnownBolusIsOutdated() throws Exception {
// given
prepareMock(0d, 0);
Assert.assertEquals(0, size());
// when
DetailedBolusInfo bolus = new DetailedBolusInfo();
bolus.isSMB = true;
bolus.lastKnownBolusTime = 0;
boolean queued = bolus(bolus, null);
// then
Assert.assertFalse(queued);
Assert.assertEquals(size(), 0);
}
}