From 829aa98097dc4a922364cfa17eccb302a4c9d500 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 7 Aug 2019 23:00:02 +0200 Subject: [PATCH] MedtronicFragment -> kotlin --- .../plugins/pump/common/data/PumpStatus.java | 2 +- .../dialog/RileyLinkBLEScanActivity.java | 3 +- .../common/hw/rileylink/RileyLinkUtil.java | 4 +- .../ResetRileyLinkConfigurationTask.java | 7 +- .../service/tasks/WakeAndTuneTask.java | 7 +- .../pump/medtronic/MedtronicFragment.java | 503 ------------------ .../pump/medtronic/MedtronicFragment.kt | 326 ++++++++++++ .../pump/medtronic/MedtronicPumpPlugin.java | 7 +- .../medtronic/comm/ui/MedtronicUITask.java | 16 +- .../pump/medtronic/defs/PumpDeviceState.java | 9 +- .../medtronic/driver/MedtronicPumpStatus.java | 4 +- .../EventMedtronicDeviceStatusChange.java | 53 -- .../EventMedtronicDeviceStatusChange.kt | 38 ++ ...ventMedtronicPumpConfigurationChanged.java | 9 - .../EventMedtronicPumpConfigurationChanged.kt | 5 + .../EventMedtronicPumpValuesChanged.java | 9 - .../events/EventMedtronicPumpValuesChanged.kt | 5 + .../pump/medtronic/util/MedtronicUtil.java | 5 +- .../queue/events/EventQueueChanged.java | 8 - .../queue/events/EventQueueChanged.kt | 5 + .../main/res/layout/medtronic_fragment.xml | 2 +- 21 files changed, 408 insertions(+), 619 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.kt delete mode 100644 app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.java create mode 100644 app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.kt diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java index a25caeebd7..11fd84a016 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/data/PumpStatus.java @@ -28,7 +28,7 @@ public abstract class PumpStatus { // other pump settings public String activeProfileName = "0"; public double reservoirRemainingUnits = 0d; - public String reservoirFullUnits = "???"; + public int reservoirFullUnits = 0; public int batteryRemaining = 0; // percent, so 0-100 public Double batteryVoltage = null; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java index 0dd5538503..dbe401601c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RileyLinkBLEScanActivity.java @@ -42,6 +42,7 @@ import java.util.Map; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.GattAttributes; @@ -108,7 +109,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity { MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus(); pumpStatus.verifyConfiguration(); // force reloading of address - MainApp.bus().post(new EventMedtronicPumpConfigurationChanged()); + RxBus.INSTANCE.send(new EventMedtronicPumpConfigurationChanged()); finish(); }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java index 9fa78e39f7..3c7ba730a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/RileyLinkUtil.java @@ -15,8 +15,8 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.encoding.Encoding4b6b; import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.data.encoding.Encoding4b6bGeoff; @@ -124,7 +124,7 @@ public class RileyLinkUtil { RileyLinkUtil.historyRileyLink.add(new RLHistoryItem(RileyLinkUtil.rileyLinkServiceData.serviceState, RileyLinkUtil.rileyLinkServiceData.errorCode, targetDevice)); - MainApp.bus().post(new EventMedtronicDeviceStatusChange(newState, errorCode)); + RxBus.INSTANCE.send(new EventMedtronicDeviceStatusChange(newState, errorCode)); return null; } else { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java index 62dcaa0f5f..cce127ffdf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/ResetRileyLinkConfigurationTask.java @@ -1,8 +1,7 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks; -import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.plugins.bus.RxBus; 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; @@ -26,11 +25,11 @@ public class ResetRileyLinkConfigurationTask extends PumpTask { @Override public void run() { - MainApp.bus().post(new EventRefreshButtonState(false)); + RxBus.INSTANCE.send(new EventRefreshButtonState(false)); MedtronicPumpPlugin.isBusy = true; RileyLinkMedtronicService.getInstance().resetRileyLinkConfiguration(); MedtronicPumpPlugin.isBusy = false; - MainApp.bus().post(new EventRefreshButtonState(true)); + RxBus.INSTANCE.send(new EventRefreshButtonState(true)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java index 3dec2cb212..5feb5ab405 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/service/tasks/WakeAndTuneTask.java @@ -1,8 +1,7 @@ package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks; -import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.plugins.bus.RxBus; 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; @@ -26,10 +25,10 @@ public class WakeAndTuneTask extends PumpTask { @Override public void run() { - MainApp.bus().post(new EventRefreshButtonState(false)); + RxBus.INSTANCE.send(new EventRefreshButtonState(false)); MedtronicPumpPlugin.isBusy = true; RileyLinkMedtronicService.getInstance().doTuneUpDevice(); MedtronicPumpPlugin.isBusy = false; - MainApp.bus().post(new EventRefreshButtonState(true)); + RxBus.INSTANCE.send(new EventRefreshButtonState(true)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java deleted file mode 100644 index 894c010476..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.java +++ /dev/null @@ -1,503 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.medtronic; - -import android.app.Activity; -import android.content.Intent; -import android.graphics.Color; -import android.os.Bundle; -import android.os.Handler; -import android.text.Spanned; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.crashlytics.android.Crashlytics; -import com.joanzapata.iconify.widget.IconTextView; -import com.squareup.otto.Subscribe; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.events.EventPumpStatusChanged; -import info.nightscout.androidaps.events.EventTempBasalChange; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.common.SubscriberFragment; -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity; -import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType; -import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; -import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; -import info.nightscout.androidaps.plugins.pump.medtronic.dialog.MedtronicHistoryActivity; -import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus; -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; -import info.nightscout.androidaps.queue.events.EventQueueChanged; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.DecimalFormatter; -import info.nightscout.androidaps.utils.SetWarnColor; - -public class MedtronicFragment extends SubscriberFragment { - - private static Logger LOG = LoggerFactory.getLogger(L.PUMP); - - @BindView(R.id.medtronic_lastconnection) - TextView lastConnectionView; - @BindView(R.id.medtronic_lastbolus) - TextView lastBolusView; - @BindView(R.id.medtronic_basabasalrate) - TextView basaBasalRateView; - - @BindView(R.id.medtronic_tempbasal) - TextView tempBasalView; - @BindView(R.id.medtronic_pumpstate_battery) - TextView batteryView; - @BindView(R.id.medtronic_rl_status) - IconTextView rileyLinkStatus; - @BindView(R.id.medtronic_reservoir) - TextView reservoirView; - @BindView(R.id.medtronic_errors) - TextView errorsView; - @BindView(R.id.medtronic_queue) - TextView queueView; - @BindView(R.id.overview_pumpstatuslayout) - LinearLayout pumpStatusLayout; - @BindView(R.id.overview_pump_medtronic) - TextView overviewPumpMedtronicView; - @BindView(R.id.medtronic_pump_status) - IconTextView pumpStatusIconView; - @BindView(R.id.medtronic_refresh) - Button refreshButton; - private Handler loopHandler = new Handler(); - - private Runnable refreshLoop = new Runnable() { - - @Override - public void run() { - updateGUI(); - loopHandler.postDelayed(refreshLoop, 60 * 1000L); - } - }; - - - public MedtronicFragment() { - } - - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - loopHandler.postDelayed(refreshLoop, 60 * 1000L); - } - - - @Override - public void onDestroy() { - super.onDestroy(); - loopHandler.removeCallbacks(refreshLoop); - } - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - try { - View view = inflater.inflate(R.layout.medtronic_fragment, container, false); - unbinder = ButterKnife.bind(this, view); - - overviewPumpMedtronicView.setBackgroundColor(MainApp.gc(R.color.colorInitializingBorder)); - - rileyLinkStatus.setText(getTranslation(RileyLinkServiceState.NotStarted.getResourceId(getTargetDevice()))); - rileyLinkStatus.setTextSize(14); - - pumpStatusIconView.setTextColor(Color.WHITE); - pumpStatusIconView.setTextSize(14); - pumpStatusIconView.setText("{fa-bed}"); - - return view; - } catch (Exception e) { - Crashlytics.logException(e); - } - - return null; - } - - - @OnClick(R.id.medtronic_history) - void onHistoryClick() { - if (MedtronicUtil.getPumpStatus().verifyConfiguration()) { - startActivity(new Intent(getContext(), MedtronicHistoryActivity.class)); - } else { - MedtronicUtil.displayNotConfiguredDialog(getContext()); - } - } - - - @OnClick(R.id.medtronic_refresh) - void onRefreshClick() { - - if (!MedtronicUtil.getPumpStatus().verifyConfiguration()) { - MedtronicUtil.displayNotConfiguredDialog(getContext()); - return; - } - - if (refreshButton != null) - refreshButton.setEnabled(false); - - MedtronicPumpPlugin.getPlugin().resetStatusState(); - - ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("Clicked refresh", new Callback() { - - @Override - public void run() { - Activity activity = getActivity(); - - if (activity != null) { - activity.runOnUiThread(() -> { - if (refreshButton != null) - refreshButton.setEnabled(true); - }); - } - } - }); - } - - - @OnClick(R.id.medtronic_stats) - void onStatsClick() { - if (MedtronicUtil.getPumpStatus().verifyConfiguration()) { - startActivity(new Intent(getContext(), RileyLinkStatusActivity.class)); - } else { - MedtronicUtil.displayNotConfiguredDialog(getContext()); - } - } - - - @Subscribe - public void onStatusEvent(final EventPumpStatusChanged c) { - updateGUI(); - } - - - @Subscribe - public void onStatusEvent(final EventRefreshButtonState e) { - if (getActivity() != null) - getActivity().runOnUiThread(() -> refreshButton.setEnabled(e.getNewState())); - } - - @Subscribe - public void onStatusEvent(final EventMedtronicDeviceStatusChange eventStatusChange) { - if (isLogEnabled()) - LOG.info("onStatusEvent(EventMedtronicDeviceStatusChange): {}", eventStatusChange); - Activity activity = getActivity(); - - if (activity != null) { - activity.runOnUiThread(() -> { - MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus(); - setDeviceStatus(pumpStatus); - }); - } - } - - - private synchronized void setDeviceStatus(MedtronicPumpStatus pumpStatus) { - - pumpStatus.rileyLinkServiceState = (RileyLinkServiceState) checkStatusSet(pumpStatus.rileyLinkServiceState, - RileyLinkUtil.getServiceState()); - - if (pumpStatus.rileyLinkServiceState != null && rileyLinkStatus != null) { - - int resourceId = pumpStatus.rileyLinkServiceState.getResourceId(getTargetDevice()); - rileyLinkStatus.setTextColor(Color.WHITE); - rileyLinkStatus.setTextSize(14); - - if (pumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted) { - rileyLinkStatus.setText(getTranslation(resourceId)); - rileyLinkStatus.setTextSize(14); - } else if (pumpStatus.rileyLinkServiceState.isConnecting()) { - rileyLinkStatus.setText("{fa-bluetooth-b spin} " + getTranslation(resourceId)); - } else if (pumpStatus.rileyLinkServiceState.isError()) { - - RileyLinkError rileyLinkError = RileyLinkUtil.getError(); - - if (rileyLinkError == null) - rileyLinkStatus.setText("{fa-bluetooth-b} " + getTranslation(resourceId)); - else - rileyLinkStatus.setText("{fa-bluetooth-b} " - + getTranslation(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump))); - - rileyLinkStatus.setTextColor(Color.RED); - } else { - rileyLinkStatus.setText("{fa-bluetooth-b} " + getTranslation(resourceId)); - } - } - - pumpStatus.rileyLinkError = (RileyLinkError) checkStatusSet(pumpStatus.rileyLinkError, RileyLinkUtil.getError()); - - if (errorsView != null) { - if (pumpStatus.rileyLinkError != null) { - int resourceId = pumpStatus.rileyLinkError.getResourceId(getTargetDevice()); - errorsView.setText(getTranslation(resourceId)); - } else - errorsView.setText("-"); - } - - pumpStatus.pumpDeviceState = (PumpDeviceState) checkStatusSet(pumpStatus.pumpDeviceState, - MedtronicUtil.getPumpDeviceState()); - - if (pumpStatusIconView != null) { - - if (pumpStatus.pumpDeviceState != null) { - - switch (pumpStatus.pumpDeviceState) { - case Sleeping: - pumpStatusIconView.setText("{fa-bed} "); // + pumpStatus.pumpDeviceState.name()); - break; - - case NeverContacted: - case WakingUp: - case PumpUnreachable: - case ErrorWhenCommunicating: - case TimeoutWhenCommunicating: - case InvalidConfiguration: - pumpStatusIconView.setText(" " + getTranslation(pumpStatus.pumpDeviceState.getResourceId())); - break; - - case Active: { - MedtronicCommandType cmd = MedtronicUtil.getCurrentCommand(); - - LOG.debug("Command: " + cmd); - - if (cmd == null) - pumpStatusIconView.setText(" " + MainApp.gs(pumpStatus.pumpDeviceState.getResourceId())); - else { - Integer resourceId = cmd.getResourceId(); - - if (cmd == MedtronicCommandType.GetHistoryData) { - - if (MedtronicUtil.frameNumber == null) { - pumpStatusIconView.setText(MainApp.gs( - R.string.medtronic_cmd_desc_get_history_request, MedtronicUtil.pageNumber)); - } else { - pumpStatusIconView.setText(MainApp.gs(resourceId, MedtronicUtil.pageNumber, - MedtronicUtil.frameNumber)); - } - - } else { - if (resourceId == null) { - pumpStatusIconView.setText(" " + cmd.getCommandDescription()); - } else { - pumpStatusIconView.setText(" " + getTranslation(resourceId)); - } - } - - } - - } - break; - - default: - LOG.warn("Unknown pump state: " + pumpStatus.pumpDeviceState); - } - } else { - pumpStatusIconView.setText("{fa-bed} "); - } - } - - if (queueView != null) { - Spanned status = ConfigBuilderPlugin.getPlugin().getCommandQueue().spannedStatus(); - if (status.toString().equals("")) { - queueView.setVisibility(View.GONE); - } else { - queueView.setVisibility(View.VISIBLE); - queueView.setText(status); - } - } - - } - - - public Object checkStatusSet(Object object1, Object object2) { - if (object1 == null) { - return object2; - } else { - if (!object1.equals(object2)) { - return object2; - } else - return object1; - } - } - - - private RileyLinkTargetDevice getTargetDevice() { - return RileyLinkTargetDevice.MedtronicPump; - } - - - private String getTranslation(int resourceId) { - return MainApp.gs(resourceId); - } - - - @Subscribe - public void onStatusEvent(final EventMedtronicPumpValuesChanged s) { - updateGUI(); - } - - - @Subscribe - public void onStatusEvent(final EventMedtronicPumpConfigurationChanged s) { - if (isLogEnabled()) - LOG.debug("EventMedtronicPumpConfigurationChanged triggered"); - MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus(); - pumpStatus.verifyConfiguration(); - updateGUI(); - } - - - @Subscribe - public void onStatusEvent(final EventTempBasalChange s) { - updateGUI(); - } - - - @Subscribe - public void onStatusEvent(final EventExtendedBolusChange s) { - updateGUI(); - } - - - @Subscribe - public void onStatusEvent(final EventQueueChanged s) { - updateGUI(); - } - - - // GUI functions - @Override - protected void updateGUI() { - Activity activity = getActivity(); - if (activity != null && basaBasalRateView != null) - activity.runOnUiThread(() -> { - - if (lastConnectionView == null) // ui not yet initialized - return; - - MedtronicPumpPlugin plugin = MedtronicPumpPlugin.getPlugin(); - MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus(); - - setDeviceStatus(pumpStatus); - - // last connection - String minAgo = DateUtil.minAgo(pumpStatus.lastConnection); - long min = (System.currentTimeMillis() - pumpStatus.lastConnection) / 1000 / 60; - if (pumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) { - lastConnectionView.setText(R.string.combo_pump_connected_now); - lastConnectionView.setTextColor(Color.WHITE); - } else if (pumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) { - - if (min < 60) { - lastConnectionView.setText(MainApp.gs(R.string.minago, min)); - } else if (min < 1440) { - int h = (int) (min / 60); - - lastConnectionView.setText(MainApp.gq(R.plurals.objective_hours, h, h) + " " - + MainApp.gs(R.string.ago)); - } else { - - int h = (int) (min / 60); - int d = h / 24; - // h = h - (d * 24); - - lastConnectionView.setText(MainApp.gq(R.plurals.objective_days, d, d) + " " - + MainApp.gs(R.string.ago)); - } - lastConnectionView.setTextColor(Color.RED); - } else { - lastConnectionView.setText(minAgo); - lastConnectionView.setTextColor(Color.WHITE); - } - - // last bolus - Double bolus = pumpStatus.lastBolusAmount; - Date bolusTime = pumpStatus.lastBolusTime; - if (bolus != null && bolusTime != null) { - long agoMsc = System.currentTimeMillis() - pumpStatus.lastBolusTime.getTime(); - double bolusMinAgo = agoMsc / 60d / 1000d; - String unit = MainApp.gs(R.string.insulin_unit_shortname); - String ago; - if ((agoMsc < 60 * 1000)) { - ago = MainApp.gs(R.string.combo_pump_connected_now); - } else if (bolusMinAgo < 60) { - ago = DateUtil.minAgo(pumpStatus.lastBolusTime.getTime()); - } else { - ago = DateUtil.hourAgo(pumpStatus.lastBolusTime.getTime()); - } - lastBolusView.setText(MainApp.gs(R.string.combo_last_bolus, bolus, unit, ago)); - } else { - lastBolusView.setText(""); - } - - // base basal rate - basaBasalRateView.setText("(" + (pumpStatus.activeProfileName) + ") " - + MainApp.gs(R.string.pump_basebasalrate, plugin.getBaseBasalRate())); - - if (ConfigBuilderPlugin.getPlugin().getActivePump().isFakingTempsByExtendedBoluses()) { - if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) { - tempBasalView.setText(TreatmentsPlugin.getPlugin() - .getRealTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); - } else { - tempBasalView.setText(""); - } - } else { - // v2 plugin - if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) { - tempBasalView.setText(TreatmentsPlugin.getPlugin() - .getTempBasalFromHistory(System.currentTimeMillis()).toStringFull()); - } else { - tempBasalView.setText(""); - } - } - - // battery - if (MedtronicUtil.getBatteryType() == BatteryType.None || pumpStatus.batteryVoltage == null) { - batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} "); - } else { - batteryView.setText("{fa-battery-" + (pumpStatus.batteryRemaining / 25) + "} " + pumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", pumpStatus.batteryVoltage)); - } - SetWarnColor.setColorInverse(batteryView, pumpStatus.batteryRemaining, 25d, 10d); - - // reservoir - reservoirView.setText(DecimalFormatter.to0Decimal(pumpStatus.reservoirRemainingUnits) + " / " - + pumpStatus.reservoirFullUnits + " " + MainApp.gs(R.string.insulin_unit_shortname)); - SetWarnColor.setColorInverse(reservoirView, pumpStatus.reservoirRemainingUnits, 50d, 20d); - - errorsView.setText(pumpStatus.getErrorInfo()); - - }); - } - - - private boolean isLogEnabled() { - return L.isEnabled(L.PUMP); - } - - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt new file mode 100644 index 0000000000..1804f273b2 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicFragment.kt @@ -0,0 +1,326 @@ +package info.nightscout.androidaps.plugins.pump.medtronic + +import android.content.Intent +import android.graphics.Color +import android.os.Bundle +import android.os.Handler +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.fragment.app.Fragment +import butterknife.OnClick +import com.squareup.otto.Subscribe +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.R +import info.nightscout.androidaps.events.EventExtendedBolusChange +import info.nightscout.androidaps.events.EventPumpStatusChanged +import info.nightscout.androidaps.events.EventTempBasalChange +import info.nightscout.androidaps.logging.L +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusActivity +import info.nightscout.androidaps.plugins.pump.medtronic.defs.BatteryType +import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType +import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState +import info.nightscout.androidaps.plugins.pump.medtronic.dialog.MedtronicHistoryActivity +import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus +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 +import info.nightscout.androidaps.queue.events.EventQueueChanged +import info.nightscout.androidaps.utils.* +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.disposables.Disposable +import kotlinx.android.synthetic.main.medtronic_fragment.* +import org.slf4j.LoggerFactory + + +class MedtronicFragment : Fragment() { + private val log = LoggerFactory.getLogger(L.PUMP) + private var disposable: CompositeDisposable = CompositeDisposable() + + operator fun CompositeDisposable.plusAssign(disposable: Disposable) { + add(disposable) + } + + private val loopHandler = Handler() + private lateinit var refreshLoop: Runnable + + init { + refreshLoop = Runnable { + activity?.runOnUiThread { updateGUI() } + loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) + } + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.medtronic_fragment, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + medtronic_pumpstatus.setBackgroundColor(MainApp.gc(R.color.colorInitializingBorder)) + + medtronic_rl_status.text = MainApp.gs(RileyLinkServiceState.NotStarted.getResourceId(RileyLinkTargetDevice.MedtronicPump)) + + medtronic_pump_status.setTextColor(Color.WHITE) + medtronic_pump_status.text = "{fa-bed}" + + medtronic_history.setOnClickListener { + if (MedtronicUtil.getPumpStatus().verifyConfiguration()) { + startActivity(Intent(context, MedtronicHistoryActivity::class.java)) + } else { + MedtronicUtil.displayNotConfiguredDialog(context) + } + } + + medtronic_refresh.setOnClickListener { + if (!MedtronicUtil.getPumpStatus().verifyConfiguration()) { + MedtronicUtil.displayNotConfiguredDialog(context) + } else { + medtronic_refresh.isEnabled = false + MedtronicPumpPlugin.getPlugin().resetStatusState() + ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("Clicked refresh", object : Callback() { + override fun run() { + activity?.runOnUiThread { medtronic_refresh.isEnabled = true } + } + }) + } + } + + medtronic_stats.setOnClickListener { + if (MedtronicUtil.getPumpStatus().verifyConfiguration()) { + startActivity(Intent(context, RileyLinkStatusActivity::class.java)) + } else { + MedtronicUtil.displayNotConfiguredDialog(context) + } + } + + updateGUI() + } + + override fun onResume() { + super.onResume() + MainApp.bus().register(this) + loopHandler.postDelayed(refreshLoop, T.mins(1).msecs()) + disposable += RxBus + .toObservable(EventRefreshButtonState::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ medtronic_refresh.isEnabled = it.newState }, { FabricPrivacy.logException(it) }) + disposable += RxBus + .toObservable(EventMedtronicDeviceStatusChange::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ + if (L.isEnabled(L.PUMP)) + log.info("onStatusEvent(EventMedtronicDeviceStatusChange): {}", it) + setDeviceStatus() + }, { FabricPrivacy.logException(it) }) + disposable += RxBus + .toObservable(EventMedtronicPumpValuesChanged::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ updateGUI() }, { FabricPrivacy.logException(it) }) + disposable += RxBus + .toObservable(EventMedtronicPumpConfigurationChanged::class.java) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe({ + if (L.isEnabled(L.PUMP)) + log.debug("EventMedtronicPumpConfigurationChanged triggered") + MedtronicUtil.getPumpStatus().verifyConfiguration() + updateGUI() + }, { FabricPrivacy.logException(it) }) + } + + override fun onPause() { + super.onPause() + disposable.clear() + MainApp.bus().unregister(this) + loopHandler.removeCallbacks(refreshLoop) + } + + @Subscribe + fun onStatusEvent(c: EventPumpStatusChanged) { + activity?.runOnUiThread { updateGUI() } + } + + @Subscribe + fun onStatusEvent(s: EventTempBasalChange) { + activity?.runOnUiThread { updateGUI() } + } + + @Subscribe + fun onStatusEvent(s: EventExtendedBolusChange) { + activity?.runOnUiThread { updateGUI() } + } + + @Subscribe + fun onStatusEvent(s: EventQueueChanged) { + activity?.runOnUiThread { updateGUI() } + } + + @Synchronized + private fun setDeviceStatus() { + val pumpStatus: MedtronicPumpStatus = MedtronicUtil.getPumpStatus() + pumpStatus.rileyLinkServiceState = checkStatusSet(pumpStatus.rileyLinkServiceState, + RileyLinkUtil.getServiceState()) as RileyLinkServiceState? + + val resourceId = pumpStatus.rileyLinkServiceState.getResourceId(RileyLinkTargetDevice.MedtronicPump) + val rileyLinkError = RileyLinkUtil.getError() + medtronic_rl_status.text = + when { + pumpStatus.rileyLinkServiceState == RileyLinkServiceState.NotStarted -> MainApp.gs(resourceId) + pumpStatus.rileyLinkServiceState.isConnecting -> "{fa-bluetooth-b spin} " + MainApp.gs(resourceId) + pumpStatus.rileyLinkServiceState.isError && rileyLinkError == null -> "{fa-bluetooth-b} " + MainApp.gs(resourceId) + pumpStatus.rileyLinkServiceState.isError && rileyLinkError != null -> "{fa-bluetooth-b} " + MainApp.gs(rileyLinkError.getResourceId(RileyLinkTargetDevice.MedtronicPump)) + else -> "{fa-bluetooth-b} " + MainApp.gs(resourceId) + } + medtronic_rl_status.setTextColor(if (rileyLinkError != null) Color.RED else Color.WHITE) + + pumpStatus.rileyLinkError = checkStatusSet(pumpStatus.rileyLinkError, RileyLinkUtil.getError()) as RileyLinkError? + + medtronic_errors.text = + pumpStatus.rileyLinkError?.let { + MainApp.gs(it.getResourceId(RileyLinkTargetDevice.MedtronicPump)) + } ?: "-" + + pumpStatus.pumpDeviceState = checkStatusSet(pumpStatus.pumpDeviceState, + MedtronicUtil.getPumpDeviceState()) as PumpDeviceState? + + when (pumpStatus.pumpDeviceState) { + null, + PumpDeviceState.Sleeping -> medtronic_pump_status.text = "{fa-bed} " // + pumpStatus.pumpDeviceState.name()); + PumpDeviceState.NeverContacted, + PumpDeviceState.WakingUp, + PumpDeviceState.PumpUnreachable, + PumpDeviceState.ErrorWhenCommunicating, + PumpDeviceState.TimeoutWhenCommunicating, + PumpDeviceState.InvalidConfiguration -> medtronic_pump_status.text = " " + MainApp.gs(pumpStatus.pumpDeviceState.resourceId) + PumpDeviceState.Active -> { + val cmd = MedtronicUtil.getCurrentCommand() + if (cmd == null) + medtronic_pump_status.text = " " + MainApp.gs(pumpStatus.pumpDeviceState.resourceId) + else { + log.debug("Command: " + cmd) + val cmdResourceId = cmd.resourceId + if (cmd == MedtronicCommandType.GetHistoryData) { + medtronic_pump_status.text = MedtronicUtil.frameNumber?.let { + MainApp.gs(cmdResourceId, MedtronicUtil.pageNumber, MedtronicUtil.frameNumber) + } + ?: MainApp.gs(R.string.medtronic_cmd_desc_get_history_request, MedtronicUtil.pageNumber) + } else { + medtronic_pump_status.text = " " + (cmdResourceId?.let { MainApp.gs(it) } + ?: cmd.getCommandDescription()) + } + } + } + else -> log.warn("Unknown pump state: " + pumpStatus.pumpDeviceState) + } + + val status = ConfigBuilderPlugin.getPlugin().commandQueue.spannedStatus() + if (status.toString() == "") { + medtronic_queue.visibility = View.GONE + } else { + medtronic_queue.visibility = View.VISIBLE + medtronic_queue.text = status + } + } + + + private fun checkStatusSet(object1: Any?, object2: Any?): Any? { + return if (object1 == null) { + object2 + } else { + if (object1 != object2) { + object2 + } else + object1 + } + } + + // GUI functions + fun updateGUI() { + val plugin = MedtronicPumpPlugin.getPlugin() + val pumpStatus = MedtronicUtil.getPumpStatus() + + setDeviceStatus() + + // last connection + if (pumpStatus.lastConnection != 0L) { + val minAgo = DateUtil.minAgo(pumpStatus.lastConnection) + val min = (System.currentTimeMillis() - pumpStatus.lastConnection) / 1000 / 60 + if (pumpStatus.lastConnection + 60 * 1000 > System.currentTimeMillis()) { + medtronic_lastconnection.setText(R.string.combo_pump_connected_now) + medtronic_lastconnection.setTextColor(Color.WHITE) + } else if (pumpStatus.lastConnection + 30 * 60 * 1000 < System.currentTimeMillis()) { + + if (min < 60) { + medtronic_lastconnection.text = MainApp.gs(R.string.minago, min) + } else if (min < 1440) { + val h = (min / 60).toInt() + medtronic_lastconnection.text = (MainApp.gq(R.plurals.objective_hours, h, h) + " " + + MainApp.gs(R.string.ago)) + } else { + val h = (min / 60).toInt() + val d = h / 24 + // h = h - (d * 24); + medtronic_lastconnection.text = (MainApp.gq(R.plurals.objective_days, d, d) + " " + + MainApp.gs(R.string.ago)) + } + medtronic_lastconnection.setTextColor(Color.RED) + } else { + medtronic_lastconnection.text = minAgo + medtronic_lastconnection.setTextColor(Color.WHITE) + } + } + + // last bolus + val bolus = pumpStatus.lastBolusAmount + val bolusTime = pumpStatus.lastBolusTime + if (bolus != null && bolusTime != null) { + val agoMsc = System.currentTimeMillis() - pumpStatus.lastBolusTime.time + val bolusMinAgo = agoMsc.toDouble() / 60.0 / 1000.0 + val unit = MainApp.gs(R.string.insulin_unit_shortname) + val ago: String + if (agoMsc < 60 * 1000) { + ago = MainApp.gs(R.string.combo_pump_connected_now) + } else if (bolusMinAgo < 60) { + ago = DateUtil.minAgo(pumpStatus.lastBolusTime.time) + } else { + ago = DateUtil.hourAgo(pumpStatus.lastBolusTime.time) + } + medtronic_lastbolus.text = MainApp.gs(R.string.combo_last_bolus, bolus, unit, ago) + } else { + medtronic_lastbolus.text = "" + } + + // base basal rate + medtronic_basabasalrate.text = ("(" + pumpStatus.activeProfileName + ") " + + MainApp.gs(R.string.pump_basebasalrate, plugin.baseBasalRate)) + + medtronic_tempbasal.text = TreatmentsPlugin.getPlugin() + .getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "" + + // battery + if (MedtronicUtil.getBatteryType() == BatteryType.None || pumpStatus.batteryVoltage == null) { + medtronic_pumpstate_battery.text = "{fa-battery-" + pumpStatus.batteryRemaining / 25 + "} " + } else { + medtronic_pumpstate_battery.text = "{fa-battery-" + pumpStatus.batteryRemaining / 25 + "} " + pumpStatus.batteryRemaining + "%" + String.format(" (%.2f V)", pumpStatus.batteryVoltage) + } + SetWarnColor.setColorInverse(medtronic_pumpstate_battery, pumpStatus.batteryRemaining.toDouble(), 25.0, 10.0) + + // reservoir + medtronic_reservoir.text = MainApp.gs(R.string.reservoirvalue, pumpStatus.reservoirRemainingUnits, pumpStatus.reservoirFullUnits) + SetWarnColor.setColorInverse(medtronic_reservoir, pumpStatus.reservoirRemainingUnits, 50.0, 20.0) + + medtronic_errors.text = pumpStatus.errorInfo + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java index 6b8e641418..064ad3b1e0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/MedtronicPumpPlugin.java @@ -39,6 +39,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.common.ManufacturerType; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; @@ -371,7 +372,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter refreshAnyStatusThatNeedsToBeRefreshed(); } - MainApp.bus().post(new EventMedtronicPumpValuesChanged()); + RxBus.INSTANCE.send(new EventMedtronicPumpValuesChanged()); } @@ -495,7 +496,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter private void setRefreshButtonEnabled(boolean enabled) { - MainApp.bus().post(new EventRefreshButtonState(enabled)); + RxBus.INSTANCE.send(new EventRefreshButtonState(enabled)); } @@ -711,7 +712,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter protected void triggerUIChange() { - MainApp.bus().post(new EventMedtronicPumpValuesChanged()); + RxBus.INSTANCE.send(new EventMedtronicPumpValuesChanged()); } private BolusDeliveryType bolusDeliveryType = BolusDeliveryType.Idle; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java index 38bbb11ae2..d6df56bb57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/ui/MedtronicUITask.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.pump.medtronic.comm.MedtronicCommunicationManager; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry; import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.BasalProfile; @@ -181,9 +182,8 @@ public class MedtronicUITask { } - public void postProcess(MedtronicUIPostprocessor postprocessor) { + void postProcess(MedtronicUIPostprocessor postprocessor) { - EventMedtronicDeviceStatusChange statusChange; if (isLogEnabled()) LOG.debug("MedtronicUITask: @@@ In execute. {}", commandType); @@ -192,15 +192,13 @@ public class MedtronicUITask { } if (responseType == MedtronicUIResponseType.Invalid) { - statusChange = new EventMedtronicDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating, - "Unsupported command in MedtronicUITask"); - MainApp.bus().post(statusChange); + RxBus.INSTANCE.send(new EventMedtronicDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating, + "Unsupported command in MedtronicUITask")); } else if (responseType == MedtronicUIResponseType.Error) { - statusChange = new EventMedtronicDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating, - errorDescription); - MainApp.bus().post(statusChange); + RxBus.INSTANCE.send(new EventMedtronicDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating, + errorDescription)); } else { - MainApp.bus().post(new EventMedtronicPumpValuesChanged()); + RxBus.INSTANCE.send(new EventMedtronicPumpValuesChanged()); MedtronicUtil.getPumpStatus().setLastCommunicationToNow(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/PumpDeviceState.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/PumpDeviceState.java index 30d0a49007..ba86963869 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/PumpDeviceState.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/PumpDeviceState.java @@ -18,19 +18,12 @@ public enum PumpDeviceState { PumpUnreachable(R.string.medtronic_pump_status_pump_unreachable), // InvalidConfiguration(R.string.medtronic_pump_status_invalid_config); - Integer resourceId = null; - - - PumpDeviceState() { - - } - + Integer resourceId; PumpDeviceState(int resourceId) { this.resourceId = resourceId; } - public Integer getResourceId() { return resourceId; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java index c6ad3fa4e4..46647e832e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/driver/MedtronicPumpStatus.java @@ -184,9 +184,9 @@ public class MedtronicPumpStatus extends PumpStatus { this.medtronicDeviceType = medtronicDeviceTypeMap.get(pumpTypePart); if (pumpTypePart.startsWith("7")) - this.reservoirFullUnits = "300"; + this.reservoirFullUnits = 300; else - this.reservoirFullUnits = "176"; + this.reservoirFullUnits = 176; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.java deleted file mode 100644 index 4582404a39..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.java +++ /dev/null @@ -1,53 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.medtronic.events; - -import info.nightscout.androidaps.events.Event; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState; -import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState; - -/** - * Created by andy on 04.06.2018. - */ -public class EventMedtronicDeviceStatusChange extends Event { - - public RileyLinkServiceState rileyLinkServiceState; - public RileyLinkError rileyLinkError; - - public PumpDeviceState pumpDeviceState; - public String errorDescription; - - - // public EventMedtronicDeviceStatusChange(RileyLinkServiceState rileyLinkServiceState, PumpDeviceState - // pumpDeviceState) { - // this.rileyLinkServiceState = rileyLinkServiceState; - // this.pumpDeviceState = pumpDeviceState; - // } - - public EventMedtronicDeviceStatusChange(RileyLinkServiceState rileyLinkServiceState) { - this(rileyLinkServiceState, null); - } - - - public EventMedtronicDeviceStatusChange(RileyLinkServiceState rileyLinkServiceState, RileyLinkError rileyLinkError) { - this.rileyLinkServiceState = rileyLinkServiceState; - this.rileyLinkError = rileyLinkError; - } - - - public EventMedtronicDeviceStatusChange(PumpDeviceState pumpDeviceState) { - this.pumpDeviceState = pumpDeviceState; - } - - - public EventMedtronicDeviceStatusChange(PumpDeviceState pumpDeviceState, String errorDescription) { - this.pumpDeviceState = pumpDeviceState; - this.errorDescription = errorDescription; - } - - - @Override - public String toString() { - return "EventMedtronicDeviceStatusChange [" + "rileyLinkServiceState=" + rileyLinkServiceState - + ", rileyLinkError=" + rileyLinkError + ", pumpDeviceState=" + pumpDeviceState + ']'; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.kt new file mode 100644 index 0000000000..79c69f86c0 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicDeviceStatusChange.kt @@ -0,0 +1,38 @@ +package info.nightscout.androidaps.plugins.pump.medtronic.events + +import info.nightscout.androidaps.events.Event +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState +import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpDeviceState + +class EventMedtronicDeviceStatusChange : Event { + + private var rileyLinkServiceState: RileyLinkServiceState? = null + private var rileyLinkError: RileyLinkError? = null + + private var pumpDeviceState: PumpDeviceState? = null + private var errorDescription: String? = null + + + constructor(rileyLinkServiceState: RileyLinkServiceState, rileyLinkError: RileyLinkError) { + this.rileyLinkServiceState = rileyLinkServiceState + this.rileyLinkError = rileyLinkError + } + + + constructor(pumpDeviceState: PumpDeviceState) { + this.pumpDeviceState = pumpDeviceState + } + + + constructor(pumpDeviceState: PumpDeviceState, errorDescription: String) { + this.pumpDeviceState = pumpDeviceState + this.errorDescription = errorDescription + } + + + override fun toString(): String { + return ("EventMedtronicDeviceStatusChange [" + "rileyLinkServiceState=" + rileyLinkServiceState + + ", rileyLinkError=" + rileyLinkError + ", pumpDeviceState=" + pumpDeviceState + ']'.toString()) + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.java deleted file mode 100644 index d5c51588b1..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.java +++ /dev/null @@ -1,9 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.medtronic.events; - -import info.nightscout.androidaps.events.Event; - -/** - * Created by andy on 04.06.2018. - */ -public class EventMedtronicPumpConfigurationChanged extends Event { -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.kt new file mode 100644 index 0000000000..458c055454 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpConfigurationChanged.kt @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.medtronic.events + +import info.nightscout.androidaps.events.Event + +class EventMedtronicPumpConfigurationChanged : Event() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.java deleted file mode 100644 index b3d43b409b..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.java +++ /dev/null @@ -1,9 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.medtronic.events; - -import info.nightscout.androidaps.events.Event; - -/** - * Created by andy on 04.06.2018. - */ -public class EventMedtronicPumpValuesChanged extends Event { -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.kt new file mode 100644 index 0000000000..b314b9db19 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/events/EventMedtronicPumpValuesChanged.kt @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.pump.medtronic.events + +import info.nightscout.androidaps.events.Event + +class EventMedtronicPumpValuesChanged : Event() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java index 79702492c6..1abc05ef4b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/util/MedtronicUtil.java @@ -19,6 +19,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -419,7 +420,7 @@ public class MedtronicUtil extends RileyLinkUtil { historyRileyLink.add(new RLHistoryItem(pumpDeviceState, RileyLinkTargetDevice.MedtronicPump)); - MainApp.bus().post(new EventMedtronicDeviceStatusChange(pumpDeviceState)); + RxBus.INSTANCE.send(new EventMedtronicDeviceStatusChange(pumpDeviceState)); } @@ -488,7 +489,7 @@ public class MedtronicUtil extends RileyLinkUtil { setCurrentCommand(currentCommand); } - MainApp.bus().post(new EventMedtronicDeviceStatusChange(pumpDeviceState)); + RxBus.INSTANCE.send(new EventMedtronicDeviceStatusChange(pumpDeviceState)); } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.java b/app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.java deleted file mode 100644 index b0a53afd13..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.java +++ /dev/null @@ -1,8 +0,0 @@ -package info.nightscout.androidaps.queue.events; - -/** - * Created by mike on 11.11.2017. - */ - -public class EventQueueChanged { -} diff --git a/app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.kt b/app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.kt new file mode 100644 index 0000000000..297d443976 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/queue/events/EventQueueChanged.kt @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.queue.events + +import info.nightscout.androidaps.events.Event + +class EventQueueChanged : Event() diff --git a/app/src/main/res/layout/medtronic_fragment.xml b/app/src/main/res/layout/medtronic_fragment.xml index 3f6be18be5..a67872fa5d 100644 --- a/app/src/main/res/layout/medtronic_fragment.xml +++ b/app/src/main/res/layout/medtronic_fragment.xml @@ -31,7 +31,7 @@ android:visibility="gone">