This commit is contained in:
Milos Kozak 2018-04-06 21:12:14 +02:00
commit 35decd0e53
7 changed files with 306 additions and 328 deletions

View file

@ -111,6 +111,7 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotificati
import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock; import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData; import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.notifications.NotificationRecyclerViewAdapter;
import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
@ -460,32 +461,32 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); final PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription();
if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation"))
return; return;
menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop)); menu.setHeaderTitle(MainApp.gs(R.string.loop));
if (activeloop.isEnabled(PluginType.LOOP)) { if (activeloop.isEnabled(PluginType.LOOP)) {
menu.add(MainApp.sResources.getString(R.string.disableloop)); menu.add(MainApp.gs(R.string.disableloop));
if (!activeloop.isSuspended()) { if (!activeloop.isSuspended()) {
menu.add(MainApp.sResources.getString(R.string.suspendloopfor1h)); menu.add(MainApp.gs(R.string.suspendloopfor1h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor2h)); menu.add(MainApp.gs(R.string.suspendloopfor2h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor3h)); menu.add(MainApp.gs(R.string.suspendloopfor3h));
menu.add(MainApp.sResources.getString(R.string.suspendloopfor10h)); menu.add(MainApp.gs(R.string.suspendloopfor10h));
if (pumpDescription.tempDurationStep15mAllowed) if (pumpDescription.tempDurationStep15mAllowed)
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor15m)); menu.add(MainApp.gs(R.string.disconnectpumpfor15m));
if (pumpDescription.tempDurationStep30mAllowed) if (pumpDescription.tempDurationStep30mAllowed)
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor30m)); menu.add(MainApp.gs(R.string.disconnectpumpfor30m));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor1h)); menu.add(MainApp.gs(R.string.disconnectpumpfor1h));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor2h)); menu.add(MainApp.gs(R.string.disconnectpumpfor2h));
menu.add(MainApp.sResources.getString(R.string.disconnectpumpfor3h)); menu.add(MainApp.gs(R.string.disconnectpumpfor3h));
} else { } else {
menu.add(MainApp.sResources.getString(R.string.resume)); menu.add(MainApp.gs(R.string.resume));
} }
} }
if (!activeloop.isEnabled(PluginType.LOOP)) if (!activeloop.isEnabled(PluginType.LOOP))
menu.add(MainApp.sResources.getString(R.string.enableloop)); menu.add(MainApp.gs(R.string.enableloop));
} else if (v == activeProfileView) { } else if (v == activeProfileView) {
menu.setHeaderTitle(MainApp.sResources.getString(R.string.profile)); menu.setHeaderTitle(MainApp.gs(R.string.profile));
menu.add(MainApp.sResources.getString(R.string.danar_viewprofile)); menu.add(MainApp.gs(R.string.danar_viewprofile));
if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() != null) { if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() != null) {
menu.add(MainApp.sResources.getString(R.string.careportal_profileswitch)); menu.add(MainApp.gs(R.string.careportal_profileswitch));
} }
} }
} }
@ -496,7 +497,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (profile == null) if (profile == null)
return true; return true;
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (item.getTitle().equals(MainApp.sResources.getString(R.string.disableloop))) { if (item.getTitle().equals(MainApp.gs(R.string.disableloop))) {
activeloop.setPluginEnabled(PluginType.LOOP, false); activeloop.setPluginEnabled(PluginType.LOOP, false);
activeloop.setFragmentVisible(PluginType.LOOP, false); activeloop.setFragmentVisible(PluginType.LOOP, false);
MainApp.getConfigBuilder().storeSettings("DisablingLoop"); MainApp.getConfigBuilder().storeSettings("DisablingLoop");
@ -505,75 +506,75 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror));
} }
} }
}); });
NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) { } else if (item.getTitle().equals(MainApp.gs(R.string.enableloop))) {
activeloop.setPluginEnabled(PluginType.LOOP, true); activeloop.setPluginEnabled(PluginType.LOOP, true);
activeloop.setFragmentVisible(PluginType.LOOP, true); activeloop.setFragmentVisible(PluginType.LOOP, true);
MainApp.getConfigBuilder().storeSettings("EnablingLoop"); MainApp.getConfigBuilder().storeSettings("EnablingLoop");
updateGUI("suspendmenu"); updateGUI("suspendmenu");
NSUpload.uploadOpenAPSOffline(0); NSUpload.uploadOpenAPSOffline(0);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) { } else if (item.getTitle().equals(MainApp.gs(R.string.resume))) {
activeloop.suspendTo(0L); activeloop.suspendTo(0L);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() { MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror));
} }
} }
}); });
NSUpload.uploadOpenAPSOffline(0); NSUpload.uploadOpenAPSOffline(0);
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) { } else if (item.getTitle().equals(MainApp.gs(R.string.suspendloopfor1h))) {
MainApp.getConfigBuilder().suspendLoop(60); MainApp.getConfigBuilder().suspendLoop(60);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) { } else if (item.getTitle().equals(MainApp.gs(R.string.suspendloopfor2h))) {
MainApp.getConfigBuilder().suspendLoop(120); MainApp.getConfigBuilder().suspendLoop(120);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) { } else if (item.getTitle().equals(MainApp.gs(R.string.suspendloopfor3h))) {
MainApp.getConfigBuilder().suspendLoop(180); MainApp.getConfigBuilder().suspendLoop(180);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) { } else if (item.getTitle().equals(MainApp.gs(R.string.suspendloopfor10h))) {
MainApp.getConfigBuilder().suspendLoop(600); MainApp.getConfigBuilder().suspendLoop(600);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor15m))) { } else if (item.getTitle().equals(MainApp.gs(R.string.disconnectpumpfor15m))) {
MainApp.getConfigBuilder().disconnectPump(15, profile); MainApp.getConfigBuilder().disconnectPump(15, profile);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) { } else if (item.getTitle().equals(MainApp.gs(R.string.disconnectpumpfor30m))) {
MainApp.getConfigBuilder().disconnectPump(30, profile); MainApp.getConfigBuilder().disconnectPump(30, profile);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) { } else if (item.getTitle().equals(MainApp.gs(R.string.disconnectpumpfor1h))) {
MainApp.getConfigBuilder().disconnectPump(60, profile); MainApp.getConfigBuilder().disconnectPump(60, profile);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) { } else if (item.getTitle().equals(MainApp.gs(R.string.disconnectpumpfor2h))) {
MainApp.getConfigBuilder().disconnectPump(120, profile); MainApp.getConfigBuilder().disconnectPump(120, profile);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) { } else if (item.getTitle().equals(MainApp.gs(R.string.disconnectpumpfor3h))) {
MainApp.getConfigBuilder().disconnectPump(180, profile); MainApp.getConfigBuilder().disconnectPump(180, profile);
updateGUI("suspendmenu"); updateGUI("suspendmenu");
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.careportal_profileswitch))) { } else if (item.getTitle().equals(MainApp.gs(R.string.careportal_profileswitch))) {
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog(); NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT; final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCHDIRECT;
profileswitch.executeProfileSwitch = true; profileswitch.executeProfileSwitch = true;
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch); newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
newDialog.show(getFragmentManager(), "NewNSTreatmentDialog"); newDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.danar_viewprofile))) { } else if (item.getTitle().equals(MainApp.gs(R.string.danar_viewprofile))) {
ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(System.currentTimeMillis()); ProfileViewerDialog pvd = ProfileViewerDialog.newInstance(System.currentTimeMillis());
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
pvd.show(manager, "ProfileViewDialog"); pvd.show(manager, "ProfileViewDialog");
@ -753,9 +754,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (!insulinAfterConstraints.equals(wizard.calculatedTotalInsulin) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) { if (!insulinAfterConstraints.equals(wizard.calculatedTotalInsulin) || !carbsAfterConstraints.equals(quickWizardEntry.carbs())) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(MainApp.sResources.getString(R.string.treatmentdeliveryerror)); builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror));
builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput)); builder.setMessage(getString(R.string.constraints_violation) + "\n" + getString(R.string.changeyourinput));
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), null); builder.setPositiveButton(MainApp.gs(R.string.ok), null);
builder.show(); builder.show();
return; return;
} }
@ -765,7 +766,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final Context context = getContext(); final Context context = getContext();
final AlertDialog.Builder builder = new AlertDialog.Builder(context); final AlertDialog.Builder builder = new AlertDialog.Builder(context);
accepted = false; accepted = false;
builder.setTitle(MainApp.sResources.getString(R.string.confirmation)); builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(confirmMessage); builder.setMessage(confirmMessage);
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
@ -789,7 +790,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror); i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment); i.putExtra("status", result.comment);
i.putExtra("title", MainApp.sResources.getString(R.string.tempbasaldeliveryerror)); i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i); MainApp.instance().startActivity(i);
} }
@ -810,7 +811,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror); i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment); i.putExtra("status", result.comment);
i.putExtra("title", MainApp.sResources.getString(R.string.treatmentdeliveryerror)); i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i); MainApp.instance().startActivity(i);
} }
@ -841,12 +842,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
MainApp.bus().register(this); MainApp.bus().register(this);
sRefreshLoop = new Runnable() { sRefreshLoop = () -> {
@Override scheduleUpdateGUI("refreshLoop");
public void run() { sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
scheduleUpdateGUI("refreshLoop");
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
}
}; };
sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L); sLoopHandler.postDelayed(sRefreshLoop, 60 * 1000L);
registerForContextMenu(apsModeView); registerForContextMenu(apsModeView);
@ -894,23 +892,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
scheduleUpdateGUI("EventExtendedBolusChange"); scheduleUpdateGUI("EventExtendedBolusChange");
} }
// Handled by EventAutosensCalculationFinished
// @Subscribe
// public void onStatusEvent(final EventNewBG ev) {
// scheduleUpdateGUI("EventNewBG");
// }
@Subscribe @Subscribe
public void onStatusEvent(final EventNewOpenLoopNotification ev) { public void onStatusEvent(final EventNewOpenLoopNotification ev) {
scheduleUpdateGUI("EventNewOpenLoopNotification"); scheduleUpdateGUI("EventNewOpenLoopNotification");
} }
// Handled by EventAutosensCalculationFinished
// @Subscribe
// public void onStatusEvent(final EventNewBasalProfile ev) {
// scheduleUpdateGUI("EventNewBasalProfile");
// }
@Subscribe @Subscribe
public void onStatusEvent(final EventTempTargetChange ev) { public void onStatusEvent(final EventTempTargetChange ev) {
scheduleUpdateGUI("EventTempTargetChange"); scheduleUpdateGUI("EventTempTargetChange");
@ -920,12 +906,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public void onStatusEvent(final EventPumpStatusChanged s) { public void onStatusEvent(final EventPumpStatusChanged s) {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) if (activity != null)
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> updatePumpStatus(s.textStatus()));
@Override
public void run() {
updatePumpStatus(s.textStatus());
}
});
} }
private void hideTempRecommendation() { private void hideTempRecommendation() {
@ -962,12 +943,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
public void run() { public void run() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) if (activity != null)
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> {
@Override updateGUI(from);
public void run() { scheduledUpdate = null;
updateGUI(from);
scheduledUpdate = null;
}
}); });
} }
} }
@ -1032,7 +1010,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
avgdeltaView.setText("øΔ15m: " + Profile.toUnitsString(glucoseStatus.short_avgdelta, glucoseStatus.short_avgdelta * Constants.MGDL_TO_MMOLL, units) + avgdeltaView.setText("øΔ15m: " + Profile.toUnitsString(glucoseStatus.short_avgdelta, glucoseStatus.short_avgdelta * Constants.MGDL_TO_MMOLL, units) +
" øΔ40m: " + Profile.toUnitsString(glucoseStatus.long_avgdelta, glucoseStatus.long_avgdelta * Constants.MGDL_TO_MMOLL, units)); " øΔ40m: " + Profile.toUnitsString(glucoseStatus.long_avgdelta, glucoseStatus.long_avgdelta * Constants.MGDL_TO_MMOLL, units));
} else { } else {
deltaView.setText("Δ " + MainApp.sResources.getString(R.string.notavailable)); deltaView.setText("Δ " + MainApp.gs(R.string.notavailable));
if (avgdeltaView != null) if (avgdeltaView != null)
avgdeltaView.setText(""); avgdeltaView.setText("");
} }
@ -1049,25 +1027,29 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus()) { if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuperBolus()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended)); apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(String.format(MainApp.sResources.getString(R.string.loopsuperbolusfor), activeloop.minutesToEndOfSuspend())); apsModeView.setText(String.format(MainApp.gs(R.string.loopsuperbolusfor), activeloop.minutesToEndOfSuspend()));
apsModeView.setTextColor(Color.WHITE);
} else if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isDisconnected()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(String.format(MainApp.gs(R.string.loopdisconnectedfor), activeloop.minutesToEndOfSuspend()));
apsModeView.setTextColor(Color.WHITE); apsModeView.setTextColor(Color.WHITE);
} else if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuspended()) { } else if (activeloop != null && activeloop.isEnabled(activeloop.getType()) && activeloop.isSuspended()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended)); apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(String.format(MainApp.sResources.getString(R.string.loopsuspendedfor), activeloop.minutesToEndOfSuspend())); apsModeView.setText(String.format(MainApp.gs(R.string.loopsuspendedfor), activeloop.minutesToEndOfSuspend()));
apsModeView.setTextColor(Color.WHITE); apsModeView.setTextColor(Color.WHITE);
} else if (pump.isSuspended()) { } else if (pump.isSuspended()) {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended)); apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.looppumpsuspended));
apsModeView.setText(MainApp.sResources.getString(R.string.pumpsuspended)); apsModeView.setText(MainApp.gs(R.string.pumpsuspended));
apsModeView.setTextColor(Color.WHITE); apsModeView.setTextColor(Color.WHITE);
} else if (activeloop != null && activeloop.isEnabled(activeloop.getType())) { } else if (activeloop != null && activeloop.isEnabled(activeloop.getType())) {
if (closedLoopEnabled.value()) { if (closedLoopEnabled.value()) {
apsModeView.setText(MainApp.sResources.getString(R.string.closedloop)); apsModeView.setText(MainApp.gs(R.string.closedloop));
} else { } else {
apsModeView.setText(MainApp.sResources.getString(R.string.openloop)); apsModeView.setText(MainApp.gs(R.string.openloop));
} }
} else { } else {
apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopdisabled)); apsModeView.setBackgroundColor(MainApp.sResources.getColor(R.color.loopdisabled));
apsModeView.setText(MainApp.sResources.getString(R.string.disabledloop)); apsModeView.setText(MainApp.gs(R.string.disabledloop));
apsModeView.setTextColor(Color.WHITE); apsModeView.setTextColor(Color.WHITE);
} }
} else { } else {
@ -1135,11 +1117,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
baseBasalView.setOnClickListener(new View.OnClickListener() { baseBasalView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String fullText = MainApp.sResources.getString(R.string.pump_basebasalrate_label) + ": " + DecimalFormatter.to2Decimal(profile.getBasal()) + "U/h\n"; String fullText = MainApp.gs(R.string.pump_basebasalrate_label) + ": " + DecimalFormatter.to2Decimal(profile.getBasal()) + "U/h\n";
if (activeTemp != null) { if (activeTemp != null) {
fullText += MainApp.sResources.getString(R.string.pump_tempbasal_label) + ": " + activeTemp.toStringFull(); fullText += MainApp.gs(R.string.pump_tempbasal_label) + ": " + activeTemp.toStringFull();
} }
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.basal), fullText, null); OKDialog.show(getActivity(), MainApp.gs(R.string.basal), fullText, null);
} }
}); });
@ -1173,7 +1155,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
extendedBolusView.setOnClickListener(new View.OnClickListener() { extendedBolusView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.extendedbolus), extendedBolus.toString(), null); OKDialog.show(getActivity(), MainApp.gs(R.string.extendedbolus), extendedBolus.toString(), null);
} }
}); });
@ -1192,17 +1174,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
activeProfileView.setText(MainApp.getConfigBuilder().getProfileName()); activeProfileView.setText(MainApp.getConfigBuilder().getProfileName());
activeProfileView.setBackgroundColor(Color.GRAY); activeProfileView.setBackgroundColor(Color.GRAY);
tempTargetView.setOnLongClickListener(new View.OnLongClickListener() { tempTargetView.setOnLongClickListener(view -> {
@Override view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
public boolean onLongClick(View view) { NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); final OptionsToShow temptarget = CareportalFragment.TEMPTARGET;
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog(); temptarget.executeTempTarget = true;
final OptionsToShow temptarget = CareportalFragment.TEMPTARGET; newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget);
temptarget.executeTempTarget = true; newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget); return true;
newTTDialog.show(getFragmentManager(), "NewNSTreatmentDialog");
return true;
}
}); });
tempTargetView.setLongClickable(true); tempTargetView.setLongClickable(true);
@ -1276,14 +1255,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (shorttextmode) { if (shorttextmode) {
String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U"; String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U";
iobView.setText(iobtext); iobView.setText(iobtext);
iobView.setOnClickListener(new View.OnClickListener() { iobView.setOnClickListener(v -> {
@Override String iobtext1 = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U\n"
public void onClick(View v) { + getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U\n"
String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U\n" + getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U\n";
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U\n" OKDialog.show(getActivity(), MainApp.gs(R.string.iob), iobtext1, null);
+ getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U\n";
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.iob), iobtext, null);
}
}); });
} else if (MainApp.sResources.getBoolean(R.bool.isTablet)) { } else if (MainApp.sResources.getBoolean(R.bool.isTablet)) {
String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
@ -1310,159 +1286,138 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// pump status from ns // pump status from ns
if (pumpDeviceStatusView != null) { if (pumpDeviceStatusView != null) {
pumpDeviceStatusView.setText(NSDeviceStatus.getInstance().getPumpStatus()); pumpDeviceStatusView.setText(NSDeviceStatus.getInstance().getPumpStatus());
pumpDeviceStatusView.setOnClickListener(new View.OnClickListener() { pumpDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.pump), NSDeviceStatus.getInstance().getExtendedPumpStatus(), null));
@Override
public void onClick(View v) {
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.pump), NSDeviceStatus.getInstance().getExtendedPumpStatus(), null);
}
});
} }
// OpenAPS status from ns // OpenAPS status from ns
if (openapsDeviceStatusView != null) { if (openapsDeviceStatusView != null) {
openapsDeviceStatusView.setText(NSDeviceStatus.getInstance().getOpenApsStatus()); openapsDeviceStatusView.setText(NSDeviceStatus.getInstance().getOpenApsStatus());
openapsDeviceStatusView.setOnClickListener(new View.OnClickListener() { openapsDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.openaps), NSDeviceStatus.getInstance().getExtendedOpenApsStatus(), null));
@Override
public void onClick(View v) {
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.openaps), NSDeviceStatus.getInstance().getExtendedOpenApsStatus(), null);
}
});
} }
// Uploader status from ns // Uploader status from ns
if (uploaderDeviceStatusView != null) { if (uploaderDeviceStatusView != null) {
uploaderDeviceStatusView.setText(NSDeviceStatus.getInstance().getUploaderStatus()); uploaderDeviceStatusView.setText(NSDeviceStatus.getInstance().getUploaderStatus());
uploaderDeviceStatusView.setOnClickListener(new View.OnClickListener() { uploaderDeviceStatusView.setOnClickListener(v -> OKDialog.show(getActivity(), MainApp.gs(R.string.uploader), NSDeviceStatus.getInstance().getExtendedUploaderStatus(), null));
@Override
public void onClick(View v) {
OKDialog.show(getActivity(), MainApp.sResources.getString(R.string.uploader), NSDeviceStatus.getInstance().getExtendedUploaderStatus(), null);
}
});
} }
// ****** GRAPH ******* // ****** GRAPH *******
new Thread(new Runnable() { new Thread(() -> {
@Override // allign to hours
public void run() { Calendar calendar = Calendar.getInstance();
// allign to hours calendar.setTimeInMillis(System.currentTimeMillis());
Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, 0);
calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0); calendar.add(Calendar.HOUR, 1);
calendar.set(Calendar.MINUTE, 0);
calendar.add(Calendar.HOUR, 1);
int hoursToFetch; int hoursToFetch;
final long toTime; final long toTime;
final long fromTime; final long fromTime;
final long endTime; final long endTime;
if (predictionsAvailable && SP.getBoolean("showprediction", false)) { if (predictionsAvailable && SP.getBoolean("showprediction", false)) {
int predHours = (int) (Math.ceil(finalLastRun.constraintsProcessed.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000)); int predHours = (int) (Math.ceil(finalLastRun.constraintsProcessed.getLatestPredictionsTime() - System.currentTimeMillis()) / (60 * 60 * 1000));
predHours = Math.min(2, predHours); predHours = Math.min(2, predHours);
predHours = Math.max(0, predHours); predHours = Math.max(0, predHours);
hoursToFetch = rangeToDisplay - predHours; hoursToFetch = rangeToDisplay - predHours;
toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding - Graphview specific toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding - Graphview specific
fromTime = toTime - hoursToFetch * 60 * 60 * 1000L; fromTime = toTime - hoursToFetch * 60 * 60 * 1000L;
endTime = toTime + predHours * 60 * 60 * 1000L; endTime = toTime + predHours * 60 * 60 * 1000L;
} else { } else {
hoursToFetch = rangeToDisplay; hoursToFetch = rangeToDisplay;
toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding - Graphview specific toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding - Graphview specific
fromTime = toTime - hoursToFetch * 60 * 60 * 1000L; fromTime = toTime - hoursToFetch * 60 * 60 * 1000L;
endTime = toTime; endTime = toTime;
} }
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
// ------------------ 1st graph // ------------------ 1st graph
Profiler.log(log, from + " - 1st graph - START", updateGUIStart); Profiler.log(log, from + " - 1st graph - START", updateGUIStart);
final GraphData graphData = new GraphData(bgGraph, IobCobCalculatorPlugin.getPlugin()); final GraphData graphData = new GraphData(bgGraph, IobCobCalculatorPlugin.getPlugin());
// **** In range Area **** // **** In range Area ****
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine); graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
// **** BG **** // **** BG ****
if (predictionsAvailable && SP.getBoolean("showprediction", false)) if (predictionsAvailable && SP.getBoolean("showprediction", false))
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed); graphData.addBgReadings(fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed);
else else
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null); graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null);
// set manual x bounds to have nice steps // set manual x bounds to have nice steps
graphData.formatAxis(fromTime, endTime); graphData.formatAxis(fromTime, endTime);
// Treatments // Treatments
graphData.addTreatments(fromTime, endTime); graphData.addTreatments(fromTime, endTime);
// add basal data // add basal data
if (pump.getPumpDescription().isTempBasalCapable && SP.getBoolean("showbasals", true)) { if (pump.getPumpDescription().isTempBasalCapable && SP.getBoolean("showbasals", true)) {
graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2d); graphData.addBasals(fromTime, now, lowLine / graphData.maxY / 1.2d);
} }
// add target line // add target line
graphData.addTargetLine(fromTime, toTime, profile); graphData.addTargetLine(fromTime, toTime, profile);
// **** NOW line **** // **** NOW line ****
graphData.addNowLine(now); graphData.addNowLine(now);
// ------------------ 2nd graph // ------------------ 2nd graph
Profiler.log(log, from + " - 2nd graph - START", updateGUIStart); Profiler.log(log, from + " - 2nd graph - START", updateGUIStart);
final GraphData secondGraphData = new GraphData(iobGraph, IobCobCalculatorPlugin.getPlugin()); final GraphData secondGraphData = new GraphData(iobGraph, IobCobCalculatorPlugin.getPlugin());
boolean useIobForScale = false; boolean useIobForScale = false;
boolean useCobForScale = false; boolean useCobForScale = false;
boolean useDevForScale = false; boolean useDevForScale = false;
boolean useRatioForScale = false; boolean useRatioForScale = false;
boolean useDSForScale = false; boolean useDSForScale = false;
if (SP.getBoolean("showiob", true)) { if (SP.getBoolean("showiob", true)) {
useIobForScale = true; useIobForScale = true;
} else if (SP.getBoolean("showcob", true)) { } else if (SP.getBoolean("showcob", true)) {
useCobForScale = true; useCobForScale = true;
} else if (SP.getBoolean("showdeviations", false)) { } else if (SP.getBoolean("showdeviations", false)) {
useDevForScale = true; useDevForScale = true;
} else if (SP.getBoolean("showratios", false)) { } else if (SP.getBoolean("showratios", false)) {
useRatioForScale = true; useRatioForScale = true;
} else if (Config.displayDeviationSlope) { } else if (Config.displayDeviationSlope) {
useDSForScale = true; useDSForScale = true;
} }
if (SP.getBoolean("showiob", true)) if (SP.getBoolean("showiob", true))
secondGraphData.addIob(fromTime, now, useIobForScale, 1d); secondGraphData.addIob(fromTime, now, useIobForScale, 1d);
if (SP.getBoolean("showcob", true)) if (SP.getBoolean("showcob", true))
secondGraphData.addCob(fromTime, now, useCobForScale, useCobForScale ? 1d : 0.5d); secondGraphData.addCob(fromTime, now, useCobForScale, useCobForScale ? 1d : 0.5d);
if (SP.getBoolean("showdeviations", false)) if (SP.getBoolean("showdeviations", false))
secondGraphData.addDeviations(fromTime, now, useDevForScale, 1d); secondGraphData.addDeviations(fromTime, now, useDevForScale, 1d);
if (SP.getBoolean("showratios", false)) if (SP.getBoolean("showratios", false))
secondGraphData.addRatio(fromTime, now, useRatioForScale, 1d); secondGraphData.addRatio(fromTime, now, useRatioForScale, 1d);
if (Config.displayDeviationSlope) if (Config.displayDeviationSlope)
secondGraphData.addDeviationSlope(fromTime, now, useDSForScale, 1d); secondGraphData.addDeviationSlope(fromTime, now, useDSForScale, 1d);
// **** NOW line **** // **** NOW line ****
// set manual x bounds to have nice steps // set manual x bounds to have nice steps
secondGraphData.formatAxis(fromTime, endTime); secondGraphData.formatAxis(fromTime, endTime);
secondGraphData.addNowLine(now); secondGraphData.addNowLine(now);
// do GUI update // do GUI update
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> {
@Override if (SP.getBoolean("showiob", true) || SP.getBoolean("showcob", true) || SP.getBoolean("showdeviations", false) || SP.getBoolean("showratios", false) || Config.displayDeviationSlope) {
public void run() { iobGraph.setVisibility(View.VISIBLE);
if (SP.getBoolean("showiob", true) || SP.getBoolean("showcob", true) || SP.getBoolean("showdeviations", false) || SP.getBoolean("showratios", false) || Config.displayDeviationSlope) { } else {
iobGraph.setVisibility(View.VISIBLE); iobGraph.setVisibility(View.GONE);
} else { }
iobGraph.setVisibility(View.GONE); // finally enforce drawing of graphs
} graphData.performUpdate();
// finally enforce drawing of graphs secondGraphData.performUpdate();
graphData.performUpdate(); Profiler.log(log, from + " - onDataChanged", updateGUIStart);
secondGraphData.performUpdate(); });
Profiler.log(log, from + " - onDataChanged", updateGUIStart);
}
});
}
} }
}).start(); }).start();
@ -1470,108 +1425,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
//Notifications //Notifications
static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
List<Notification> notificationsList;
RecyclerViewAdapter(List<Notification> notificationsList) {
this.notificationsList = notificationsList;
}
@Override
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false);
return new NotificationsViewHolder(v);
}
@Override
public void onBindViewHolder(NotificationsViewHolder holder, int position) {
Notification notification = notificationsList.get(position);
holder.dismiss.setTag(notification);
if (Objects.equals(notification.text, MainApp.sResources.getString(R.string.nsalarm_staledata)))
holder.dismiss.setText("snooze");
holder.text.setText(notification.text);
holder.time.setText(DateUtil.timeString(notification.date));
if (notification.level == Notification.URGENT)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationUrgent));
else if (notification.level == Notification.NORMAL)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationNormal));
else if (notification.level == Notification.LOW)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationLow));
else if (notification.level == Notification.INFO)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationInfo));
else if (notification.level == Notification.ANNOUNCEMENT)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationAnnouncement));
}
@Override
public int getItemCount() {
return notificationsList.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv;
TextView time;
TextView text;
Button dismiss;
NotificationsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.notification_cardview);
time = (TextView) itemView.findViewById(R.id.notification_time);
text = (TextView) itemView.findViewById(R.id.notification_text);
dismiss = (Button) itemView.findViewById(R.id.notification_dismiss);
dismiss.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Notification notification = (Notification) v.getTag();
switch (v.getId()) {
case R.id.notification_dismiss:
MainApp.bus().post(new EventDismissNotification(notification.id));
if (notification.nsAlarm != null) {
BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
}
// Adding current time to snooze if we got staleData
log.debug("Notification text is: " + notification.text);
if (notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))) {
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L));
}
break;
}
}
}
}
void updateNotifications() { void updateNotifications() {
Activity activity = getActivity(); NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
if (activity != null) nstore.removeExpired();
activity.runOnUiThread(new Runnable() { nstore.unSnooze();
@Override if (nstore.store.size() > 0) {
public void run() { NotificationRecyclerViewAdapter adapter = new NotificationRecyclerViewAdapter(nstore.store);
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore; notificationsView.setAdapter(adapter);
nstore.removeExpired(); notificationsView.setVisibility(View.VISIBLE);
nstore.unSnooze(); } else {
if (nstore.store.size() > 0) { notificationsView.setVisibility(View.GONE);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(nstore.store); }
notificationsView.setAdapter(adapter);
notificationsView.setVisibility(View.VISIBLE);
} else {
notificationsView.setVisibility(View.GONE);
}
}
});
} }
} }

View file

@ -72,8 +72,8 @@ public class OverviewPlugin extends PluginBase {
@Subscribe @Subscribe
public void onStatusEvent(final EventNewNotification n) { public void onStatusEvent(final EventNewNotification n) {
notificationStore.add(n.notification); if (notificationStore.add(n.notification))
MainApp.bus().post(new EventRefreshOverview("EventNewNotification")); MainApp.bus().post(new EventRefreshOverview("EventNewNotification"));
} }
@Subscribe @Subscribe

View file

@ -0,0 +1,107 @@
package info.nightscout.androidaps.plugins.Overview.notifications;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastAckAlarm;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter<NotificationRecyclerViewAdapter.NotificationsViewHolder> {
private static Logger log = LoggerFactory.getLogger(NotificationRecyclerViewAdapter.class);
private List<Notification> notificationsList;
public NotificationRecyclerViewAdapter(List<Notification> notificationsList) {
this.notificationsList = notificationsList;
}
@Override
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false);
return new NotificationsViewHolder(v);
}
@Override
public void onBindViewHolder(NotificationsViewHolder holder, int position) {
Notification notification = notificationsList.get(position);
holder.dismiss.setTag(notification);
if (Objects.equals(notification.text, MainApp.gs(R.string.nsalarm_staledata)))
holder.dismiss.setText("snooze");
holder.text.setText(notification.text);
holder.time.setText(DateUtil.timeString(notification.date));
if (notification.level == Notification.URGENT)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationUrgent));
else if (notification.level == Notification.NORMAL)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationNormal));
else if (notification.level == Notification.LOW)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationLow));
else if (notification.level == Notification.INFO)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationInfo));
else if (notification.level == Notification.ANNOUNCEMENT)
holder.cv.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.notificationAnnouncement));
}
@Override
public int getItemCount() {
return notificationsList.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
CardView cv;
TextView time;
TextView text;
Button dismiss;
NotificationsViewHolder(View itemView) {
super(itemView);
cv = (CardView) itemView.findViewById(R.id.notification_cardview);
time = (TextView) itemView.findViewById(R.id.notification_time);
text = (TextView) itemView.findViewById(R.id.notification_text);
dismiss = (Button) itemView.findViewById(R.id.notification_dismiss);
dismiss.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Notification notification = (Notification) v.getTag();
switch (v.getId()) {
case R.id.notification_dismiss:
MainApp.bus().post(new EventDismissNotification(notification.id));
if (notification.nsAlarm != null) {
BroadcastAckAlarm.handleClearAlarm(notification.nsAlarm, MainApp.instance().getApplicationContext(), 60 * 60 * 1000L);
}
// Adding current time to snooze if we got staleData
log.debug("Notification text is: " + notification.text);
if (notification.text.equals(MainApp.sResources.getString(R.string.nsalarm_staledata))) {
NotificationStore nstore = OverviewPlugin.getPlugin().notificationStore;
long msToSnooze = SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L;
log.debug("snooze nsalarm_staledatavalue in minutes is " + SP.getInt("nsalarm_staledatavalue", 15) + "\n in ms is: " + msToSnooze + " currentTimeMillis is: " + System.currentTimeMillis());
nstore.snoozeTo(System.currentTimeMillis() + (SP.getInt("nsalarm_staledatavalue", 15) * 60 * 1000L));
}
break;
}
}
}
}

View file

@ -49,13 +49,13 @@ public class NotificationStore {
} }
} }
public synchronized void add(Notification n) { public synchronized boolean add(Notification n) {
log.info("Notification received: " + n.text); log.info("Notification received: " + n.text);
for (Notification storeNotification : store) { for (Notification storeNotification : store) {
if (storeNotification.id == n.id) { if (storeNotification.id == n.id) {
storeNotification.date = n.date; storeNotification.date = n.date;
storeNotification.validTo = n.validTo; storeNotification.validTo = n.validTo;
return; return false;
} }
} }
store.add(n); store.add(n);
@ -71,6 +71,7 @@ public class NotificationStore {
} }
Collections.sort(store, new NotificationComparator()); Collections.sort(store, new NotificationComparator());
return true;
} }
public synchronized boolean remove(int id) { public synchronized boolean remove(int id) {

View file

@ -306,12 +306,6 @@ public class CommandQueue {
return false; return false;
} }
if (isRunning(Command.CommandType.BASALPROFILE)) {
if (callback != null)
callback.result(executingNowError()).run();
return false;
}
if (!MainApp.isEngineeringModeOrRelease()) { if (!MainApp.isEngineeringModeOrRelease()) {
Notification notification = new Notification(Notification.NOT_ENG_MODE_OR_RELEASE, MainApp.sResources.getString(R.string.not_eng_mode_or_release), Notification.URGENT); Notification notification = new Notification(Notification.NOT_ENG_MODE_OR_RELEASE, MainApp.sResources.getString(R.string.not_eng_mode_or_release), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));

View file

@ -1,5 +1,8 @@
package info.nightscout.androidaps.queue.commands; package info.nightscout.androidaps.queue.commands;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
@ -17,6 +20,7 @@ import info.nightscout.androidaps.queue.Callback;
*/ */
public class CommandSetProfile extends Command { public class CommandSetProfile extends Command {
private static Logger log = LoggerFactory.getLogger(CommandSetProfile.class);
private Profile profile; private Profile profile;
public CommandSetProfile(Profile profile, Callback callback) { public CommandSetProfile(Profile profile, Callback callback) {
@ -27,6 +31,13 @@ public class CommandSetProfile extends Command {
@Override @Override
public void execute() { public void execute() {
if (ConfigBuilderPlugin.getCommandQueue().isThisProfileSet(profile)) {
log.debug("QUEUE: Correct profile already set");
if (callback != null)
callback.result(new PumpEnactResult().success(true).enacted(false)).run();
return;
}
PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setNewBasalProfile(profile); PumpEnactResult r = ConfigBuilderPlugin.getActivePump().setNewBasalProfile(profile);
if (callback != null) if (callback != null)
callback.result(r).run(); callback.result(r).run();

View file

@ -997,5 +997,5 @@
<string name="food_short">Food</string> <string name="food_short">Food</string>
<string name="iobcobcalculator" translatable="false">IobCobCalculator</string> <string name="iobcobcalculator" translatable="false">IobCobCalculator</string>
<string name="waitingfortimesynchronization">Waiting for time synchronization (%d sec)</string> <string name="waitingfortimesynchronization">Waiting for time synchronization (%d sec)</string>
<string name="loopdisconnectedfor">Disconnected (%d m)</string>
</resources> </resources>