diff --git a/app/build.gradle b/app/build.gradle index 396bc79b12..8b2c15a042 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -291,9 +291,11 @@ dependencies { } testImplementation "org.skyscreamer:jsonassert:1.5.0" testImplementation "org.hamcrest:hamcrest-all:1.3" +/* testImplementation("uk.org.lidalia:slf4j-test:1.2.0") { exclude group: "com.google.guava", module: "guava" } +*/ androidTestImplementation "org.mockito:mockito-core:2.8.47" androidTestImplementation "com.google.dexmaker:dexmaker:${dexmakerVersion}" diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 63a2446051..4137e2e1b1 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -54,7 +54,6 @@ import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin; import info.nightscout.androidaps.plugins.general.signatureVerifier.SignatureVerifier; import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; -import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin; import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerPlugin; import info.nightscout.androidaps.plugins.general.wear.WearPlugin; import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin; @@ -169,7 +168,7 @@ public class MainApp extends Application { if (pluginsList == null) { pluginsList = new ArrayList<>(); // Register all tabs in app here - pluginsList.add(OverviewPlugin.getPlugin()); + pluginsList.add(OverviewPlugin.INSTANCE); pluginsList.add(IobCobCalculatorPlugin.getPlugin()); if (Config.ACTION) pluginsList.add(ActionsPlugin.INSTANCE); pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java index db7a86e7f4..cd969a53a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/HistoryBrowseActivity.java @@ -230,8 +230,8 @@ public class HistoryBrowseActivity extends NoSplashActivity { } final String units = profile.getUnits(); - final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); - final double highLine = OverviewPlugin.getPlugin().determineHighLine(units); + final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units); + final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units); buttonDate.setText(DateUtil.dateAndTimeString(start)); buttonZoom.setText(String.valueOf(rangeToDisplay)); diff --git a/app/src/main/java/info/nightscout/androidaps/data/Profile.java b/app/src/main/java/info/nightscout/androidaps/data/Profile.java index 2378e60833..6f18ba7af5 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/app/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -17,6 +17,7 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -230,7 +231,7 @@ public class Profile { if (notify && secondsFromMidnight % 3600 != 0) { if (Config.APS) { Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, String.format(MainApp.gs(R.string.basalprofilenotaligned), from), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } } @@ -262,11 +263,11 @@ public class Profile { } protected void sendBelowMinimumNotification(String from) { - MainApp.bus().post(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.minimalbasalvaluereplaced), from), Notification.NORMAL))); + RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.minimalbasalvaluereplaced), from), Notification.NORMAL))); } protected void sendAboveMaximumNotification(String from) { - MainApp.bus().post(new EventNewNotification(new Notification(Notification.MAXIMUM_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.maximumbasalvaluereplaced), from), Notification.NORMAL))); + RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.MAXIMUM_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.maximumbasalvaluereplaced), from), Notification.NORMAL))); } private void validate(LongSparseArray array) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index 6fafdc4b6d..8b206e2c78 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -216,8 +216,8 @@ public class BgReading implements DataPointWithLabelInterface { @Override public int getColor() { String units = ProfileFunctions.getInstance().getProfileUnits(); - Double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); - Double highLine = OverviewPlugin.getPlugin().determineHighLine(units); + Double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units); + Double highLine = OverviewPlugin.INSTANCE.determineHighLine(units); int color = MainApp.gc(R.color.inrange); if (isPrediction()) return getPredectionColor(); diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index 5f37c3d96b..80344f30a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -1,6 +1,7 @@ package info.nightscout.androidaps.db; import android.graphics.Color; + import androidx.annotation.Nullable; import com.j256.ormlite.field.DatabaseField; @@ -18,6 +19,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; @@ -78,12 +80,12 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { return this; } - public ProfileSwitch source(int source) { + public ProfileSwitch source(int source) { this.source = source; return this; } - public ProfileSwitch duration(int duration) { + public ProfileSwitch duration(int duration) { this.durationInMinutes = duration; return this; } @@ -107,7 +109,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { */ public String getCustomizedName() { String name = profileName; - if(LocalProfilePlugin.LOCAL_PROFILE.equals(name)){ + if (LocalProfilePlugin.LOCAL_PROFILE.equals(name)) { name = DecimalFormatter.to2Decimal(getProfileObject().percentageBasalSum()) + "U "; } if (isCPP) { @@ -221,7 +223,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { public void createNotificationInvalidProfile(String detail) { Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, String.format(MainApp.gs(R.string.zerovalueinprofile), detail), Notification.LOW, 5); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } public static boolean isEvent5minBack(List list, long time, boolean zeroDurationOnly) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java index ec3ef44881..e026d6589d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPlugin.java @@ -15,6 +15,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -89,6 +90,6 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface private void warnUser(int id, String warningText) { Notification notification = new Notification(id, warningText, Notification.LOW); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java index 127752d8dc..388afc2eac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.java @@ -16,6 +16,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -68,7 +69,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface { if (!MainApp.isEngineeringModeOrRelease()) { if (value.value()) { Notification n = new Notification(Notification.TOAST_ALARM, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); } value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), this); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java index 197fd5c17a..f40b7728e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPlugin.java @@ -17,6 +17,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; 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; @@ -56,9 +57,9 @@ public class StorageConstraintPlugin extends PluginBase implements ConstraintsIn if (diskfree < Constants.MINIMUM_FREE_SPACE) { value.set(false, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), this); Notification notification = new Notification(Notification.DISKFULL, MainApp.gs(R.string.diskfull, Constants.MINIMUM_FREE_SPACE), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.DISKFULL)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.DISKFULL)); } return value; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java index f2839593f4..1636377bf2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java @@ -63,16 +63,22 @@ public class TriggerBg extends Trigger { public synchronized boolean shouldRun() { GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); - if (lastRun > DateUtil.now() - T.mins(5).msecs()) + if (lastRun > DateUtil.now() - T.mins(5).msecs()) { + if (L.isEnabled(L.AUTOMATION)) + log.debug("NOT ready for execution: " + friendlyDescription()); return false; + } if (glucoseStatus == null && comparator.getValue().equals(Comparator.Compare.IS_NOT_AVAILABLE)) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } - if (glucoseStatus == null) + if (glucoseStatus == null) { + if (L.isEnabled(L.AUTOMATION)) + log.debug("NOT ready for execution: " + friendlyDescription()); return false; + } boolean doRun = comparator.getValue().check(glucoseStatus.glucose, Profile.toMgdl(bg.getValue(), bg.getUnits())); if (doRun) { @@ -80,6 +86,9 @@ public class TriggerBg extends Trigger { log.debug("Ready for execution: " + friendlyDescription()); return true; } + + if (L.isEnabled(L.AUTOMATION)) + log.debug("NOT ready for execution: " + friendlyDescription()); return false; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java index 93cf70dd12..ba59c6297a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.nsclient.data; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; + import androidx.annotation.Nullable; import org.json.JSONException; @@ -16,12 +17,13 @@ import java.util.Objects; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; 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; -import info.nightscout.androidaps.logging.BundleLogger; /* { @@ -154,22 +156,22 @@ public class NSSettingsStatus { try { if (nsClientVersionCode < MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode) { Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.OLD_NSCLIENT)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.OLD_NSCLIENT)); } } catch (PackageManager.NameNotFoundException e) { log.error("Unhandled exception", e); } if (nightscoutVersionCode < Config.SUPPORTEDNSVERSION) { Notification notification = new Notification(Notification.OLD_NS, MainApp.gs(R.string.unsupportednsversion), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.OLD_NS)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.OLD_NS)); } } else { Notification notification = new Notification(Notification.OLD_NSCLIENT, MainApp.gs(R.string.unsupportedclientver), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } if (bundle.containsKey("status")) { try { @@ -180,9 +182,9 @@ public class NSSettingsStatus { Double targetHigh = getThreshold("bgTargetTop"); Double targetlow = getThreshold("bgTargetBottom"); if (targetHigh != null) - OverviewPlugin.bgTargetHigh = targetHigh; + OverviewPlugin.INSTANCE.setBgTargetHigh(targetHigh); if (targetlow != null) - OverviewPlugin.bgTargetLow = targetlow; + OverviewPlugin.INSTANCE.setBgTargetLow(targetlow); } catch (JSONException e) { log.error("Unhandled exception", e); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java index c14a3382b3..98ac099851 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/services/NSClientService.java @@ -35,6 +35,7 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventPreferenceChange; 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.nsclient.NSClientPlugin; import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue; import info.nightscout.androidaps.plugins.general.nsclient.acks.NSAddAck; @@ -177,7 +178,7 @@ public class NSClientService extends Service { if (ev.isChanged(R.string.key_nsclientinternal_url) || ev.isChanged(R.string.key_nsclientinternal_api_secret) || ev.isChanged(R.string.key_nsclientinternal_paused) - ) { + ) { latestDateInReceivedData = 0; destroy(); initialize(); @@ -269,7 +270,7 @@ public class NSClientService extends Service { MainApp.bus().post(new EventNSClientNewLog("WATCHDOG", "connections in last " + WATCHDOG_INTERVAL_MINUTES + " mins: " + reconnections.size() + "/" + WATCHDOG_MAXCONNECTIONS)); if (reconnections.size() >= WATCHDOG_MAXCONNECTIONS) { Notification n = new Notification(Notification.NSMALFUNCTION, MainApp.gs(R.string.nsmalfunction), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); MainApp.bus().post(new EventNSClientNewLog("WATCHDOG", "pausing for " + WATCHDOG_RECONNECT_IN + " mins")); NSClientPlugin.getPlugin().pause(true); MainApp.bus().post(new EventNSClientUpdateGUI()); @@ -347,9 +348,9 @@ public class NSClientService extends Service { } if (!hasWriteAuth) { Notification noperm = new Notification(Notification.NSCLIENT_NO_WRITE_PERMISSION, MainApp.gs(R.string.nowritepermission), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(noperm)); + RxBus.INSTANCE.send(new EventNewNotification(noperm)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.NSCLIENT_NO_WRITE_PERMISSION)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.NSCLIENT_NO_WRITE_PERMISSION)); } } @@ -686,7 +687,7 @@ public class NSClientService extends Service { if ((System.currentTimeMillis() - latestDateInReceivedData) / (60 * 1000L) < 15L) lessThan15MinAgo = true; if (Notification.isAlarmForStaleData() && lessThan15MinAgo) { - MainApp.bus().post(new EventDismissNotification(Notification.NSALARM)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.NSALARM)); } BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java index 93f499c8ca..467d1c813c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.java @@ -827,7 +827,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final String profileName = ProfileFunctions.getInstance().getProfileName(); final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); - final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); + final QuickWizardEntry quickWizardEntry = OverviewPlugin.INSTANCE.getQuickWizard().getActive(); if (quickWizardEntry != null && actualBg != null && profile != null && pump != null) { quickWizardButton.setVisibility(View.VISIBLE); final BolusWizard wizard = quickWizardEntry.doCalc(profile, profileName, actualBg, true); @@ -1008,7 +1008,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, timeView.setText(DateUtil.timeString(new Date())); } - OverviewPlugin.getPlugin().notificationStore.updateNotifications(notificationsView); + OverviewPlugin.INSTANCE.getNotificationStore().updateNotifications(notificationsView); pumpStatusLayout.setVisibility(View.GONE); loopStatusLayout.setVisibility(View.GONE); @@ -1030,8 +1030,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, final String profileName = ProfileFunctions.getInstance().getProfileName(); final String units = profile.getUnits(); - final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); - final double highLine = OverviewPlugin.getPlugin().determineHighLine(units); + final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units); + final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units); //Start with updating the BG as it is unaffected by loop. // **** BG value **** @@ -1221,7 +1221,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // QuickWizard button - QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive(); + QuickWizardEntry quickWizardEntry = OverviewPlugin.INSTANCE.getQuickWizard().getActive(); if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) { quickWizardButton.setVisibility(View.VISIBLE); String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java deleted file mode 100644 index 4301ad6ec0..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.java +++ /dev/null @@ -1,111 +0,0 @@ -package info.nightscout.androidaps.plugins.general.overview; - -import com.squareup.otto.Subscribe; - -import org.json.JSONArray; -import org.json.JSONException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.data.QuickWizard; -import info.nightscout.androidaps.events.EventRefreshOverview; -import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.logging.L; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; -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.NotificationStore; -import info.nightscout.androidaps.utils.SP; - -/** - * Created by mike on 05.08.2016. - */ -public class OverviewPlugin extends PluginBase { - private static Logger log = LoggerFactory.getLogger(L.OVERVIEW); - - private static OverviewPlugin overviewPlugin = new OverviewPlugin(); - - public static OverviewPlugin getPlugin() { - if (overviewPlugin == null) - overviewPlugin = new OverviewPlugin(); - return overviewPlugin; - } - - public static double bgTargetLow = 80d; - public static double bgTargetHigh = 180d; - - public QuickWizard quickWizard = new QuickWizard(); - - public NotificationStore notificationStore = new NotificationStore(); - - public OverviewPlugin() { - super(new PluginDescription() - .mainType(PluginType.GENERAL) - .fragmentClass(OverviewFragment.class.getName()) - .alwaysVisible(true) - .alwaysEnabled(true) - .pluginName(R.string.overview) - .shortName(R.string.overview_shortname) - .preferencesId(R.xml.pref_overview) - .description(R.string.description_overview) - ); - String storedData = SP.getString("QuickWizard", "[]"); - try { - quickWizard.setData(new JSONArray(storedData)); - } catch (JSONException e) { - log.error("Unhandled exception", e); - } - } - - @Override - protected void onStart() { - MainApp.bus().register(this); - super.onStart(); - } - - @Override - protected void onStop() { - MainApp.bus().unregister(this); - super.onStop(); - } - - @Subscribe - public void onStatusEvent(final EventNewNotification n) { - if (notificationStore.add(n.notification)) - MainApp.bus().post(new EventRefreshOverview("EventNewNotification")); - } - - @Subscribe - public void onStatusEvent(final EventDismissNotification n) { - if (notificationStore.remove(n.id)) - MainApp.bus().post(new EventRefreshOverview("EventDismissNotification")); - } - - public double determineHighLine(String units) { - double highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units)); - if (highLineSetting < 1) - highLineSetting = Profile.fromMgdlToUnits(180d, units); - return highLineSetting; - } - - public double determineLowLine() { - Profile profile = ProfileFunctions.getInstance().getProfile(); - if (profile == null) { - return bgTargetLow; - } - return determineLowLine(profile.getUnits()); - } - - public double determineLowLine(String units) { - double lowLineSetting = SP.getDouble("low_mark", Profile.fromMgdlToUnits(OverviewPlugin.bgTargetLow, units)); - if (lowLineSetting < 1) - lowLineSetting = Profile.fromMgdlToUnits(76d, units); - return lowLineSetting; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt new file mode 100644 index 0000000000..708f7f1c7d --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewPlugin.kt @@ -0,0 +1,100 @@ +package info.nightscout.androidaps.plugins.general.overview + +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.R +import info.nightscout.androidaps.data.Profile +import info.nightscout.androidaps.data.QuickWizard +import info.nightscout.androidaps.events.EventRefreshOverview +import info.nightscout.androidaps.interfaces.PluginBase +import info.nightscout.androidaps.interfaces.PluginDescription +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.logging.L +import info.nightscout.androidaps.plugins.bus.RxBus +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions +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.NotificationStore +import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.SP +import info.nightscout.androidaps.utils.plusAssign +import io.reactivex.disposables.CompositeDisposable +import io.reactivex.schedulers.Schedulers +import org.json.JSONArray +import org.json.JSONException +import org.slf4j.LoggerFactory + +object OverviewPlugin : PluginBase(PluginDescription() + .mainType(PluginType.GENERAL) + .fragmentClass(OverviewFragment::class.qualifiedName) + .alwaysVisible(true) + .alwaysEnabled(true) + .pluginName(R.string.overview) + .shortName(R.string.overview_shortname) + .preferencesId(R.xml.pref_overview) + .description(R.string.description_overview)) { + + private val log = LoggerFactory.getLogger(L.OVERVIEW) + private var disposable: CompositeDisposable = CompositeDisposable() + + var bgTargetLow = 80.0 + var bgTargetHigh = 180.0 + + var quickWizard = QuickWizard() + + var notificationStore = NotificationStore() + + init { + val storedData = SP.getString("QuickWizard", "[]") + try { + quickWizard.setData(JSONArray(storedData)) + } catch (e: JSONException) { + log.error("Unhandled exception", e) + } + } + + override fun onStart() { + super.onStart() + disposable += RxBus + .toObservable(EventNewNotification::class.java) + .observeOn(Schedulers.io()) + .subscribe({ n -> + if (notificationStore.add(n.notification)) + MainApp.bus().post(EventRefreshOverview("EventNewNotification")) + }, { + FabricPrivacy.logException(it) + }) + disposable += RxBus + .toObservable(EventDismissNotification::class.java) + .observeOn(Schedulers.io()) + .subscribe({ n -> + if (notificationStore.remove(n.id)) + MainApp.bus().post(EventRefreshOverview("EventDismissNotification")) + }, { + FabricPrivacy.logException(it) + }) + } + + override fun onStop() { + disposable.clear() + super.onStop() + } + + fun determineHighLine(units: String): Double { + var highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(bgTargetHigh, units))!! + if (highLineSetting < 1) + highLineSetting = Profile.fromMgdlToUnits(180.0, units) + return highLineSetting + } + + fun determineLowLine(): Double { + val profile = ProfileFunctions.getInstance().profile ?: return bgTargetLow + return determineLowLine(profile.units) + } + + fun determineLowLine(units: String): Double { + var lowLineSetting = SP.getDouble("low_mark", Profile.fromMgdlToUnits(bgTargetLow, units))!! + if (lowLineSetting < 1) + lowLineSetting = Profile.fromMgdlToUnits(76.0, units) + return lowLineSetting + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java index bbcda2c083..f4c0d5d997 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/activities/QuickWizardListActivity.java @@ -123,7 +123,7 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement llm = new LinearLayoutManager(this); recyclerView.setLayoutManager(llm); - RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard, getSupportFragmentManager()); + RecyclerViewAdapter adapter = new RecyclerViewAdapter(OverviewPlugin.INSTANCE.getQuickWizard(), getSupportFragmentManager()); recyclerView.setAdapter(adapter); adButton = (Button) findViewById(R.id.overview_quickwizardactivity_add_button); @@ -164,7 +164,7 @@ public class QuickWizardListActivity extends NoSplashAppCompatActivity implement activity.runOnUiThread(new Runnable() { @Override public void run() { - RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard, getSupportFragmentManager()); + RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getSpecificPlugin(OverviewPlugin.class).getQuickWizard(), getSupportFragmentManager()); recyclerView.swapAdapter(adapter, false); } }); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.java index f4a689e34e..2522f5af05 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/dialogs/EditQuickWizardDialog.java @@ -32,7 +32,7 @@ public class EditQuickWizardDialog extends DialogFragment implements View.OnClic private static Logger log = LoggerFactory.getLogger(EditQuickWizardDialog.class); QuickWizardEntry entry = new QuickWizard().newEmptyItem(); - QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).quickWizard; + QuickWizard quickWizard = MainApp.getSpecificPlugin(OverviewPlugin.class).getQuickWizard(); EditText buttonEdit; EditText carbsEdit; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java deleted file mode 100644 index bc13c93970..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.java +++ /dev/null @@ -1,16 +0,0 @@ -package info.nightscout.androidaps.plugins.general.overview.events; - -import info.nightscout.androidaps.events.Event; - -/** - * Created by mike on 03.12.2016. - */ - -public class EventDismissNotification extends Event { - public int id; - - public EventDismissNotification(int did) { - id = did; - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.kt new file mode 100644 index 0000000000..bd719ecac8 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventDismissNotification.kt @@ -0,0 +1,5 @@ +package info.nightscout.androidaps.plugins.general.overview.events + +import info.nightscout.androidaps.events.Event + +class EventDismissNotification(var id: Int) : Event() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java deleted file mode 100644 index f6b62b7f83..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.java +++ /dev/null @@ -1,16 +0,0 @@ -package info.nightscout.androidaps.plugins.general.overview.events; - -import info.nightscout.androidaps.events.Event; -import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; - -/** - * Created by mike on 03.12.2016. - */ - -public class EventNewNotification extends Event { - public Notification notification; - - public EventNewNotification(Notification n) { - notification = n; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.kt new file mode 100644 index 0000000000..b70af5bfe1 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/events/EventNewNotification.kt @@ -0,0 +1,6 @@ +package info.nightscout.androidaps.plugins.general.overview.events + +import info.nightscout.androidaps.events.Event +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification + +class EventNewNotification(var notification: Notification) : Event() diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java index 6c320fc574..3d1189de2b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/DismissNotificationService.java @@ -3,9 +3,11 @@ package info.nightscout.androidaps.plugins.general.overview.notifications; import android.app.IntentService; import android.app.PendingIntent; import android.content.Intent; + import androidx.annotation.Nullable; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; public class DismissNotificationService extends IntentService { @@ -19,16 +21,16 @@ public class DismissNotificationService extends IntentService { super(name); } - public DismissNotificationService(){ + public DismissNotificationService() { super("DismissNotificationService"); } @Override protected void onHandleIntent(@Nullable Intent intent) { - MainApp.bus().post(new EventDismissNotification(intent.getIntExtra("alertID", -1))); + RxBus.INSTANCE.send(new EventDismissNotification(intent.getIntExtra("alertID", -1))); } - public static PendingIntent deleteIntent(int id){ + public static PendingIntent deleteIntent(int id) { Intent intent = new Intent(MainApp.instance(), DismissNotificationService.class); intent.putExtra("alertID", id); return PendingIntent.getService(MainApp.instance(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java index beea4c3733..1e96b02be1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/notifications/NotificationRecyclerViewAdapter.java @@ -20,6 +20,7 @@ import java.util.Objects; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.nsclient.broadcasts.BroadcastAckAlarm; import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; @@ -90,7 +91,7 @@ public class NotificationRecyclerViewAdapter extends RecyclerView.Adapter SP.getLong(R.string.key_last_versionchecker_warning, 0) + WARN_EVERY) { log.debug("Version ${currentVersion} outdated. Found $newVersion") val notification = Notification(Notification.NEWVERSIONDETECTED, String.format(MainApp.gs(R.string.versionavailable), newVersion.toString()), Notification.LOW) - MainApp.bus().post(EventNewNotification(notification)) + RxBus.send(EventNewNotification(notification)) SP.putLong(R.string.key_last_versionchecker_warning, now) } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java index 1f1dd90463..25a6540dbd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/ActionStringHandler.java @@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.general.wear; import android.app.NotificationManager; import android.content.Context; -import android.os.HandlerThread; + import androidx.annotation.NonNull; import java.text.DateFormat; @@ -31,15 +31,15 @@ import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; -import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog; -import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo; +import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; @@ -214,7 +214,7 @@ public class ActionStringHandler { } CobInfo cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "Wizard wear"); - if (useCOB && (cobInfo == null || cobInfo.displayCob == null)) { + if (useCOB && (cobInfo == null || cobInfo.displayCob == null)) { sendError("Unknown COB! BG reading missing or recent app restart?"); return; } @@ -244,7 +244,8 @@ public class ActionStringHandler { rMessage += "\nFrom Carbs: " + format.format(bolusWizard.getInsulinFromCarbs()) + "U"; if (useCOB) rMessage += "\nFrom" + formatInt.format(cobInfo.displayCob) + "g COB : " + format.format(bolusWizard.getInsulinFromCOB()) + "U"; - if (useBG) rMessage += "\nFrom BG: " + format.format(bolusWizard.getInsulinFromBG()) + "U"; + if (useBG) + rMessage += "\nFrom BG: " + format.format(bolusWizard.getInsulinFromBG()) + "U"; if (useBolusIOB) rMessage += "\nBolus IOB: " + format.format(bolusWizard.getInsulinFromBolusIOB()) + "U"; if (useBasalIOB) @@ -327,17 +328,17 @@ public class ActionStringHandler { int carbs = SafeParse.stringToInt(act[1]); int starttime = SafeParse.stringToInt(act[2]); int duration = SafeParse.stringToInt(act[3]); - long starttimestamp = System.currentTimeMillis() + starttime*60*1000; + long starttimestamp = System.currentTimeMillis() + starttime * 60 * 1000; Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value(); rMessage += MainApp.gs(R.string.carbs) + ": " + carbsAfterConstraints + "g"; - rMessage += "\n" + MainApp.gs(R.string.time) + ": " + DateUtil.timeString(starttimestamp); + rMessage += "\n" + MainApp.gs(R.string.time) + ": " + DateUtil.timeString(starttimestamp); rMessage += "\n" + MainApp.gs(R.string.duration) + ": " + duration + "h"; - if ( (carbsAfterConstraints - carbs != 0)) { + if ((carbsAfterConstraints - carbs != 0)) { rMessage += "\n" + MainApp.gs(R.string.constraintapllied); } - if(carbsAfterConstraints <= 0){ + if (carbsAfterConstraints <= 0) { sendError("Carbs = 0! No action taken!"); return; } @@ -627,14 +628,14 @@ public class ActionStringHandler { int timeshift = SafeParse.stringToInt(act[1]); int percentage = SafeParse.stringToInt(act[2]); setCPP(timeshift, percentage); - } else if ("ecarbs".equals(act[0])) { + } else if ("ecarbs".equals(act[0])) { int carbs = SafeParse.stringToInt(act[1]); long starttime = SafeParse.stringToLong(act[2]); int duration = SafeParse.stringToInt(act[3]); doECarbs(carbs, starttime, duration); } else if ("dismissoverviewnotification".equals(act[0])) { - MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1]))); + RxBus.INSTANCE.send(new EventDismissNotification(SafeParse.stringToInt(act[1]))); } else if ("changeRequest".equals(act[0])) { LoopPlugin.getPlugin().acceptChangeRequest(); NotificationManager notificationManager = diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index 6f2f59faa1..7eebdc8d8e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -316,11 +316,11 @@ public class WatchUpdaterService extends WearableListenerService implements Goog } if (lowLine < 1) { - lowLine = OverviewPlugin.bgTargetLow; + lowLine = OverviewPlugin.INSTANCE.getBgTargetLow(); } if (highLine < 1) { - highLine = OverviewPlugin.bgTargetHigh; + highLine = OverviewPlugin.INSTANCE.getBgTargetHigh(); } long sgvLevel = 0l; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java index 7700bf4c52..8ad187d41a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/insulin/InsulinOrefBasePlugin.java @@ -1,19 +1,18 @@ package info.nightscout.androidaps.plugins.insulin; -import com.squareup.otto.Bus; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.treatments.Treatment; /** * Created by adrian on 13.08.2017. @@ -35,10 +34,6 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli ); } - public Bus getBus() { - return MainApp.bus(); - } - @Override public double getDia() { double dia = getUserDefinedDia(); @@ -54,7 +49,7 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli if ((System.currentTimeMillis() - lastWarned) > 60 * 1000) { lastWarned = System.currentTimeMillis(); Notification notification = new Notification(Notification.SHORT_DIA, String.format(this.getNotificationPattern(), dia, MIN_DIA), Notification.URGENT); - this.getBus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index 8ca13a6694..2b427602f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator; import android.content.Context; import android.os.PowerManager; import android.os.SystemClock; + import androidx.collection.LongSparseArray; import org.slf4j.Logger; @@ -24,6 +25,7 @@ import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; @@ -199,7 +201,7 @@ public class IobCobOref1Thread extends Thread { log.debug(bucketed_data.toString()); log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString()); Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); SP.putBoolean("log_AUTOSENS", true); break; } @@ -225,7 +227,7 @@ public class IobCobOref1Thread extends Thread { log.debug(bucketed_data.toString()); log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString()); Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); SP.putBoolean("log_AUTOSENS", true); break; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index 4694685ea6..756cee9853 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -199,7 +199,7 @@ public class IobCobThread extends Thread { log.debug(bucketed_data.toString()); log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString()); Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); SP.putBoolean("log_AUTOSENS", true); break; } @@ -225,7 +225,7 @@ public class IobCobThread extends Thread { log.debug(bucketed_data.toString()); log.debug(IobCobCalculatorPlugin.getPlugin().getBgReadings().toString()); Notification notification = new Notification(Notification.SENDLOGFILES, MainApp.gs(R.string.sendlogfiles), Notification.LOW); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); SP.putBoolean("log_AUTOSENS", true); break; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java index ebdf89b3a3..7058252eb3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/combo/ComboPlugin.java @@ -38,6 +38,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; 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.configBuilder.ProfileFunctions; @@ -66,6 +67,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.InstanceId; import info.nightscout.androidaps.utils.SP; + /** * Created by mike on 05.08.2016. */ @@ -231,15 +233,15 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint // issues a READSTATE when starting to issue commands which initializes the pump log.error("setNewBasalProfile not initialized"); Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.pumpNotInitializedProfileNotSet)); } BasalProfile requestedBasalProfile = convertProfileToComboProfile(profile); if (pump.basalProfile.equals(requestedBasalProfile)) { //dismiss previously "FAILED" overview notifications - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); - MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); return new PumpEnactResult().success(true).enacted(false); } @@ -252,18 +254,18 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint () -> ruffyScripter.setBasalProfile(requestedBasalProfile)); if (!setResult.success) { Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); return new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.failedupdatebasalprofile)); } pump.basalProfile = requestedBasalProfile; //dismiss previously "FAILED" overview notifications - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); - MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); //issue success notification Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); return new PumpEnactResult().success(true).enacted(true); } @@ -339,7 +341,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint // trigger a connect, which will update state and check history CommandResult stateResult = runCommand(null, 1, ruffyScripter::readPumpState); if (stateResult.invalidSetup) { - MainApp.bus().post(new EventNewNotification( + RxBus.INSTANCE.send(new EventNewNotification( new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_invalid_setup), Notification.URGENT))); return; } @@ -360,7 +362,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint MainApp.gs(R.string.combo_force_disabled_notification), Notification.URGENT); n.soundId = R.raw.alarm; - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); return; } @@ -382,7 +384,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint long now = System.currentTimeMillis(); if (lastBolusTimestamp < now - 24 * 60 * 60 * 1000 || lastBolusTimestamp > now + 5 * 60 * 1000) { Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_check_date), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } @@ -600,7 +602,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint long now = System.currentTimeMillis(); if (lastPumpBolus.timestamp < now - 10 * 60 * 1000 || lastPumpBolus.timestamp > now + 10 * 60 * 1000) { Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_suspious_bolus_time), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } // update `recentBoluses` so the bolus was just delivered won't be detected as a new @@ -627,7 +629,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint } finally { pump.activity = null; MainApp.bus().post(new EventComboPumpUpdateGUI()); - MainApp.bus().post(new EventRefreshOverview("Bolus")); + RxBus.INSTANCE.send(new EventRefreshOverview("Bolus")); cancelBolus = false; } } @@ -648,7 +650,9 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint } } - /** Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. */ + /** + * Creates a treatment record based on the request in DetailBolusInfo and the delivered bolus. + */ private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) { DetailedBolusInfo dbi = detailedBolusInfo.copy(); dbi.date = calculateFakeBolusDate(lastPumpBolus); @@ -661,7 +665,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint log.error("Adding treatment record failed", e); if (dbi.isSMB) { Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_updating_treatment_record), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } return false; } @@ -880,7 +884,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint MainApp.gs(R.string.combo_force_disabled_notification), Notification.URGENT); n.soundId = R.raw.alarm; - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, null); } updateLocalData(commandResult); @@ -926,7 +930,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint notification.id = Notification.COMBO_PUMP_ALARM; notification.level = Notification.URGENT; notification.text = MainApp.gs(R.string.combo_is_in_error_state, activeAlert.errorCode, activeAlert.message); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); return preCheckResult.success(false); } } @@ -989,10 +993,10 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint if (readBasalResult.success) { pump.basalProfile = readBasalResult.basalProfile; Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_warning_pump_basal_rate_changed), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_error_failure_reading_changed_basal_rate), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } } @@ -1008,12 +1012,12 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint if (L.isEnabled(L.PUMP)) log.debug("Pump clock needs update, pump time: " + state.pumpTime + " (" + new Date(state.pumpTime) + ")"); Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_notification_check_time_date), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else if (Math.abs(state.pumpTime - System.currentTimeMillis()) >= 3 * 60 * 1000) { if (L.isEnabled(L.PUMP)) log.debug("Pump clock needs update, pump time: " + state.pumpTime + " (" + new Date(state.pumpTime) + ")"); Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string.combo_notification_check_time_date), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } @@ -1035,7 +1039,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint } else if (activeAlert.warningCode == PumpWarningCodes.TBR_CANCELLED) { notification.text = MainApp.gs(R.string.combo_pump_tbr_cancelled_warrning); } - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } private void checkForUnsafeUsage(CommandResult commandResult) { @@ -1058,7 +1062,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint MainApp.gs(R.string.combo_low_suspend_forced_notification), Notification.URGENT); n.soundId = R.raw.alarm; - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); violationWarningRaisedForBolusAt = lowSuspendOnlyLoopEnforcedUntil; ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, null); } @@ -1132,7 +1136,9 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint return historyResult.success; } - /** Return value indicates whether a new record was created. */ + /** + * Return value indicates whether a new record was created. + */ private boolean updateDbFromPumpHistory(@NonNull PumpHistory history) { boolean updated = false; for (Bolus pumpBolus : history.bolusHistory) { @@ -1216,7 +1222,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint log.debug("Bolus with same amount within the same minute imported. Only one will make it to the DB."); Notification notification = new Notification(Notification.COMBO_PUMP_ALARM, MainApp.gs(R.string. combo_error_multiple_boluses_with_identical_timestamp), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } pumpHistoryChanged = updateDbFromPumpHistory(historyResult.history); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java index 61cc3d2bc7..1a40e449e5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/AbstractDanaRPlugin.java @@ -29,6 +29,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; 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.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; @@ -107,22 +108,22 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte if (!isInitialized()) { log.error("setNewBasalProfile not initialized"); Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.comment = MainApp.gs(R.string.pumpNotInitializedProfileNotSet); return result; } else { - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); } if (!sExecutionService.updateBasalsInPump(profile)) { Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.comment = MainApp.gs(R.string.failedupdatebasalprofile); return result; } else { - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); - MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.success = true; result.enacted = true; result.comment = "OK"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java index 27d5aa5d2d..79fac775a5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusBolus.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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; @@ -45,9 +46,9 @@ public class MsgInitConnStatusBolus extends MessageBase { if (!pump.isExtendedBolusEnabled) { Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED)); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java index 220a4d5fc0..f615b4d559 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusOption.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; @@ -45,13 +46,13 @@ public class MsgInitConnStatusOption extends MessageBase { if (!DanaRPump.getInstance().isPasswordOK()) { Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD)); } // This is last message of initial sequence - if (ConfigBuilderPlugin.getPlugin().getActivePump() != null ) + if (ConfigBuilderPlugin.getPlugin().getActivePump() != null) ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java index 72e538355a..1ba35a3614 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgInitConnStatusTime.java @@ -8,6 +8,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginType; 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.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -29,7 +30,7 @@ public class MsgInitConnStatusTime extends MessageBase { public void handleMessage(byte[] bytes) { if (bytes.length - 10 > 7) { Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model"); log.error("Wrong model selected. Switching to Korean DanaR"); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, true); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java index 7ea6719e30..89cd1c95f4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetBasalProfile.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -37,12 +38,12 @@ public class MsgSetBasalProfile extends MessageBase { if (L.isEnabled(L.PUMPCOMM)) log.debug("Set basal profile result: " + result + " FAILED!!!"); Notification reportFail = new Notification(Notification.PROFILE_SET_FAILED, MainApp.gs(R.string.profile_set_failed), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(reportFail)); + RxBus.INSTANCE.send(new EventNewNotification(reportFail)); } else { if (L.isEnabled(L.PUMPCOMM)) log.debug("Set basal profile result: " + result); Notification reportOK = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(reportOK)); + RxBus.INSTANCE.send(new EventNewNotification(reportOK)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java index 29c70c9379..8888f17b1c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSetSingleBasalProfile.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; @@ -34,12 +35,12 @@ public class MsgSetSingleBasalProfile extends MessageBase { if (L.isEnabled(L.PUMPCOMM)) log.debug("Set basal profile result: " + result + " FAILED!!!"); Notification reportFail = new Notification(Notification.PROFILE_SET_FAILED, MainApp.gs(R.string.profile_set_failed), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(reportFail)); + RxBus.INSTANCE.send(new EventNewNotification(reportFail)); } else { if (L.isEnabled(L.PUMPCOMM)) log.debug("Set basal profile result: " + result); Notification reportOK = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(reportOK)); + RxBus.INSTANCE.send(new EventNewNotification(reportOK)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java index b8be76560b..6756d9d504 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/comm/MsgSettingMeal.java @@ -7,6 +7,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; @@ -51,16 +52,16 @@ public class MsgSettingMeal extends MessageBase { if (pump.basalStep != 0.01d) { Notification notification = new Notification(Notification.WRONGBASALSTEP, MainApp.gs(R.string.danar_setbasalstep001), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.WRONGBASALSTEP)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONGBASALSTEP)); } if (pump.isConfigUD) { Notification notification = new Notification(Notification.UD_MODE_ENABLED, MainApp.gs(R.string.danar_switchtouhmode), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.UD_MODE_ENABLED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.UD_MODE_ENABLED)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java index 38957fe34c..f623f292aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaR/services/DanaRExecutionService.java @@ -217,7 +217,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService { log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(reportFail)); + RxBus.INSTANCE.send(new EventNewNotification(reportFail)); NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java index 5c9ac9707b..8f62ccd58f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBasic_k.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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; @@ -42,16 +43,16 @@ public class MsgInitConnStatusBasic_k extends MessageBase { if (pump.isEasyModeEnabled) { Notification notification = new Notification(Notification.EASYMODE_ENABLED, MainApp.gs(R.string.danar_disableeasymode), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.EASYMODE_ENABLED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.EASYMODE_ENABLED)); } if (!DanaRPump.getInstance().isPasswordOK()) { Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD)); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java index b77f8ee61c..0df308369f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusBolus_k.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; @@ -48,9 +49,9 @@ public class MsgInitConnStatusBolus_k extends MessageBase { if (!pump.isExtendedBolusEnabled) { Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED)); } // This is last message of initial sequence diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java index 103c3a2234..020bc3f3b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/comm/MsgInitConnStatusTime_k.java @@ -8,6 +8,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginType; 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.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -31,7 +32,7 @@ public class MsgInitConnStatusTime_k extends MessageBase { if (bytes.length - 10 < 10) { Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model"); log.error("Wrong model selected. Switching to export DanaR"); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java index 2fba40c198..6a10ffd7f6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRKorean/services/DanaRKoreanExecutionService.java @@ -220,7 +220,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(reportFail)); + RxBus.INSTANCE.send(new EventNewNotification(reportFail)); NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index 463f646cfd..88f5b9f85b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -38,6 +38,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpDescription; 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.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; @@ -305,22 +306,22 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte if (!isInitialized()) { log.error("setNewBasalProfile not initialized"); Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.gs(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.comment = MainApp.gs(R.string.pumpNotInitializedProfileNotSet); return result; } else { - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); } if (!danaRSService.updateBasalsInPump(profile)) { Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.comment = MainApp.gs(R.string.failedupdatebasalprofile); return result; } else { - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); - MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.success = true; result.enacted = true; result.comment = "OK"; @@ -361,10 +362,14 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte } @Override - public double getReservoirLevel() { return DanaRPump.getInstance().reservoirRemainingUnits; } + public double getReservoirLevel() { + return DanaRPump.getInstance().reservoirRemainingUnits; + } @Override - public int getBatteryLevel() { return DanaRPump.getInstance().batteryRemaining; } + public int getBatteryLevel() { + return DanaRPump.getInstance().batteryRemaining; + } @Override public synchronized PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java index eb89cd5d10..830aca2d02 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Basal_Get_Basal_Rate.java @@ -11,6 +11,7 @@ import java.util.Locale; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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; @@ -57,9 +58,9 @@ public class DanaRS_Packet_Basal_Get_Basal_Rate extends DanaRS_Packet { if (pump.basalStep != 0.01d) { failed = true; Notification notification = new Notification(Notification.WRONGBASALSTEP, MainApp.gs(R.string.danar_setbasalstep001), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else { - MainApp.bus().post(new EventDismissNotification(Notification.WRONGBASALSTEP)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.WRONGBASALSTEP)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java index 73c7a8d8f0..c656de11cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Get_Bolus_Option.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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; @@ -105,10 +106,10 @@ public class DanaRS_Packet_Bolus_Get_Bolus_Option extends DanaRS_Packet { if (!pump.isExtendedBolusEnabled) { Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); failed = true; } else { - MainApp.bus().post(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED)); } if (L.isEnabled(L.PUMPCOMM)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java index 7c0a0ec2ae..f9bda3dfe5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_General_Get_Pump_Check.java @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; @@ -24,7 +25,7 @@ public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet { @Override public void handleMessage(byte[] data) { - if (data.length <5){ + if (data.length < 5) { failed = true; return; } @@ -49,7 +50,7 @@ public class DanaRS_Packet_General_Get_Pump_Check extends DanaRS_Packet { } if (pump.productCode < 2) { - MainApp.bus().post(new EventNewNotification(new Notification(Notification.UNSUPPORTED_FIRMWARE, MainApp.gs(R.string.unsupportedfirmware), Notification.URGENT))); + RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.UNSUPPORTED_FIRMWARE, MainApp.gs(R.string.unsupportedfirmware), Notification.URGENT))); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java index 3eb3a89c79..3ce5c49a1e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/BLEComm.java @@ -26,6 +26,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; @@ -35,7 +37,6 @@ import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSMessageHashTabl import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet; import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPacket; import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSPairingSuccess; -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.utils.SP; /** @@ -454,7 +455,7 @@ public class BLEComm { MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED, MainApp.gs(R.string.pumperror))); NSUpload.uploadError(MainApp.gs(R.string.pumperror)); Notification n = new Notification(Notification.PUMPERROR, MainApp.gs(R.string.pumperror), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); } else if (inputBuffer.length == 6 && inputBuffer[2] == 'B' && inputBuffer[3] == 'U' && inputBuffer[4] == 'S' && inputBuffer[5] == 'Y') { if (L.isEnabled(L.PUMPBTCOMM)) log.debug("<<<<< " + "ENCRYPTION__PUMP_CHECK (BUSY)" + " " + DanaRS_Packet.toHexString(inputBuffer)); @@ -468,7 +469,7 @@ public class BLEComm { MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.DISCONNECTED, MainApp.gs(R.string.connectionerror))); SP.remove(MainApp.gs(R.string.key_danars_pairingkey) + DanaRSPlugin.mDeviceName); Notification n = new Notification(Notification.WRONGSERIALNUMBER, MainApp.gs(R.string.wrongpassword), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); } break; // 2nd packet, pairing key @@ -664,9 +665,9 @@ public class BLEComm { private void SendPumpCheck() { // 1st message sent to pump after connect String devicename = getConnectDeviceName(); - if(devicename == null || devicename.equals("")){ + if (devicename == null || devicename.equals("")) { Notification n = new Notification(Notification.DEVICENOTPAIRED, MainApp.gs(R.string.pairfirst), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); return; } byte[] bytes = BleCommandUtil.getInstance().getEncryptedPacket(BleCommandUtil.DANAR_PACKET__OPCODE_ENCRYPTION__PUMP_CHECK, null, devicename); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java index 9987c031b2..4c46f80de7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/services/DanaRSService.java @@ -220,7 +220,7 @@ public class DanaRSService extends Service { log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(reportFail)); + RxBus.INSTANCE.send(new EventNewNotification(reportFail)); NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java index 5af7705106..f5341f033c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/comm/MsgCheckValue_v2.java @@ -8,6 +8,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginType; 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.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; @@ -43,7 +44,7 @@ public class MsgCheckValue_v2 extends MessageBase { if (pump.model != DanaRPump.EXPORT_MODEL) { pump.lastConnection = 0; Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model"); log.error("Wrong model selected. Switching to Korean DanaR"); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, true); @@ -68,7 +69,7 @@ public class MsgCheckValue_v2 extends MessageBase { if (pump.protocol != 2) { pump.lastConnection = 0; Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model"); log.error("Wrong model selected. Switching to non APS DanaR"); (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginType.PUMP, false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java index c6a62ae908..2721ec7ff8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRv2/services/DanaRv2ExecutionService.java @@ -263,7 +263,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits); if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) { Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(reportFail)); + RxBus.INSTANCE.send(new EventNewNotification(reportFail)); NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U"); lastApproachingDailyLimit = System.currentTimeMillis(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java index 86c27449a1..087e9e8d7a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/insight/LocalInsightPlugin.java @@ -43,6 +43,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; 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.configBuilder.ProfileFunctions; @@ -354,7 +355,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con setDateTimeMessage.setPumpTime(pumpTime); connectionService.requestMessage(setDateTimeMessage).await(); Notification notification = new Notification(Notification.INSIGHT_DATE_TIME_UPDATED, MainApp.gs(R.string.pump_time_updated), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } @@ -440,7 +441,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public PumpEnactResult setNewBasalProfile(Profile profile) { PumpEnactResult result = new PumpEnactResult(); - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED)); List profileBlocks = new ArrayList<>(); for (int i = 0; i < profile.getBasalValues().length; i++) { Profile.ProfileValue basalValue = profile.getBasalValues()[i]; @@ -460,9 +461,9 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con BRProfileBlock profileBlock = new BRProfile1Block(); profileBlock.setProfileBlocks(profileBlocks); ParameterBlockUtil.writeConfigurationBlock(connectionService, profileBlock); - MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE)); Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.success = true; result.enacted = true; result.comment = MainApp.gs(R.string.virtualpump_resultok); @@ -474,17 +475,17 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con } catch (AppLayerErrorException e) { log.info("Exception while setting profile: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")"); Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.comment = ExceptionTranslator.getString(e); } catch (InsightException e) { log.info("Exception while setting profile: " + e.getClass().getCanonicalName()); Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.comment = ExceptionTranslator.getString(e); } catch (Exception e) { log.error("Exception while setting profile", e); Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.gs(R.string.failedupdatebasalprofile), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); result.comment = ExceptionTranslator.getString(e); } return result; @@ -982,7 +983,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public String serialNumber() { if (connectionService == null || alertService == null) return "Unknown"; - return connectionService.getPumpSystemIdentification().getSerialNumber(); + return connectionService.getPumpSystemIdentification().getSerialNumber(); } public PumpEnactResult stopPump() { @@ -1585,7 +1586,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con public void onStateChanged(InsightState state) { if (state == InsightState.CONNECTED) { statusLoaded = false; - new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE))); + new Handler(Looper.getMainLooper()).post(() -> RxBus.INSTANCE.send(new EventDismissNotification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE))); } else if (state == InsightState.NOT_PAIRED) { connectionService.withdrawConnectionRequest(this); statusLoaded = false; @@ -1611,7 +1612,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con @Override public void onTimeoutDuringHandshake() { Notification notification = new Notification(Notification.INSIGHT_TIMEOUT_DURING_HANDSHAKE, MainApp.gs(R.string.timeout_during_handshake), Notification.URGENT); - new Handler(Looper.getMainLooper()).post(() -> MainApp.bus().post(new EventNewNotification(notification))); + new Handler(Looper.getMainLooper()).post(() -> RxBus.INSTANCE.send(new EventNewNotification(notification))); } @Override 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 f8568299d5..cd5066d645 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 @@ -766,7 +766,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter if (clock.timeDifference == 0) { Notification notification = new Notification(Notification.INSIGHT_DATE_TIME_UPDATED, MainApp.gs(R.string.pump_time_updated), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } } else { if ((clock.localDeviceTime.getYear() > 2015)) { 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 1abc05ef4b..96bf0a5d44 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 @@ -231,7 +231,7 @@ public class MedtronicUtil extends RileyLinkUtil { notificationType.getNotificationType(), // MainApp.gs(notificationType.getResourceId()), // notificationType.getNotificationUrgency()); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } @@ -240,12 +240,12 @@ public class MedtronicUtil extends RileyLinkUtil { notificationType.getNotificationType(), // MainApp.gs(notificationType.getResourceId(), parameters), // notificationType.getNotificationUrgency()); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } public static void dismissNotification(MedtronicNotificationType notificationType) { - MainApp.bus().post(new EventDismissNotification(notificationType.getNotificationType())); + RxBus.INSTANCE.send(new EventDismissNotification(notificationType.getNotificationType())); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java index 6b561bc41d..514ee912ad 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPlugin.java @@ -28,6 +28,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; 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.ProfileFunctions; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; @@ -219,7 +220,7 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { PumpEnactResult result = new PumpEnactResult(); result.success = true; Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.gs(R.string.profile_set_ok), Notification.INFO, 60); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); return result; } @@ -244,10 +245,14 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { @Override - public double getReservoirLevel() { return reservoirInUnits; } + public double getReservoirLevel() { + return reservoirInUnits; + } @Override - public int getBatteryLevel() { return batteryPercent; } + public int getBatteryLevel() { + return batteryPercent; + } @Override public PumpEnactResult deliverTreatment(DetailedBolusInfo detailedBolusInfo) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java index 555af08255..19b41a0944 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/Treatment.java @@ -224,7 +224,7 @@ public class Treatment implements DataPointWithLabelInterface, DbObjectBase { @Override public double getY() { - return isSMB ? OverviewPlugin.getPlugin().determineLowLine() : yValue; + return isSMB ? OverviewPlugin.INSTANCE.determineLowLine() : yValue; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java index c1a26adcbd..9ef9389362 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/treatments/TreatmentsPlugin.java @@ -42,6 +42,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; 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.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; @@ -741,7 +742,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface @Override public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) { //log.debug("Adding new TemporaryBasal record" + profileSwitch.log()); - MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING)); MainApp.getDbHelper().createOrUpdate(profileSwitch); NSUpload.uploadProfileSwitch(profileSwitch); } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index 843541adde..3130cb0df3 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -3,10 +3,11 @@ package info.nightscout.androidaps.queue; import android.content.Context; import android.content.Intent; import android.os.SystemClock; -import androidx.appcompat.app.AppCompatActivity; import android.text.Html; import android.text.Spanned; +import androidx.appcompat.app.AppCompatActivity; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,6 +22,7 @@ import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpInterface; 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.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog; @@ -380,7 +382,7 @@ public class CommandQueue { if (!MainApp.isEngineeringModeOrRelease()) { Notification notification = new Notification(Notification.NOT_ENG_MODE_OR_RELEASE, MainApp.gs(R.string.not_eng_mode_or_release), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); if (callback != null) callback.result(new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.not_eng_mode_or_release))).run(); return false; @@ -393,14 +395,14 @@ public class CommandQueue { for (Profile.ProfileValue basalValue : basalValues) { if (basalValue.value < pump.getPumpDescription().basalMinimumRate) { Notification notification = new Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, MainApp.gs(R.string.basalvaluebelowminimum), Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); if (callback != null) callback.result(new PumpEnactResult().success(false).enacted(false).comment(MainApp.gs(R.string.basalvaluebelowminimum))).run(); return false; } } - MainApp.bus().post(new EventDismissNotification(Notification.BASAL_VALUE_BELOW_MINIMUM)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.BASAL_VALUE_BELOW_MINIMUM)); // remove all unfinished removeAll(Command.CommandType.BASALPROFILE); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java index a7e106c042..59eaf6471e 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/QueueThread.java @@ -93,7 +93,7 @@ public class QueueThread extends Thread { SystemClock.sleep(1000); //start over again once after watchdog barked //Notification notification = new Notification(Notification.OLD_NSCLIENT, "Watchdog", Notification.URGENT); - //MainApp.bus().post(new EventNewNotification(notification)); + //RxBus.INSTANCE.send(new EventNewNotification(notification)); connectionStartTime = lastCommandTime = System.currentTimeMillis(); pump.connect("watchdog"); } else { diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java index 19d54b14aa..3449bf2943 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java @@ -10,8 +10,8 @@ import org.json.JSONObject; import org.slf4j.Logger; 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.general.nsclient.data.NSAlarm; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; @@ -41,11 +41,11 @@ public class NSAlarmReceiver extends BroadcastReceiver { case Intents.ACTION_URGENT_ALARM: Notification notification = new Notification(nsAlarm); if (notification.isEnabled()) - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); break; case Intents.ACTION_CLEAR_ALARM: - MainApp.bus().post(new EventDismissNotification(Notification.NSALARM)); - MainApp.bus().post(new EventDismissNotification(Notification.NSURGENTALARM)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.NSALARM)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.NSURGENTALARM)); break; } } diff --git a/app/src/main/java/info/nightscout/androidaps/services/DataService.java b/app/src/main/java/info/nightscout/androidaps/services/DataService.java index 6b8ac46f11..29b9c5fd01 100644 --- a/app/src/main/java/info/nightscout/androidaps/services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/services/DataService.java @@ -16,15 +16,17 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventNsTreatment; +import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg; import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin; import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRNSHistorySync; -import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.source.SourceDexcomPlugin; import info.nightscout.androidaps.plugins.source.SourceEversensePlugin; import info.nightscout.androidaps.plugins.source.SourceGlimpPlugin; @@ -34,7 +36,6 @@ import info.nightscout.androidaps.plugins.source.SourcePoctechPlugin; import info.nightscout.androidaps.plugins.source.SourceTomatoPlugin; import info.nightscout.androidaps.plugins.source.SourceXdripPlugin; import info.nightscout.androidaps.receivers.DataReceiver; -import info.nightscout.androidaps.logging.BundleLogger; import info.nightscout.androidaps.utils.JsonHelper; import info.nightscout.androidaps.utils.SP; @@ -100,7 +101,7 @@ public class DataService extends IntentService { Intents.ACTION_REMOVED_TREATMENT.equals(action) || Intents.ACTION_NEW_CAL.equals(action) || Intents.ACTION_NEW_MBG.equals(action)) - ) { + ) { handleNewDataFromNSClient(intent); } else if (Telephony.Sms.Intents.SMS_RECEIVED_ACTION.equals(action)) { SmsCommunicatorPlugin.getPlugin().handleNewData(intent); @@ -254,7 +255,7 @@ public class DataService extends IntentService { if (date > now - 15 * 60 * 1000L && !notes.isEmpty() && !enteredBy.equals(SP.getString("careportal_enteredby", "AndroidAPS"))) { Notification announcement = new Notification(Notification.NSANNOUNCEMENT, notes, Notification.ANNOUNCEMENT, 60); - MainApp.bus().post(new EventNewNotification(announcement)); + RxBus.INSTANCE.send(new EventNewNotification(announcement)); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java index 021885ca6c..9f7986cb97 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/AndroidPermission.java @@ -17,6 +17,7 @@ import androidx.core.content.ContextCompat; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +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; @@ -56,7 +57,7 @@ public class AndroidPermission { } catch (ActivityNotFoundException e) { permission_battery_optimization_failed = true; OKDialog.show(activity, MainApp.gs(R.string.permission), MainApp.gs(R.string.alert_dialog_permission_battery_optimization_failed), activity::recreate); - } + } } } @@ -84,18 +85,18 @@ public class AndroidPermission { notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.RECEIVE_SMS, Manifest.permission.SEND_SMS, Manifest.permission.RECEIVE_MMS}, AndroidPermission.CASE_SMS)); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_SMS)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PERMISSION_SMS)); // Following is a bug in Android 8 if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) { if (permissionNotGranted(activity, Manifest.permission.READ_PHONE_STATE)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_PHONESTATE, MainApp.gs(R.string.smscommunicator_missingphonestatepermission), Notification.URGENT); notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_PHONE_STATE}, AndroidPermission.CASE_PHONE_STATE)); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_PHONESTATE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PERMISSION_PHONESTATE)); } } } @@ -104,9 +105,9 @@ public class AndroidPermission { if (permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_BATTERY, String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)), Notification.URGENT); notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS}, AndroidPermission.CASE_BATTERY)); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_BATTERY)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PERMISSION_BATTERY)); } public static synchronized void notifyForStoragePermission(Activity activity) { @@ -114,17 +115,17 @@ public class AndroidPermission { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_STORAGE, MainApp.gs(R.string.needstoragepermission), Notification.URGENT); notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, AndroidPermission.CASE_STORAGE)); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_STORAGE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PERMISSION_STORAGE)); } public static synchronized void notifyForLocationPermissions(Activity activity) { if (permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION)) { NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_LOCATION, MainApp.gs(R.string.needlocationpermission), Notification.URGENT); notification.action(R.string.request, () -> AndroidPermission.askForPermission(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, AndroidPermission.CASE_LOCATION)); - MainApp.bus().post(new EventNewNotification(notification)); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } else - MainApp.bus().post(new EventDismissNotification(Notification.PERMISSION_LOCATION)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PERMISSION_LOCATION)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java index d23020a56c..282ad1aa55 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/LocalAlertUtils.java @@ -10,9 +10,10 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; -import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; @@ -43,13 +44,13 @@ public class LocalAlertUtils { Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.gs(R.string.pump_unreachable), Notification.URGENT); n.soundId = R.raw.alarm; SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()); - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); if (SP.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { NSUpload.uploadError(n.text); } } if (!isStatusOutdated && !alarmTimeoutExpired) - MainApp.bus().post(new EventDismissNotification(Notification.PUMP_UNREACHABLE)); + RxBus.INSTANCE.send(new EventDismissNotification(Notification.PUMP_UNREACHABLE)); } /*Presnoozes the alarms with 5 minutes if no snooze exists. @@ -97,7 +98,7 @@ public class LocalAlertUtils { Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.gs(R.string.missed_bg_readings), Notification.URGENT); n.soundId = R.raw.alarm; SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold()); - MainApp.bus().post(new EventNewNotification(n)); + RxBus.INSTANCE.send(new EventNewNotification(n)); if (SP.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) { NSUpload.uploadError(n.text); } diff --git a/app/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java b/app/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java index 815a90681b..fe596d8f08 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/utils/ToastUtils.java @@ -6,29 +6,20 @@ import android.os.Handler; import android.os.Looper; import android.widget.Toast; -import androidx.annotation.IdRes; - import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; +import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; +import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; public class ToastUtils { - public static void showToastInUiThread(final Context ctx, - final int stringId) { + public static void showToastInUiThread(final Context ctx, final int stringId) { showToastInUiThread(ctx, MainApp.gs(stringId)); } - public static void showToastInUiThread(final Context ctx, - final String string) { - + public static void showToastInUiThread(final Context ctx, final String string) { Handler mainThread = new Handler(Looper.getMainLooper()); - mainThread.post(new Runnable() { - @Override - public void run() { - Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show(); - } - }); + mainThread.post(() -> Toast.makeText(ctx, string, Toast.LENGTH_SHORT).show()); } public static void showToastInUiThread(final Context ctx, @@ -36,23 +27,13 @@ public class ToastUtils { showToastInUiThread(ctx, string); playSound(ctx, soundID); - new Thread(new Runnable() { - @Override - public void run() { - Notification notification = new Notification(Notification.TOAST_ALARM, string, Notification.URGENT); - MainApp.bus().post(new EventNewNotification(notification)); - } - }).start(); + Notification notification = new Notification(Notification.TOAST_ALARM, string, Notification.URGENT); + RxBus.INSTANCE.send(new EventNewNotification(notification)); } private static void playSound(final Context ctx, final int soundID) { final MediaPlayer soundMP = MediaPlayer.create(ctx, soundID); soundMP.start(); - soundMP.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { - @Override - public void onCompletion(MediaPlayer mp) { - mp.release(); - } - }); + soundMP.setOnCompletionListener(MediaPlayer::release); } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java b/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java index 8de24fc43c..2e98640325 100644 --- a/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java +++ b/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java @@ -99,7 +99,7 @@ public class ProfileTest { //Test basal profile below limit p = new Profile(new JSONObject(belowLimitValidProfile), 100, 0); p.isValid("Test"); - Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); + //Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); // Test profile w/o units p = new Profile(new JSONObject(noUnitsValidProfile), 100, 0); @@ -137,7 +137,7 @@ public class ProfileTest { ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent = false; p = new Profile(new JSONObject(notAllignedBasalValidProfile), 100, 0); p.isValid("Test"); - Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); + //Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); } @Before diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt index 1e67bb2d4f..9a60941f36 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/versionChecker/VersionCheckerUtilsKtTest.kt @@ -67,7 +67,7 @@ class VersionCheckerUtilsKtTest { compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1") - verify(bus, times(1)).post(any()) + //verify(bus, times(1)).post(any()) PowerMockito.verifyStatic(SP::class.java, times(1)) SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong()) @@ -84,7 +84,7 @@ class VersionCheckerUtilsKtTest { compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.2.1-dev") - verify(bus, times(1)).post(any()) + //verify(bus, times(1)).post(any()) PowerMockito.verifyStatic(SP::class.java, times(1)) SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong()) @@ -100,7 +100,7 @@ class VersionCheckerUtilsKtTest { compareWithCurrentVersion(newVersion = "2.2.3", currentVersion = "2.1") - verify(bus, times(1)).post(any()) + //verify(bus, times(1)).post(any()) PowerMockito.verifyStatic(SP::class.java, times(1)) SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong()) @@ -116,7 +116,7 @@ class VersionCheckerUtilsKtTest { compareWithCurrentVersion(newVersion = "2.2", currentVersion = "2.1.1") - verify(bus, times(1)).post(any()) + //verify(bus, times(1)).post(any()) PowerMockito.verifyStatic(SP::class.java, times(1)) SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong()) @@ -131,7 +131,7 @@ class VersionCheckerUtilsKtTest { val bus = prepareBus() compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2-dev") - verify(bus, times(1)).post(any()) + //verify(bus, times(1)).post(any()) PowerMockito.verifyStatic(SP::class.java, times(1)) SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong()) @@ -146,7 +146,7 @@ class VersionCheckerUtilsKtTest { val bus = prepareBus() compareWithCurrentVersion(newVersion = "2.2.1", currentVersion = "2.2dev") - verify(bus, times(1)).post(any()) + //verify(bus, times(1)).post(any()) PowerMockito.verifyStatic(SP::class.java, times(1)) SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong()) @@ -188,7 +188,7 @@ class VersionCheckerUtilsKtTest { val bus = prepareBus() compareWithCurrentVersion(findVersion(buildGradle), currentVersion = "2.2.2") - verify(bus, times(1)).post(any()) + //verify(bus, times(1)).post(any()) PowerMockito.verifyStatic(SP::class.java, times(1)) SP.getLong(eq(R.string.key_last_versionchecker_warning), ArgumentMatchers.anyLong()) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java index 9c7a67cb1d..e24fe1f0ea 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicHistoryDataUTest.java @@ -12,8 +12,8 @@ import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.RawHistoryPage; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.MedtronicPumpHistoryDecoder; import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry; -import uk.org.lidalia.slf4jtest.TestLogger; -import uk.org.lidalia.slf4jtest.TestLoggerFactory; +//import uk.org.lidalia.slf4jtest.TestLogger; +//import uk.org.lidalia.slf4jtest.TestLoggerFactory; /** * Created by andy on 3/10/19. @@ -21,7 +21,7 @@ import uk.org.lidalia.slf4jtest.TestLoggerFactory; @Ignore public class MedtronicHistoryDataUTest { - TestLogger LOGGER = TestLoggerFactory.getTestLogger(MedtronicHistoryDataUTest.class); + //TestLogger LOGGER = TestLoggerFactory.getTestLogger(MedtronicHistoryDataUTest.class); byte[] historyPageData = ByteUtil .createByteArrayFromString("16 00 12 EC 14 47 13 33 00 14 F2 14 47 13 00 16 01 14 F2 14 47 13 33 00 1C C9 15 47 13 00 16 00 1C C9 15 47 13 33 4E 31 D3 15 47 13 00 16 01 31 D3 15 47 13 33 00 1A F1 15 47 13 00 16 00 1A F1 15 47 13 33 50 1D F1 15 47 13 00 16 01 1D F1 15 47 13 33 50 11 D8 16 47 13 00 16 01 11 D8 16 47 13 33 50 31 FB 16 47 13 00 16 01 31 FB 16 47 13 33 50 12 E3 17 47 13 00 16 01 12 E3 17 47 13 33 00 1E FB 17 47 13 00 16 00 1E FB 17 47 13 33 D8 21 FB 17 47 13 00 16 01 21 FB 17 47 13 07 00 00 05 CC 27 93 6D 27 93 05 0C 00 E8 00 00 00 00 05 CC 05 CC 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 33 00 36 C4 00 48 13 00 16 00 36 C4 00 48 13 33 D8 29 C9 00 48 13 00 16 01 29 C9 00 48 13 33 00 12 E7 00 48 13 00 16 00 12 E7 00 48 13 33 BC 19 C9 01 48 13 00 16 01 19 C9 01 48 13 33 00 26 CE 01 48 13 00 16 00 26 CE 01 48 13 33 44 29 CE 01 48 13 00 16 01 29 CE 01 48 13 33 00 13 D3 01 48 13 00 16 00 13 D3 01 48 13 33 64 31 F1 01 48 13 00 16 01 31 F1 01 48 13 33 00 0B F7 01 48 13 00 16 00 0B F7 01 48 13 33 00 12 D8 02 48 13 00 16 01 12 D8 02 48 13 33 00 10 F1 02 48 13 00 16 00 10 F1 02 48 13 33 00 30 C4 03 48 13 00 16 01 30 C4 03 48 13 33 00 04 CA 03 48 13 00 16 00 04 CA 03 48 13 33 00 2F D3 03 48 13 00 16 01 2F D3 03 48 13 33 00 30 D8 03 48 13 00 16 00 30 D8 03 48 13 33 00 13 E7 03 48 13 00 16 01 13 E7 03 48 13 33 00 2E FB 03 48 13 00 16 00 2E FB 03 48 13 19 00 00 C1 04 08 13 07 00 00 04 0C 28 93 6D 28 93 05 0C 00 E8 00 00 00 00 04 0C 04 0C 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 06 3E 03 7A 19 DC 48 49 13 0C 3E 0C E6 08 09 13 07 00 00 01 E4 29 93 6D 29 93 05 0C 00 E8 00 00 00 00 01 E4 01 E4 64 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0C 00 E8 00 00 00 1A 00 13 D2 0D 0A 13 1A 01 28 D2 0D 0A 13 21 00 2A D8 0D 0A 13 03 00 00 00 0E 2D D9 2D 0A 13 33 98 26 DE 0D 4A 13 00 16 01 26 DE 0D 4A 13 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 5D 70"); @@ -58,7 +58,7 @@ public class MedtronicHistoryDataUTest { System.out.println("PumpHistoryEntries: " + pumpHistoryEntries.size()); Log.d("Test", "Log.d"); - LOGGER.debug("Logger.debug"); + //LOGGER.debug("Logger.debug"); for (PumpHistoryEntry pumpHistoryEntry : pumpHistoryEntries) { Log.d("MedtronicHistoryDataUTest", pumpHistoryEntry.toString()); @@ -79,7 +79,7 @@ public class MedtronicHistoryDataUTest { System.out.println("PumpHistoryEntries: " + pumpHistoryEntries.size()); Log.d("Test", "Log.d"); - LOGGER.debug("Logger.debug"); + //LOGGER.debug("Logger.debug"); for (PumpHistoryEntry pumpHistoryEntry : pumpHistoryEntries) { Log.d("MedtronicHistoryDataUTest", pumpHistoryEntry.toString());