Merge branch 'dev' into survey
This commit is contained in:
commit
7bbf30ec65
|
@ -109,7 +109,7 @@ android {
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
versionCode 1500
|
versionCode 1500
|
||||||
version "2.4-dev-g"
|
version "2.4-dev-i"
|
||||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||||
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
|
buildConfigField "String", "REMOTE", '"' + generateGitRemote() + '"'
|
||||||
|
@ -242,8 +242,6 @@ dependencies {
|
||||||
implementation 'androidx.percentlayout:percentlayout:1.0.0'
|
implementation 'androidx.percentlayout:percentlayout:1.0.0'
|
||||||
implementation "com.wdullaer:materialdatetimepicker:2.3.0"
|
implementation "com.wdullaer:materialdatetimepicker:2.3.0"
|
||||||
|
|
||||||
// Otto bus will be replaced by rx
|
|
||||||
implementation "com.squareup:otto:1.3.7"
|
|
||||||
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
|
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
|
||||||
|
|
||||||
implementation "com.j256.ormlite:ormlite-core:${ormLiteVersion}"
|
implementation "com.j256.ormlite:ormlite-core:${ormLiteVersion}"
|
||||||
|
@ -288,9 +286,6 @@ dependencies {
|
||||||
testImplementation("com.google.truth:truth:0.39") {
|
testImplementation("com.google.truth:truth:0.39") {
|
||||||
exclude group: "com.google.guava", module: "guava"
|
exclude group: "com.google.guava", module: "guava"
|
||||||
}
|
}
|
||||||
testImplementation("org.robolectric:robolectric:4.2.1") {
|
|
||||||
exclude group: "com.google.guava", module: "guava"
|
|
||||||
}
|
|
||||||
testImplementation "org.skyscreamer:jsonassert:1.5.0"
|
testImplementation "org.skyscreamer:jsonassert:1.5.0"
|
||||||
testImplementation "org.hamcrest:hamcrest-all:1.3"
|
testImplementation "org.hamcrest:hamcrest-all:1.3"
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,96 +0,0 @@
|
||||||
package com.squareup.otto;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ConcurrentModificationException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logs events has they're being posted to and dispatched from the event bus.
|
|
||||||
* <p>
|
|
||||||
* A summary of event-receiver calls that occurred so far is logged
|
|
||||||
* after 10s (after startup) and then again every 60s.
|
|
||||||
*/
|
|
||||||
public class LoggingBus extends Bus {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(L.EVENTS);
|
|
||||||
|
|
||||||
private static long everyMinute = System.currentTimeMillis() + 10 * 1000;
|
|
||||||
private Map<String, Set<String>> event2Receiver = new HashMap<>();
|
|
||||||
|
|
||||||
public LoggingBus(ThreadEnforcer enforcer) {
|
|
||||||
super(enforcer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void post(Object event) {
|
|
||||||
if (event instanceof DeadEvent) {
|
|
||||||
log.debug("Event has no receiver: " + ((DeadEvent) event).event + ", source: " + ((DeadEvent) event).source);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(event instanceof Event)) {
|
|
||||||
log.error("Posted event not an event class: " + event.getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("<<< " + event);
|
|
||||||
try {
|
|
||||||
StackTraceElement caller = new Throwable().getStackTrace()[1];
|
|
||||||
String className = caller.getClassName();
|
|
||||||
className = className.substring(className.lastIndexOf(".") + 1);
|
|
||||||
log.debug(" source: " + className + "." + caller.getMethodName() + ":" + caller.getLineNumber());
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
log.debug(" source: <unknown>");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
super.post(event);
|
|
||||||
} catch (IllegalStateException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void dispatch(Object event, EventHandler wrapper) {
|
|
||||||
try {
|
|
||||||
log.debug(">>> " + event);
|
|
||||||
Field methodField = wrapper.getClass().getDeclaredField("method");
|
|
||||||
methodField.setAccessible(true);
|
|
||||||
Method targetMethod = (Method) methodField.get(wrapper);
|
|
||||||
String className = targetMethod.getDeclaringClass().getSimpleName();
|
|
||||||
String methodName = targetMethod.getName();
|
|
||||||
String receiverMethod = className + "." + methodName;
|
|
||||||
log.debug(" receiver: " + receiverMethod);
|
|
||||||
|
|
||||||
String key = event.getClass().getSimpleName();
|
|
||||||
if (!event2Receiver.containsKey(key)) event2Receiver.put(key, new HashSet<String>());
|
|
||||||
event2Receiver.get(key).add(receiverMethod);
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
log.debug(" receiver: <unknown>");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (everyMinute < System.currentTimeMillis()) {
|
|
||||||
log.debug("***************** Event -> receiver pairings seen so far ****************");
|
|
||||||
for (Map.Entry<String, Set<String>> stringSetEntry : event2Receiver.entrySet()) {
|
|
||||||
log.debug(" " + stringSetEntry.getKey());
|
|
||||||
for (String s : stringSetEntry.getValue()) {
|
|
||||||
log.debug(" -> " + s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.debug("*************************************************************************");
|
|
||||||
everyMinute = System.currentTimeMillis() + 60 * 1000;
|
|
||||||
}
|
|
||||||
} catch (ConcurrentModificationException ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
super.dispatch(event, wrapper);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,6 +21,7 @@ import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
@ -33,7 +34,6 @@ import com.google.android.material.navigation.NavigationView;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import com.joanzapata.iconify.Iconify;
|
import com.joanzapata.iconify.Iconify;
|
||||||
import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -46,13 +46,13 @@ import info.nightscout.androidaps.activities.SingleFragmentActivity;
|
||||||
import info.nightscout.androidaps.activities.SurveyActivity;
|
import info.nightscout.androidaps.activities.SurveyActivity;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventFeatureRunning;
|
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRebuildTabs;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
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.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||||
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt;
|
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt;
|
||||||
|
@ -64,9 +64,12 @@ import info.nightscout.androidaps.utils.LocaleHelper;
|
||||||
import info.nightscout.androidaps.utils.OKDialog;
|
import info.nightscout.androidaps.utils.OKDialog;
|
||||||
import info.nightscout.androidaps.utils.PasswordProtection;
|
import info.nightscout.androidaps.utils.PasswordProtection;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class MainActivity extends NoSplashAppCompatActivity {
|
public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
protected PowerManager.WakeLock mWakeLock;
|
protected PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
|
@ -78,9 +81,6 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (L.isEnabled(L.CORE))
|
|
||||||
log.debug("onCreate");
|
|
||||||
|
|
||||||
Iconify.with(new FontAwesomeModule());
|
Iconify.with(new FontAwesomeModule());
|
||||||
LocaleHelper.onCreate(this, "en");
|
LocaleHelper.onCreate(this, "en");
|
||||||
|
|
||||||
|
@ -96,14 +96,10 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
actionBarDrawerToggle.syncState();
|
actionBarDrawerToggle.syncState();
|
||||||
|
|
||||||
// initialize screen wake lock
|
// initialize screen wake lock
|
||||||
onEventPreferenceChange(new EventPreferenceChange(R.string.key_keep_screen_on));
|
processPreferenceChange(new EventPreferenceChange(R.string.key_keep_screen_on));
|
||||||
|
|
||||||
doMigrations();
|
doMigrations();
|
||||||
|
|
||||||
registerBus();
|
|
||||||
setupTabs();
|
|
||||||
setupViews(false);
|
|
||||||
|
|
||||||
final ViewPager viewPager = findViewById(R.id.pager);
|
final ViewPager viewPager = findViewById(R.id.pager);
|
||||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -144,8 +140,34 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
if (L.isEnabled(L.CORE))
|
setupTabs();
|
||||||
log.debug("onResume");
|
setupViews();
|
||||||
|
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventRebuildTabs.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> {
|
||||||
|
String lang = SP.getString(R.string.key_language, "en");
|
||||||
|
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||||
|
if (event.getRecreate()) {
|
||||||
|
recreate();
|
||||||
|
} else {
|
||||||
|
setupTabs();
|
||||||
|
setupViews();
|
||||||
|
}
|
||||||
|
|
||||||
|
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(this::processPreferenceChange, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
|
||||||
if (!SP.getBoolean(R.string.key_setupwizard_processed, false)) {
|
if (!SP.getBoolean(R.string.key_setupwizard_processed, false)) {
|
||||||
Intent intent = new Intent(this, SetupWizardActivity.class);
|
Intent intent = new Intent(this, SetupWizardActivity.class);
|
||||||
|
@ -160,22 +182,23 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
AndroidPermission.notifyForLocationPermissions(this);
|
AndroidPermission.notifyForLocationPermissions(this);
|
||||||
AndroidPermission.notifyForSMSPermissions(this);
|
AndroidPermission.notifyForSMSPermissions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainApp.bus().post(new EventFeatureRunning(EventFeatureRunning.Feature.MAIN));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (L.isEnabled(L.CORE))
|
|
||||||
log.debug("onDestroy");
|
|
||||||
if (mWakeLock != null)
|
if (mWakeLock != null)
|
||||||
if (mWakeLock.isHeld())
|
if (mWakeLock.isHeld())
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Override
|
||||||
public void onEventPreferenceChange(final EventPreferenceChange ev) {
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
disposable.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processPreferenceChange(final EventPreferenceChange ev) {
|
||||||
if (ev.isChanged(R.string.key_keep_screen_on)) {
|
if (ev.isChanged(R.string.key_keep_screen_on)) {
|
||||||
boolean keepScreenOn = SP.getBoolean(R.string.key_keep_screen_on, false);
|
boolean keepScreenOn = SP.getBoolean(R.string.key_keep_screen_on, false);
|
||||||
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
|
@ -190,36 +213,10 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
private void setupViews() {
|
||||||
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);
|
TabPageAdapter pageAdapter = new TabPageAdapter(getSupportFragmentManager(), this);
|
||||||
NavigationView navigationView = findViewById(R.id.navigation_view);
|
NavigationView navigationView = findViewById(R.id.navigation_view);
|
||||||
navigationView.setNavigationItemSelectedListener(menuItem -> {
|
navigationView.setNavigationItemSelectedListener(menuItem -> true);
|
||||||
return true;
|
|
||||||
});
|
|
||||||
Menu menu = navigationView.getMenu();
|
Menu menu = navigationView.getMenu();
|
||||||
menu.clear();
|
menu.clear();
|
||||||
for (PluginBase p : MainApp.getPluginsList()) {
|
for (PluginBase p : MainApp.getPluginsList()) {
|
||||||
|
@ -238,8 +235,8 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
}
|
}
|
||||||
ViewPager mPager = findViewById(R.id.pager);
|
ViewPager mPager = findViewById(R.id.pager);
|
||||||
mPager.setAdapter(pageAdapter);
|
mPager.setAdapter(pageAdapter);
|
||||||
if (switchToLast)
|
//if (switchToLast)
|
||||||
mPager.setCurrentItem(pageAdapter.getCount() - 1, false);
|
// mPager.setCurrentItem(pageAdapter.getCount() - 1, false);
|
||||||
checkPluginPreferences(mPager);
|
checkPluginPreferences(mPager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,15 +262,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() {
|
private void checkEula() {
|
||||||
//SP.removeBoolean(R.string.key_i_understand);
|
//SP.removeBoolean(R.string.key_i_understand);
|
||||||
boolean IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
|
boolean IUnderstand = SP.getBoolean(R.string.key_i_understand, false);
|
||||||
|
@ -290,10 +278,10 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
|
|
||||||
// guarantee that the unreachable threshold is at least 30 and of type String
|
// guarantee that the unreachable threshold is at least 30 and of type String
|
||||||
// Added in 1.57 at 21.01.2018
|
// Added in 1.57 at 21.01.2018
|
||||||
Integer unreachable_threshold = SP.getInt(R.string.key_pump_unreachable_threshold, 30);
|
int unreachable_threshold = SP.getInt(R.string.key_pump_unreachable_threshold, 30);
|
||||||
SP.remove(R.string.key_pump_unreachable_threshold);
|
SP.remove(R.string.key_pump_unreachable_threshold);
|
||||||
if (unreachable_threshold < 30) unreachable_threshold = 30;
|
if (unreachable_threshold < 30) unreachable_threshold = 30;
|
||||||
SP.putString(R.string.key_pump_unreachable_threshold, unreachable_threshold.toString());
|
SP.putString(R.string.key_pump_unreachable_threshold, Integer.toString(unreachable_threshold));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -309,19 +297,16 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
String message = "Target range is changed in current version.\n\nIt's not taken from preferences but from profile.\n\n!!! REVIEW YOUR SETTINGS !!!";
|
String message = "Target range is changed in current version.\n\nIt's not taken from preferences but from profile.\n\n!!! REVIEW YOUR SETTINGS !!!";
|
||||||
message += "\n\nOld settings: " + oldRange;
|
message += "\n\nOld settings: " + oldRange;
|
||||||
message += "\nProfile settings: " + newRange;
|
message += "\nProfile settings: " + newRange;
|
||||||
OKDialog.show(this, "Target range change", message, new Runnable() {
|
OKDialog.show(this, "Target range change", message, () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
SP.remove("openapsma_min_bg");
|
SP.remove("openapsma_min_bg");
|
||||||
SP.remove("openapsma_max_bg");
|
SP.remove("openapsma_max_bg");
|
||||||
SP.remove("openapsma_target_bg");
|
SP.remove("openapsma_target_bg");
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
if (permissions.length != 0) {
|
if (permissions.length != 0) {
|
||||||
if (ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(this, permissions[0]) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
@ -406,7 +391,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
|
||||||
case R.id.nav_exit:
|
case R.id.nav_exit:
|
||||||
log.debug("Exiting");
|
log.debug("Exiting");
|
||||||
MainApp.instance().stopKeepAliveService();
|
MainApp.instance().stopKeepAliveService();
|
||||||
MainApp.bus().post(new EventAppExit());
|
RxBus.INSTANCE.send(new EventAppExit());
|
||||||
MainApp.closeDbHelper();
|
MainApp.closeDbHelper();
|
||||||
finish();
|
finish();
|
||||||
System.runFinalization();
|
System.runFinalization();
|
||||||
|
|
|
@ -13,9 +13,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||||
import com.crashlytics.android.Crashlytics;
|
import com.crashlytics.android.Crashlytics;
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||||
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
import com.squareup.otto.LoggingBus;
|
|
||||||
import com.squareup.otto.ThreadEnforcer;
|
|
||||||
|
|
||||||
import net.danlew.android.joda.JodaTimeAndroid;
|
import net.danlew.android.joda.JodaTimeAndroid;
|
||||||
|
|
||||||
|
@ -101,7 +98,6 @@ public class MainApp extends Application {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||||
private static KeepAliveReceiver keepAliveReceiver;
|
private static KeepAliveReceiver keepAliveReceiver;
|
||||||
|
|
||||||
private static Bus sBus;
|
|
||||||
private static MainApp sInstance;
|
private static MainApp sInstance;
|
||||||
public static Resources sResources;
|
public static Resources sResources;
|
||||||
|
|
||||||
|
@ -157,8 +153,6 @@ public class MainApp extends Application {
|
||||||
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile();
|
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile();
|
||||||
devBranch = BuildConfig.VERSION.contains("-") || BuildConfig.VERSION.matches(".*[a-zA-Z]+.*");
|
devBranch = BuildConfig.VERSION.contains("-") || BuildConfig.VERSION.matches(".*[a-zA-Z]+.*");
|
||||||
|
|
||||||
sBus = L.isEnabled(L.EVENTS) && devBranch ? new LoggingBus(ThreadEnforcer.ANY) : new Bus(ThreadEnforcer.ANY);
|
|
||||||
|
|
||||||
registerLocalBroadcastReceiver();
|
registerLocalBroadcastReceiver();
|
||||||
|
|
||||||
//trigger here to see the new version on app start after an update
|
//trigger here to see the new version on app start after an update
|
||||||
|
@ -285,10 +279,6 @@ public class MainApp extends Application {
|
||||||
KeepAliveReceiver.cancelAlarm(this);
|
KeepAliveReceiver.cancelAlarm(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bus bus() {
|
|
||||||
return sBus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String gs(int id) {
|
public static String gs(int id) {
|
||||||
return sResources.getString(id);
|
return sResources.getString(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import androidx.appcompat.widget.PopupMenu;
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
|
||||||
import com.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -30,6 +29,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.events.EventCustomCalculationFinished;
|
import info.nightscout.androidaps.events.EventCustomCalculationFinished;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
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.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
|
import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
|
||||||
|
@ -39,12 +39,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.EventAutosensCalculationFinished;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import info.nightscout.androidaps.utils.T;
|
import info.nightscout.androidaps.utils.T;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class HistoryBrowseActivity extends NoSplashActivity {
|
public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class);
|
private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
ImageButton chartButton;
|
ImageButton chartButton;
|
||||||
|
|
||||||
|
@ -165,14 +168,33 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
MainApp.bus().unregister(this);
|
disposable.clear();
|
||||||
iobCobCalculatorPlugin.stopCalculation("onPause");
|
iobCobCalculatorPlugin.stopCalculation("onPause");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.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)
|
||||||
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventIobCalculationProgress.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> {
|
||||||
|
if (iobCalculationProgressView != null)
|
||||||
|
iobCalculationProgressView.setText(event.getProgress());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
// set start of current day
|
// set start of current day
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||||
|
@ -193,26 +215,6 @@ public class HistoryBrowseActivity extends NoSplashActivity {
|
||||||
iobCobCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished);
|
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(() -> {
|
|
||||||
if (iobCalculationProgressView != null)
|
|
||||||
iobCalculationProgressView.setText(e.progress);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateGUI(String from) {
|
void updateGUI(String from) {
|
||||||
log.debug("updateGUI from: " + from);
|
log.debug("updateGUI from: " + from);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRebuildTabs;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
|
||||||
|
@ -68,17 +68,16 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
MainApp.bus().post(new EventPreferenceChange(key));
|
|
||||||
RxBus.INSTANCE.send(new EventPreferenceChange(key));
|
RxBus.INSTANCE.send(new EventPreferenceChange(key));
|
||||||
if (key.equals("language")) {
|
if (key.equals("language")) {
|
||||||
String lang = sharedPreferences.getString("language", "en");
|
String lang = sharedPreferences.getString("language", "en");
|
||||||
LocaleHelper.setLocale(getApplicationContext(), lang);
|
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||||
MainApp.bus().post(new EventRefreshGui(true));
|
RxBus.INSTANCE.send(new EventRebuildTabs(true));
|
||||||
//recreate() does not update language so better close settings
|
//recreate() does not update language so better close settings
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
if (key.equals("short_tabtitles")) {
|
if (key.equals("short_tabtitles")) {
|
||||||
MainApp.bus().post(new EventRefreshGui());
|
RxBus.INSTANCE.send(new EventRebuildTabs());
|
||||||
}
|
}
|
||||||
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
|
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);
|
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
|
||||||
|
|
|
@ -33,7 +33,7 @@ class SurveyActivity : NoSplashAppCompatActivity() {
|
||||||
|
|
||||||
val tdds = TddCalculator.calculate(7)
|
val tdds = TddCalculator.calculate(7)
|
||||||
val averageTdd = TddCalculator.averageTDD(tdds)
|
val averageTdd = TddCalculator.averageTDD(tdds)
|
||||||
survey_tdds.text = MainApp.gs(R.string.tdd) + ":\n" + TddCalculator.toText(tdds) + MainApp.gs(R.string.average) + ":\n" + TddCalculator.toText(averageTdd)
|
survey_tdds.text = MainApp.gs(R.string.tdd) + ":\n" + TddCalculator.toText(tdds) + MainApp.gs(R.string.average) + ":\n" + averageTdd.toText()
|
||||||
|
|
||||||
survey_profile.setOnClickListener {
|
survey_profile.setOnClickListener {
|
||||||
val age = SafeParse.stringToDouble(survey_age.text.toString())
|
val age = SafeParse.stringToDouble(survey_age.text.toString())
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
package info.nightscout.androidaps.activities;
|
package info.nightscout.androidaps.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -18,7 +16,7 @@ import android.widget.TableLayout;
|
||||||
import android.widget.TableRow;
|
import android.widget.TableRow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -39,6 +37,7 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TDD;
|
import info.nightscout.androidaps.db.TDD;
|
||||||
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
import info.nightscout.androidaps.events.EventPumpStatusChanged;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
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.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
||||||
|
@ -49,11 +48,15 @@ import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin;
|
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import info.nightscout.androidaps.utils.SafeParse;
|
import info.nightscout.androidaps.utils.SafeParse;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class TDDStatsActivity extends NoSplashActivity {
|
public class TDDStatsActivity extends NoSplashActivity {
|
||||||
private static Logger log = LoggerFactory.getLogger(TDDStatsActivity.class);
|
private static Logger log = LoggerFactory.getLogger(TDDStatsActivity.class);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
TextView statusView, statsMessage, totalBaseBasal2;
|
TextView statusView, statsMessage, totalBaseBasal2;
|
||||||
EditText totalBaseBasal;
|
EditText totalBaseBasal;
|
||||||
|
@ -74,13 +77,25 @@ public class TDDStatsActivity extends NoSplashActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
MainApp.bus().register(this);
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventPumpStatusChanged.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> statusView.setText(event.getStatus()), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventDanaRSyncStatus.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> {
|
||||||
|
log.debug("EventDanaRSyncStatus: " + event.getMessage());
|
||||||
|
statusView.setText(event.getMessage());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
MainApp.bus().unregister(this);
|
disposable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -519,31 +534,6 @@ public class TDDStatsActivity extends NoSplashActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventDanaRSyncStatus s) {
|
|
||||||
log.debug("EventDanaRSyncStatus: " + s.message);
|
|
||||||
runOnUiThread(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
statusView.setText(s.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventPumpStatusChanged c) {
|
|
||||||
runOnUiThread(
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
statusView.setText(c.textStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isOldData(List<TDD> historyList) {
|
public static boolean isOldData(List<TDD> historyList) {
|
||||||
Object activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
Object activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||||
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||||
|
|
|
@ -243,7 +243,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
new java.util.TimerTask() {
|
new java.util.TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MainApp.bus().post(new EventRefreshOverview("resetDatabases"));
|
RxBus.INSTANCE.send(new EventRefreshOverview("resetDatabases"));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
3000
|
3000
|
||||||
|
@ -412,7 +412,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (L.isEnabled(L.DATABASE))
|
if (L.isEnabled(L.DATABASE))
|
||||||
log.debug("Firing EventNewBg");
|
log.debug("Firing EventNewBg");
|
||||||
MainApp.bus().post(new EventNewBG(bgReading));
|
|
||||||
RxBus.INSTANCE.send(new EventNewBG(bgReading));
|
RxBus.INSTANCE.send(new EventNewBG(bgReading));
|
||||||
scheduledBgPost = null;
|
scheduledBgPost = null;
|
||||||
}
|
}
|
||||||
|
@ -738,7 +737,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (L.isEnabled(L.DATABASE))
|
if (L.isEnabled(L.DATABASE))
|
||||||
log.debug("Firing EventTempTargetChange");
|
log.debug("Firing EventTempTargetChange");
|
||||||
MainApp.bus().post(new EventTempTargetChange());
|
RxBus.INSTANCE.send(new EventTempTargetChange());
|
||||||
scheduledTemTargetPost = null;
|
scheduledTemTargetPost = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1035,10 +1034,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (L.isEnabled(L.DATABASE))
|
if (L.isEnabled(L.DATABASE))
|
||||||
log.debug("Firing EventTempBasalChange");
|
log.debug("Firing EventTempBasalChange");
|
||||||
MainApp.bus().post(new EventReloadTempBasalData());
|
RxBus.INSTANCE.send(new EventReloadTempBasalData());
|
||||||
MainApp.bus().post(new EventTempBasalChange());
|
RxBus.INSTANCE.send(new EventTempBasalChange());
|
||||||
if (earliestDataChange != null)
|
if (earliestDataChange != null)
|
||||||
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
RxBus.INSTANCE.send(new EventNewHistoryData(earliestDataChange));
|
||||||
earliestDataChange = null;
|
earliestDataChange = null;
|
||||||
scheduledTemBasalsPost = null;
|
scheduledTemBasalsPost = null;
|
||||||
}
|
}
|
||||||
|
@ -1371,9 +1370,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (L.isEnabled(L.DATABASE))
|
if (L.isEnabled(L.DATABASE))
|
||||||
log.debug("Firing EventExtendedBolusChange");
|
log.debug("Firing EventExtendedBolusChange");
|
||||||
MainApp.bus().post(new EventReloadTreatmentData(new EventExtendedBolusChange()));
|
RxBus.INSTANCE.send(new EventReloadTreatmentData(new EventExtendedBolusChange()));
|
||||||
if (earliestDataChange != null)
|
if (earliestDataChange != null)
|
||||||
MainApp.bus().post(new EventNewHistoryData(earliestDataChange));
|
RxBus.INSTANCE.send(new EventNewHistoryData(earliestDataChange));
|
||||||
earliestDataChange = null;
|
earliestDataChange = null;
|
||||||
scheduledExtendedBolusPost = null;
|
scheduledExtendedBolusPost = null;
|
||||||
}
|
}
|
||||||
|
@ -1577,7 +1576,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (L.isEnabled(L.DATABASE))
|
if (L.isEnabled(L.DATABASE))
|
||||||
log.debug("Firing scheduleCareportalEventChange");
|
log.debug("Firing scheduleCareportalEventChange");
|
||||||
MainApp.bus().post(new EventCareportalEventChange());
|
RxBus.INSTANCE.send(new EventCareportalEventChange());
|
||||||
scheduledCareportalEventPost = null;
|
scheduledCareportalEventPost = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1729,8 +1728,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (L.isEnabled(L.DATABASE))
|
if (L.isEnabled(L.DATABASE))
|
||||||
log.debug("Firing EventProfileNeedsUpdate");
|
log.debug("Firing EventProfileNeedsUpdate");
|
||||||
MainApp.bus().post(new EventReloadProfileSwitchData());
|
RxBus.INSTANCE.send(new EventReloadProfileSwitchData());
|
||||||
MainApp.bus().post(new EventProfileNeedsUpdate());
|
RxBus.INSTANCE.send(new EventProfileNeedsUpdate());
|
||||||
scheduledProfileSwitchEventPost = null;
|
scheduledProfileSwitchEventPost = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
|
||||||
|
|
||||||
/** Base class for all events posted on the event bus. */
|
|
||||||
public abstract class Event {
|
|
||||||
static {
|
|
||||||
ReflectionToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return ReflectionToStringBuilder.toString(this);
|
|
||||||
}
|
|
||||||
}
|
|
18
app/src/main/java/info/nightscout/androidaps/events/Event.kt
Normal file
18
app/src/main/java/info/nightscout/androidaps/events/Event.kt
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle
|
||||||
|
|
||||||
|
/** Base class for all events posted on the event bus. */
|
||||||
|
abstract class Event {
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return ReflectionToStringBuilder.toString(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
ReflectionToStringBuilder.setDefaultStyle(ToStringStyle.SHORT_PREFIX_STYLE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/** Base class for events to update the UI, mostly a specific tab. */
|
|
||||||
public class EventAcceptOpenLoopChange extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventAcceptOpenLoopChange : Event()
|
|
@ -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,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 23.01.2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventAppInitialized extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventAppInitialized : Event()
|
|
@ -1,21 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by adrian on 07/02/17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventBolusRequested extends Event {
|
|
||||||
private double amount;
|
|
||||||
|
|
||||||
public EventBolusRequested (double amount){
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getAmount() {
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAmount(double amount) {
|
|
||||||
this.amount = amount;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventBolusRequested(var amount: Double) : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 25.05.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventCareportalEventChange extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventCareportalEventChange : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 17.02.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventConfigBuilderChange extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventConfigBuilderChange : Event()
|
|
@ -1,4 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
public class EventCustomActionsChanged extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventCustomActionsChanged : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 13.02.2018.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventCustomCalculationFinished extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventCustomCalculationFinished : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 15.05.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventExtendedBolusChange extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventExtendedBolusChange : EventLoop()
|
|
@ -1,36 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by jamorham on 07/02/2018.
|
|
||||||
*
|
|
||||||
* Event to indicate that an app feature is being used, for example bolus wizard being opened
|
|
||||||
*
|
|
||||||
* The purpose this has been created for is to enable opportunistic connection to the pump
|
|
||||||
* so that it is already connected before the user wishes to enact a pump function
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventFeatureRunning extends Event {
|
|
||||||
|
|
||||||
private Feature feature = Feature.UNKNOWN;
|
|
||||||
|
|
||||||
public EventFeatureRunning() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventFeatureRunning(Feature feature) {
|
|
||||||
this.feature = feature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Feature getFeature() {
|
|
||||||
return feature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Feature {
|
|
||||||
UNKNOWN,
|
|
||||||
MAIN,
|
|
||||||
WIZARD,
|
|
||||||
|
|
||||||
JUST_ADD_MORE_HERE
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 20.09.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventFoodDatabaseChanged extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventFoodDatabaseChanged : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 13.12.2016.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventInitializationChanged extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventInitializationChanged : Event()
|
|
@ -1,11 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
import android.location.Location;
|
|
||||||
|
|
||||||
public class EventLocationChange extends Event {
|
|
||||||
public Location location;
|
|
||||||
|
|
||||||
public EventLocationChange(Location location) {
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import android.location.Location
|
||||||
|
|
||||||
|
class EventLocationChange(var location: Location) : Event()
|
|
@ -1,5 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/** Supeclass for all events concerned with input or output into or from the LoopPlugin. */
|
|
||||||
public abstract class EventLoop extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
/** Supeclass for all events concerned with input or output into or from the LoopPlugin. */
|
||||||
|
abstract class EventLoop : Event()
|
|
@ -1,17 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.utils.StringUtils;
|
|
||||||
|
|
||||||
public class EventNetworkChange extends Event {
|
|
||||||
|
|
||||||
public boolean mobileConnected = false;
|
|
||||||
public boolean wifiConnected = false;
|
|
||||||
|
|
||||||
public String ssid = "";
|
|
||||||
public boolean roaming = false;
|
|
||||||
|
|
||||||
public String getSsid() {
|
|
||||||
return StringUtils.removeSurroundingQuotes(ssid);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.utils.StringUtils
|
||||||
|
|
||||||
|
class EventNetworkChange : Event() {
|
||||||
|
|
||||||
|
var mobileConnected = false
|
||||||
|
var wifiConnected = false
|
||||||
|
|
||||||
|
var ssid = ""
|
||||||
|
var roaming = false
|
||||||
|
|
||||||
|
fun connectedSsid(): String {
|
||||||
|
return StringUtils.removeSurroundingQuotes(ssid)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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()
|
|
@ -1,35 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event which is published with data fetched from NightScout specific for the
|
|
||||||
* Food-class.
|
|
||||||
*
|
|
||||||
* Payload is the from NS retrieved JSON-String which should be handled by all
|
|
||||||
* subscriber.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventNsFood extends Event {
|
|
||||||
|
|
||||||
public static final int ADD = 0;
|
|
||||||
public static final int UPDATE = 1;
|
|
||||||
public static final int REMOVE = 2;
|
|
||||||
|
|
||||||
private final int mode;
|
|
||||||
|
|
||||||
private final Bundle payload;
|
|
||||||
|
|
||||||
public EventNsFood(int mode, Bundle payload) {
|
|
||||||
this.mode = mode;
|
|
||||||
this.payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMode() {
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Bundle getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event which is published with data fetched from NightScout specific for the
|
||||||
|
* Food-class.
|
||||||
|
*
|
||||||
|
* Payload is the from NS retrieved JSON-String which should be handled by all
|
||||||
|
* subscriber.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class EventNsFood(val mode: Int, val payload: Bundle) : Event() {
|
||||||
|
companion object {
|
||||||
|
val ADD = 0
|
||||||
|
val UPDATE = 1
|
||||||
|
val REMOVE = 2
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,36 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event which is published with data fetched from NightScout specific for the
|
|
||||||
* Treatment-class.
|
|
||||||
* <p>
|
|
||||||
* Payload is the from NS retrieved JSON-String which should be handled by all
|
|
||||||
* subscriber.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventNsTreatment extends Event {
|
|
||||||
|
|
||||||
public static final int ADD = 0;
|
|
||||||
public static final int UPDATE = 1;
|
|
||||||
public static final int REMOVE = 2;
|
|
||||||
|
|
||||||
private final int mode;
|
|
||||||
|
|
||||||
private final JSONObject payload;
|
|
||||||
|
|
||||||
public EventNsTreatment(int mode, JSONObject payload) {
|
|
||||||
this.mode = mode;
|
|
||||||
this.payload = payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getMode() {
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONObject getPayload() {
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event which is published with data fetched from NightScout specific for the
|
||||||
|
* Treatment-class.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Payload is the from NS retrieved JSON-String which should be handled by all
|
||||||
|
* subscriber.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class EventNsTreatment(val mode: Int, val payload: JSONObject) : Event() {
|
||||||
|
companion object {
|
||||||
|
val ADD = 0
|
||||||
|
val UPDATE = 1
|
||||||
|
val REMOVE = 2
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,63 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 19.02.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventPumpStatusChanged extends Event {
|
|
||||||
public static final int CONNECTING = 0;
|
|
||||||
public static final int CONNECTED = 1;
|
|
||||||
public static final int HANDSHAKING = 2;
|
|
||||||
public static final int PERFORMING = 3;
|
|
||||||
public static final int DISCONNECTING = 4;
|
|
||||||
public static final int DISCONNECTED = 5;
|
|
||||||
|
|
||||||
public int sStatus = DISCONNECTED;
|
|
||||||
public int sSecondsElapsed = 0;
|
|
||||||
public String sPerfomingAction = "";
|
|
||||||
|
|
||||||
public static String error = "";
|
|
||||||
|
|
||||||
public EventPumpStatusChanged(int status) {
|
|
||||||
sStatus = status;
|
|
||||||
sSecondsElapsed = 0;
|
|
||||||
error = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventPumpStatusChanged(int status, int secondsElapsed) {
|
|
||||||
sStatus = status;
|
|
||||||
sSecondsElapsed = secondsElapsed;
|
|
||||||
error = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventPumpStatusChanged(int status, String error) {
|
|
||||||
sStatus = status;
|
|
||||||
sSecondsElapsed = 0;
|
|
||||||
this.error = error;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventPumpStatusChanged(String action) {
|
|
||||||
sStatus = PERFORMING;
|
|
||||||
sSecondsElapsed = 0;
|
|
||||||
sPerfomingAction = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String textStatus() {
|
|
||||||
if (sStatus == CONNECTING)
|
|
||||||
return String.format(MainApp.gs(R.string.danar_history_connectingfor), sSecondsElapsed);
|
|
||||||
else if (sStatus == HANDSHAKING)
|
|
||||||
return MainApp.gs(R.string.handshaking);
|
|
||||||
else if (sStatus == CONNECTED)
|
|
||||||
return MainApp.gs(R.string.connected);
|
|
||||||
else if (sStatus == PERFORMING)
|
|
||||||
return sPerfomingAction;
|
|
||||||
else if (sStatus == DISCONNECTING)
|
|
||||||
return MainApp.gs(R.string.disconnecting);
|
|
||||||
else if (sStatus == DISCONNECTED)
|
|
||||||
return "";
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
|
||||||
|
class EventPumpStatusChanged : EventStatus {
|
||||||
|
|
||||||
|
enum class Status {
|
||||||
|
CONNECTING,
|
||||||
|
CONNECTED,
|
||||||
|
HANDSHAKING,
|
||||||
|
PERFORMING,
|
||||||
|
DISCONNECTING,
|
||||||
|
DISCONNECTED
|
||||||
|
}
|
||||||
|
|
||||||
|
var sStatus: Status = Status.DISCONNECTED
|
||||||
|
var sSecondsElapsed = 0
|
||||||
|
var sPerfomingAction = ""
|
||||||
|
var error = ""
|
||||||
|
|
||||||
|
constructor(status: Status) {
|
||||||
|
sStatus = status
|
||||||
|
sSecondsElapsed = 0
|
||||||
|
error = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(status: Status, secondsElapsed: Int) {
|
||||||
|
sStatus = status
|
||||||
|
sSecondsElapsed = secondsElapsed
|
||||||
|
error = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(status: Status, error: String) {
|
||||||
|
sStatus = status
|
||||||
|
sSecondsElapsed = 0
|
||||||
|
this.error = error
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(action: String) {
|
||||||
|
sStatus = Status.PERFORMING
|
||||||
|
sSecondsElapsed = 0
|
||||||
|
sPerfomingAction = action
|
||||||
|
}
|
||||||
|
|
||||||
|
// status for startup wizard
|
||||||
|
override fun getStatus(): String {
|
||||||
|
if (sStatus == Status.CONNECTING)
|
||||||
|
return String.format(MainApp.gs(R.string.danar_history_connectingfor), sSecondsElapsed)
|
||||||
|
else if (sStatus == Status.HANDSHAKING)
|
||||||
|
return MainApp.gs(R.string.handshaking)
|
||||||
|
else if (sStatus == Status.CONNECTED)
|
||||||
|
return MainApp.gs(R.string.connected)
|
||||||
|
else if (sStatus == Status.PERFORMING)
|
||||||
|
return sPerfomingAction
|
||||||
|
else if (sStatus == Status.DISCONNECTING)
|
||||||
|
return MainApp.gs(R.string.disconnecting)
|
||||||
|
else if (sStatus == Status.DISCONNECTED)
|
||||||
|
return ""
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventRebuildTabs @JvmOverloads constructor(var recreate: Boolean = false) : 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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 16.06.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventRefreshOverview extends Event {
|
|
||||||
public String from;
|
|
||||||
|
|
||||||
public EventRefreshOverview(String from) {
|
|
||||||
this.from = from;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventRefreshOverview(var from: String) : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 12.06.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventReloadProfileSwitchData extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventReloadProfileSwitchData : Event()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 29.05.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventReloadTempBasalData extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventReloadTempBasalData : Event()
|
|
@ -1,13 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 29.05.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventReloadTreatmentData extends Event {
|
|
||||||
public Object next;
|
|
||||||
|
|
||||||
public EventReloadTreatmentData(Object next) {
|
|
||||||
this.next = next;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventReloadTreatmentData(var next: Event) : Event()
|
|
@ -0,0 +1,6 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
// pass string to startup wizard
|
||||||
|
abstract class EventStatus :Event() {
|
||||||
|
abstract fun getStatus() : String
|
||||||
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 05.06.2016.
|
|
||||||
*/
|
|
||||||
public class EventTempBasalChange extends EventLoop {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventTempBasalChange : EventLoop()
|
|
@ -1,8 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 13.01.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EventTempTargetChange extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
class EventTempTargetChange : Event()
|
|
@ -1,17 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 04.06.2016.
|
|
||||||
*/
|
|
||||||
public class EventTreatmentChange extends EventLoop {
|
|
||||||
@Nullable
|
|
||||||
public final Treatment treatment;
|
|
||||||
|
|
||||||
public EventTreatmentChange(Treatment treatment) {
|
|
||||||
this.treatment = treatment;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||||
|
|
||||||
|
class EventTreatmentChange(val treatment: Treatment?) : EventLoop()
|
|
@ -1,5 +0,0 @@
|
||||||
package info.nightscout.androidaps.events;
|
|
||||||
|
|
||||||
/** Base class for events to update the UI, mostly a specific tab. */
|
|
||||||
public abstract class EventUpdateGui extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package info.nightscout.androidaps.events
|
||||||
|
|
||||||
|
/** Base class for events to update the UI, mostly a specific tab. */
|
||||||
|
abstract class EventUpdateGui : Event()
|
|
@ -5,20 +5,19 @@ import android.os.SystemClock;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.EventConfigBuilderUpdateGui;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.events.EventConfigBuilderChange;
|
||||||
|
import info.nightscout.androidaps.events.EventRebuildTabs;
|
||||||
import info.nightscout.androidaps.logging.L;
|
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.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.EventConfigBuilderUpdateGui;
|
||||||
import info.nightscout.androidaps.queue.CommandQueue;
|
import info.nightscout.androidaps.queue.CommandQueue;
|
||||||
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 09.06.2016.
|
* Created by mike on 09.06.2016.
|
||||||
|
@ -81,8 +80,8 @@ public abstract class PluginBase {
|
||||||
setFragmentVisible(type, enabled);
|
setFragmentVisible(type, enabled);
|
||||||
ConfigBuilderPlugin.getPlugin().processOnEnabledCategoryChanged(this, getType());
|
ConfigBuilderPlugin.getPlugin().processOnEnabledCategoryChanged(this, getType());
|
||||||
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled");
|
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled");
|
||||||
MainApp.bus().post(new EventRefreshGui());
|
RxBus.INSTANCE.send(new EventRebuildTabs());
|
||||||
MainApp.bus().post(new EventConfigBuilderChange());
|
RxBus.INSTANCE.send(new EventConfigBuilderChange());
|
||||||
RxBus.INSTANCE.send(new EventConfigBuilderUpdateGui());
|
RxBus.INSTANCE.send(new EventConfigBuilderUpdateGui());
|
||||||
ConfigBuilderPlugin.getPlugin().logPluginStatus();
|
ConfigBuilderPlugin.getPlugin().logPluginStatus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ import android.os.SystemClock;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -62,12 +60,15 @@ import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import info.nightscout.androidaps.utils.T;
|
import info.nightscout.androidaps.utils.T;
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
import info.nightscout.androidaps.utils.ToastUtils;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class LoopPlugin extends PluginBase {
|
public class LoopPlugin extends PluginBase {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
private static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
||||||
|
|
||||||
|
@ -116,9 +117,39 @@ public class LoopPlugin extends PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
MainApp.bus().register(this);
|
|
||||||
createNotificationChannel();
|
createNotificationChannel();
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventTempTargetChange.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
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() {
|
private void createNotificationChannel() {
|
||||||
|
@ -135,8 +166,8 @@ public class LoopPlugin extends PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
|
disposable.clear();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -145,43 +176,10 @@ public class LoopPlugin extends PluginBase {
|
||||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
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() {
|
public long suspendedTo() {
|
||||||
return loopSuspendedTill;
|
return loopSuspendedTill;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventTempTargetChange ev) {
|
|
||||||
new Thread(() -> invoke("EventTempTargetChange", true)).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void suspendTo(long endTime) {
|
public void suspendTo(long endTime) {
|
||||||
loopSuspendedTill = endTime;
|
loopSuspendedTill = endTime;
|
||||||
isSuperBolus = false;
|
isSuperBolus = false;
|
||||||
|
@ -439,7 +437,7 @@ public class LoopPlugin extends PluginBase {
|
||||||
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
|
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
// mId allows you to update the notification later on.
|
// mId allows you to update the notification later on.
|
||||||
mNotificationManager.notify(Constants.notificationID, builder.build());
|
mNotificationManager.notify(Constants.notificationID, builder.build());
|
||||||
MainApp.bus().post(new EventNewOpenLoopNotification());
|
RxBus.INSTANCE.send(new EventNewOpenLoopNotification());
|
||||||
|
|
||||||
// Send to Wear
|
// Send to Wear
|
||||||
ActionStringHandler.handleInitiate("changeRequest");
|
ActionStringHandler.handleInitiate("changeRequest");
|
||||||
|
@ -472,7 +470,7 @@ public class LoopPlugin extends PluginBase {
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
SP.incInt(R.string.key_ObjectivesmanualEnacts);
|
SP.incInt(R.string.key_ObjectivesmanualEnacts);
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventAcceptOpenLoopChange());
|
RxBus.INSTANCE.send(new EventAcceptOpenLoopChange());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
FabricPrivacy.getInstance().logCustom("AcceptTemp");
|
FabricPrivacy.getInstance().logCustom("AcceptTemp");
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.loop.events;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 07.08.2016.
|
|
||||||
*/
|
|
||||||
public class EventNewOpenLoopNotification extends Event {
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package info.nightscout.androidaps.plugins.aps.loop.events
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.events.Event
|
||||||
|
|
||||||
|
class EventNewOpenLoopNotification : Event()
|
|
@ -1,22 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.common;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
|
|
||||||
abstract public class SubscriberFragment extends Fragment {
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
MainApp.bus().register(this);
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void updateGUI();
|
|
||||||
}
|
|
|
@ -20,6 +20,7 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefRapidActingPlugin;
|
||||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin;
|
||||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
||||||
|
@ -67,14 +68,12 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
MainApp.bus().register(this);
|
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
MainApp.bus().unregister(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +82,7 @@ public class ConfigBuilderPlugin extends PluginBase {
|
||||||
upgradeSettings();
|
upgradeSettings();
|
||||||
loadSettings();
|
loadSettings();
|
||||||
setAlwaysEnabledPluginsEnabled();
|
setAlwaysEnabledPluginsEnabled();
|
||||||
MainApp.bus().post(new EventAppInitialized());
|
RxBus.INSTANCE.send(new EventAppInitialized());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAlwaysEnabledPluginsEnabled() {
|
private void setAlwaysEnabledPluginsEnabled() {
|
||||||
|
|
|
@ -3,12 +3,12 @@ package info.nightscout.androidaps.plugins.configBuilder
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.*
|
import android.widget.*
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.activities.PreferencesActivity
|
import info.nightscout.androidaps.activities.PreferencesActivity
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui
|
import info.nightscout.androidaps.events.EventRebuildTabs
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||||
import info.nightscout.androidaps.utils.PasswordProtection
|
import info.nightscout.androidaps.utils.PasswordProtection
|
||||||
|
|
||||||
class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment,
|
class PluginViewHolder internal constructor(private val fragment: ConfigBuilderFragment,
|
||||||
|
@ -34,7 +34,7 @@ class PluginViewHolder internal constructor(private val fragment: ConfigBuilderF
|
||||||
pluginVisibility.setOnClickListener {
|
pluginVisibility.setOnClickListener {
|
||||||
plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked)
|
plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked)
|
||||||
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible")
|
ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible")
|
||||||
MainApp.bus().post(EventRefreshGui())
|
RxBus.send(EventRebuildTabs())
|
||||||
ConfigBuilderPlugin.getPlugin().logPluginStatus()
|
ConfigBuilderPlugin.getPlugin().logPluginStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ package info.nightscout.androidaps.plugins.configBuilder;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -23,14 +23,18 @@ import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
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.general.overview.dialogs.ErrorHelperActivity;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
public class ProfileFunctions {
|
public class ProfileFunctions {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.PROFILE);
|
private static Logger log = LoggerFactory.getLogger(L.PROFILE);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private static ProfileFunctions profileFunctions = null;
|
private static ProfileFunctions profileFunctions = null;
|
||||||
|
|
||||||
|
@ -44,12 +48,11 @@ public class ProfileFunctions {
|
||||||
ProfileFunctions.getInstance(); // register to bus at start
|
ProfileFunctions.getInstance(); // register to bus at start
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfileFunctions() {
|
private ProfileFunctions() {
|
||||||
MainApp.bus().register(this);
|
disposable.add(RxBus.INSTANCE
|
||||||
}
|
.toObservable(EventProfileNeedsUpdate.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
@Subscribe
|
.subscribe(event -> {
|
||||||
public void onProfileSwitch(EventProfileNeedsUpdate ignored) {
|
|
||||||
if (L.isEnabled(L.PROFILE))
|
if (L.isEnabled(L.PROFILE))
|
||||||
log.debug("onProfileSwitch");
|
log.debug("onProfileSwitch");
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().setProfile(getProfile(), new Callback() {
|
ConfigBuilderPlugin.getPlugin().getCommandQueue().setProfile(getProfile(), new Callback() {
|
||||||
|
@ -64,9 +67,11 @@ public class ProfileFunctions {
|
||||||
MainApp.instance().startActivity(i);
|
MainApp.instance().startActivity(i);
|
||||||
}
|
}
|
||||||
if (result.enacted)
|
if (result.enacted)
|
||||||
MainApp.bus().post(new EventNewBasalProfile());
|
RxBus.INSTANCE.send(new EventNewBasalProfile());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProfileName() {
|
public String getProfileName() {
|
||||||
|
|
|
@ -37,9 +37,9 @@ public abstract class Objective {
|
||||||
this.gate = gate;
|
this.gate = gate;
|
||||||
startedOn = SP.getLong("Objectives_" + spName + "_started", 0L);
|
startedOn = SP.getLong("Objectives_" + spName + "_started", 0L);
|
||||||
accomplishedOn = SP.getLong("Objectives_" + spName + "_accomplished", 0L);
|
accomplishedOn = SP.getLong("Objectives_" + spName + "_accomplished", 0L);
|
||||||
if ((accomplishedOn - DateUtil.now()) > T.days(1).msecs()) { // more than 1 day in the future
|
if ((accomplishedOn - DateUtil.now()) > T.hours(3).msecs() || (startedOn - DateUtil.now()) > T.hours(3).msecs()) { // more than 3 hours in the future
|
||||||
setStartedOn(0);
|
startedOn = 0;
|
||||||
setAccomplishedOn(0);
|
accomplishedOn = 0;
|
||||||
}
|
}
|
||||||
setupTasks(tasks);
|
setupTasks(tasks);
|
||||||
for (Task task : tasks) task.objective = this;
|
for (Task task : tasks) task.objective = this;
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class Objective2 extends Objective {
|
||||||
);
|
);
|
||||||
tasks.add(new ExamTask(R.string.pumpdisconnect_label, R.string.pumpdisconnect_label,"pumpdisconnect")
|
tasks.add(new ExamTask(R.string.pumpdisconnect_label, R.string.pumpdisconnect_label,"pumpdisconnect")
|
||||||
.option(new Option(R.string.pumpdisconnect_letknow, true))
|
.option(new Option(R.string.pumpdisconnect_letknow, true))
|
||||||
|
.option(new Option(R.string.pumpdisconnect_suspend, false))
|
||||||
.option(new Option(R.string.pumpdisconnect_dontchnage, false))
|
.option(new Option(R.string.pumpdisconnect_dontchnage, false))
|
||||||
.hint(new Hint(R.string.pumpdisconnect_hint1))
|
.hint(new Hint(R.string.pumpdisconnect_hint1))
|
||||||
);
|
);
|
||||||
|
@ -45,6 +46,7 @@ public class Objective2 extends Objective {
|
||||||
.option(new Option(R.string.objectives_storeelsewhere, true))
|
.option(new Option(R.string.objectives_storeelsewhere, true))
|
||||||
.option(new Option(R.string.objectives_doexportonstart, false))
|
.option(new Option(R.string.objectives_doexportonstart, false))
|
||||||
.option(new Option(R.string.objectives_doexportafterchange, true))
|
.option(new Option(R.string.objectives_doexportafterchange, true))
|
||||||
|
.option(new Option(R.string.objectives_doexportafterobjective, true))
|
||||||
.option(new Option(R.string.objectives_doexportafterfirtssettings, true))
|
.option(new Option(R.string.objectives_doexportafterfirtssettings, true))
|
||||||
.hint(new Hint(R.string.objectives_hint1))
|
.hint(new Hint(R.string.objectives_hint1))
|
||||||
.hint(new Hint(R.string.objectives_hint2))
|
.hint(new Hint(R.string.objectives_hint2))
|
||||||
|
@ -65,6 +67,7 @@ public class Objective2 extends Objective {
|
||||||
.option(new Option(R.string.exercise_switchprofileabove100, false))
|
.option(new Option(R.string.exercise_switchprofileabove100, false))
|
||||||
.option(new Option(R.string.exercise_stoploop, false))
|
.option(new Option(R.string.exercise_stoploop, false))
|
||||||
.option(new Option(R.string.exercise_doitbeforestart, true))
|
.option(new Option(R.string.exercise_doitbeforestart, true))
|
||||||
|
.option(new Option(R.string.exercise_afterstart, true))
|
||||||
.hint(new Hint(R.string.exercise_hint1))
|
.hint(new Hint(R.string.exercise_hint1))
|
||||||
);
|
);
|
||||||
tasks.add(new ExamTask(R.string.suspendloop_label, R.string.suspendloop_doigetinsulin,"suspendloop")
|
tasks.add(new ExamTask(R.string.suspendloop_label, R.string.suspendloop_doigetinsulin,"suspendloop")
|
||||||
|
|
|
@ -1,329 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.general.actions;
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.activities.HistoryBrowseActivity;
|
|
||||||
import info.nightscout.androidaps.activities.TDDStatsActivity;
|
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
|
||||||
import info.nightscout.androidaps.events.EventCustomActionsChanged;
|
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
|
||||||
import info.nightscout.androidaps.events.EventInitializationChanged;
|
|
||||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
|
||||||
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
|
|
||||||
import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.general.actions.dialogs.NewExtendedBolusDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.general.actions.dialogs.NewTempBasalDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.OptionsToShow;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
import info.nightscout.androidaps.utils.SingleClickButton;
|
|
||||||
|
|
||||||
public class ActionsFragment extends SubscriberFragment implements View.OnClickListener {
|
|
||||||
|
|
||||||
private View actionsFragmentView;
|
|
||||||
private SingleClickButton profileSwitch;
|
|
||||||
private SingleClickButton tempTarget;
|
|
||||||
private SingleClickButton extendedBolus;
|
|
||||||
private SingleClickButton extendedBolusCancel;
|
|
||||||
private SingleClickButton tempBasal;
|
|
||||||
private SingleClickButton tempBasalCancel;
|
|
||||||
private SingleClickButton fill;
|
|
||||||
private SingleClickButton tddStats;
|
|
||||||
private SingleClickButton history;
|
|
||||||
|
|
||||||
private Map<String, CustomAction> pumpCustomActions = new HashMap<>();
|
|
||||||
private List<SingleClickButton> pumpCustomButtons = new ArrayList<>();
|
|
||||||
|
|
||||||
public ActionsFragment() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
View view = inflater.inflate(R.layout.actions_fragment, container, false);
|
|
||||||
|
|
||||||
profileSwitch = view.findViewById(R.id.actions_profileswitch);
|
|
||||||
tempTarget = view.findViewById(R.id.actions_temptarget);
|
|
||||||
extendedBolus = view.findViewById(R.id.actions_extendedbolus);
|
|
||||||
extendedBolusCancel = view.findViewById(R.id.actions_extendedbolus_cancel);
|
|
||||||
tempBasal = view.findViewById(R.id.actions_settempbasal);
|
|
||||||
tempBasalCancel = view.findViewById(R.id.actions_canceltempbasal);
|
|
||||||
fill = view.findViewById(R.id.actions_fill);
|
|
||||||
tddStats = view.findViewById(R.id.actions_tddstats);
|
|
||||||
history = view.findViewById(R.id.actions_historybrowser);
|
|
||||||
|
|
||||||
profileSwitch.setOnClickListener(this);
|
|
||||||
tempTarget.setOnClickListener(this);
|
|
||||||
extendedBolus.setOnClickListener(this);
|
|
||||||
extendedBolusCancel.setOnClickListener(this);
|
|
||||||
tempBasal.setOnClickListener(this);
|
|
||||||
tempBasalCancel.setOnClickListener(this);
|
|
||||||
fill.setOnClickListener(this);
|
|
||||||
history.setOnClickListener(this);
|
|
||||||
tddStats.setOnClickListener(this);
|
|
||||||
|
|
||||||
actionsFragmentView = view;
|
|
||||||
|
|
||||||
updateGUI();
|
|
||||||
SP.putBoolean(R.string.key_objectiveuseactions, true);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventInitializationChanged ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventRefreshOverview ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventExtendedBolusChange ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventTempBasalChange ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventCustomActionsChanged ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (ConfigBuilderPlugin.getPlugin().getActiveProfileInterface() != null && ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getProfile() != null) {
|
|
||||||
profileSwitch.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
profileSwitch.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ProfileFunctions.getInstance().getProfile() == null) {
|
|
||||||
tempTarget.setVisibility(View.GONE);
|
|
||||||
extendedBolus.setVisibility(View.GONE);
|
|
||||||
extendedBolusCancel.setVisibility(View.GONE);
|
|
||||||
tempBasal.setVisibility(View.GONE);
|
|
||||||
tempBasalCancel.setVisibility(View.GONE);
|
|
||||||
fill.setVisibility(View.GONE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
|
||||||
final boolean basalprofileEnabled = MainApp.isEngineeringModeOrRelease()
|
|
||||||
&& pump.getPumpDescription().isSetBasalProfileCapable;
|
|
||||||
|
|
||||||
if (!basalprofileEnabled || !pump.isInitialized() || pump.isSuspended())
|
|
||||||
profileSwitch.setVisibility(View.GONE);
|
|
||||||
else
|
|
||||||
profileSwitch.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
if (!pump.getPumpDescription().isExtendedBolusCapable || !pump.isInitialized() || pump.isSuspended() || pump.isFakingTempsByExtendedBoluses()) {
|
|
||||||
extendedBolus.setVisibility(View.GONE);
|
|
||||||
extendedBolusCancel.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
ExtendedBolus activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis());
|
|
||||||
if (activeExtendedBolus != null) {
|
|
||||||
extendedBolus.setVisibility(View.GONE);
|
|
||||||
extendedBolusCancel.setVisibility(View.VISIBLE);
|
|
||||||
extendedBolusCancel.setText(MainApp.gs(R.string.cancel) + " " + activeExtendedBolus.toString());
|
|
||||||
} else {
|
|
||||||
extendedBolus.setVisibility(View.VISIBLE);
|
|
||||||
extendedBolusCancel.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!pump.getPumpDescription().isTempBasalCapable || !pump.isInitialized() || pump.isSuspended()) {
|
|
||||||
tempBasal.setVisibility(View.GONE);
|
|
||||||
tempBasalCancel.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
final TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis());
|
|
||||||
if (activeTemp != null) {
|
|
||||||
tempBasal.setVisibility(View.GONE);
|
|
||||||
tempBasalCancel.setVisibility(View.VISIBLE);
|
|
||||||
tempBasalCancel.setText(MainApp.gs(R.string.cancel) + " " + activeTemp.toStringShort());
|
|
||||||
} else {
|
|
||||||
tempBasal.setVisibility(View.VISIBLE);
|
|
||||||
tempBasalCancel.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pump.getPumpDescription().isRefillingCapable || !pump.isInitialized() || pump.isSuspended())
|
|
||||||
fill.setVisibility(View.GONE);
|
|
||||||
else
|
|
||||||
fill.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
if (!Config.APS)
|
|
||||||
tempTarget.setVisibility(View.GONE);
|
|
||||||
else
|
|
||||||
tempTarget.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
if (!pump.getPumpDescription().supportsTDDs)
|
|
||||||
tddStats.setVisibility(View.GONE);
|
|
||||||
else
|
|
||||||
tddStats.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
checkPumpCustomActions();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
View.OnClickListener pumpCustomActionsListener = v -> {
|
|
||||||
|
|
||||||
SingleClickButton btn = (SingleClickButton) v;
|
|
||||||
|
|
||||||
CustomAction customAction = this.pumpCustomActions.get(btn.getText().toString());
|
|
||||||
|
|
||||||
ConfigBuilderPlugin.getPlugin().getActivePump().executeCustomAction(customAction.getCustomActionType());
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private void checkPumpCustomActions() {
|
|
||||||
|
|
||||||
PumpInterface activePump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
|
||||||
|
|
||||||
removePumpCustomActions();
|
|
||||||
|
|
||||||
if (activePump == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<CustomAction> customActions = activePump.getCustomActions();
|
|
||||||
|
|
||||||
if (customActions != null && customActions.size() > 0) {
|
|
||||||
|
|
||||||
LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout);
|
|
||||||
|
|
||||||
for (CustomAction customAction : customActions) {
|
|
||||||
|
|
||||||
if (!customAction.isEnabled())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
SingleClickButton btn = new SingleClickButton(getContext(), null, android.R.attr.buttonStyle);
|
|
||||||
btn.setText(MainApp.gs(customAction.getName()));
|
|
||||||
|
|
||||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
|
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f);
|
|
||||||
layoutParams.setMargins(20, 8, 20, 8); // 10,3,10,3
|
|
||||||
|
|
||||||
btn.setLayoutParams(layoutParams);
|
|
||||||
btn.setOnClickListener(pumpCustomActionsListener);
|
|
||||||
|
|
||||||
Drawable top = getResources().getDrawable(customAction.getIconResourceId());
|
|
||||||
btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null);
|
|
||||||
|
|
||||||
ll.addView(btn);
|
|
||||||
|
|
||||||
this.pumpCustomActions.put(MainApp.gs(customAction.getName()), customAction);
|
|
||||||
this.pumpCustomButtons.add(btn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void removePumpCustomActions() {
|
|
||||||
|
|
||||||
if (pumpCustomActions.size() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
LinearLayout ll = actionsFragmentView.findViewById(R.id.action_buttons_layout);
|
|
||||||
|
|
||||||
for (SingleClickButton customButton : pumpCustomButtons) {
|
|
||||||
ll.removeView(customButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
pumpCustomButtons.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
FragmentManager manager = getFragmentManager();
|
|
||||||
switch (view.getId()) {
|
|
||||||
case R.id.actions_profileswitch:
|
|
||||||
NewNSTreatmentDialog newDialog = new NewNSTreatmentDialog();
|
|
||||||
final OptionsToShow profileswitch = CareportalFragment.PROFILESWITCH;
|
|
||||||
profileswitch.executeProfileSwitch = true;
|
|
||||||
newDialog.setOptions(profileswitch, R.string.careportal_profileswitch);
|
|
||||||
newDialog.show(manager, "NewNSTreatmentDialog");
|
|
||||||
break;
|
|
||||||
case R.id.actions_temptarget:
|
|
||||||
NewNSTreatmentDialog newTTDialog = new NewNSTreatmentDialog();
|
|
||||||
final OptionsToShow temptarget = CareportalFragment.TEMPTARGET;
|
|
||||||
temptarget.executeTempTarget = true;
|
|
||||||
newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget);
|
|
||||||
newTTDialog.show(manager, "NewNSTreatmentDialog");
|
|
||||||
break;
|
|
||||||
case R.id.actions_extendedbolus:
|
|
||||||
NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog();
|
|
||||||
newExtendedDialog.show(manager, "NewExtendedDialog");
|
|
||||||
break;
|
|
||||||
case R.id.actions_extendedbolus_cancel:
|
|
||||||
if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) {
|
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelExtended(null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case R.id.actions_canceltempbasal:
|
|
||||||
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress()) {
|
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().cancelTempBasal(true, null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case R.id.actions_settempbasal:
|
|
||||||
NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
|
|
||||||
newTempDialog.show(manager, "NewTempDialog");
|
|
||||||
break;
|
|
||||||
case R.id.actions_fill:
|
|
||||||
FillDialog fillDialog = new FillDialog();
|
|
||||||
fillDialog.show(manager, "FillDialog");
|
|
||||||
break;
|
|
||||||
case R.id.actions_historybrowser:
|
|
||||||
startActivity(new Intent(getContext(), HistoryBrowseActivity.class));
|
|
||||||
break;
|
|
||||||
case R.id.actions_tddstats:
|
|
||||||
startActivity(new Intent(getContext(), TDDStatsActivity.class));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,242 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.actions
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import info.nightscout.androidaps.Config
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.R
|
||||||
|
import info.nightscout.androidaps.activities.HistoryBrowseActivity
|
||||||
|
import info.nightscout.androidaps.activities.TDDStatsActivity
|
||||||
|
import info.nightscout.androidaps.events.*
|
||||||
|
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.actions.defs.CustomAction
|
||||||
|
import info.nightscout.androidaps.plugins.general.actions.dialogs.FillDialog
|
||||||
|
import info.nightscout.androidaps.plugins.general.actions.dialogs.NewExtendedBolusDialog
|
||||||
|
import info.nightscout.androidaps.plugins.general.actions.dialogs.NewTempBasalDialog
|
||||||
|
import info.nightscout.androidaps.plugins.general.careportal.CareportalFragment
|
||||||
|
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.queue.Callback
|
||||||
|
import info.nightscout.androidaps.utils.*
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import kotlinx.android.synthetic.main.actions_fragment.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class ActionsFragment : Fragment() {
|
||||||
|
|
||||||
|
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||||
|
|
||||||
|
private val pumpCustomActions = HashMap<String, CustomAction>()
|
||||||
|
private val pumpCustomButtons = ArrayList<SingleClickButton>()
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?): View? {
|
||||||
|
return inflater.inflate(R.layout.actions_fragment, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
actions_profileswitch.setOnClickListener {
|
||||||
|
val newDialog = NewNSTreatmentDialog()
|
||||||
|
val profileSwitch = CareportalFragment.PROFILESWITCH
|
||||||
|
profileSwitch.executeProfileSwitch = true
|
||||||
|
newDialog.setOptions(profileSwitch, R.string.careportal_profileswitch)
|
||||||
|
fragmentManager?.let { newDialog.show(it, "NewNSTreatmentDialog") }
|
||||||
|
}
|
||||||
|
actions_temptarget.setOnClickListener {
|
||||||
|
val newTTDialog = NewNSTreatmentDialog()
|
||||||
|
val temptarget = CareportalFragment.TEMPTARGET
|
||||||
|
temptarget.executeTempTarget = true
|
||||||
|
newTTDialog.setOptions(temptarget, R.string.careportal_temporarytarget)
|
||||||
|
fragmentManager?.let { newTTDialog.show(it, "NewNSTreatmentDialog") }
|
||||||
|
}
|
||||||
|
actions_extendedbolus.setOnClickListener {
|
||||||
|
fragmentManager?.let { NewExtendedBolusDialog().show(it, "NewExtendedDialog") }
|
||||||
|
}
|
||||||
|
actions_extendedbolus_cancel.setOnClickListener {
|
||||||
|
if (TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress) {
|
||||||
|
ConfigBuilderPlugin.getPlugin().commandQueue.cancelExtended(object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
if (!result.success)
|
||||||
|
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.extendedbolusdeliveryerror))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actions_settempbasal.setOnClickListener { fragmentManager?.let { NewTempBasalDialog().show(it, "NewTempDialog") } }
|
||||||
|
actions_canceltempbasal.setOnClickListener {
|
||||||
|
if (TreatmentsPlugin.getPlugin().isTempBasalInProgress) {
|
||||||
|
ConfigBuilderPlugin.getPlugin().commandQueue.cancelTempBasal(true, object : Callback() {
|
||||||
|
override fun run() {
|
||||||
|
if (!result.success)
|
||||||
|
ToastUtils.showToastInUiThread(MainApp.instance().applicationContext, MainApp.gs(R.string.tempbasaldeliveryerror))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
actions_fill.setOnClickListener { fragmentManager?.let { FillDialog().show(it, "FillDialog") } }
|
||||||
|
actions_historybrowser.setOnClickListener { startActivity(Intent(context, HistoryBrowseActivity::class.java)) }
|
||||||
|
actions_tddstats.setOnClickListener { startActivity(Intent(context, TDDStatsActivity::class.java)) }
|
||||||
|
|
||||||
|
SP.putBoolean(R.string.key_objectiveuseactions, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventInitializationChanged::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({
|
||||||
|
updateGui()
|
||||||
|
}, {
|
||||||
|
FabricPrivacy.logException(it)
|
||||||
|
})
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventRefreshOverview::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({
|
||||||
|
updateGui()
|
||||||
|
}, {
|
||||||
|
FabricPrivacy.logException(it)
|
||||||
|
})
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventExtendedBolusChange::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({
|
||||||
|
updateGui()
|
||||||
|
}, {
|
||||||
|
FabricPrivacy.logException(it)
|
||||||
|
})
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventTempBasalChange::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({
|
||||||
|
updateGui()
|
||||||
|
}, {
|
||||||
|
FabricPrivacy.logException(it)
|
||||||
|
})
|
||||||
|
disposable += RxBus
|
||||||
|
.toObservable(EventCustomActionsChanged::class.java)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe({
|
||||||
|
updateGui()
|
||||||
|
}, {
|
||||||
|
FabricPrivacy.logException(it)
|
||||||
|
})
|
||||||
|
updateGui()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
disposable.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun updateGui() {
|
||||||
|
actions_profileswitch?.visibility =
|
||||||
|
if (ConfigBuilderPlugin.getPlugin().activeProfileInterface?.profile != null) View.VISIBLE
|
||||||
|
else View.GONE
|
||||||
|
|
||||||
|
if (ProfileFunctions.getInstance().profile == null) {
|
||||||
|
actions_temptarget?.visibility = View.GONE
|
||||||
|
actions_extendedbolus?.visibility = View.GONE
|
||||||
|
actions_extendedbolus_cancel?.visibility = View.GONE
|
||||||
|
actions_settempbasal?.visibility = View.GONE
|
||||||
|
actions_canceltempbasal?.visibility = View.GONE
|
||||||
|
actions_fill?.visibility = View.GONE
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val pump = ConfigBuilderPlugin.getPlugin().activePump ?: return
|
||||||
|
val basalProfileEnabled = MainApp.isEngineeringModeOrRelease() && pump.pumpDescription.isSetBasalProfileCapable
|
||||||
|
|
||||||
|
actions_profileswitch?.visibility = if (!basalProfileEnabled || !pump.isInitialized || pump.isSuspended) View.GONE else View.VISIBLE
|
||||||
|
|
||||||
|
if (!pump.pumpDescription.isExtendedBolusCapable || !pump.isInitialized || pump.isSuspended || pump.isFakingTempsByExtendedBoluses || Config.APS) {
|
||||||
|
actions_extendedbolus?.visibility = View.GONE
|
||||||
|
actions_extendedbolus_cancel?.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
val activeExtendedBolus = TreatmentsPlugin.getPlugin().getExtendedBolusFromHistory(System.currentTimeMillis())
|
||||||
|
if (activeExtendedBolus != null) {
|
||||||
|
actions_extendedbolus?.visibility = View.GONE
|
||||||
|
actions_extendedbolus_cancel?.visibility = View.VISIBLE
|
||||||
|
actions_extendedbolus_cancel?.text = MainApp.gs(R.string.cancel) + " " + activeExtendedBolus.toString()
|
||||||
|
} else {
|
||||||
|
actions_extendedbolus?.visibility = View.VISIBLE
|
||||||
|
actions_extendedbolus_cancel?.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pump.pumpDescription.isTempBasalCapable || !pump.isInitialized || pump.isSuspended) {
|
||||||
|
actions_settempbasal?.visibility = View.GONE
|
||||||
|
actions_canceltempbasal?.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
val activeTemp = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(System.currentTimeMillis())
|
||||||
|
if (activeTemp != null) {
|
||||||
|
actions_settempbasal?.visibility = View.GONE
|
||||||
|
actions_canceltempbasal?.visibility = View.VISIBLE
|
||||||
|
actions_canceltempbasal?.text = MainApp.gs(R.string.cancel) + " " + activeTemp.toStringShort()
|
||||||
|
} else {
|
||||||
|
actions_settempbasal?.visibility = View.VISIBLE
|
||||||
|
actions_canceltempbasal?.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actions_fill?.visibility =
|
||||||
|
if (!pump.pumpDescription.isRefillingCapable || !pump.isInitialized || pump.isSuspended) View.GONE
|
||||||
|
else View.VISIBLE
|
||||||
|
|
||||||
|
actions_temptarget?.visibility = if (!Config.APS) View.GONE else View.VISIBLE
|
||||||
|
actions_tddstats?.visibility = if (!pump.pumpDescription.supportsTDDs) View.GONE else View.VISIBLE
|
||||||
|
checkPumpCustomActions()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkPumpCustomActions() {
|
||||||
|
val activePump = ConfigBuilderPlugin.getPlugin().activePump ?: return
|
||||||
|
val customActions = activePump.customActions ?: return
|
||||||
|
removePumpCustomActions()
|
||||||
|
|
||||||
|
for (customAction in customActions) {
|
||||||
|
if (!customAction.isEnabled) continue
|
||||||
|
|
||||||
|
val btn = SingleClickButton(context, null, android.R.attr.buttonStyle)
|
||||||
|
btn.text = MainApp.gs(customAction.name)
|
||||||
|
|
||||||
|
val layoutParams = LinearLayout.LayoutParams(
|
||||||
|
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0.5f)
|
||||||
|
layoutParams.setMargins(20, 8, 20, 8) // 10,3,10,3
|
||||||
|
|
||||||
|
btn.layoutParams = layoutParams
|
||||||
|
btn.setOnClickListener { v ->
|
||||||
|
val b = v as SingleClickButton
|
||||||
|
val action = this.pumpCustomActions[b.text.toString()]
|
||||||
|
ConfigBuilderPlugin.getPlugin().activePump!!.executeCustomAction(action!!.customActionType)
|
||||||
|
}
|
||||||
|
|
||||||
|
val top = resources.getDrawable(customAction.iconResourceId)
|
||||||
|
btn.setCompoundDrawablesWithIntrinsicBounds(null, top, null, null)
|
||||||
|
|
||||||
|
action_buttons_layout?.addView(btn)
|
||||||
|
|
||||||
|
this.pumpCustomActions[MainApp.gs(customAction.name)] = customAction
|
||||||
|
this.pumpCustomButtons.add(btn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun removePumpCustomActions() {
|
||||||
|
for (customButton in pumpCustomButtons) action_buttons_layout?.removeView(customButton)
|
||||||
|
pumpCustomButtons.clear()
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,7 @@ import info.nightscout.androidaps.interfaces.PluginType
|
||||||
|
|
||||||
object ActionsPlugin : PluginBase(PluginDescription()
|
object ActionsPlugin : PluginBase(PluginDescription()
|
||||||
.mainType(PluginType.GENERAL)
|
.mainType(PluginType.GENERAL)
|
||||||
.fragmentClass(ActionsFragment::class.java.name)
|
.fragmentClass(ActionsFragment::class.qualifiedName)
|
||||||
.pluginName(R.string.actions)
|
.pluginName(R.string.actions)
|
||||||
.shortName(R.string.actions_shortname)
|
.shortName(R.string.actions_shortname)
|
||||||
.description(R.string.description_actions))
|
.description(R.string.description_actions))
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.L
|
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.bus.RxBus
|
||||||
import info.nightscout.androidaps.plugins.general.automation.actions.*
|
import info.nightscout.androidaps.plugins.general.automation.actions.*
|
||||||
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged
|
import info.nightscout.androidaps.plugins.general.automation.events.EventAutomationDataChanged
|
||||||
|
@ -160,11 +161,16 @@ object AutomationPlugin : PluginBase(PluginDescription()
|
||||||
private fun processActions() {
|
private fun processActions() {
|
||||||
if (!isEnabled(PluginType.GENERAL))
|
if (!isEnabled(PluginType.GENERAL))
|
||||||
return
|
return
|
||||||
|
if (LoopPlugin.getPlugin().isSuspended) {
|
||||||
|
if (L.isEnabled(L.AUTOMATION))
|
||||||
|
log.debug("Loop deactivated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (L.isEnabled(L.AUTOMATION))
|
if (L.isEnabled(L.AUTOMATION))
|
||||||
log.debug("processActions")
|
log.debug("processActions")
|
||||||
for (event in automationEvents) {
|
for (event in automationEvents) {
|
||||||
if (event.isEnabled() && event.trigger.shouldRun() && event.preconditions.shouldRun()) {
|
if (event.isEnabled && event.trigger.shouldRun() && event.preconditions.shouldRun()) {
|
||||||
val actions = event.actions
|
val actions = event.actions
|
||||||
for (action in actions) {
|
for (action in actions) {
|
||||||
action.doAction(object : Callback() {
|
action.doAction(object : Callback() {
|
||||||
|
@ -221,7 +227,8 @@ object AutomationPlugin : PluginBase(PluginDescription()
|
||||||
TriggerWifiSsid(),
|
TriggerWifiSsid(),
|
||||||
TriggerLocation(),
|
TriggerLocation(),
|
||||||
TriggerAutosensValue(),
|
TriggerAutosensValue(),
|
||||||
TriggerBolusAgo()
|
TriggerBolusAgo(),
|
||||||
|
TriggerPumpLastConnection()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,146 @@
|
||||||
|
package info.nightscout.androidaps.plugins.general.automation.triggers;
|
||||||
|
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.Comparator;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.InputDuration;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
||||||
|
import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
import info.nightscout.androidaps.utils.JsonHelper;
|
||||||
|
import info.nightscout.androidaps.utils.T;
|
||||||
|
|
||||||
|
public class TriggerPumpLastConnection extends Trigger {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(L.AUTOMATION);
|
||||||
|
private InputDuration minutesAgo = new InputDuration(0, InputDuration.TimeUnit.MINUTES);
|
||||||
|
private Comparator comparator = new Comparator();
|
||||||
|
|
||||||
|
public TriggerPumpLastConnection() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
private TriggerPumpLastConnection(TriggerPumpLastConnection triggerPumpLastConnection) {
|
||||||
|
super();
|
||||||
|
minutesAgo = new InputDuration(triggerPumpLastConnection.minutesAgo);
|
||||||
|
lastRun = triggerPumpLastConnection.lastRun;
|
||||||
|
comparator = new Comparator(triggerPumpLastConnection.comparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getValue() {
|
||||||
|
return minutesAgo.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Comparator getComparator() {
|
||||||
|
return comparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized boolean shouldRun() {
|
||||||
|
|
||||||
|
if (lastRun > DateUtil.now() - T.mins(5).msecs())
|
||||||
|
return false;
|
||||||
|
long lastConnection = ConfigBuilderPlugin.getPlugin().getActivePump().lastDataTime();
|
||||||
|
|
||||||
|
if (lastConnection == 0 && comparator.getValue() == Comparator.Compare.IS_NOT_AVAILABLE)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
double minutesAgo = (double) (DateUtil.now() - lastConnection) / (60 * 1000);
|
||||||
|
if (L.isEnabled(L.AUTOMATION))
|
||||||
|
log.debug("Last connection min ago: " + minutesAgo);
|
||||||
|
|
||||||
|
boolean doRun = comparator.getValue().check((minutesAgo), getValue());
|
||||||
|
if (doRun) {
|
||||||
|
if (L.isEnabled(L.AUTOMATION))
|
||||||
|
log.debug("Ready for execution: " + friendlyDescription());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized String toJSON() {
|
||||||
|
JSONObject o = new JSONObject();
|
||||||
|
try {
|
||||||
|
o.put("type", TriggerPumpLastConnection.class.getName());
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
data.put("minutesAgo", getValue());
|
||||||
|
data.put("lastRun", lastRun);
|
||||||
|
data.put("comparator", comparator.getValue().toString());
|
||||||
|
o.put("data", data);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return o.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Trigger fromJSON(String data) {
|
||||||
|
try {
|
||||||
|
JSONObject d = new JSONObject(data);
|
||||||
|
minutesAgo.setMinutes(JsonHelper.safeGetInt(d, "minutesAgo"));
|
||||||
|
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||||
|
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int friendlyName() {
|
||||||
|
return R.string.automation_trigger_pump_last_connection_label;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String friendlyDescription() {
|
||||||
|
return MainApp.gs(R.string.automation_trigger_pump_last_connection_compared, MainApp.gs(comparator.getValue().getStringRes()), (int) getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Integer> icon() {
|
||||||
|
return Optional.of(R.drawable.remove);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Trigger duplicate() {
|
||||||
|
return new TriggerPumpLastConnection(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
TriggerPumpLastConnection setValue(int requestedValue) {
|
||||||
|
this.minutesAgo.setMinutes(requestedValue);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TriggerPumpLastConnection lastRun(long lastRun) {
|
||||||
|
this.lastRun = lastRun;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
TriggerPumpLastConnection comparator(Comparator.Compare compare) {
|
||||||
|
this.comparator = new Comparator().setValue(compare);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateDialog(LinearLayout root, FragmentManager fragmentManager) {
|
||||||
|
new LayoutBuilder()
|
||||||
|
.add(new StaticLabel(R.string.automation_trigger_pump_last_connection_label))
|
||||||
|
.add(comparator)
|
||||||
|
.add(new LabelWithElement(MainApp.gs(R.string.automation_trigger_pump_last_connection_description) + ": ", "", minutesAgo))
|
||||||
|
.build(root);
|
||||||
|
}
|
||||||
|
}
|
|
@ -59,13 +59,13 @@ public class TriggerWifiSsid extends Trigger {
|
||||||
if (lastRun > DateUtil.now() - T.mins(5).msecs())
|
if (lastRun > DateUtil.now() - T.mins(5).msecs())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!eventNetworkChange.wifiConnected && comparator.getValue() == Comparator.Compare.IS_NOT_AVAILABLE) {
|
if (!eventNetworkChange.getWifiConnected() && comparator.getValue() == Comparator.Compare.IS_NOT_AVAILABLE) {
|
||||||
if (L.isEnabled(L.AUTOMATION))
|
if (L.isEnabled(L.AUTOMATION))
|
||||||
log.debug("Ready for execution: " + friendlyDescription());
|
log.debug("Ready for execution: " + friendlyDescription());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean doRun = eventNetworkChange.wifiConnected && comparator.getValue().check(eventNetworkChange.getSsid(), getValue());
|
boolean doRun = eventNetworkChange.getWifiConnected() && comparator.getValue().check(eventNetworkChange.connectedSsid(), getValue());
|
||||||
if (doRun) {
|
if (doRun) {
|
||||||
if (L.isEnabled(L.AUTOMATION))
|
if (L.isEnabled(L.AUTOMATION))
|
||||||
log.debug("Ready for execution: " + friendlyDescription());
|
log.debug("Ready for execution: " + friendlyDescription());
|
||||||
|
|
|
@ -4,14 +4,14 @@ package info.nightscout.androidaps.plugins.general.careportal;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -22,19 +22,18 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.general.careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
|
import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import info.nightscout.androidaps.utils.SetWarnColor;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
public class CareportalFragment extends SubscriberFragment implements View.OnClickListener {
|
public class CareportalFragment extends Fragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(CareportalFragment.class);
|
private static Logger log = LoggerFactory.getLogger(CareportalFragment.class);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
TextView iage;
|
TextView iage;
|
||||||
TextView cage;
|
TextView cage;
|
||||||
|
@ -71,7 +70,6 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
try {
|
|
||||||
View view = inflater.inflate(R.layout.careportal_fragment, container, false);
|
View view = inflater.inflate(R.layout.careportal_fragment, container, false);
|
||||||
|
|
||||||
view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this);
|
view.findViewById(R.id.careportal_bgcheck).setOnClickListener(this);
|
||||||
|
@ -117,13 +115,24 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
if (Config.NSCLIENT)
|
if (Config.NSCLIENT)
|
||||||
statsLayout.setVisibility(View.GONE); // visible on overview
|
statsLayout.setVisibility(View.GONE); // visible on overview
|
||||||
|
|
||||||
updateGUI();
|
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
|
||||||
FabricPrivacy.logException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
@Override
|
||||||
|
public synchronized void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventCareportalEventChange.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> updateGUI(), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
disposable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -203,12 +212,6 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
|
||||||
newDialog.show(manager, "NewNSTreatmentDialog");
|
newDialog.show(manager, "NewNSTreatmentDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventCareportalEventChange c) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
protected void updateGUI() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
updateAge(activity, sage, iage, cage, pbage);
|
updateAge(activity, sage, iage, cage, pbage);
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
package info.nightscout.androidaps.plugins.general.food;
|
package info.nightscout.androidaps.plugins.general.food;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -18,7 +14,10 @@ import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -31,17 +30,20 @@ import java.util.Set;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
|
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SpinnerHelper;
|
import info.nightscout.androidaps.utils.SpinnerHelper;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 16.10.2017.
|
* Created by mike on 16.10.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class FoodFragment extends SubscriberFragment {
|
public class FoodFragment extends Fragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(FoodFragment.class);
|
private static Logger log = LoggerFactory.getLogger(FoodFragment.class);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
EditText filter;
|
EditText filter;
|
||||||
ImageView clearFilter;
|
ImageView clearFilter;
|
||||||
|
@ -59,7 +61,6 @@ public class FoodFragment extends SubscriberFragment {
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
try {
|
|
||||||
View view = inflater.inflate(R.layout.food_fragment, container, false);
|
View view = inflater.inflate(R.layout.food_fragment, container, false);
|
||||||
filter = (EditText) view.findViewById(R.id.food_filter);
|
filter = (EditText) view.findViewById(R.id.food_filter);
|
||||||
clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter);
|
clearFilter = (ImageView) view.findViewById(R.id.food_clearfilter);
|
||||||
|
@ -130,18 +131,23 @@ public class FoodFragment extends SubscriberFragment {
|
||||||
fillSubcategories();
|
fillSubcategories();
|
||||||
filterData();
|
filterData();
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
|
||||||
FabricPrivacy.logException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
@Override
|
||||||
|
public synchronized void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventFoodDatabaseChanged.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
updateGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Override
|
||||||
@SuppressWarnings("unused")
|
public synchronized void onPause() {
|
||||||
public void onStatusEvent(final EventFoodDatabaseChanged ev) {
|
super.onPause();
|
||||||
loadData();
|
disposable.clear();
|
||||||
filterData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadData() {
|
void loadData() {
|
||||||
|
@ -207,20 +213,12 @@ public class FoodFragment extends SubscriberFragment {
|
||||||
filtered.add(f);
|
filtered.add(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGUI();
|
updateGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected void updateGui() {
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
recyclerView.swapAdapter(new FoodFragment.RecyclerViewAdapter(filtered), true);
|
recyclerView.swapAdapter(new FoodFragment.RecyclerViewAdapter(filtered), true);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.FoodsViewHolder> {
|
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.FoodsViewHolder> {
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.food;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
||||||
|
@ -11,7 +12,6 @@ import com.j256.ormlite.dao.Dao;
|
||||||
import com.j256.ormlite.dao.DaoManager;
|
import com.j256.ormlite.dao.DaoManager;
|
||||||
import com.j256.ormlite.support.ConnectionSource;
|
import com.j256.ormlite.support.ConnectionSource;
|
||||||
import com.j256.ormlite.table.TableUtils;
|
import com.j256.ormlite.table.TableUtils;
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -34,6 +34,10 @@ import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
|
import info.nightscout.androidaps.events.EventFoodDatabaseChanged;
|
||||||
import info.nightscout.androidaps.events.EventNsFood;
|
import info.nightscout.androidaps.events.EventNsFood;
|
||||||
import info.nightscout.androidaps.logging.L;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 24.09.2017.
|
* Created by mike on 24.09.2017.
|
||||||
|
@ -41,6 +45,7 @@ import info.nightscout.androidaps.logging.L;
|
||||||
|
|
||||||
public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
private Logger log = LoggerFactory.getLogger(L.DATAFOOD);
|
private Logger log = LoggerFactory.getLogger(L.DATAFOOD);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService foodEventWorker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private static ScheduledFuture<?> scheduledFoodEventPost = null;
|
private static ScheduledFuture<?> scheduledFoodEventPost = null;
|
||||||
|
@ -48,7 +53,34 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
public FoodService() {
|
public FoodService() {
|
||||||
onCreate();
|
onCreate();
|
||||||
dbInitialize();
|
dbInitialize();
|
||||||
MainApp.bus().register(this);
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNsFood.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
int mode = event.getMode();
|
||||||
|
Bundle payload = event.getPayload();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (payload.containsKey("food")) {
|
||||||
|
JSONObject json = new JSONObject(payload.getString("food"));
|
||||||
|
if (mode == EventNsFood.Companion.getADD() || mode == EventNsFood.Companion.getUPDATE())
|
||||||
|
this.createFoodFromJsonIfNotExists(json);
|
||||||
|
else
|
||||||
|
this.deleteNS(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.containsKey("foods")) {
|
||||||
|
JSONArray array = new JSONArray(payload.getString("foods"));
|
||||||
|
if (mode == EventNsFood.Companion.getADD() || mode == EventNsFood.Companion.getUPDATE())
|
||||||
|
this.createFoodFromJsonIfNotExists(array);
|
||||||
|
else
|
||||||
|
this.deleteNS(array);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("Unhandled Exception", e);
|
||||||
|
}
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -79,34 +111,6 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void handleNsEvent(EventNsFood event) {
|
|
||||||
int mode = event.getMode();
|
|
||||||
Bundle payload = event.getPayload();
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (payload.containsKey("food")) {
|
|
||||||
JSONObject json = new JSONObject(payload.getString("food"));
|
|
||||||
if (mode == EventNsFood.ADD || mode == EventNsFood.UPDATE) {
|
|
||||||
this.createFoodFromJsonIfNotExists(json);
|
|
||||||
} else {
|
|
||||||
this.deleteNS(json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (payload.containsKey("foods")) {
|
|
||||||
JSONArray array = new JSONArray(payload.getString("foods"));
|
|
||||||
if (mode == EventNsFood.ADD || mode == EventNsFood.UPDATE) {
|
|
||||||
this.createFoodFromJsonIfNotExists(array);
|
|
||||||
} else {
|
|
||||||
this.deleteNS(array);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled Exception", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
@ -162,7 +166,7 @@ public class FoodService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (L.isEnabled(L.DATAFOOD))
|
if (L.isEnabled(L.DATAFOOD))
|
||||||
log.debug("Firing EventFoodChange");
|
log.debug("Firing EventFoodChange");
|
||||||
MainApp.bus().post(event);
|
RxBus.INSTANCE.send(event);
|
||||||
callback.setPost(null);
|
callback.setPost(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.utils.OKDialog;
|
import info.nightscout.androidaps.utils.OKDialog;
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
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), () -> {
|
OKDialog.show(context, MainApp.gs(R.string.setting_imported), MainApp.gs(R.string.restartingapp), () -> {
|
||||||
log.debug("Exiting");
|
log.debug("Exiting");
|
||||||
MainApp.instance().stopKeepAliveService();
|
MainApp.instance().stopKeepAliveService();
|
||||||
MainApp.bus().post(new EventAppExit());
|
RxBus.INSTANCE.send(new EventAppExit());
|
||||||
MainApp.closeDbHelper();
|
MainApp.closeDbHelper();
|
||||||
if (context instanceof Activity) {
|
if (context instanceof Activity) {
|
||||||
((Activity)context).finish();
|
((Activity)context).finish();
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.general.nsclient;
|
package info.nightscout.androidaps.plugins.general.nsclient;
|
||||||
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -17,18 +16,22 @@ import android.widget.CompoundButton;
|
||||||
import android.widget.ScrollView;
|
import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
|
||||||
|
public class NSClientFragment extends Fragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
public class NSClientFragment extends SubscriberFragment implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
|
||||||
private TextView logTextView;
|
private TextView logTextView;
|
||||||
private TextView queueTextView;
|
private TextView queueTextView;
|
||||||
private TextView urlTextView;
|
private TextView urlTextView;
|
||||||
|
@ -45,7 +48,6 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
try {
|
|
||||||
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
|
View view = inflater.inflate(R.layout.nsclientinternal_fragment, container, false);
|
||||||
|
|
||||||
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
|
logScrollview = (ScrollView) view.findViewById(R.id.nsclientinternal_logscrollview);
|
||||||
|
@ -76,20 +78,31 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
showqueue.setOnClickListener(this);
|
showqueue.setOnClickListener(this);
|
||||||
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
showqueue.setPaintFlags(showqueue.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||||
|
|
||||||
updateGUI();
|
|
||||||
return view;
|
return view;
|
||||||
} catch (Exception e) {
|
|
||||||
FabricPrivacy.logException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
@Override
|
||||||
|
public synchronized void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNSClientUpdateGUI.class)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
updateGui();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
disposable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
case R.id.nsclientinternal_restart:
|
case R.id.nsclientinternal_restart:
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
FabricPrivacy.getInstance().logCustom("NSClientRestart");
|
FabricPrivacy.getInstance().logCustom("NSClientRestart");
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_delivernow:
|
case R.id.nsclientinternal_delivernow:
|
||||||
|
@ -108,7 +121,7 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
UploadQueue.clearQueue();
|
UploadQueue.clearQueue();
|
||||||
updateGUI();
|
updateGui();
|
||||||
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
|
FabricPrivacy.getInstance().logCustom("NSClientClearQueue");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -116,7 +129,7 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
builder.show();
|
builder.show();
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_showqueue:
|
case R.id.nsclientinternal_showqueue:
|
||||||
MainApp.bus().post(new EventNSClientNewLog("QUEUE", NSClientPlugin.getPlugin().queue().textList()));
|
RxBus.INSTANCE.send(new EventNSClientNewLog("QUEUE", NSClientPlugin.getPlugin().queue().textList()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,27 +139,18 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
switch (buttonView.getId()) {
|
switch (buttonView.getId()) {
|
||||||
case R.id.nsclientinternal_paused:
|
case R.id.nsclientinternal_paused:
|
||||||
NSClientPlugin.getPlugin().pause(isChecked);
|
NSClientPlugin.getPlugin().pause(isChecked);
|
||||||
updateGUI();
|
updateGui();
|
||||||
FabricPrivacy.getInstance().logCustom("NSClientPause");
|
FabricPrivacy.getInstance().logCustom("NSClientPause");
|
||||||
break;
|
break;
|
||||||
case R.id.nsclientinternal_autoscroll:
|
case R.id.nsclientinternal_autoscroll:
|
||||||
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
|
SP.putBoolean(R.string.key_nsclientinternal_autoscroll, isChecked);
|
||||||
NSClientPlugin.getPlugin().autoscroll = isChecked;
|
NSClientPlugin.getPlugin().autoscroll = isChecked;
|
||||||
updateGUI();
|
updateGui();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
protected void updateGui() {
|
||||||
public void onStatusEvent(final EventNSClientUpdateGUI ev) {
|
|
||||||
updateGUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void updateGUI() {
|
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity != null)
|
|
||||||
activity.runOnUiThread(() -> {
|
|
||||||
NSClientPlugin.getPlugin().updateLog();
|
NSClientPlugin.getPlugin().updateLog();
|
||||||
pausedCheckbox.setChecked(SP.getBoolean(R.string.key_nsclientinternal_paused, false));
|
pausedCheckbox.setChecked(SP.getBoolean(R.string.key_nsclientinternal_paused, false));
|
||||||
logTextView.setText(NSClientPlugin.getPlugin().textLog);
|
logTextView.setText(NSClientPlugin.getPlugin().textLog);
|
||||||
|
@ -157,7 +161,6 @@ public class NSClientFragment extends SubscriberFragment implements View.OnClick
|
||||||
Spanned queuetext = Html.fromHtml(MainApp.gs(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
|
Spanned queuetext = Html.fromHtml(MainApp.gs(R.string.queue) + " <b>" + UploadQueue.size() + "</b>");
|
||||||
queueTextView.setText(queuetext);
|
queueTextView.setText(queuetext);
|
||||||
statusTextView.setText(NSClientPlugin.getPlugin().status);
|
statusTextView.setText(NSClientPlugin.getPlugin().status);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import android.os.IBinder;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -22,7 +20,6 @@ import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.events.EventAppExit;
|
import info.nightscout.androidaps.events.EventAppExit;
|
||||||
import info.nightscout.androidaps.events.EventChargingState;
|
import info.nightscout.androidaps.events.EventChargingState;
|
||||||
import info.nightscout.androidaps.events.EventNetworkChange;
|
import info.nightscout.androidaps.events.EventNetworkChange;
|
||||||
|
@ -31,15 +28,20 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.logging.L;
|
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.EventNSClientNewLog;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
|
import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService;
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
import info.nightscout.androidaps.utils.ToastUtils;
|
||||||
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.schedulers.Schedulers;
|
||||||
|
|
||||||
public class NSClientPlugin extends PluginBase {
|
public class NSClientPlugin extends PluginBase {
|
||||||
private Logger log = LoggerFactory.getLogger(L.NSCLIENT);
|
private Logger log = LoggerFactory.getLogger(L.NSCLIENT);
|
||||||
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
static NSClientPlugin nsClientPlugin;
|
static NSClientPlugin nsClientPlugin;
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
nsClientReceiverDelegate =
|
nsClientReceiverDelegate =
|
||||||
new NsClientReceiverDelegate(MainApp.instance().getApplicationContext(), MainApp.bus());
|
new NsClientReceiverDelegate(MainApp.instance().getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed() {
|
public boolean isAllowed() {
|
||||||
|
@ -97,41 +99,64 @@ public class NSClientPlugin extends PluginBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
MainApp.bus().register(this);
|
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
Intent intent = new Intent(context, NSClientService.class);
|
Intent intent = new Intent(context, NSClientService.class);
|
||||||
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
nsClientReceiverDelegate.registerReceivers();
|
nsClientReceiverDelegate.registerReceivers();
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNSClientStatus.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
status = event.getStatus();
|
||||||
|
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNetworkChange.class)
|
||||||
|
.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)
|
||||||
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventNSClientNewLog.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> {
|
||||||
|
addToLog(event);
|
||||||
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
|
log.debug(event.getAction() + " " + event.getLogText());
|
||||||
|
}, FabricPrivacy::logException)
|
||||||
|
);
|
||||||
|
disposable.add(RxBus.INSTANCE
|
||||||
|
.toObservable(EventChargingState.class)
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.subscribe(event -> nsClientReceiverDelegate.onStatusEvent(event), FabricPrivacy::logException)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
MainApp.bus().unregister(this);
|
MainApp.instance().getApplicationContext().unbindService(mConnection);
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
|
||||||
context.unbindService(mConnection);
|
|
||||||
|
|
||||||
nsClientReceiverDelegate.unregisterReceivers();
|
nsClientReceiverDelegate.unregisterReceivers();
|
||||||
|
disposable.clear();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(EventPreferenceChange ev) {
|
|
||||||
nsClientReceiverDelegate.onStatusEvent(ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventChargingState ev) {
|
|
||||||
nsClientReceiverDelegate.onStatusEvent(ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventNetworkChange ev) {
|
|
||||||
nsClientReceiverDelegate.onStatusEvent(ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
private ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
|
@ -149,33 +174,12 @@ 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);
|
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
|
||||||
log.debug(ev.action + " " + ev.logText);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventNSClientStatus ev) {
|
|
||||||
status = ev.status;
|
|
||||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void clearLog() {
|
synchronized void clearLog() {
|
||||||
handler.post(() -> {
|
handler.post(() -> {
|
||||||
synchronized (listLog) {
|
synchronized (listLog) {
|
||||||
listLog.clear();
|
listLog.clear();
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +192,7 @@ public class NSClientPlugin extends PluginBase {
|
||||||
listLog.remove(0);
|
listLog.remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainApp.bus().post(new EventNSClientUpdateGUI());
|
RxBus.INSTANCE.send(new EventNSClientUpdateGUI());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +218,6 @@ public class NSClientPlugin extends PluginBase {
|
||||||
public void pause(boolean newState) {
|
public void pause(boolean newState) {
|
||||||
SP.putBoolean(R.string.key_nsclientinternal_paused, newState);
|
SP.putBoolean(R.string.key_nsclientinternal_paused, newState);
|
||||||
paused = newState;
|
paused = newState;
|
||||||
MainApp.bus().post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
|
||||||
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,12 @@ import android.content.IntentFilter;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
|
||||||
import info.nightscout.androidaps.events.EventChargingState;
|
import info.nightscout.androidaps.events.EventChargingState;
|
||||||
import info.nightscout.androidaps.events.EventNetworkChange;
|
import info.nightscout.androidaps.events.EventNetworkChange;
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.receivers.ChargingStateReceiver;
|
import info.nightscout.androidaps.receivers.ChargingStateReceiver;
|
||||||
import info.nightscout.androidaps.receivers.NetworkChangeReceiver;
|
import info.nightscout.androidaps.receivers.NetworkChangeReceiver;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
@ -21,7 +19,6 @@ import info.nightscout.androidaps.utils.SP;
|
||||||
class NsClientReceiverDelegate {
|
class NsClientReceiverDelegate {
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final Bus bus;
|
|
||||||
|
|
||||||
private NetworkChangeReceiver networkChangeReceiver = new NetworkChangeReceiver();
|
private NetworkChangeReceiver networkChangeReceiver = new NetworkChangeReceiver();
|
||||||
private ChargingStateReceiver chargingStateReceiver = new ChargingStateReceiver();
|
private ChargingStateReceiver chargingStateReceiver = new ChargingStateReceiver();
|
||||||
|
@ -30,9 +27,8 @@ class NsClientReceiverDelegate {
|
||||||
private boolean allowedNetworkState = true;
|
private boolean allowedNetworkState = true;
|
||||||
boolean allowed = true;
|
boolean allowed = true;
|
||||||
|
|
||||||
NsClientReceiverDelegate(Context context, Bus bus) {
|
NsClientReceiverDelegate(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.bus = bus;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void registerReceivers() {
|
void registerReceivers() {
|
||||||
|
@ -46,14 +42,14 @@ class NsClientReceiverDelegate {
|
||||||
|
|
||||||
EventNetworkChange event = networkChangeReceiver.grabNetworkStatus(context);
|
EventNetworkChange event = networkChangeReceiver.grabNetworkStatus(context);
|
||||||
if (event != null)
|
if (event != null)
|
||||||
bus.post(event);
|
RxBus.INSTANCE.send(event);
|
||||||
|
|
||||||
context.registerReceiver(chargingStateReceiver,
|
context.registerReceiver(chargingStateReceiver,
|
||||||
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||||
|
|
||||||
EventChargingState eventChargingState = chargingStateReceiver.grabChargingState(context);
|
EventChargingState eventChargingState = chargingStateReceiver.grabChargingState(context);
|
||||||
if (eventChargingState != null)
|
if (eventChargingState != null)
|
||||||
bus.post(eventChargingState);
|
RxBus.INSTANCE.send(eventChargingState);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +65,11 @@ class NsClientReceiverDelegate {
|
||||||
) {
|
) {
|
||||||
EventNetworkChange event = networkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
|
EventNetworkChange event = networkChangeReceiver.grabNetworkStatus(MainApp.instance().getApplicationContext());
|
||||||
if (event != null)
|
if (event != null)
|
||||||
bus.post(event);
|
RxBus.INSTANCE.send(event);
|
||||||
} else if (ev.isChanged(R.string.key_ns_chargingonly)) {
|
} else if (ev.isChanged(R.string.key_ns_chargingonly)) {
|
||||||
EventChargingState event = chargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
|
EventChargingState event = chargingStateReceiver.grabChargingState(MainApp.instance().getApplicationContext());
|
||||||
if (event != null)
|
if (event != null)
|
||||||
bus.post(event);
|
RxBus.INSTANCE.send(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +95,6 @@ class NsClientReceiverDelegate {
|
||||||
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
boolean newAllowedState = allowedChargingState && allowedNetworkState;
|
||||||
if (newAllowedState != allowed) {
|
if (newAllowedState != allowed) {
|
||||||
allowed = newAllowedState;
|
allowed = newAllowedState;
|
||||||
bus.post(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
|
||||||
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
RxBus.INSTANCE.send(new EventPreferenceChange(R.string.key_nsclientinternal_paused));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,13 +118,13 @@ class NsClientReceiverDelegate {
|
||||||
|
|
||||||
boolean newAllowedState = true;
|
boolean newAllowedState = true;
|
||||||
|
|
||||||
if (ev.wifiConnected) {
|
if (ev.getWifiConnected()) {
|
||||||
if (!allowedSSIDs.trim().isEmpty() &&
|
if (!allowedSSIDs.trim().isEmpty() &&
|
||||||
(!allowedSSIDs.contains(ev.getSsid()) && !allowedSSIDs.contains(ev.ssid))) {
|
(!allowedSSIDs.contains(ev.connectedSsid()) && !allowedSSIDs.contains(ev.getSsid()))) {
|
||||||
newAllowedState = false;
|
newAllowedState = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((!allowRoaming && ev.roaming) || wifiOnly) {
|
if ((!allowRoaming && ev.getRoaming()) || wifiOnly) {
|
||||||
newAllowedState = false;
|
newAllowedState = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart;
|
||||||
import io.socket.client.Ack;
|
import io.socket.client.Ack;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ public class NSAddAck extends Event implements Ack {
|
||||||
nsClientID = response.getString("NSCLIENT_ID");
|
nsClientID = response.getString("NSCLIENT_ID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MainApp.bus().post(this);
|
RxBus.INSTANCE.send(this);
|
||||||
return;
|
return;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
|
@ -44,7 +44,7 @@ public class NSAddAck extends Event implements Ack {
|
||||||
if (response.has("result")) {
|
if (response.has("result")) {
|
||||||
_id = null;
|
_id = null;
|
||||||
if (response.getString("result").contains("Not")) {
|
if (response.getString("result").contains("Not")) {
|
||||||
MainApp.bus().post(new EventNSClientRestart());
|
RxBus.INSTANCE.send(new EventNSClientRestart());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
|
|
|
@ -2,13 +2,10 @@ package info.nightscout.androidaps.plugins.general.nsclient.acks;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.events.Event;
|
import info.nightscout.androidaps.events.Event;
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||||
import io.socket.client.Ack;
|
import io.socket.client.Ack;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 02.01.2016.
|
|
||||||
*/
|
|
||||||
public class NSAuthAck extends Event implements Ack{
|
public class NSAuthAck extends Event implements Ack{
|
||||||
public boolean read = false;
|
public boolean read = false;
|
||||||
public boolean write = false;
|
public boolean write = false;
|
||||||
|
@ -19,6 +16,6 @@ public class NSAuthAck extends Event implements Ack{
|
||||||
read = response.optBoolean("read");
|
read = response.optBoolean("read");
|
||||||
write = response.optBoolean("write");
|
write = response.optBoolean("write");
|
||||||
write_treatment = response.optBoolean("write_treatment");
|
write_treatment = response.optBoolean("write_treatment");
|
||||||
MainApp.bus().post(this);
|
RxBus.INSTANCE.send(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue