Events to RxBus
This commit is contained in:
parent
7596775331
commit
30cf4f77da
48 changed files with 582 additions and 517 deletions
|
@ -52,6 +52,7 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
|||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
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.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt;
|
||||
|
@ -63,9 +64,12 @@ import info.nightscout.androidaps.utils.LocaleHelper;
|
|||
import info.nightscout.androidaps.utils.OKDialog;
|
||||
import info.nightscout.androidaps.utils.PasswordProtection;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public class MainActivity extends NoSplashAppCompatActivity {
|
||||
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
protected PowerManager.WakeLock mWakeLock;
|
||||
|
||||
|
@ -99,7 +103,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
|
||||
doMigrations();
|
||||
|
||||
registerBus();
|
||||
setupTabs();
|
||||
setupViews(false);
|
||||
|
||||
|
@ -142,6 +145,36 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventRefreshGui.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> {
|
||||
String lang = SP.getString(R.string.key_language, "en");
|
||||
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||
if (event.getRecreate()) {
|
||||
recreate();
|
||||
} else {
|
||||
try { // activity may be destroyed
|
||||
setupTabs();
|
||||
setupViews(false);
|
||||
} catch (IllegalStateException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
boolean keepScreenOn = Config.NSCLIENT && SP.getBoolean(R.string.key_keep_screen_on, false);
|
||||
if (keepScreenOn)
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> onEventPreferenceChange(event), FabricPrivacy::logException)
|
||||
);
|
||||
|
||||
if (L.isEnabled(L.CORE))
|
||||
log.debug("onResume");
|
||||
|
@ -160,7 +193,9 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
AndroidPermission.notifyForSMSPermissions(this);
|
||||
}
|
||||
|
||||
MainApp.bus().post(new EventFeatureRunning(EventFeatureRunning.Feature.MAIN));
|
||||
MainApp.bus().
|
||||
|
||||
post(new EventFeatureRunning(EventFeatureRunning.Feature.MAIN));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -173,7 +208,13 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
public void onEventPreferenceChange(final EventPreferenceChange ev) {
|
||||
if (ev.isChanged(R.string.key_keep_screen_on)) {
|
||||
boolean keepScreenOn = SP.getBoolean(R.string.key_keep_screen_on, false);
|
||||
|
@ -189,30 +230,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventRefreshGui ev) {
|
||||
String lang = SP.getString(R.string.key_language, "en");
|
||||
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||
runOnUiThread(() -> {
|
||||
if (ev.recreate) {
|
||||
recreate();
|
||||
} else {
|
||||
try { // activity may be destroyed
|
||||
setupTabs();
|
||||
setupViews(false);
|
||||
} catch (IllegalStateException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
boolean keepScreenOn = Config.NSCLIENT && SP.getBoolean(R.string.key_keep_screen_on, false);
|
||||
if (keepScreenOn)
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
else
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
});
|
||||
}
|
||||
|
||||
private void setupViews(boolean switchToLast) {
|
||||
TabPageAdapter pageAdapter = new TabPageAdapter(getSupportFragmentManager(), this);
|
||||
NavigationView navigationView = findViewById(R.id.navigation_view);
|
||||
|
@ -264,15 +281,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void registerBus() {
|
||||
try {
|
||||
MainApp.bus().unregister(this);
|
||||
} catch (RuntimeException x) {
|
||||
// Ignore
|
||||
}
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
private void checkEula() {
|
||||
//SP.removeBoolean(R.string.key_i_understand);
|
||||
boolean IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
|
||||
|
@ -405,7 +413,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
|||
case R.id.nav_exit:
|
||||
log.debug("Exiting");
|
||||
MainApp.instance().stopKeepAliveService();
|
||||
MainApp.bus().post(new EventAppExit());
|
||||
RxBus.INSTANCE.send(new EventAppExit());
|
||||
MainApp.closeDbHelper();
|
||||
finish();
|
||||
System.runFinalization();
|
||||
|
|
|
@ -68,17 +68,16 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
|||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
MainApp.bus().post(new EventPreferenceChange(key));
|
||||
RxBus.INSTANCE.send(new EventPreferenceChange(key));
|
||||
if (key.equals("language")) {
|
||||
String lang = sharedPreferences.getString("language", "en");
|
||||
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||
MainApp.bus().post(new EventRefreshGui(true));
|
||||
RxBus.INSTANCE.send(new EventRefreshGui(true));
|
||||
//recreate() does not update language so better close settings
|
||||
finish();
|
||||
}
|
||||
if (key.equals("short_tabtitles")) {
|
||||
MainApp.bus().post(new EventRefreshGui());
|
||||
RxBus.INSTANCE.send(new EventRefreshGui());
|
||||
}
|
||||
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
|
||||
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
|
||||
|
|
|
@ -1720,7 +1720,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
if (L.isEnabled(L.DATABASE))
|
||||
log.debug("Firing EventProfileNeedsUpdate");
|
||||
RxBus.INSTANCE.send(new EventReloadProfileSwitchData());
|
||||
MainApp.bus().post(new EventProfileNeedsUpdate());
|
||||
RxBus.INSTANCE.send(new EventProfileNeedsUpdate());
|
||||
scheduledProfileSwitchEventPost = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 07.07.2016.
|
||||
*/
|
||||
public class EventAppExit extends Event {
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
class EventAppExit : Event()
|
|
@ -1,25 +0,0 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
|
||||
/**
|
||||
* Created by mike on 19.06.2016.
|
||||
*/
|
||||
public class EventPreferenceChange extends Event {
|
||||
public String changedKey;
|
||||
public EventPreferenceChange(String key) {
|
||||
changedKey = key;
|
||||
}
|
||||
|
||||
public EventPreferenceChange(int resourceID) {
|
||||
changedKey = MainApp.gs(resourceID);
|
||||
}
|
||||
|
||||
public boolean isChanged(int id) {
|
||||
return changedKey.equals(MainApp.gs(id));
|
||||
}
|
||||
|
||||
public boolean isChanged(String id) {
|
||||
return changedKey.equals(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
import info.nightscout.androidaps.MainApp
|
||||
|
||||
class EventPreferenceChange : Event {
|
||||
private var changedKey: String? = null
|
||||
|
||||
constructor(key: String) {
|
||||
changedKey = key
|
||||
}
|
||||
|
||||
constructor(resourceID: Int) {
|
||||
changedKey = MainApp.gs(resourceID)
|
||||
}
|
||||
|
||||
fun isChanged(id: Int): Boolean {
|
||||
return changedKey == MainApp.gs(id)
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 02.06.2017.
|
||||
*/
|
||||
|
||||
public class EventProfileNeedsUpdate extends Event {
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
class EventProfileNeedsUpdate : Event()
|
|
@ -1,4 +0,0 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
public class EventProfileStoreChanged extends Event {
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
class EventProfileStoreChanged : Event()
|
|
@ -1,14 +0,0 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 13.06.2016.
|
||||
*/
|
||||
public class EventRefreshGui extends Event {
|
||||
public boolean recreate = false;
|
||||
public EventRefreshGui(boolean recreate) {
|
||||
this.recreate = recreate;
|
||||
}
|
||||
public EventRefreshGui(){
|
||||
this(false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
class EventRefreshGui @JvmOverloads constructor(var recreate: Boolean = false) : Event()
|
|
@ -81,7 +81,7 @@ public abstract class PluginBase {
|
|||
setFragmentVisible(type, enabled);
|
||||
ConfigBuilderPlugin.getPlugin().processOnEnabledCategoryChanged(this, getType());
|
||||
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled");
|
||||
MainApp.bus().post(new EventRefreshGui());
|
||||
RxBus.INSTANCE.send(new EventRefreshGui());
|
||||
MainApp.bus().post(new EventConfigBuilderChange());
|
||||
RxBus.INSTANCE.send(new EventConfigBuilderUpdateGui());
|
||||
ConfigBuilderPlugin.getPlugin().logPluginStatus();
|
||||
|
|
|
@ -9,6 +9,7 @@ import info.nightscout.androidaps.activities.PreferencesActivity
|
|||
import info.nightscout.androidaps.events.EventRefreshGui
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
import info.nightscout.androidaps.utils.PasswordProtection
|
||||
|
||||
class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment,
|
||||
|
@ -34,7 +35,7 @@ class PluginViewHolder internal constructor(private val fragment: ConfigBuilderF
|
|||
pluginVisibility.setOnClickListener {
|
||||
plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked)
|
||||
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible")
|
||||
MainApp.bus().post(EventRefreshGui())
|
||||
RxBus.send(EventRefreshGui())
|
||||
ConfigBuilderPlugin.getPlugin().logPluginStatus()
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ package info.nightscout.androidaps.plugins.configBuilder;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -29,9 +29,12 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class ProfileFunctions {
|
||||
private static Logger log = LoggerFactory.getLogger(L.PROFILE);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static ProfileFunctions profileFunctions = null;
|
||||
|
||||
|
@ -45,29 +48,30 @@ public class ProfileFunctions {
|
|||
ProfileFunctions.getInstance(); // register to bus at start
|
||||
}
|
||||
|
||||
ProfileFunctions() {
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProfileSwitch(EventProfileNeedsUpdate ignored) {
|
||||
if (L.isEnabled(L.PROFILE))
|
||||
log.debug("onProfileSwitch");
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().setProfile(getProfile(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!result.success) {
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.boluserror);
|
||||
i.putExtra("status", result.comment);
|
||||
i.putExtra("title", MainApp.gs(R.string.failedupdatebasalprofile));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
}
|
||||
if (result.enacted)
|
||||
RxBus.INSTANCE.send(new EventNewBasalProfile());
|
||||
}
|
||||
});
|
||||
private ProfileFunctions() {
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventProfileNeedsUpdate.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PROFILE))
|
||||
log.debug("onProfileSwitch");
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().setProfile(getProfile(), new Callback() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!result.success) {
|
||||
Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
|
||||
i.putExtra("soundid", R.raw.boluserror);
|
||||
i.putExtra("status", result.comment);
|
||||
i.putExtra("title", MainApp.gs(R.string.failedupdatebasalprofile));
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
MainApp.instance().startActivity(i);
|
||||
}
|
||||
if (result.enacted)
|
||||
RxBus.INSTANCE.send(new EventNewBasalProfile());
|
||||
}
|
||||
});
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
public String getProfileName() {
|
||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.MainApp;
|
|||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.utils.OKDialog;
|
||||
import info.nightscout.androidaps.utils.ToastUtils;
|
||||
|
||||
|
@ -136,7 +137,7 @@ public class ImportExportPrefs {
|
|||
OKDialog.show(context, MainApp.gs(R.string.setting_imported), MainApp.gs(R.string.restartingapp), () -> {
|
||||
log.debug("Exiting");
|
||||
MainApp.instance().stopKeepAliveService();
|
||||
MainApp.bus().post(new EventAppExit());
|
||||
RxBus.INSTANCE.send(new EventAppExit());
|
||||
MainApp.closeDbHelper();
|
||||
if (context instanceof Activity) {
|
||||
((Activity)context).finish();
|
||||
|
|
|
@ -22,7 +22,6 @@ import info.nightscout.androidaps.Config;
|
|||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventChargingState;
|
||||
import info.nightscout.androidaps.events.EventNetworkChange;
|
||||
|
@ -31,6 +30,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.nsclient.events.EventNSClientNewLog;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
|
||||
|
@ -121,6 +121,21 @@ public class NSClientPlugin extends PluginBase {
|
|||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> nsClientReceiverDelegate.onStatusEvent(event), FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> nsClientReceiverDelegate.onStatusEvent(event), FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (nsClientService != null) {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
nsClientReceiverDelegate.unregisterReceivers();
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,11 +149,6 @@ public class NSClientPlugin extends PluginBase {
|
|||
super.onStop();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventPreferenceChange ev) {
|
||||
nsClientReceiverDelegate.onStatusEvent(ev);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventChargingState ev) {
|
||||
nsClientReceiverDelegate.onStatusEvent(ev);
|
||||
|
@ -161,14 +171,6 @@ public class NSClientPlugin extends PluginBase {
|
|||
}
|
||||
};
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppExit ignored) {
|
||||
if (nsClientService != null) {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
nsClientReceiverDelegate.unregisterReceivers();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNSClientNewLog ev) {
|
||||
addToLog(ev);
|
||||
|
@ -220,7 +222,6 @@ public class NSClientPlugin extends PluginBase {
|
|||
public void pause(boolean newState) {
|
||||
SP.putBoolean(R.string.key_nsclientinternal_paused, newState);
|
||||
paused = newState;
|
||||
MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,6 @@ class NsClientReceiverDelegate {
|
|||
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
||||
if (newAllowedState != allowed) {
|
||||
allowed = newAllowedState;
|
||||
bus.post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,17 +117,6 @@ public class NSClientService extends Service {
|
|||
|
||||
public NSClientService() {
|
||||
registerBus();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventConfigBuilderChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (nsEnabled != NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL)) {
|
||||
latestDateInReceivedData = 0;
|
||||
destroy();
|
||||
initialize();
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
if (handler == null) {
|
||||
HandlerThread handlerThread = new HandlerThread(NSClientService.class.getSimpleName() + "Handler");
|
||||
handlerThread.start();
|
||||
|
@ -143,11 +132,47 @@ public class NSClientService extends Service {
|
|||
public void onCreate() {
|
||||
super.onCreate();
|
||||
mWakeLock.acquire();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventConfigBuilderChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (nsEnabled != NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL)) {
|
||||
latestDateInReceivedData = 0;
|
||||
destroy();
|
||||
initialize();
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (event.isChanged(R.string.key_nsclientinternal_url) ||
|
||||
event.isChanged(R.string.key_nsclientinternal_api_secret) ||
|
||||
event.isChanged(R.string.key_nsclientinternal_paused)
|
||||
) {
|
||||
latestDateInReceivedData = 0;
|
||||
destroy();
|
||||
initialize();
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.NSCLIENT))
|
||||
log.debug("EventAppExit received");
|
||||
destroy();
|
||||
stopSelf();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
disposable.clear();
|
||||
if (mWakeLock.isHeld()) mWakeLock.release();
|
||||
}
|
||||
|
||||
|
@ -177,28 +202,6 @@ public class NSClientService extends Service {
|
|||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventAppExit event) {
|
||||
if (L.isEnabled(L.NSCLIENT))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
destroy();
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventPreferenceChange ev) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNSClientRestart ev) {
|
||||
latestDateInReceivedData = 0;
|
||||
|
|
|
@ -924,6 +924,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
.subscribe(event -> scheduleUpdateGUI("EventAutosensCalculationFinished"),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventProfileNeedsUpdate.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> scheduleUpdateGUI("EventProfileNeedsUpdate"),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> scheduleUpdateGUI("EventPreferenceChange"),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPumpStatusChanged.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -941,21 +953,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
updateGUI("onResume");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||
scheduleUpdateGUI("EventPreferenceChange");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewOpenLoopNotification ev) {
|
||||
scheduleUpdateGUI("EventNewOpenLoopNotification");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventProfileNeedsUpdate ev) {
|
||||
scheduleUpdateGUI("EventProfileNeedsUpdate");
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventIobCalculationProgress e) {
|
||||
Activity activity = getActivity();
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
package info.nightscout.androidaps.plugins.general.persistentNotification;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Keeps AndroidAPS in foreground state, so it won't be terminated by Android nor get restricted by the background execution limits
|
||||
*/
|
||||
public class DummyService extends Service {
|
||||
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -28,6 +29,30 @@ public class DummyService extends Service {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
// TODO: I guess this was moved here in order to adhere to the 5 seconds rule to call "startForeground" after a Service was called as Foreground service?
|
||||
// As onCreate() is not called every time a service is started, copied to onStartCommand().
|
||||
startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().getLastNotification());
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP)) log.debug("EventAppExit received");
|
||||
stopSelf();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (L.isEnabled(L.CORE)) log.debug("onDestroy");
|
||||
disposable.clear();
|
||||
super.onDestroy();
|
||||
stopForeground(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
|
@ -35,28 +60,4 @@ public class DummyService extends Service {
|
|||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventAppExit event) {
|
||||
if (L.isEnabled(L.CORE))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
// TODO: I guess this was moved here in order to adhere to the 5 seconds rule to call "startForeground" after a Service was called as Foreground service?
|
||||
// As onCreate() is not called every time a service is started, copied to onStartCommand().
|
||||
startForeground(PersistentNotificationPlugin.ONGOING_NOTIFICATION_ID, PersistentNotificationPlugin.getPlugin().getLastNotification());
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (L.isEnabled(L.CORE))
|
||||
log.debug("onDestroy");
|
||||
MainApp.bus().unregister(this);
|
||||
stopForeground(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,6 @@ import androidx.core.app.NotificationCompat;
|
|||
import androidx.core.app.RemoteInput;
|
||||
import androidx.core.app.TaskStackBuilder;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
|
@ -95,7 +93,6 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
protected void onStart() {
|
||||
super.onStart();
|
||||
createNotificationChannel(); // make sure channels exist before triggering updates through the bus
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventRefreshOverview.class)
|
||||
.observeOn(Schedulers.io())
|
||||
|
@ -138,6 +135,12 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
.subscribe(event -> triggerNotificationUpdate(false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> triggerNotificationUpdate(false),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
triggerNotificationUpdate(true);
|
||||
}
|
||||
|
||||
|
@ -155,7 +158,6 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
MainApp.instance().stopService(new Intent(MainApp.instance(), DummyService.class));
|
||||
super.onStop();
|
||||
|
@ -332,11 +334,4 @@ public class PersistentNotificationPlugin extends PluginBase {
|
|||
throw new IllegalStateException("Notification is null");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||
triggerNotificationUpdate(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import info.nightscout.androidaps.data.ProfileStore;
|
|||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
|
@ -50,15 +51,19 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.SafeParse;
|
||||
import info.nightscout.androidaps.utils.XdripCalibrations;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class SmsCommunicatorPlugin extends PluginBase {
|
||||
private static Logger log = LoggerFactory.getLogger(L.SMS);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static SmsCommunicatorPlugin smsCommunicatorPlugin;
|
||||
|
||||
|
@ -92,18 +97,23 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
|||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
MainApp.bus().register(this);
|
||||
super.onStart();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
processSettings(event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void processSettings(final EventPreferenceChange ev) {
|
||||
private void processSettings(final EventPreferenceChange ev) {
|
||||
if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
|
||||
String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.general.wear;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
|
@ -28,7 +27,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutos
|
|||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
|
@ -114,6 +112,17 @@ public class WearPlugin extends PluginBase {
|
|||
.subscribe(event -> sendDataToWatch(true, true, true),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
// possibly new high or low mark
|
||||
resendDataToWatch();
|
||||
// status may be formated differently
|
||||
sendDataToWatch(true, false, false);
|
||||
},
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventRefreshOverview.class)
|
||||
.observeOn(Schedulers.io())
|
||||
|
@ -173,14 +182,6 @@ public class WearPlugin extends PluginBase {
|
|||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||
// possibly new high or low mark
|
||||
resendDataToWatch();
|
||||
// status may be formated differently
|
||||
sendDataToWatch(true, false, false);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventOverviewBolusProgress ev) {
|
||||
if (!ev.isSMB() || SP.getBoolean("wear_notifySMB", true)) {
|
||||
|
|
|
@ -128,6 +128,12 @@ public class StatuslinePlugin extends PluginBase {
|
|||
.subscribe(event -> sendStatus(),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> sendStatus(),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -207,12 +213,6 @@ public class StatuslinePlugin extends PluginBase {
|
|||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||
// status may be formated differently
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppInitialized ev) {
|
||||
sendStatus();
|
||||
|
|
|
@ -151,6 +151,36 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventPreferenceChange
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
if (event.isChanged(R.string.key_openapsama_autosens_period) ||
|
||||
event.isChanged(R.string.key_age) ||
|
||||
event.isChanged(R.string.key_absorption_maxtime) ||
|
||||
event.isChanged(R.string.key_openapsama_min_5m_carbimpact) ||
|
||||
event.isChanged(R.string.key_absorption_cutoff) ||
|
||||
event.isChanged(R.string.key_openapsama_autosens_max) ||
|
||||
event.isChanged(R.string.key_openapsama_autosens_min)
|
||||
) {
|
||||
stopCalculation("onEventPreferenceChange");
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records" + " BasalData: " + basalDataTable.size() + " records");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
basalDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, true, event);
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -730,33 +760,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEventPreferenceChange(EventPreferenceChange ev) {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
if (ev.isChanged(R.string.key_openapsama_autosens_period) ||
|
||||
ev.isChanged(R.string.key_age) ||
|
||||
ev.isChanged(R.string.key_absorption_maxtime) ||
|
||||
ev.isChanged(R.string.key_openapsama_min_5m_carbimpact) ||
|
||||
ev.isChanged(R.string.key_absorption_cutoff) ||
|
||||
ev.isChanged(R.string.key_openapsama_autosens_max) ||
|
||||
ev.isChanged(R.string.key_openapsama_autosens_min)
|
||||
) {
|
||||
stopCalculation("onEventPreferenceChange");
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records" + " BasalData: " + basalDataTable.size() + " records");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
basalDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, true, ev);
|
||||
}
|
||||
}
|
||||
|
||||
// When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated
|
||||
@Subscribe
|
||||
public void onEventNewHistoryData(EventNewHistoryData ev) {
|
||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
|
|||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
|
@ -83,7 +84,7 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
|
|||
edited = false;
|
||||
if (L.isEnabled(L.PROFILE))
|
||||
log.debug("Storing settings: " + getRawProfile().getData().toString());
|
||||
MainApp.bus().post(new EventProfileStoreChanged());
|
||||
RxBus.INSTANCE.send(new EventProfileStoreChanged());
|
||||
}
|
||||
|
||||
public synchronized void loadSettings() {
|
||||
|
|
|
@ -78,7 +78,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface {
|
|||
profile = new ProfileStore(new JSONObject(profileString));
|
||||
storeNSProfile();
|
||||
if (isEnabled(PluginType.PROFILE)) {
|
||||
MainApp.bus().post(new EventProfileStoreChanged());
|
||||
RxBus.INSTANCE.send(new EventProfileStoreChanged());
|
||||
RxBus.INSTANCE.send(new EventNSProfileUpdateGUI());
|
||||
}
|
||||
if (L.isEnabled(L.PROFILE))
|
||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
|
|||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
/**
|
||||
|
@ -75,7 +76,7 @@ public class SimpleProfilePlugin extends PluginBase implements ProfileInterface
|
|||
createConvertedProfile();
|
||||
if (L.isEnabled(L.PROFILE))
|
||||
log.debug("Storing settings: " + getRawProfile().getData().toString());
|
||||
MainApp.bus().post(new EventProfileStoreChanged());
|
||||
RxBus.INSTANCE.send(new EventProfileStoreChanged());
|
||||
}
|
||||
|
||||
private void loadSettings() {
|
||||
|
|
|
@ -6,8 +6,6 @@ import android.content.ServiceConnection;
|
|||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -31,6 +29,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.general.overview.events.EventOverviewBolusProgress;
|
||||
import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
|
||||
|
@ -39,6 +38,9 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by andy on 23.04.18.
|
||||
|
@ -47,13 +49,14 @@ import info.nightscout.androidaps.utils.DecimalFormatter;
|
|||
// When using this class, make sure that your first step is to create mConnection (see MedtronicPumpPlugin)
|
||||
|
||||
public abstract class PumpPluginAbstract extends PluginBase implements PumpInterface, ConstraintsInterface {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(L.PUMP);
|
||||
|
||||
protected static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult().success(false)
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump_driver));
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_supported_by_pump_driver));
|
||||
protected static final PumpEnactResult OPERATION_NOT_YET_SUPPORTED = new PumpEnactResult().success(false)
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
||||
.enacted(false).comment(MainApp.gs(R.string.pump_operation_not_yet_supported_by_pump));
|
||||
|
||||
protected PumpDescription pumpDescription = new PumpDescription();
|
||||
protected PumpStatus pumpStatus;
|
||||
|
@ -80,15 +83,21 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
Intent intent = new Intent(context, getServiceClass());
|
||||
context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
|
||||
serviceRunning = true;
|
||||
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
MainApp.instance().getApplicationContext().unbindService(serviceConnection);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
onStartCustomActions();
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,7 +108,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
serviceRunning = false;
|
||||
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -121,14 +130,6 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
*/
|
||||
public abstract Class getServiceClass();
|
||||
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppExit e) {
|
||||
MainApp.instance().getApplicationContext().unbindService(serviceConnection);
|
||||
}
|
||||
|
||||
|
||||
public PumpStatus getPumpStatusData() {
|
||||
return pumpStatus;
|
||||
}
|
||||
|
@ -239,7 +240,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes, Profile profile,
|
||||
boolean enforceNew) {
|
||||
boolean enforceNew) {
|
||||
if (isLoggingEnabled())
|
||||
LOG.warn("setTempBasalAbsolute [PumpPluginAbstract] - Not implemented.");
|
||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||
|
@ -248,7 +249,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
|
||||
@Override
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile,
|
||||
boolean enforceNew) {
|
||||
boolean enforceNew) {
|
||||
if (isLoggingEnabled())
|
||||
LOG.warn("setTempBasalPercent [PumpPluginAbstract] - Not implemented.");
|
||||
return getOperationNotSupportedWithCustomText(R.string.pump_operation_not_supported_by_pump_driver);
|
||||
|
@ -340,7 +341,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (tb != null) {
|
||||
extended.put("TempBasalAbsoluteRate",
|
||||
tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
|
||||
tb.tempBasalConvertedToAbsolute(System.currentTimeMillis(), profile));
|
||||
extended.put("TempBasalStart", DateUtil.dateAndTimeString(tb.date));
|
||||
extended.put("TempBasalRemaining", tb.getPlannedRemainingMinutes());
|
||||
}
|
||||
|
@ -372,20 +373,20 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
String ret = "";
|
||||
if (pumpStatus.lastConnection != 0) {
|
||||
Long agoMsec = System.currentTimeMillis() - pumpStatus.lastConnection;
|
||||
int agoMin = (int)(agoMsec / 60d / 1000d);
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
ret += "LastConn: " + agoMin + " min ago\n";
|
||||
}
|
||||
if (pumpStatus.lastBolusTime != null && pumpStatus.lastBolusTime.getTime() != 0) {
|
||||
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pumpStatus.lastBolusAmount) + "U @" + //
|
||||
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
|
||||
android.text.format.DateFormat.format("HH:mm", pumpStatus.lastBolusTime) + "\n";
|
||||
}
|
||||
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin()
|
||||
.getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
.getRealTempBasalFromHistory(System.currentTimeMillis());
|
||||
if (activeTemp != null) {
|
||||
ret += "Temp: " + activeTemp.toStringFull() + "\n";
|
||||
}
|
||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(
|
||||
System.currentTimeMillis());
|
||||
System.currentTimeMillis());
|
||||
if (activeExtendedBolus != null) {
|
||||
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
|
||||
}
|
||||
|
@ -409,7 +410,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
if (isLoggingEnabled())
|
||||
LOG.error("deliverTreatment: Invalid input");
|
||||
return new PumpEnactResult().success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
|
||||
.comment(MainApp.gs(R.string.danar_invalidinput));
|
||||
.comment(MainApp.gs(R.string.danar_invalidinput));
|
||||
} else if (detailedBolusInfo.insulin > 0) {
|
||||
// bolus needed, ask pump to deliver it
|
||||
return deliverBolus(detailedBolusInfo);
|
||||
|
@ -427,7 +428,7 @@ public abstract class PumpPluginAbstract extends PluginBase implements PumpInter
|
|||
LOG.debug("deliverTreatment: Carb only treatment.");
|
||||
|
||||
return new PumpEnactResult().success(true).enacted(true).bolusDelivered(0d)
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(MainApp.gs(R.string.virtualpump_resultok));
|
||||
.carbsDelivered(detailedBolusInfo.carbs).comment(MainApp.gs(R.string.virtualpump_resultok));
|
||||
}
|
||||
} finally {
|
||||
triggerUIChange();
|
||||
|
|
|
@ -5,8 +5,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
|
@ -22,19 +20,23 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
|||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStartWithSpeed;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.Round;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class DanaRPlugin extends AbstractDanaRPlugin {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static DanaRPlugin plugin = null;
|
||||
|
||||
|
@ -55,7 +57,27 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
Context context = MainApp.instance().getApplicationContext();
|
||||
Intent intent = new Intent(context, DanaRExecutionService.class);
|
||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (isEnabled(PluginType.PUMP)) {
|
||||
boolean previousValue = useExtendedBoluses;
|
||||
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
|
||||
|
||||
if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
|
||||
sExecutionService.extendedBolusStop();
|
||||
}
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
|
@ -64,7 +86,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
Context context = MainApp.instance().getApplicationContext();
|
||||
context.unbindService(mConnection);
|
||||
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -84,24 +106,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppExit e) {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange s) {
|
||||
if (isEnabled(PluginType.PUMP)) {
|
||||
boolean previousValue = useExtendedBoluses;
|
||||
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
|
||||
|
||||
if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
|
||||
sExecutionService.extendedBolusStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin base interface
|
||||
@Override
|
||||
public String getName() {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class MsgInitConnStatusTime extends MessageBase {
|
|||
}
|
||||
|
||||
ConfigBuilderPlugin.getPlugin().storeSettings("ChangingDanaDriver");
|
||||
MainApp.bus().post(new EventRefreshGui());
|
||||
RxBus.INSTANCE.send(new EventRefreshGui());
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||
failed = false;
|
||||
return;
|
||||
|
|
|
@ -67,15 +67,51 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.queue.commands.Command;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
public DanaRExecutionService() {
|
||||
mBinder = new LocalBinder();
|
||||
|
||||
registerBus();
|
||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
|
||||
stopSelf();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
disposable.clear();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public class LocalBinder extends Binder {
|
||||
|
@ -84,21 +120,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
}
|
||||
|
||||
private void registerBus() {
|
||||
try {
|
||||
MainApp.bus().unregister(this);
|
||||
} catch (RuntimeException x) {
|
||||
// Ignore
|
||||
}
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange pch) {
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (mConnectionInProgress)
|
||||
return;
|
||||
|
@ -407,19 +428,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventAppExit event) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
|
||||
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
public PumpEnactResult setUserOptions() {
|
||||
if (!isConnected())
|
||||
return new PumpEnactResult().success(false);
|
||||
|
|
|
@ -5,10 +5,6 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -22,7 +18,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
|||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
|
@ -30,13 +26,17 @@ import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusStart;
|
|||
import info.nightscout.androidaps.plugins.pump.danaRKorean.services.DanaRKoreanExecutionService;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.Round;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static DanaRKoreanPlugin plugin = null;
|
||||
|
||||
|
@ -58,7 +58,27 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
Context context = MainApp.instance().getApplicationContext();
|
||||
Intent intent = new Intent(context, DanaRKoreanExecutionService.class);
|
||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (isEnabled(PluginType.PUMP)) {
|
||||
boolean previousValue = useExtendedBoluses;
|
||||
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
|
||||
|
||||
if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
|
||||
sExecutionService.extendedBolusStop();
|
||||
}
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
|
@ -67,7 +87,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
Context context = MainApp.instance().getApplicationContext();
|
||||
context.unbindService(mConnection);
|
||||
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -87,24 +107,6 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppExit e) {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange s) {
|
||||
if (isEnabled(PluginType.PUMP)) {
|
||||
boolean previousValue = useExtendedBoluses;
|
||||
useExtendedBoluses = SP.getBoolean(R.string.key_danar_useextended, false);
|
||||
|
||||
if (useExtendedBoluses != previousValue && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
|
||||
sExecutionService.extendedBolusStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin base interface
|
||||
@Override
|
||||
public String getName() {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class MsgInitConnStatusTime_k extends MessageBase {
|
|||
}
|
||||
|
||||
ConfigBuilderPlugin.getPlugin().storeSettings("ChangingKoreanDanaDriver");
|
||||
MainApp.bus().post(new EventRefreshGui());
|
||||
RxBus.INSTANCE.send(new EventRefreshGui());
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -59,51 +59,58 @@ import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgStatusBasic_k
|
|||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.queue.commands.Command;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
public DanaRKoreanExecutionService() {
|
||||
mBinder = new LocalBinder();
|
||||
|
||||
registerBus();
|
||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
|
||||
stopSelf();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
disposable.clear();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public class LocalBinder extends Binder {
|
||||
public DanaRKoreanExecutionService getServiceInstance() {
|
||||
return DanaRKoreanExecutionService.this;
|
||||
}
|
||||
}
|
||||
|
||||
private void registerBus() {
|
||||
try {
|
||||
MainApp.bus().unregister(this);
|
||||
} catch (RuntimeException x) {
|
||||
// Ignore
|
||||
}
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventAppExit event) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
|
||||
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange pch) {
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
if (mConnectionInProgress)
|
||||
return;
|
||||
|
@ -173,7 +180,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
|
|||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
|
||||
mSerialIOThread.sendMessage(new MsgSettingBasal());
|
||||
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
|
||||
MainApp.bus().post(new EventProfileNeedsUpdate());
|
||||
RxBus.INSTANCE.send(new EventProfileNeedsUpdate());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,9 +59,12 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.Round;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by mike on 03.09.2017.
|
||||
|
@ -69,6 +72,8 @@ import info.nightscout.androidaps.utils.T;
|
|||
|
||||
public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface {
|
||||
private Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static DanaRSPlugin plugin = null;
|
||||
|
||||
public static DanaRSPlugin getPlugin() {
|
||||
|
@ -114,6 +119,13 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
onStatusEvent(new EventDanaRSDeviceChange()); // load device name
|
||||
super.onStart();
|
||||
}
|
||||
|
@ -124,6 +136,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
context.unbindService(mConnection);
|
||||
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -148,12 +161,6 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
|
|||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppExit e) {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventDanaRSDeviceChange e) {
|
||||
mDeviceAddress = SP.getString(R.string.key_danars_address, "");
|
||||
|
|
|
@ -6,8 +6,6 @@ import android.os.Binder;
|
|||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -27,6 +25,7 @@ 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;
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.BolusProgressDialog;
|
||||
import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
|
||||
|
@ -80,12 +79,15 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.queue.commands.Command;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class DanaRSService extends Service {
|
||||
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private BLEComm bleComm = BLEComm.getInstance(this);
|
||||
|
||||
|
@ -105,6 +107,25 @@ public class DanaRSService extends Service {
|
|||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP)) log.debug("EventAppExit received");
|
||||
stopSelf();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
disposable.clear();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return bleComm.isConnected;
|
||||
}
|
||||
|
@ -150,7 +171,7 @@ public class DanaRSService extends Service {
|
|||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
|
||||
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate()); // basal profile, basalStep, maxBasal
|
||||
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
|
||||
MainApp.bus().post(new EventProfileNeedsUpdate());
|
||||
RxBus.INSTANCE.send(new EventProfileNeedsUpdate());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,7 +271,7 @@ public class DanaRSService extends Service {
|
|||
} else {
|
||||
msg = new DanaRS_Packet_APS_History_Events(lastHistoryFetched);
|
||||
if (L.isEnabled(L.PUMPCOMM))
|
||||
log.debug("Loading event history from: " +DateUtil.dateAndTimeFullString(lastHistoryFetched));
|
||||
log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched));
|
||||
}
|
||||
bleComm.sendMessage(msg);
|
||||
while (!msg.done && bleComm.isConnected()) {
|
||||
|
@ -529,14 +550,6 @@ public class DanaRSService extends Service {
|
|||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventAppExit event) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
void waitForWholeMinute() {
|
||||
while (true) {
|
||||
long time = DateUtil.now();
|
||||
|
|
|
@ -6,8 +6,6 @@ import android.content.Intent;
|
|||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
|
@ -17,6 +15,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
|||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.AbstractDanaRPlugin;
|
||||
|
@ -26,14 +25,18 @@ import info.nightscout.androidaps.plugins.pump.danaRv2.services.DanaRv2Execution
|
|||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.Round;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static DanaRv2Plugin plugin = null;
|
||||
|
||||
|
@ -56,7 +59,13 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
Intent intent = new Intent(context, DanaRv2ExecutionService.class);
|
||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
|
@ -65,7 +74,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
Context context = MainApp.instance().getApplicationContext();
|
||||
context.unbindService(mConnection);
|
||||
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -85,12 +94,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
|||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAppExit e) {
|
||||
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||
}
|
||||
|
||||
// Plugin base interface
|
||||
@Override
|
||||
public String getName() {
|
||||
|
|
|
@ -61,7 +61,7 @@ public class MsgCheckValue_v2 extends MessageBase {
|
|||
}
|
||||
|
||||
ConfigBuilderPlugin.getPlugin().storeSettings("ChangingDanaRv2Driver");
|
||||
MainApp.bus().post(new EventRefreshGui());
|
||||
RxBus.INSTANCE.send(new EventRefreshGui());
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||
return;
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class MsgCheckValue_v2 extends MessageBase {
|
|||
}
|
||||
|
||||
ConfigBuilderPlugin.getPlugin().storeSettings("ChangingDanaRv2Driver");
|
||||
MainApp.bus().post(new EventRefreshGui());
|
||||
RxBus.INSTANCE.send(new EventRefreshGui());
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ import android.content.IntentFilter;
|
|||
import android.os.Binder;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -74,17 +72,20 @@ import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.queue.commands.Command;
|
||||
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.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private long lastHistoryFetched = 0;
|
||||
|
||||
public DanaRv2ExecutionService() {
|
||||
mBinder = new LocalBinder();
|
||||
|
||||
registerBus();
|
||||
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
|
||||
}
|
||||
|
||||
|
@ -94,32 +95,36 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
}
|
||||
}
|
||||
|
||||
private void registerBus() {
|
||||
try {
|
||||
MainApp.bus().unregister(this);
|
||||
} catch (RuntimeException x) {
|
||||
// Ignore
|
||||
}
|
||||
MainApp.bus().register(this);
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
|
||||
stopSelf();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventAppExit event) {
|
||||
if (L.isEnabled(L.PUMP))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("Application exit");
|
||||
|
||||
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
|
||||
|
||||
stopSelf();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange pch) {
|
||||
if (mSerialIOThread != null)
|
||||
mSerialIOThread.disconnect("EventPreferenceChange");
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
disposable.clear();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
|
@ -190,7 +195,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
|
|||
RxBus.INSTANCE.send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
|
||||
mSerialIOThread.sendMessage(new MsgSettingBasal());
|
||||
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
|
||||
MainApp.bus().post(new EventProfileNeedsUpdate());
|
||||
RxBus.INSTANCE.send(new EventProfileNeedsUpdate());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ package info.nightscout.androidaps.plugins.pump.virtual;
|
|||
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -41,8 +39,11 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
|||
import info.nightscout.androidaps.plugins.pump.virtual.events.EventVirtualPumpUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.InstanceId;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -50,6 +51,7 @@ import info.nightscout.androidaps.utils.SP;
|
|||
*/
|
||||
public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
||||
private Logger log = LoggerFactory.getLogger(L.PUMP);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
Integer batteryPercent = 50;
|
||||
Integer reservoirInUnits = 50;
|
||||
|
@ -122,22 +124,23 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
|
|||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (event.isChanged(R.string.key_virtualpump_type))
|
||||
refreshConfiguration();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
refreshConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
MainApp.bus().unregister(this);
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventPreferenceChange s) {
|
||||
if (s.isChanged(R.string.key_virtualpump_type))
|
||||
refreshConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFakingTempsByExtendedBoluses() {
|
||||
return (Config.NSCLIENT) && fromNSAreCommingFakedExtendedBoluses;
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.widget.TextView;
|
|||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -32,6 +33,7 @@ import info.nightscout.androidaps.db.ProfileSwitch;
|
|||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
|
@ -39,14 +41,18 @@ import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
|
|||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
/**
|
||||
* Created by mike on 13/01/17.
|
||||
*/
|
||||
|
||||
public class TreatmentsProfileSwitchFragment extends SubscriberFragment implements View.OnClickListener {
|
||||
public class TreatmentsProfileSwitchFragment extends Fragment implements View.OnClickListener {
|
||||
private Logger log = LoggerFactory.getLogger(L.UI);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
|
@ -195,10 +201,26 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
|
|||
if (nsUploadOnly)
|
||||
refreshFromNS.setVisibility(View.GONE);
|
||||
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onResume() {
|
||||
super.onResume();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventProfileNeedsUpdate.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGUI(), FabricPrivacy::logException)
|
||||
);
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onPause() {
|
||||
super.onPause();
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
|
@ -218,20 +240,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
|
|||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventProfileNeedsUpdate ev) {
|
||||
updateGUI();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getProfileSwitchData(false)), false);
|
||||
}
|
||||
});
|
||||
recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getProfileSwitchData(false)), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.data.Profile;
|
|||
import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||
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.queue.commands.Command;
|
||||
|
@ -73,7 +74,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
|
|||
}
|
||||
|
||||
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASALPROFILE)) {
|
||||
MainApp.bus().post(new EventProfileNeedsUpdate());
|
||||
RxBus.INSTANCE.send(new EventProfileNeedsUpdate());
|
||||
} else if (isStatusOutdated && !pump.isBusy()) {
|
||||
lastReadStatus = System.currentTimeMillis();
|
||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("KeepAlive. Status outdated.", null);
|
||||
|
|
|
@ -11,23 +11,24 @@ import android.os.IBinder;
|
|||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventAppExit;
|
||||
import info.nightscout.androidaps.events.EventLocationChange;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class LocationService extends Service {
|
||||
private static Logger log = LoggerFactory.getLogger(L.LOCATION);
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private LocationManager mLocationManager = null;
|
||||
private static final float LOCATION_DISTANCE = 10f;
|
||||
|
@ -125,7 +126,14 @@ public class LocationService extends Service {
|
|||
} catch (IllegalArgumentException ex) {
|
||||
log.error("network provider does not exist, " + ex.getMessage());
|
||||
}
|
||||
MainApp.bus().register(this);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventAppExit.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (L.isEnabled(L.CORE)) log.debug("EventAppExit received");
|
||||
stopSelf();
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,15 +151,7 @@ public class LocationService extends Service {
|
|||
log.error("fail to remove location listener, ignore", ex);
|
||||
}
|
||||
}
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(EventAppExit event) {
|
||||
if (L.isEnabled(L.CORE))
|
||||
log.debug("EventAppExit received");
|
||||
|
||||
stopSelf();
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
private void initializeLocationManager() {
|
||||
|
|
|
@ -107,6 +107,16 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateButtons(), FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventProfileNeedsUpdate.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateButtons(), FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventProfileStoreChanged.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateButtons(), FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
@ -116,16 +126,6 @@ public class SetupWizardActivity extends NoSplashAppCompatActivity {
|
|||
updateButtons();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEventProfileStoreChanged(EventProfileStoreChanged ignored) {
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEventProfileSwitchChange(EventProfileNeedsUpdate ignored) {
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void generateLayout() {
|
||||
SWScreen currentScreen = screens.get(currentWizardPage);
|
||||
LinearLayout layout = SWItem.generateLayout(this.findViewById(R.id.sw_content_fields));
|
||||
|
|
|
@ -98,7 +98,6 @@ public class SWItem {
|
|||
public void run() {
|
||||
if (L.isEnabled(L.CORE))
|
||||
log.debug("Firing EventPreferenceChange");
|
||||
MainApp.bus().post(new EventPreferenceChange(preferenceId));
|
||||
RxBus.INSTANCE.send(new EventPreferenceChange(preferenceId));
|
||||
MainApp.bus().post(new EventSWUpdate());
|
||||
scheduledEventPost = null;
|
||||
|
|
Loading…
Reference in a new issue