Events to RxBus
This commit is contained in:
parent
64f16c5a7b
commit
0f792dc092
19 changed files with 190 additions and 195 deletions
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.events.EventCustomCalculationFinished;
|
||||
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.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
|
||||
|
@ -39,12 +40,15 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorP
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public class HistoryBrowseActivity extends NoSplashActivity {
|
||||
private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class);
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
ImageButton chartButton;
|
||||
|
||||
|
@ -166,6 +170,7 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
|||
public void onPause() {
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
iobCobCalculatorPlugin.stopCalculation("onPause");
|
||||
}
|
||||
|
||||
|
@ -173,6 +178,18 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> {
|
||||
if (event.getCause() == eventCustomCalculationFinished) {
|
||||
log.debug("EventAutosensCalculationFinished");
|
||||
synchronized (HistoryBrowseActivity.this) {
|
||||
updateGUI("EventAutosensCalculationFinished");
|
||||
}
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// set start of current day
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
|
@ -193,18 +210,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
|||
iobCobCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished e) {
|
||||
if (e.getCause() == eventCustomCalculationFinished) {
|
||||
log.debug("EventAutosensCalculationFinished");
|
||||
runOnUiThread(() -> {
|
||||
synchronized (HistoryBrowseActivity.this) {
|
||||
updateGUI("EventAutosensCalculationFinished");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventIobCalculationProgress e) {
|
||||
runOnUiThread(() -> {
|
||||
|
|
|
@ -412,7 +412,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void run() {
|
||||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("Firing EventNewBg");
|
||||
MainApp.bus().post(new EventNewBG(bgReading));
|
||||
RxBus.INSTANCE.send(new EventNewBG(bgReading));
|
||||
scheduledBgPost = null;
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.06.2016.
|
||||
*/
|
||||
public class EventNewBG extends EventLoop {
|
||||
@Nullable
|
||||
public final BgReading bgReading;
|
||||
|
||||
public EventNewBG(BgReading bgReading) {
|
||||
this.bgReading = bgReading;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
import info.nightscout.androidaps.db.BgReading
|
||||
|
||||
class EventNewBG(val bgReading: BgReading?) : EventLoop()
|
|
@ -1,7 +0,0 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 04.06.2016.
|
||||
*/
|
||||
public class EventNewBasalProfile extends Event {
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
class EventNewBasalProfile : Event()
|
|
@ -129,6 +129,30 @@ public class LoopPlugin extends PluginBase {
|
|||
invoke("EventTempTargetChange", true);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
/**
|
||||
* This method is triggered once autosens calculation has completed, so the LoopPlugin
|
||||
* has current data to work with. However, autosens calculation can be triggered by multiple
|
||||
* sources and currently only a new BG should trigger a loop run. Hence we return early if
|
||||
* the event causing the calculation is not EventNewBg.
|
||||
* <p>
|
||||
*/
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
// Autosens calculation not triggered by a new BG
|
||||
if (!(event.getCause() instanceof EventNewBG)) return;
|
||||
|
||||
BgReading bgReading = DatabaseHelper.actualBg();
|
||||
// BG outdated
|
||||
if (bgReading == null) return;
|
||||
// already looped with that value
|
||||
if (bgReading.date <= lastBgTriggeredRun) return;
|
||||
|
||||
lastBgTriggeredRun = bgReading.date;
|
||||
invoke("AutosenseCalculation for " + bgReading, true);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
private void createNotificationChannel() {
|
||||
|
@ -156,33 +180,6 @@ public class LoopPlugin extends PluginBase {
|
|||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is triggered once autosens calculation has completed, so the LoopPlugin
|
||||
* has current data to work with. However, autosens calculation can be triggered by multiple
|
||||
* sources and currently only a new BG should trigger a loop run. Hence we return early if
|
||||
* the event causing the calculation is not EventNewBg.
|
||||
* <p>
|
||||
*/
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
if (!(ev.getCause() instanceof EventNewBG)) {
|
||||
// Autosens calculation not triggered by a new BG
|
||||
return;
|
||||
}
|
||||
BgReading bgReading = DatabaseHelper.actualBg();
|
||||
if (bgReading == null) {
|
||||
// BG outdated
|
||||
return;
|
||||
}
|
||||
if (bgReading.date <= lastBgTriggeredRun) {
|
||||
// already looped with that value
|
||||
return;
|
||||
}
|
||||
|
||||
lastBgTriggeredRun = bgReading.date;
|
||||
invoke("AutosenseCalculation for " + bgReading, true);
|
||||
}
|
||||
|
||||
public long suspendedTo() {
|
||||
return loopSuspendedTill;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
|||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
|
@ -64,7 +65,7 @@ public class ProfileFunctions {
|
|||
MainApp.instance().startActivity(i);
|
||||
}
|
||||
if (result.enacted)
|
||||
MainApp.bus().post(new EventNewBasalProfile());
|
||||
RxBus.INSTANCE.send(new EventNewBasalProfile());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -918,6 +918,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
.subscribe(event -> scheduleUpdateGUI("EventInitializationChanged"),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> scheduleUpdateGUI("EventAutosensCalculationFinished"),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPumpStatusChanged.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -940,11 +946,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
scheduleUpdateGUI("EventPreferenceChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
scheduleUpdateGUI("EventAutosensCalculationFinished");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewOpenLoopNotification ev) {
|
||||
scheduleUpdateGUI("EventNewOpenLoopNotification");
|
||||
|
|
|
@ -126,6 +126,18 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
.subscribe(event -> triggerNotificationUpdate(false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventNewBasalProfile.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> triggerNotificationUpdate(false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> triggerNotificationUpdate(false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
triggerNotificationUpdate(true);
|
||||
}
|
||||
|
||||
|
@ -327,14 +339,4 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
triggerNotificationUpdate(false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
triggerNotificationUpdate(false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBasalProfile ev) {
|
||||
triggerNotificationUpdate(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,25 +81,37 @@ public class WearPlugin extends PluginBase {
|
|||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventOpenAPSUpdateGui.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(eventOpenAPSUpdateGui -> sendDataToWatch(true, true, false),
|
||||
.subscribe(event -> sendDataToWatch(true, true, false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventExtendedBolusChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(eventOpenAPSUpdateGui -> sendDataToWatch(true, true, false),
|
||||
.subscribe(event -> sendDataToWatch(true, true, false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventTempBasalChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(eventOpenAPSUpdateGui -> sendDataToWatch(true, true, false),
|
||||
.subscribe(event -> sendDataToWatch(true, true, false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventTreatmentChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(eventOpenAPSUpdateGui -> sendDataToWatch(true, true, false),
|
||||
.subscribe(event -> sendDataToWatch(true, true, false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventNewBasalProfile.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> sendDataToWatch(false, true, false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> sendDataToWatch(true, true, true),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
|
@ -169,16 +181,6 @@ public class WearPlugin extends PluginBase {
|
|||
sendDataToWatch(true, false, false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
sendDataToWatch(true, true, true);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewBasalProfile ev) {
|
||||
sendDataToWatch(false, true, false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
||||
if (!ev.isSMB() || SP.getBoolean("wear_notifySMB", true)) {
|
||||
|
|
|
@ -122,6 +122,12 @@ public class StatuslinePlugin extends PluginBase {
|
|||
.subscribe(event -> sendStatus(),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> sendStatus(),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -207,11 +213,6 @@ public class StatuslinePlugin extends PluginBase {
|
|||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppInitialized ev) {
|
||||
sendStatus();
|
||||
|
|
|
@ -91,6 +91,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
protected void onStart() {
|
||||
super.onStart();
|
||||
MainApp.bus().register(this);
|
||||
// EventConfigBuilderChange
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventConfigBuilderChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
|
@ -110,6 +111,46 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
runCalculation("onEventConfigBuilderChange", System.currentTimeMillis(), false, true, event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventNewBasalProfile
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventNewBasalProfile.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
if (ConfigBuilderPlugin.getPlugin() == null)
|
||||
return; // app still initializing
|
||||
if (event == null) { // on init no need of reset
|
||||
return;
|
||||
}
|
||||
stopCalculation("onNewProfile");
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data because of new profile. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
basalDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventNewBG
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventNewBG.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
stopCalculation("onEventNewBG");
|
||||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -664,18 +705,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, ev);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@SuppressWarnings("unused")
|
||||
public void onEventNewBG(EventNewBG ev) {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
stopCalculation("onEventNewBG");
|
||||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, ev);
|
||||
}
|
||||
|
||||
public void stopCalculation(String from) {
|
||||
if (thread != null && thread.getState() != Thread.State.TERMINATED) {
|
||||
stopCalculationTrigger = true;
|
||||
|
@ -701,29 +730,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNewProfile(EventNewBasalProfile ev) {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
if (ConfigBuilderPlugin.getPlugin() == null)
|
||||
return; // app still initializing
|
||||
if (ev == null) { // on init no need of reset
|
||||
return;
|
||||
}
|
||||
stopCalculation("onNewProfile");
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data because of new profile. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
basalDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, ev);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEventPreferenceChange(EventPreferenceChange ev) {
|
||||
if (this != getPlugin()) {
|
||||
|
|
|
@ -387,7 +387,7 @@ public class IobCobOref1Thread extends Thread {
|
|||
}
|
||||
new Thread(() -> {
|
||||
SystemClock.sleep(1000);
|
||||
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
|
||||
RxBus.INSTANCE.send(new EventAutosensCalculationFinished(cause));
|
||||
}).start();
|
||||
} finally {
|
||||
if (mWakeLock != null)
|
||||
|
|
|
@ -312,7 +312,6 @@ public class IobCobThread extends Thread {
|
|||
}
|
||||
new Thread(() -> {
|
||||
SystemClock.sleep(1000);
|
||||
MainApp.bus().post(new EventAutosensCalculationFinished(cause));
|
||||
RxBus.INSTANCE.send(new EventAutosensCalculationFinished(cause));
|
||||
}).start();
|
||||
} finally {
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
package info.nightscout.androidaps.plugins.source;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -21,19 +20,22 @@ import info.nightscout.androidaps.Constants;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
/**
|
||||
* Created by mike on 16.10.2017.
|
||||
*/
|
||||
|
||||
public class BGSourceFragment extends SubscriberFragment {
|
||||
public class BGSourceFragment extends Fragment {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
RecyclerView recyclerView;
|
||||
|
||||
String units = Constants.MGDL;
|
||||
|
@ -66,19 +68,25 @@ public class BGSourceFragment extends SubscriberFragment {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished unused) {
|
||||
updateGUI();
|
||||
@Override
|
||||
public synchronized void onResume() {
|
||||
super.onResume();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGUI(), FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onPause() {
|
||||
disposable.clear();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(() -> {
|
||||
long now = System.currentTimeMillis();
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false)), true);
|
||||
});
|
||||
}
|
||||
|
||||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.BgReadingsViewHolder> {
|
||||
|
|
|
@ -269,6 +269,11 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
updateGui();
|
||||
}
|
||||
|
||||
|
@ -278,15 +283,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
|||
disposable.clear();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
updateGui();
|
||||
}
|
||||
|
||||
private void updateGui() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(() -> {
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTreatmentsFromHistory()), false);
|
||||
if (TreatmentsPlugin.getPlugin().getLastCalculationTreatments() != null) {
|
||||
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.getPlugin().getLastCalculationTreatments().iob) + " " + MainApp.gs(R.string.insulin_unit_shortname));
|
||||
|
@ -297,7 +294,6 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
|||
} else {
|
||||
deleteFutureTreatments.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -191,6 +191,11 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
updateGui();
|
||||
}
|
||||
|
||||
|
@ -200,15 +205,8 @@ public class TreatmentsExtendedBolusesFragment extends Fragment {
|
|||
disposable.clear();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
updateGui();
|
||||
}
|
||||
|
||||
private void updateGui() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null && recyclerView != null)
|
||||
activity.runOnUiThread(() -> recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory()), false));
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory()), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -217,6 +217,11 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
updateGui();
|
||||
}
|
||||
|
||||
|
@ -226,20 +231,11 @@ public class TreatmentsTemporaryBasalsFragment extends Fragment {
|
|||
disposable.clear();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ignored) {
|
||||
updateGui();
|
||||
}
|
||||
|
||||
private void updateGui() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(() -> {
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getPlugin().getTemporaryBasalsFromHistory()), false);
|
||||
IobTotal tempBasalsCalculation = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals();
|
||||
if (tempBasalsCalculation != null)
|
||||
tempBasalTotalView.setText(DecimalFormatter.to2Decimal(tempBasalsCalculation.basaliob, " U"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue