hide pump control buttons when pump is not initialized

This commit is contained in:
Milos Kozak 2016-12-13 22:50:51 +01:00
parent cb4330ddcd
commit 738d4c1c2a
10 changed files with 106 additions and 24 deletions

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 13.12.2016.
*/
public class EventInitializationChanged {
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.Actions;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
@ -13,6 +14,7 @@ import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
@ -72,29 +74,41 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl
MainApp.bus().register(this);
}
@Subscribe
public void onStatusEvent(final EventInitializationChanged ev) {
updateGUIIfVisible();
}
@Subscribe
public void onStatusEvent(final EventRefreshGui ev) {
updateGUIIfVisible();
}
void updateGUIIfVisible() {
if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable)
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable || !MainApp.getConfigBuilder().isInitialized())
profileSwitch.setVisibility(View.GONE);
else
profileSwitch.setVisibility(View.VISIBLE);
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable)
if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable || !MainApp.getConfigBuilder().isInitialized())
extendedBolus.setVisibility(View.GONE);
else
extendedBolus.setVisibility(View.VISIBLE);
if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable)
if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable || !MainApp.getConfigBuilder().isInitialized())
tempBasal.setVisibility(View.GONE);
else
tempBasal.setVisibility(View.VISIBLE);
if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable)
if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable || !MainApp.getConfigBuilder().isInitialized())
fill.setVisibility(View.GONE);
else
fill.setVisibility(View.VISIBLE);
}
});
}
@Override

View file

@ -30,6 +30,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaR.DanaRPump;
@ -328,6 +329,7 @@ public class ExecutionService extends Service {
danaRPump.lastConnection = now;
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -9,6 +9,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaR.DanaRPump;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
/**
@ -43,6 +44,8 @@ public class MsgInitConnStatusBolus extends MessageBase {
if (!pump.isExtendedBolusEnabled) {
Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.sResources.getString(R.string.danar_enableextendedbolus), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else {
MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
}
}
}

View file

@ -30,6 +30,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.plugins.DanaR.comm.*;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRBolusStart;
@ -319,6 +320,7 @@ public class ExecutionService extends Service {
danaRKoreanPump.lastConnection = now;
MainApp.bus().post(new EventDanaRNewStatus());
MainApp.bus().post(new EventInitializationChanged());
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPump;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
public class MsgInitConnStatusBasic extends MessageBase {
@ -41,6 +42,8 @@ public class MsgInitConnStatusBasic extends MessageBase {
if (pump.isEasyModeEnabled) {
Notification notification = new Notification(Notification.EASYMODE_ENABLED, MainApp.sResources.getString(R.string.danar_disableeasymode), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else {
MainApp.bus().post(new EventDismissNotification(Notification.EASYMODE_ENABLED));
}
}
}

View file

@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPump;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
/**
@ -46,6 +47,8 @@ public class MsgInitConnStatusBolus extends MessageBase {
if (!pump.isExtendedBolusEnabled) {
Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.sResources.getString(R.string.danar_enableextendedbolus), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else {
MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
}
}
}

View file

@ -9,7 +9,10 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.DanaR.DanaRPump;
import info.nightscout.androidaps.plugins.DanaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPump;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
/**
@ -24,7 +27,7 @@ public class MsgSettingMeal extends MessageBase {
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPlugin.getDanaRPump();
DanaRKoreanPump pump = DanaRKoreanPlugin.getDanaRPump();
pump.basalStep = intFromBuff(bytes, 0, 1) / 100d;
pump.bolusStep = intFromBuff(bytes, 1, 1) / 100d;
boolean bolusEnabled = intFromBuff(bytes, 2, 1) == 1;
@ -44,6 +47,8 @@ public class MsgSettingMeal extends MessageBase {
if (pump.isConfigUD) {
Notification notification = new Notification(Notification.UD_MODE_ENABLED, MainApp.sResources.getString(R.string.danar_switchtouhmode), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
} else {
MainApp.bus().post(new EventDismissNotification(Notification.UD_MODE_ENABLED));
}
}

View file

@ -55,6 +55,7 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange;
@ -364,6 +365,11 @@ public class OverviewFragment extends Fragment {
updateGUIIfVisible();
}
@Subscribe
public void onStatusEvent(final EventInitializationChanged ev) {
updateGUIIfVisible();
}
@Subscribe
public void onStatusEvent(final EventPreferenceChange ev) {
updateGUIIfVisible();
@ -486,22 +492,22 @@ public class OverviewFragment extends Fragment {
apsModeView.setVisibility(View.GONE);
}
// **** Temp button ****
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
PumpInterface pump = MainApp.getConfigBuilder();
boolean showAcceptButton = !MainApp.getConfigBuilder().isClosedModeEnabled(); // Open mode needed
showAcceptButton = showAcceptButton && finalLastRun != null && finalLastRun.lastAPSRun != null; // aps result must exist
showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result
showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.changeRequested; // change is requested
if (showAcceptButton) {
if (showAcceptButton && pump.isInitialized()) {
acceptTempLayout.setVisibility(View.VISIBLE);
acceptTempButton.setText(getContext().getString(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed);
} else {
acceptTempLayout.setVisibility(View.GONE);
}
// **** Temp button ****
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
PumpInterface pump = MainApp.getConfigBuilder();
if (pump.isTempBasalInProgress()) {
TempBasal activeTemp = pump.getTempBasal();
cancelTempLayout.setVisibility(View.VISIBLE);
@ -531,7 +537,7 @@ public class OverviewFragment extends Fragment {
});
activeProfileView.setLongClickable(true);
if (profile == null) {
if (profile == null || !pump.isInitialized()) {
// disable all treatment buttons because we are not able to check constraints without profile
wizardButton.setVisibility(View.INVISIBLE);
treatmentButton.setVisibility(View.INVISIBLE);
@ -545,7 +551,7 @@ public class OverviewFragment extends Fragment {
// QuickWizard button
QuickWizard.QuickWizardEntry quickWizardEntry = getPlugin().quickWizard.getActive();
if (quickWizardEntry != null && lastBG != null) {
if (quickWizardEntry != null && lastBG != null && pump.isInitialized()) {
quickWizardLayout.setVisibility(View.VISIBLE);
String text = MainApp.sResources.getString(R.string.bolus) + ": " + quickWizardEntry.buttonText() + " " + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
BolusWizard wizard = new BolusWizard();

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.SimpleProfile;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
@ -12,13 +13,18 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.utils.SafeParse;
public class SimpleProfileFragment extends Fragment implements FragmentBase {
@ -56,6 +62,8 @@ public class SimpleProfileFragment extends Fragment implements FragmentBase {
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch);
onStatusEvent(null);
mgdlView.setChecked(simpleProfilePlugin.mgdl);
mmolView.setChecked(simpleProfilePlugin.mmol);
diaView.setText(simpleProfilePlugin.dia.toString());
@ -131,4 +139,32 @@ public class SimpleProfileFragment extends Fragment implements FragmentBase {
return layout;
}
@Override
public void onPause() {
super.onPause();
MainApp.bus().unregister(this);
}
@Override
public void onResume() {
super.onResume();
MainApp.bus().register(this);
}
@Subscribe
public void onStatusEvent(final EventInitializationChanged e) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!MainApp.getConfigBuilder().isInitialized()) {
profileswitchButton.setVisibility(View.GONE);
} else {
profileswitchButton.setVisibility(View.VISIBLE);
}
}
});
}
}