MedtronicFragment remove static variables
This commit is contained in:
parent
9226a561db
commit
858759873a
5 changed files with 28 additions and 37 deletions
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment;
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,11 +26,11 @@ public class ResetRileyLinkConfigurationTask extends PumpTask {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MedtronicFragment.refreshButtonEnabled(false);
|
MainApp.bus().post(new EventRefreshButtonState(false));
|
||||||
MedtronicPumpPlugin.isBusy = true;
|
MedtronicPumpPlugin.isBusy = true;
|
||||||
RileyLinkMedtronicService.getInstance().resetRileyLinkConfiguration();
|
RileyLinkMedtronicService.getInstance().resetRileyLinkConfiguration();
|
||||||
MedtronicPumpPlugin.isBusy = false;
|
MedtronicPumpPlugin.isBusy = false;
|
||||||
MedtronicFragment.refreshButtonEnabled(true);
|
MainApp.bus().post(new EventRefreshButtonState(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
|
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
|
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment;
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,11 +26,10 @@ public class WakeAndTuneTask extends PumpTask {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MedtronicFragment.refreshButtonEnabled(false);
|
MainApp.bus().post(new EventRefreshButtonState(false));
|
||||||
MedtronicPumpPlugin.isBusy = true;
|
MedtronicPumpPlugin.isBusy = true;
|
||||||
RileyLinkMedtronicService.getInstance().doTuneUpDevice();
|
RileyLinkMedtronicService.getInstance().doTuneUpDevice();
|
||||||
MedtronicPumpPlugin.isBusy = false;
|
MedtronicPumpPlugin.isBusy = false;
|
||||||
MedtronicFragment.refreshButtonEnabled(true);
|
MainApp.bus().post(new EventRefreshButtonState(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpSta
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicDeviceStatusChange;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged;
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpConfigurationChanged;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged;
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
|
@ -65,8 +66,6 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
@BindView(R.id.medtronic_basabasalrate)
|
@BindView(R.id.medtronic_basabasalrate)
|
||||||
TextView basaBasalRateView;
|
TextView basaBasalRateView;
|
||||||
|
|
||||||
// @BindView(R.id.medtronic_btconnection)
|
|
||||||
// TextView btConnectionView;
|
|
||||||
@BindView(R.id.medtronic_tempbasal)
|
@BindView(R.id.medtronic_tempbasal)
|
||||||
TextView tempBasalView;
|
TextView tempBasalView;
|
||||||
@BindView(R.id.medtronic_pumpstate_battery)
|
@BindView(R.id.medtronic_pumpstate_battery)
|
||||||
|
@ -88,9 +87,6 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
@BindView(R.id.medtronic_refresh)
|
@BindView(R.id.medtronic_refresh)
|
||||||
Button refreshButton;
|
Button refreshButton;
|
||||||
private Handler loopHandler = new Handler();
|
private Handler loopHandler = new Handler();
|
||||||
private static Activity localActivity;
|
|
||||||
|
|
||||||
static Button refreshButtonStatic;
|
|
||||||
|
|
||||||
private Runnable refreshLoop = new Runnable() {
|
private Runnable refreshLoop = new Runnable() {
|
||||||
|
|
||||||
|
@ -126,7 +122,7 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
View view = inflater.inflate(R.layout.medtronic_fragment, container, false);
|
View view = inflater.inflate(R.layout.medtronic_fragment, container, false);
|
||||||
unbinder = ButterKnife.bind(this, view);
|
unbinder = ButterKnife.bind(this, view);
|
||||||
|
|
||||||
overviewPumpMedtronicView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder));
|
overviewPumpMedtronicView.setBackgroundColor(MainApp.gc(R.color.colorInitializingBorder));
|
||||||
|
|
||||||
rileyLinkStatus.setText(getTranslation(RileyLinkServiceState.NotStarted.getResourceId(getTargetDevice())));
|
rileyLinkStatus.setText(getTranslation(RileyLinkServiceState.NotStarted.getResourceId(getTargetDevice())));
|
||||||
rileyLinkStatus.setTextSize(14);
|
rileyLinkStatus.setTextSize(14);
|
||||||
|
@ -135,8 +131,6 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
pumpStatusIconView.setTextSize(14);
|
pumpStatusIconView.setTextSize(14);
|
||||||
pumpStatusIconView.setText("{fa-bed}");
|
pumpStatusIconView.setText("{fa-bed}");
|
||||||
|
|
||||||
refreshButtonStatic = refreshButton;
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Crashlytics.logException(e);
|
Crashlytics.logException(e);
|
||||||
|
@ -164,8 +158,8 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refreshButtonStatic != null)
|
if (refreshButton != null)
|
||||||
refreshButtonStatic.setEnabled(false);
|
refreshButton.setEnabled(false);
|
||||||
|
|
||||||
MedtronicPumpPlugin.getPlugin().resetStatusState();
|
MedtronicPumpPlugin.getPlugin().resetStatusState();
|
||||||
|
|
||||||
|
@ -177,8 +171,8 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
|
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
if (refreshButtonStatic != null)
|
if (refreshButton != null)
|
||||||
refreshButtonStatic.setEnabled(true);
|
refreshButton.setEnabled(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,22 +196,12 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void refreshButtonEnabled(boolean enable) {
|
@Subscribe
|
||||||
if (localActivity != null) {
|
public void onStatusEvent(final EventRefreshButtonState e) {
|
||||||
localActivity.runOnUiThread(() -> {
|
if (getActivity() != null)
|
||||||
if (refreshButtonStatic != null) {
|
getActivity().runOnUiThread(() -> refreshButton.setEnabled(e.getNewState()));
|
||||||
refreshButtonStatic.setEnabled(enable);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Activity getCustomActivity() {
|
|
||||||
return localActivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventMedtronicDeviceStatusChange eventStatusChange) {
|
public void onStatusEvent(final EventMedtronicDeviceStatusChange eventStatusChange) {
|
||||||
if (isLogEnabled())
|
if (isLogEnabled())
|
||||||
|
@ -225,7 +209,6 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
localActivity = activity;
|
|
||||||
activity.runOnUiThread(() -> {
|
activity.runOnUiThread(() -> {
|
||||||
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
|
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
|
||||||
setDeviceStatus(pumpStatus);
|
setDeviceStatus(pumpStatus);
|
||||||
|
@ -363,12 +346,12 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RileyLinkTargetDevice getTargetDevice() {
|
private RileyLinkTargetDevice getTargetDevice() {
|
||||||
return RileyLinkTargetDevice.MedtronicPump;
|
return RileyLinkTargetDevice.MedtronicPump;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getTranslation(int resourceId) {
|
private String getTranslation(int resourceId) {
|
||||||
return MainApp.gs(resourceId);
|
return MainApp.gs(resourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,8 +400,7 @@ public class MedtronicFragment extends SubscriberFragment {
|
||||||
if (lastConnectionView == null) // ui not yet initialized
|
if (lastConnectionView == null) // ui not yet initialized
|
||||||
return;
|
return;
|
||||||
|
|
||||||
localActivity = activity;
|
MedtronicPumpPlugin plugin = MedtronicPumpPlugin.getPlugin();
|
||||||
MedtronicPumpPlugin plugin = (MedtronicPumpPlugin) MedtronicPumpPlugin.getPlugin();
|
|
||||||
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
|
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
|
||||||
|
|
||||||
setDeviceStatus(pumpStatus);
|
setDeviceStatus(pumpStatus);
|
||||||
|
|
|
@ -73,6 +73,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicStatusRef
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType;
|
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicUIResponseType;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged;
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventMedtronicPumpValuesChanged;
|
||||||
|
import info.nightscout.androidaps.plugins.pump.medtronic.events.EventRefreshButtonState;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
|
||||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||||
|
@ -494,7 +495,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
||||||
|
|
||||||
|
|
||||||
private void setRefreshButtonEnabled(boolean enabled) {
|
private void setRefreshButtonEnabled(boolean enabled) {
|
||||||
MedtronicFragment.refreshButtonEnabled(enabled);
|
MainApp.bus().post(new EventRefreshButtonState(enabled));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.medtronic.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventRefreshButtonState (val newState : Boolean): Event()
|
Loading…
Reference in a new issue