Events to RxBus
This commit is contained in:
parent
4ed8f0a1e1
commit
1aa8771f4d
16 changed files with 68 additions and 145 deletions
|
@ -33,7 +33,6 @@ import com.google.android.material.navigation.NavigationView;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import com.joanzapata.iconify.Iconify;
|
import com.joanzapata.iconify.Iconify;
|
||||||
import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -45,7 +44,6 @@ import info.nightscout.androidaps.activities.PreferencesActivity;
|
||||||
import info.nightscout.androidaps.activities.SingleFragmentActivity;
|
import info.nightscout.androidaps.activities.SingleFragmentActivity;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventFeatureRunning;
|
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
@ -192,11 +190,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
AndroidPermission.notifyForLocationPermissions(this);
|
AndroidPermission.notifyForLocationPermissions(this);
|
||||||
AndroidPermission.notifyForSMSPermissions(this);
|
AndroidPermission.notifyForSMSPermissions(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
MainApp.bus().
|
|
||||||
|
|
||||||
post(new EventFeatureRunning(EventFeatureRunning.Feature.MAIN));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
|
||||||
|
|
||||||
/** Base class for all events posted on the event bus. */
|
|
||||||
public abstract class Event {
|
|
||||||
static {
|
|
||||||
ReflectionToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return ReflectionToStringBuilder.toString(this);
|
|
||||||
}
|
|
||||||
}
|
|
18
app/src/main/java/info/nightscout/androidaps/events/Event.kt
Normal file
18
app/src/main/java/info/nightscout/androidaps/events/Event.kt
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle
|
||||||
|
|
||||||
|
/** Base class for all events posted on the event bus. */
|
||||||
|
abstract class Event {
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return ReflectionToStringBuilder.toString(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
ReflectionToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 23.01.2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventAppInitialized extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventAppInitialized : Event()
|
|
@ -1,21 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 07/02/17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventBolusRequested extends Event {
|
|
||||||
private double amount;
|
|
||||||
|
|
||||||
public EventBolusRequested (double amount){
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getAmount() {
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAmount(double amount) {
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventBolusRequested(var amount: Double) : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 13.02.2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventCustomCalculationFinished extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventCustomCalculationFinished : Event()
|
|
@ -1,36 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by jamorham on 07/02/2018.
|
|
||||||
*
|
|
||||||
* Event to indicate that an app feature is being used, for example bolus wizard being opened
|
|
||||||
*
|
|
||||||
* The purpose this has been created for is to enable opportunistic connection to the pump
|
|
||||||
* so that it is already connected before the user wishes to enact a pump function
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventFeatureRunning extends Event {
|
|
||||||
|
|
||||||
private Feature feature = Feature.UNKNOWN;
|
|
||||||
|
|
||||||
public EventFeatureRunning() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventFeatureRunning(Feature feature) {
|
|
||||||
this.feature = feature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Feature getFeature() {
|
|
||||||
return feature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Feature {
|
|
||||||
UNKNOWN,
|
|
||||||
MAIN,
|
|
||||||
WIZARD,
|
|
||||||
|
|
||||||
JUST_ADD_MORE_HERE
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
||||||
|
@ -83,7 +84,7 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
upgradeSettings();
|
upgradeSettings();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
setAlwaysEnabledPluginsEnabled();
|
setAlwaysEnabledPluginsEnabled();
|
||||||
MainApp.bus().post(new EventAppInitialized());
|
RxBus.INSTANCE.send(new EventAppInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAlwaysEnabledPluginsEnabled() {
|
private void setAlwaysEnabledPluginsEnabled() {
|
||||||
|
|
|
@ -16,7 +16,6 @@ import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.data.Profile
|
import info.nightscout.androidaps.data.Profile
|
||||||
import info.nightscout.androidaps.db.BgReading
|
import info.nightscout.androidaps.db.BgReading
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper
|
import info.nightscout.androidaps.db.DatabaseHelper
|
||||||
import info.nightscout.androidaps.events.EventFeatureRunning
|
|
||||||
import info.nightscout.androidaps.interfaces.Constraint
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
@ -68,11 +67,6 @@ class WizardDialog : DialogFragment() {
|
||||||
this.parentContext = null
|
this.parentContext = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
|
||||||
super.onResume()
|
|
||||||
MainApp.bus().post(EventFeatureRunning(EventFeatureRunning.Feature.WIZARD))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
override fun onSaveInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onSaveInstanceState(savedInstanceState)
|
super.onSaveInstanceState(savedInstanceState)
|
||||||
savedInstanceState.putDouble("treatments_wizard_bginput", treatments_wizard_bginput.value)
|
savedInstanceState.putDouble("treatments_wizard_bginput", treatments_wizard_bginput.value)
|
||||||
|
|
|
@ -120,8 +120,7 @@ public class WearPlugin extends PluginBase {
|
||||||
resendDataToWatch();
|
resendDataToWatch();
|
||||||
// status may be formated differently
|
// status may be formated differently
|
||||||
sendDataToWatch(true, false, false);
|
sendDataToWatch(true, false, false);
|
||||||
},
|
}, FabricPrivacy::logException
|
||||||
FabricPrivacy::logException
|
|
||||||
));
|
));
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventRefreshOverview.class)
|
.toObservable(EventRefreshOverview.class)
|
||||||
|
@ -129,8 +128,18 @@ public class WearPlugin extends PluginBase {
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
if (WatchUpdaterService.shouldReportLoopStatus(LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)))
|
if (WatchUpdaterService.shouldReportLoopStatus(LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)))
|
||||||
sendDataToWatch(true, false, false);
|
sendDataToWatch(true, false, false);
|
||||||
},
|
}, FabricPrivacy::logException
|
||||||
FabricPrivacy::logException
|
));
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventBolusRequested.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
String status = String.format(MainApp.gs(R.string.bolusrequested), event.getAmount());
|
||||||
|
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
||||||
|
intent.putExtra("progresspercent", 0);
|
||||||
|
intent.putExtra("progressstatus", status);
|
||||||
|
ctx.startService(intent);
|
||||||
|
}, FabricPrivacy::logException
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,16 +201,6 @@ public class WearPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventBolusRequested ev) {
|
|
||||||
String status = String.format(MainApp.gs(R.string.bolusrequested), ev.getAmount());
|
|
||||||
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
|
|
||||||
intent.putExtra("progresspercent", 0);
|
|
||||||
intent.putExtra("progressstatus", status);
|
|
||||||
ctx.startService(intent);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
|
||||||
if (ev.result == null) return;
|
if (ev.result == null) return;
|
||||||
|
|
|
@ -8,8 +8,6 @@ import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
|
@ -88,7 +86,6 @@ public class StatuslinePlugin extends PluginBase {
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
MainApp.bus().register(this);
|
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventRefreshOverview.class)
|
.toObservable(EventRefreshOverview.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
|
@ -134,12 +131,17 @@ public class StatuslinePlugin extends PluginBase {
|
||||||
.subscribe(event -> sendStatus(),
|
.subscribe(event -> sendStatus(),
|
||||||
FabricPrivacy::logException
|
FabricPrivacy::logException
|
||||||
));
|
));
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventAppInitialized.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> sendStatus(),
|
||||||
|
FabricPrivacy::logException
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
sendStatus();
|
sendStatus();
|
||||||
}
|
}
|
||||||
|
@ -211,11 +213,4 @@ public class StatuslinePlugin extends PluginBase {
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventAppInitialized ev) {
|
|
||||||
sendStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
basalDataTable = new LongSparseArray<>();
|
basalDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event);
|
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event);
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
// EventNewBG
|
// EventNewBG
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
|
@ -149,9 +149,9 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
stopCalculation("onEventNewBG");
|
stopCalculation("onEventNewBG");
|
||||||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
// EventPreferenceChange
|
// EventPreferenceChange
|
||||||
disposable.add(RxBus.INSTANCE
|
disposable.add(RxBus.INSTANCE
|
||||||
.toObservable(EventPreferenceChange.class)
|
.toObservable(EventPreferenceChange.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
|
@ -179,7 +179,20 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, true, event);
|
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, true, event);
|
||||||
}
|
}
|
||||||
}, FabricPrivacy::logException)
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
// EventAppInitialized
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventAppInitialized.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
if (this != getPlugin()) {
|
||||||
|
if (L.isEnabled(L.AUTOSENS))
|
||||||
|
log.debug("Ignoring event for non default instance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event);
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,18 +737,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
public void stopCalculation(String from) {
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public void onEventAppInitialized(EventAppInitialized ev) {
|
|
||||||
if (this != getPlugin()) {
|
|
||||||
if (L.isEnabled(L.AUTOSENS))
|
|
||||||
log.debug("Ignoring event for non default instance");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopCalculation(String from) {
|
|
||||||
if (thread != null && thread.getState() != Thread.State.TERMINATED) {
|
if (thread != null && thread.getState() != Thread.State.TERMINATED) {
|
||||||
stopCalculationTrigger = true;
|
stopCalculationTrigger = true;
|
||||||
if (L.isEnabled(L.AUTOSENS))
|
if (L.isEnabled(L.AUTOSENS))
|
||||||
|
|
|
@ -249,7 +249,7 @@ public class CommandQueue {
|
||||||
// not when the Bolus command is starting. The command closes the dialog upon completion).
|
// not when the Bolus command is starting. The command closes the dialog upon completion).
|
||||||
showBolusProgressDialog(detailedBolusInfo.insulin, detailedBolusInfo.context);
|
showBolusProgressDialog(detailedBolusInfo.insulin, detailedBolusInfo.context);
|
||||||
// Notify Wear about upcoming bolus
|
// Notify Wear about upcoming bolus
|
||||||
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
|
RxBus.INSTANCE.send(new EventBolusRequested(detailedBolusInfo.insulin));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue