MedtronicFragment remove static variables

This commit is contained in:
Milos Kozak 2019-08-07 18:45:33 +02:00
parent 9226a561db
commit 858759873a
5 changed files with 28 additions and 37 deletions

View file

@ -1,8 +1,10 @@
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.medtronic.MedtronicFragment;
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;
/**
@ -24,11 +26,11 @@ public class ResetRileyLinkConfigurationTask extends PumpTask {
@Override
public void run() {
MedtronicFragment.refreshButtonEnabled(false);
MainApp.bus().post(new EventRefreshButtonState(false));
MedtronicPumpPlugin.isBusy = true;
RileyLinkMedtronicService.getInstance().resetRileyLinkConfiguration();
MedtronicPumpPlugin.isBusy = false;
MedtronicFragment.refreshButtonEnabled(true);
MainApp.bus().post(new EventRefreshButtonState(true));
}
}

View file

@ -1,8 +1,10 @@
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.medtronic.MedtronicFragment;
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;
/**
@ -24,11 +26,10 @@ public class WakeAndTuneTask extends PumpTask {
@Override
public void run() {
MedtronicFragment.refreshButtonEnabled(false);
MainApp.bus().post(new EventRefreshButtonState(false));
MedtronicPumpPlugin.isBusy = true;
RileyLinkMedtronicService.getInstance().doTuneUpDevice();
MedtronicPumpPlugin.isBusy = false;
MedtronicFragment.refreshButtonEnabled(true);
MainApp.bus().post(new EventRefreshButtonState(true));
}
}

View file

@ -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.EventMedtronicPumpConfigurationChanged;
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.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
@ -65,8 +66,6 @@ public class MedtronicFragment extends SubscriberFragment {
@BindView(R.id.medtronic_basabasalrate)
TextView basaBasalRateView;
// @BindView(R.id.medtronic_btconnection)
// TextView btConnectionView;
@BindView(R.id.medtronic_tempbasal)
TextView tempBasalView;
@BindView(R.id.medtronic_pumpstate_battery)
@ -88,9 +87,6 @@ public class MedtronicFragment extends SubscriberFragment {
@BindView(R.id.medtronic_refresh)
Button refreshButton;
private Handler loopHandler = new Handler();
private static Activity localActivity;
static Button refreshButtonStatic;
private Runnable refreshLoop = new Runnable() {
@ -126,7 +122,7 @@ public class MedtronicFragment extends SubscriberFragment {
View view = inflater.inflate(R.layout.medtronic_fragment, container, false);
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.setTextSize(14);
@ -135,8 +131,6 @@ public class MedtronicFragment extends SubscriberFragment {
pumpStatusIconView.setTextSize(14);
pumpStatusIconView.setText("{fa-bed}");
refreshButtonStatic = refreshButton;
return view;
} catch (Exception e) {
Crashlytics.logException(e);
@ -164,8 +158,8 @@ public class MedtronicFragment extends SubscriberFragment {
return;
}
if (refreshButtonStatic != null)
refreshButtonStatic.setEnabled(false);
if (refreshButton != null)
refreshButton.setEnabled(false);
MedtronicPumpPlugin.getPlugin().resetStatusState();
@ -177,8 +171,8 @@ public class MedtronicFragment extends SubscriberFragment {
if (activity != null) {
activity.runOnUiThread(() -> {
if (refreshButtonStatic != null)
refreshButtonStatic.setEnabled(true);
if (refreshButton != null)
refreshButton.setEnabled(true);
});
}
}
@ -202,21 +196,11 @@ public class MedtronicFragment extends SubscriberFragment {
}
public static void refreshButtonEnabled(boolean enable) {
if (localActivity != null) {
localActivity.runOnUiThread(() -> {
if (refreshButtonStatic != null) {
refreshButtonStatic.setEnabled(enable);
@Subscribe
public void onStatusEvent(final EventRefreshButtonState e) {
if (getActivity() != null)
getActivity().runOnUiThread(() -> refreshButton.setEnabled(e.getNewState()));
}
});
}
}
public static Activity getCustomActivity() {
return localActivity;
}
@Subscribe
public void onStatusEvent(final EventMedtronicDeviceStatusChange eventStatusChange) {
@ -225,7 +209,6 @@ public class MedtronicFragment extends SubscriberFragment {
Activity activity = getActivity();
if (activity != null) {
localActivity = activity;
activity.runOnUiThread(() -> {
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
setDeviceStatus(pumpStatus);
@ -363,12 +346,12 @@ public class MedtronicFragment extends SubscriberFragment {
}
public RileyLinkTargetDevice getTargetDevice() {
private RileyLinkTargetDevice getTargetDevice() {
return RileyLinkTargetDevice.MedtronicPump;
}
public String getTranslation(int resourceId) {
private String getTranslation(int resourceId) {
return MainApp.gs(resourceId);
}
@ -417,8 +400,7 @@ public class MedtronicFragment extends SubscriberFragment {
if (lastConnectionView == null) // ui not yet initialized
return;
localActivity = activity;
MedtronicPumpPlugin plugin = (MedtronicPumpPlugin) MedtronicPumpPlugin.getPlugin();
MedtronicPumpPlugin plugin = MedtronicPumpPlugin.getPlugin();
MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
setDeviceStatus(pumpStatus);

View file

@ -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.driver.MedtronicPumpStatus;
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.util.MedtronicConst;
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) {
MedtronicFragment.refreshButtonEnabled(enabled);
MainApp.bus().post(new EventRefreshButtonState(enabled));
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.events
import info.nightscout.androidaps.events.Event
class EventRefreshButtonState (val newState : Boolean): Event()