Merge branch 'dev' into omnipod_eros_bart

This commit is contained in:
Andy Rozman 2019-11-09 16:17:43 +00:00
commit ef50bc5365
479 changed files with 12591 additions and 7821 deletions

View file

@ -109,7 +109,7 @@ android {
targetSdkVersion 28 targetSdkVersion 28
multiDexEnabled true multiDexEnabled true
versionCode 1500 versionCode 1500
version "2.4-dev-f" version "2.6-dev"
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() + '"'
@ -240,8 +240,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}"
@ -286,14 +284,13 @@ 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"
/*
testImplementation("uk.org.lidalia:slf4j-test:1.2.0") { testImplementation("uk.org.lidalia:slf4j-test:1.2.0") {
exclude group: "com.google.guava", module: "guava" exclude group: "com.google.guava", module: "guava"
} }
*/
androidTestImplementation "org.mockito:mockito-core:2.8.47" androidTestImplementation "org.mockito:mockito-core:2.8.47"
androidTestImplementation "com.google.dexmaker:dexmaker:${dexmakerVersion}" androidTestImplementation "com.google.dexmaker:dexmaker:${dexmakerVersion}"

View file

@ -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);
}
}

View file

@ -12,13 +12,4 @@ public class Config {
public static final boolean PUMPCONTROL = BuildConfig.FLAVOR.equals("pumpcontrol"); public static final boolean PUMPCONTROL = BuildConfig.FLAVOR.equals("pumpcontrol");
public static final boolean PUMPDRIVERS = BuildConfig.FLAVOR.equals("full") || BuildConfig.FLAVOR.equals("pumpcontrol"); public static final boolean PUMPDRIVERS = BuildConfig.FLAVOR.equals("full") || BuildConfig.FLAVOR.equals("pumpcontrol");
public static final boolean ACTION = !NSCLIENT;
public static final boolean MDI = !NSCLIENT;
public static final boolean OTHERPROFILES = !NSCLIENT;
public static final boolean SAFETY = !NSCLIENT;
public static final boolean SMSCOMMUNICATORENABLED = !NSCLIENT;
} }

View file

@ -36,6 +36,8 @@ public class Constants {
public static final int CPP_MIN_TIMESHIFT = -6; public static final int CPP_MIN_TIMESHIFT = -6;
public static final int CPP_MAX_TIMESHIFT = 23; public static final int CPP_MAX_TIMESHIFT = 23;
public static final double MAX_PROFILE_SWITCH_DURATION = 7 * 24 * 60; // [min] ~ 7 days
//DanaR //DanaR
public static final double dailyLimitWarning = 0.95d; public static final double dailyLimitWarning = 0.95d;

View file

@ -6,7 +6,6 @@ import android.content.pm.PackageManager;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.os.PowerManager;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.util.Linkify; import android.text.util.Linkify;
@ -21,6 +20,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 +33,6 @@ import com.google.android.material.navigation.NavigationView;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import com.joanzapata.iconify.Iconify; import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.FontAwesomeModule; import com.joanzapata.iconify.fonts.FontAwesomeModule;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -45,16 +44,16 @@ import info.nightscout.androidaps.activities.PreferencesActivity;
import info.nightscout.androidaps.activities.SingleFragmentActivity; import info.nightscout.androidaps.activities.SingleFragmentActivity;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventFeatureRunning;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.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.constraints.versionChecker.VersionCheckerUtilsKt;
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.setupwizard.SetupWizardActivity; import info.nightscout.androidaps.setupwizard.SetupWizardActivity;
import info.nightscout.androidaps.tabs.TabPageAdapter; import info.nightscout.androidaps.tabs.TabPageAdapter;
import info.nightscout.androidaps.utils.AndroidPermission; import info.nightscout.androidaps.utils.AndroidPermission;
@ -63,11 +62,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;
private ActionBarDrawerToggle actionBarDrawerToggle; private ActionBarDrawerToggle actionBarDrawerToggle;
@ -77,11 +77,8 @@ 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.INSTANCE.update(getApplicationContext());
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
setSupportActionBar(findViewById(R.id.toolbar)); setSupportActionBar(findViewById(R.id.toolbar));
@ -95,14 +92,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
@ -124,6 +117,43 @@ public class MainActivity extends NoSplashAppCompatActivity {
VersionCheckerUtilsKt.triggerCheckVersion(); VersionCheckerUtilsKt.triggerCheckVersion();
FabricPrivacy.setUserStats(); FabricPrivacy.setUserStats();
setupTabs();
setupViews();
disposable.add(RxBus.INSTANCE
.toObservable(EventRebuildTabs.class)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> {
LocaleHelper.INSTANCE.update(getApplicationContext());
if (event.getRecreate()) {
recreate();
} else {
setupTabs();
setupViews();
}
setWakeLock();
}, 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)) {
Intent intent = new Intent(this, SetupWizardActivity.class);
startActivity(intent);
} else {
checkEula();
}
AndroidPermission.notifyForStoragePermission(this);
AndroidPermission.notifyForBatteryOptimizationPermission(this);
if (Config.PUMPDRIVERS) {
AndroidPermission.notifyForLocationPermissions(this);
AndroidPermission.notifyForSMSPermissions(this);
}
} }
private void checkPluginPreferences(ViewPager viewPager) { private void checkPluginPreferences(ViewPager viewPager) {
@ -139,86 +169,29 @@ public class MainActivity extends NoSplashAppCompatActivity {
actionBarDrawerToggle.syncState(); actionBarDrawerToggle.syncState();
} }
@Override
protected void onResume() {
super.onResume();
if (L.isEnabled(L.CORE))
log.debug("onResume");
if (!SP.getBoolean(R.string.key_setupwizard_processed, false)) {
Intent intent = new Intent(this, SetupWizardActivity.class);
startActivity(intent);
} else {
checkEula();
}
AndroidPermission.notifyForStoragePermission(this);
AndroidPermission.notifyForBatteryOptimizationPermission(this);
if (Config.PUMPDRIVERS) {
AndroidPermission.notifyForLocationPermissions(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.isHeld())
mWakeLock.release();
super.onDestroy(); super.onDestroy();
disposable.clear();
} }
@Subscribe private void setWakeLock() {
public void onEventPreferenceChange(final EventPreferenceChange ev) {
if (ev.isChanged(R.string.key_keep_screen_on)) {
boolean keepScreenOn = SP.getBoolean(R.string.key_keep_screen_on, false); boolean keepScreenOn = SP.getBoolean(R.string.key_keep_screen_on, false);
final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (keepScreenOn) {
mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "AndroidAPS:MainActivity_onEventPreferenceChange");
if (!mWakeLock.isHeld())
mWakeLock.acquire();
} else {
if (mWakeLock != null && mWakeLock.isHeld())
mWakeLock.release();
}
}
}
@Subscribe
public void onStatusEvent(final EventRefreshGui ev) {
String lang = SP.getString(R.string.key_language, "en");
LocaleHelper.setLocale(getApplicationContext(), lang);
runOnUiThread(() -> {
if (ev.recreate) {
recreate();
} else {
try { // activity may be destroyed
setupTabs();
setupViews(true);
} catch (IllegalStateException e) {
log.error("Unhandled exception", e);
}
}
boolean keepScreenOn = Config.NSCLIENT && SP.getBoolean(R.string.key_keep_screen_on, false);
if (keepScreenOn) if (keepScreenOn)
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
else else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
});
} }
private void setupViews(boolean switchToLast) { public void processPreferenceChange(final EventPreferenceChange ev) {
if (ev.isChanged(R.string.key_keep_screen_on))
setWakeLock();
}
private void setupViews() {
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()) {
@ -237,8 +210,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);
} }
@ -264,15 +237,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);
@ -289,10 +253,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));
} }
@ -308,19 +272,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) {
@ -405,7 +366,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();

View file

@ -6,16 +6,12 @@ import android.content.IntentFilter;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.SystemClock; import android.os.SystemClock;
import androidx.annotation.Nullable;
import androidx.annotation.PluralsRes; import androidx.annotation.PluralsRes;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; 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;
@ -39,7 +35,9 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin; import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin;
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.constraints.signatureVerifier.SignatureVerifierPlugin;
import info.nightscout.androidaps.plugins.constraints.storage.StorageConstraintPlugin; import info.nightscout.androidaps.plugins.constraints.storage.StorageConstraintPlugin;
import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerPlugin;
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin; import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin;
import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin; import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin;
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
@ -52,10 +50,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.receivers.AckAlarmRec
import info.nightscout.androidaps.plugins.general.nsclient.receivers.DBAccessReceiver; import info.nightscout.androidaps.plugins.general.nsclient.receivers.DBAccessReceiver;
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin; import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin; import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin;
import info.nightscout.androidaps.plugins.general.signatureVerifier.SignatureVerifier;
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.general.tidepool.TidepoolPlugin;
import info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerPlugin;
import info.nightscout.androidaps.plugins.general.wear.WearPlugin; import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin; import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin; import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
@ -73,7 +68,6 @@ 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.plugins.pump.mdi.MDIPlugin; import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin; import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
@ -94,16 +88,16 @@ import info.nightscout.androidaps.receivers.NSAlarmReceiver;
import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver; import info.nightscout.androidaps.receivers.TimeDateOrTZChangeReceiver;
import info.nightscout.androidaps.services.Intents; import info.nightscout.androidaps.services.Intents;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.LocaleHelper;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
import static info.nightscout.androidaps.plugins.general.versionChecker.VersionCheckerUtilsKt.triggerCheckVersion; import static info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtilsKt.triggerCheckVersion;
public class MainApp extends Application { 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;
@ -131,6 +125,7 @@ public class MainApp extends Application {
log.debug("onCreate"); log.debug("onCreate");
sInstance = this; sInstance = this;
sResources = getResources(); sResources = getResources();
LocaleHelper.INSTANCE.update(this);
sConstraintsChecker = new ConstraintChecker(); sConstraintsChecker = new ConstraintChecker();
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class); sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
@ -159,8 +154,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
@ -170,9 +163,9 @@ public class MainApp extends Application {
if (pluginsList == null) { if (pluginsList == null) {
pluginsList = new ArrayList<>(); pluginsList = new ArrayList<>();
// Register all tabs in app here // Register all tabs in app here
pluginsList.add(OverviewPlugin.getPlugin()); pluginsList.add(OverviewPlugin.INSTANCE);
pluginsList.add(IobCobCalculatorPlugin.getPlugin()); pluginsList.add(IobCobCalculatorPlugin.getPlugin());
if (Config.ACTION) pluginsList.add(ActionsPlugin.INSTANCE); if (!Config.NSCLIENT) pluginsList.add(ActionsPlugin.INSTANCE);
pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin()); pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin());
pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin()); pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin());
pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin()); pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin());
@ -185,26 +178,25 @@ public class MainApp extends Application {
if (Config.PUMPDRIVERS) pluginsList.add(DanaRv2Plugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(DanaRv2Plugin.getPlugin());
if (Config.PUMPDRIVERS) pluginsList.add(DanaRSPlugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(DanaRSPlugin.getPlugin());
if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(LocalInsightPlugin.getPlugin());
pluginsList.add(CareportalPlugin.getPlugin());
if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin()); if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin());
if (Config.PUMPDRIVERS && engineeringMode) if (Config.PUMPDRIVERS) pluginsList.add(MedtronicPumpPlugin.getPlugin());
pluginsList.add(MedtronicPumpPlugin.getPlugin());
if (Config.PUMPDRIVERS && engineeringMode) if (Config.PUMPDRIVERS && engineeringMode)
pluginsList.add(OmnipodPumpPlugin.getPlugin()); pluginsList.add(OmnipodPumpPlugin.getPlugin());
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (!Config.NSCLIENT) pluginsList.add(MDIPlugin.getPlugin());
pluginsList.add(VirtualPumpPlugin.getPlugin()); pluginsList.add(VirtualPumpPlugin.getPlugin());
pluginsList.add(CareportalPlugin.getPlugin());
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin()); if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin()); if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin()); if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
pluginsList.add(NSProfilePlugin.getPlugin()); pluginsList.add(NSProfilePlugin.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin()); if (!Config.NSCLIENT) pluginsList.add(SimpleProfilePlugin.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin()); if (!Config.NSCLIENT) pluginsList.add(LocalProfilePlugin.getPlugin());
pluginsList.add(TreatmentsPlugin.getPlugin()); pluginsList.add(TreatmentsPlugin.getPlugin());
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin()); if (!Config.NSCLIENT) pluginsList.add(SafetyPlugin.getPlugin());
if (Config.SAFETY) pluginsList.add(VersionCheckerPlugin.INSTANCE); if (!Config.NSCLIENT) pluginsList.add(VersionCheckerPlugin.INSTANCE);
if (Config.SAFETY) pluginsList.add(StorageConstraintPlugin.getPlugin()); if (Config.APS) pluginsList.add(StorageConstraintPlugin.getPlugin());
if (Config.SAFETY) pluginsList.add(SignatureVerifier.getPlugin()); if (Config.APS) pluginsList.add(SignatureVerifierPlugin.getPlugin());
if (Config.APS) pluginsList.add(ObjectivesPlugin.INSTANCE); if (Config.APS) pluginsList.add(ObjectivesPlugin.INSTANCE);
pluginsList.add(SourceXdripPlugin.getPlugin()); pluginsList.add(SourceXdripPlugin.getPlugin());
pluginsList.add(SourceNSClientPlugin.getPlugin()); pluginsList.add(SourceNSClientPlugin.getPlugin());
@ -214,7 +206,7 @@ public class MainApp extends Application {
pluginsList.add(SourcePoctechPlugin.getPlugin()); pluginsList.add(SourcePoctechPlugin.getPlugin());
pluginsList.add(SourceTomatoPlugin.getPlugin()); pluginsList.add(SourceTomatoPlugin.getPlugin());
pluginsList.add(SourceEversensePlugin.getPlugin()); pluginsList.add(SourceEversensePlugin.getPlugin());
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin()); if (!Config.NSCLIENT) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
pluginsList.add(FoodPlugin.getPlugin()); pluginsList.add(FoodPlugin.getPlugin());
pluginsList.add(WearPlugin.initPlugin(this)); pluginsList.add(WearPlugin.initPlugin(this));
@ -289,10 +281,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);
} }
@ -394,19 +382,6 @@ public class MainApp extends Application {
return newList; return newList;
} }
@Nullable
public static <T extends PluginBase> T getSpecificPlugin(Class<T> pluginClass) {
if (pluginsList != null) {
for (PluginBase p : pluginsList) {
if (pluginClass.isAssignableFrom(p.getClass()))
return (T) p;
}
} else {
log.error("pluginsList=null");
}
return null;
}
public static boolean isEngineeringModeOrRelease() { public static boolean isEngineeringModeOrRelease() {
if (!Config.APS) if (!Config.APS)
return true; return true;

View file

@ -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);
@ -230,8 +232,8 @@ public class HistoryBrowseActivity extends NoSplashActivity {
} }
final String units = profile.getUnits(); final String units = profile.getUnits();
final double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); final double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
final double highLine = OverviewPlugin.getPlugin().determineHighLine(units); final double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
buttonDate.setText(DateUtil.dateAndTimeString(start)); buttonDate.setText(DateUtil.dateAndTimeString(start));
buttonZoom.setText(String.valueOf(rangeToDisplay)); buttonZoom.setText(String.valueOf(rangeToDisplay));

View file

@ -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,14 @@ 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"); RxBus.INSTANCE.send(new EventRebuildTabs(true));
LocaleHelper.setLocale(getApplicationContext(), lang);
MainApp.bus().post(new EventRefreshGui(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);
@ -209,6 +206,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning))); scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical))); scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights))); scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights_extended)));
} }
} }

View file

@ -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,38 +534,13 @@ 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 = DanaRPlugin.getPlugin();
PumpInterface danaRS = MainApp.getSpecificPlugin(DanaRSPlugin.class); PumpInterface danaRS = DanaRSPlugin.getPlugin();
PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class); PumpInterface danaV2 = DanaRv2Plugin.getPlugin();
PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class); PumpInterface danaKorean = DanaRKoreanPlugin.getPlugin();
PumpInterface insight = MainApp.getSpecificPlugin(LocalInsightPlugin.class); PumpInterface insight = LocalInsightPlugin.getPlugin();
boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight; boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight;

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
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.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
@ -231,7 +232,7 @@ public class Profile {
if (notify && secondsFromMidnight % 3600 != 0) { if (notify && secondsFromMidnight % 3600 != 0) {
if (Config.APS) { if (Config.APS) {
Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, String.format(MainApp.gs(R.string.basalprofilenotaligned), from), Notification.NORMAL); Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, String.format(MainApp.gs(R.string.basalprofilenotaligned), from), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification)); RxBus.INSTANCE.send(new EventNewNotification(notification));
} }
} }
} }
@ -263,11 +264,11 @@ public class Profile {
} }
protected void sendBelowMinimumNotification(String from) { protected void sendBelowMinimumNotification(String from) {
MainApp.bus().post(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.minimalbasalvaluereplaced), from), Notification.NORMAL))); RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.minimalbasalvaluereplaced), from), Notification.NORMAL)));
} }
protected void sendAboveMaximumNotification(String from) { protected void sendAboveMaximumNotification(String from) {
MainApp.bus().post(new EventNewNotification(new Notification(Notification.MAXIMUM_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.maximumbasalvaluereplaced), from), Notification.NORMAL))); RxBus.INSTANCE.send(new EventNewNotification(new Notification(Notification.MAXIMUM_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.maximumbasalvaluereplaced), from), Notification.NORMAL)));
} }
private void validate(LongSparseArray array) { private void validate(LongSparseArray array) {

View file

@ -1,86 +0,0 @@
package info.nightscout.androidaps.data;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 12.10.2016.
*/
public class QuickWizard {
private static Logger log = LoggerFactory.getLogger(QuickWizard.class);
private JSONArray storage = new JSONArray();
public void setData(JSONArray newData) {
storage = newData;
}
public void save() {
SP.putString("QuickWizard", storage.toString());
}
public int size() {
return storage.length();
}
public QuickWizardEntry get(int position) {
try {
return new QuickWizardEntry((JSONObject) storage.get(position), position);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
return null;
}
public Boolean isActive() {
for (int i = 0; i < storage.length(); i++) {
try {
if (new QuickWizardEntry((JSONObject) storage.get(i), i).isActive()) return true;
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
}
return false;
}
public QuickWizardEntry getActive() {
for (int i = 0; i < storage.length(); i++) {
QuickWizardEntry entry;
try {
entry = new QuickWizardEntry((JSONObject) storage.get(i), i);
} catch (JSONException e) {
continue;
}
if (entry.isActive()) return entry;
}
return null;
}
public QuickWizardEntry newEmptyItem() {
return new QuickWizardEntry();
}
public void addOrUpdate(QuickWizardEntry newItem) {
if (newItem.position == -1)
storage.put(newItem.storage);
else {
try {
storage.put(newItem.position, newItem.storage);
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
}
save();
}
public void remove(int position) {
storage.remove(position);
save();
}
}

View file

@ -0,0 +1,52 @@
package info.nightscout.androidaps.data
import info.nightscout.androidaps.utils.SP
import org.json.JSONArray
import org.json.JSONObject
object QuickWizard {
private var storage = JSONArray()
init {
setData(JSONArray(SP.getString("QuickWizard", "[]")))
}
fun getActive(): QuickWizardEntry? {
for (i in 0 until storage.length()) {
val entry = QuickWizardEntry(storage.get(i) as JSONObject, i)
if (entry.isActive) return entry
}
return null
}
fun setData(newData: JSONArray) {
storage = newData
}
fun save() {
SP.putString("QuickWizard", storage.toString())
}
fun size(): Int = storage.length()
operator fun get(position: Int): QuickWizardEntry =
QuickWizardEntry(storage.get(position) as JSONObject, position)
fun newEmptyItem(): QuickWizardEntry {
return QuickWizardEntry()
}
fun addOrUpdate(newItem: QuickWizardEntry) {
if (newItem.position == -1)
storage.put(newItem.storage)
else
storage.put(newItem.position, newItem.storage)
save()
}
fun remove(position: Int) {
storage.remove(position)
save()
}
}

View file

@ -216,8 +216,8 @@ public class BgReading implements DataPointWithLabelInterface {
@Override @Override
public int getColor() { public int getColor() {
String units = ProfileFunctions.getInstance().getProfileUnits(); String units = ProfileFunctions.getInstance().getProfileUnits();
Double lowLine = OverviewPlugin.getPlugin().determineLowLine(units); Double lowLine = OverviewPlugin.INSTANCE.determineLowLine(units);
Double highLine = OverviewPlugin.getPlugin().determineHighLine(units); Double highLine = OverviewPlugin.INSTANCE.determineHighLine(units);
int color = MainApp.gc(R.color.inrange); int color = MainApp.gc(R.color.inrange);
if (isPrediction()) if (isPrediction())
return getPredectionColor(); return getPredectionColor();

View file

@ -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;
} }
} }
@ -1720,8 +1719,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;
} }
} }

View file

@ -1,6 +1,8 @@
package info.nightscout.androidaps.db; package info.nightscout.androidaps.db;
import android.graphics.Color; import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.field.DatabaseField;
@ -18,11 +20,13 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.interfaces.Interval;
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.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin; import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter; import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.T;
@ -156,7 +160,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
// -------- Interval interface --------- // -------- Interval interface ---------
Long cuttedEnd = null; private Long cuttedEnd = null;
public long durationInMsec() { public long durationInMsec() {
return durationInMinutes * 60 * 1000L; return durationInMinutes * 60 * 1000L;
@ -212,16 +216,17 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
@Override @Override
public boolean isValid() { public boolean isValid() {
boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date)); boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date));
if (!isValid) ProfileSwitch active = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(DateUtil.now());
long activeProfileSwitchDate = active != null ? active.date : -1L;
if (!isValid && date == activeProfileSwitchDate)
createNotificationInvalidProfile(DateUtil.dateAndTimeString(date)); createNotificationInvalidProfile(DateUtil.dateAndTimeString(date));
return isValid; return isValid;
} }
public void createNotificationInvalidProfile(String detail) { private void createNotificationInvalidProfile(String detail) {
Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, String.format(MainApp.gs(R.string.zerovalueinprofile), detail), Notification.LOW, 5); Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, String.format(MainApp.gs(R.string.zerovalueinprofile), detail), Notification.LOW, 5);
MainApp.bus().post(new EventNewNotification(notification)); RxBus.INSTANCE.send(new EventNewNotification(notification));
} }
public static boolean isEvent5minBack(List<ProfileSwitch> list, long time, boolean zeroDurationOnly) { public static boolean isEvent5minBack(List<ProfileSwitch> list, long time, boolean zeroDurationOnly) {
@ -290,6 +295,7 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
return Color.CYAN; return Color.CYAN;
} }
@NonNull
public String toString() { public String toString() {
return "ProfileSwitch{" + return "ProfileSwitch{" +
"date=" + date + "date=" + date +

View file

@ -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);
}
}

View 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)
}
}
}

View file

@ -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 {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventAcceptOpenLoopChange : Event()

View file

@ -1,7 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 07.07.2016.
*/
public class EventAppExit extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventAppExit : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 23.01.2018.
*/
public class EventAppInitialized extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventAppInitialized : Event()

View file

@ -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;
}
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventBolusRequested(var amount: Double) : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 25.05.2017.
*/
public class EventCareportalEventChange extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventCareportalEventChange : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 17.02.2017.
*/
public class EventConfigBuilderChange extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventConfigBuilderChange : Event()

View file

@ -1,4 +0,0 @@
package info.nightscout.androidaps.events;
public class EventCustomActionsChanged extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventCustomActionsChanged : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 13.02.2018.
*/
public class EventCustomCalculationFinished extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventCustomCalculationFinished : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 15.05.2017.
*/
public class EventExtendedBolusChange extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventExtendedBolusChange : EventLoop()

View file

@ -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
}
}

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 20.09.2017.
*/
public class EventFoodDatabaseChanged extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventFoodDatabaseChanged : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 13.12.2016.
*/
public class EventInitializationChanged extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventInitializationChanged : Event()

View file

@ -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;
}
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.events
import android.location.Location
class EventLocationChange(var location: Location) : Event()

View file

@ -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 {
}

View file

@ -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()

View file

@ -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);
}
}

View file

@ -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)
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.events
import info.nightscout.androidaps.db.BgReading
class EventNewBG(val bgReading: BgReading?) : EventLoop()

View file

@ -1,7 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 04.06.2016.
*/
public class EventNewBasalProfile extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventNewBasalProfile : Event()

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -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;
}
}

View file

@ -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
}
}

View file

@ -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);
}
}

View file

@ -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)
}
}

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 02.06.2017.
*/
public class EventProfileNeedsUpdate extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventProfileNeedsUpdate : Event()

View file

@ -1,4 +0,0 @@
package info.nightscout.androidaps.events;
public class EventProfileStoreChanged extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventProfileStoreChanged : Event()

View file

@ -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 "";
}
}

View file

@ -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 ""
}
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventRebuildTabs @JvmOverloads constructor(var recreate: Boolean = false) : Event()

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventRefreshOverview(var from: String) : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 12.06.2017.
*/
public class EventReloadProfileSwitchData extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventReloadProfileSwitchData : Event()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 29.05.2017.
*/
public class EventReloadTempBasalData extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventReloadTempBasalData : Event()

View file

@ -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;
}
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventReloadTreatmentData(var next: Event) : Event()

View file

@ -0,0 +1,6 @@
package info.nightscout.androidaps.events
// pass string to startup wizard
abstract class EventStatus :Event() {
abstract fun getStatus() : String
}

View file

@ -1,7 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 05.06.2016.
*/
public class EventTempBasalChange extends EventLoop {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventTempBasalChange : EventLoop()

View file

@ -1,8 +0,0 @@
package info.nightscout.androidaps.events;
/**
* Created by mike on 13.01.2017.
*/
public class EventTempTargetChange extends Event {
}

View file

@ -0,0 +1,3 @@
package info.nightscout.androidaps.events
class EventTempTargetChange : Event()

View file

@ -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;
}
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.events
import info.nightscout.androidaps.plugins.treatments.Treatment
class EventTreatmentChange(val treatment: Treatment?) : EventLoop()

View file

@ -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 {
}

View file

@ -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()

View file

@ -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();
} }

View file

@ -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;
@ -52,6 +50,7 @@ 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.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler; import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
@ -62,12 +61,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 +118,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 +167,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 +177,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 +438,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 +471,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");
@ -647,7 +646,12 @@ public class LoopPlugin extends PluginBase {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror)); Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
} }
} }
}); });
@ -656,7 +660,12 @@ public class LoopPlugin extends PluginBase {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror)); Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
} }
} }
}); });
@ -667,7 +676,12 @@ public class LoopPlugin extends PluginBase {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.extendedbolusdeliveryerror)); Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.extendedbolusdeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
} }
} }
}); });
@ -681,7 +695,12 @@ public class LoopPlugin extends PluginBase {
@Override @Override
public void run() { public void run() {
if (!result.success) { if (!result.success) {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.tempbasaldeliveryerror)); Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class);
i.putExtra("soundid", R.raw.boluserror);
i.putExtra("status", result.comment);
i.putExtra("title", MainApp.gs(R.string.tempbasaldeliveryerror));
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainApp.instance().startActivity(i);
} }
} }
}); });

View file

@ -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 {
}

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.plugins.aps.loop.events
import info.nightscout.androidaps.events.Event
class EventNewOpenLoopNotification : Event()

View file

@ -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();
}

View file

@ -68,6 +68,7 @@ class ConfigBuilderFragment : Fragment() {
@Synchronized @Synchronized
private fun updateGUI() { private fun updateGUI() {
configbuilder_categories.removeAllViews()
createViewsForPlugins(R.string.configbuilder_profile, R.string.configbuilder_profile_description, PluginType.PROFILE, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface::class.java, PluginType.PROFILE)) createViewsForPlugins(R.string.configbuilder_profile, R.string.configbuilder_profile_description, PluginType.PROFILE, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface::class.java, PluginType.PROFILE))
createViewsForPlugins(R.string.configbuilder_insulin, R.string.configbuilder_insulin_description, PluginType.INSULIN, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface::class.java, PluginType.INSULIN)) createViewsForPlugins(R.string.configbuilder_insulin, R.string.configbuilder_insulin_description, PluginType.INSULIN, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface::class.java, PluginType.INSULIN))
createViewsForPlugins(R.string.configbuilder_bgsource, R.string.configbuilder_bgsource_description, PluginType.BGSOURCE, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface::class.java, PluginType.BGSOURCE)) createViewsForPlugins(R.string.configbuilder_bgsource, R.string.configbuilder_bgsource_description, PluginType.BGSOURCE, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface::class.java, PluginType.BGSOURCE))

View file

@ -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() {

View file

@ -1,44 +0,0 @@
package info.nightscout.androidaps.plugins.configBuilder;
import androidx.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.logging.L;
/**
* Created by mike on 08.08.2017.
*/
public class DetailedBolusInfoStorage {
private static Logger log = LoggerFactory.getLogger(L.PUMP);
private static List<DetailedBolusInfo> store = new ArrayList<>();
public static synchronized void add(DetailedBolusInfo detailedBolusInfo) {
log.debug("Stored bolus info: " + detailedBolusInfo);
store.add(detailedBolusInfo);
}
@Nullable
public static synchronized DetailedBolusInfo findDetailedBolusInfo(long bolustime) {
DetailedBolusInfo found = null;
for (int i = 0; i < store.size(); i++) {
long infoTime = store.get(i).date;
if (L.isEnabled(L.PUMP))
log.debug("Existing bolus info: " + store.get(i));
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {
found = store.get(i);
if (L.isEnabled(L.PUMP))
log.debug("Using & removing bolus info: " + store.get(i));
store.remove(i);
break;
}
}
return found;
}
}

View file

@ -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()
} }

View file

@ -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() {

View file

@ -15,6 +15,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
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.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
@ -89,6 +90,6 @@ public class DstHelperPlugin extends PluginBase implements ConstraintsInterface
private void warnUser(int id, String warningText) { private void warnUser(int id, String warningText) {
Notification notification = new Notification(id, warningText, Notification.LOW); Notification notification = new Notification(id, warningText, Notification.LOW);
MainApp.bus().post(new EventNewNotification(notification)); RxBus.INSTANCE.send(new EventNewNotification(notification));
} }
} }

View file

@ -18,19 +18,20 @@ import androidx.recyclerview.widget.LinearSmoothScroller
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog import info.nightscout.androidaps.plugins.constraints.objectives.activities.ObjectivesExamDialog
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective.ExamTask
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.receivers.NetworkChangeReceiver
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.HtmlHelper
import info.nightscout.androidaps.utils.SP
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.objectives_fragment.* import kotlinx.android.synthetic.main.objectives_fragment.*
import org.slf4j.LoggerFactory
class ObjectivesFragment : Fragment() { class ObjectivesFragment : Fragment() {
private val log = LoggerFactory.getLogger(L.CONSTRAINTS)
private val objectivesAdapter = ObjectivesAdapter() private val objectivesAdapter = ObjectivesAdapter()
private val handler = Handler(Looper.getMainLooper()) private val handler = Handler(Looper.getMainLooper())
@ -50,7 +51,6 @@ class ObjectivesFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
objectives_recyclerview.layoutManager = LinearLayoutManager(view.context) objectives_recyclerview.layoutManager = LinearLayoutManager(view.context)
objectives_recyclerview.adapter = objectivesAdapter objectives_recyclerview.adapter = objectivesAdapter
objectives_fake.setOnClickListener { updateGUI() } objectives_fake.setOnClickListener { updateGUI() }
@ -104,17 +104,14 @@ class ObjectivesFragment : Fragment() {
for (i in 0 until ObjectivesPlugin.objectives.size) { for (i in 0 until ObjectivesPlugin.objectives.size) {
val objective = ObjectivesPlugin.objectives[i] val objective = ObjectivesPlugin.objectives[i]
if (!objective.isStarted || !objective.isAccomplished) { if (!objective.isStarted || !objective.isAccomplished) {
val smoothScroller = object : LinearSmoothScroller(context!!) { context?.let {
override fun getVerticalSnapPreference(): Int { val smoothScroller = object : LinearSmoothScroller(it) {
return SNAP_TO_START override fun getVerticalSnapPreference(): Int = SNAP_TO_START
} override fun calculateTimeForScrolling(dx: Int): Int = super.calculateTimeForScrolling(dx) * 4
override fun calculateTimeForScrolling(dx: Int): Int {
return super.calculateTimeForScrolling(dx) * 4
}
} }
smoothScroller.targetPosition = i smoothScroller.targetPosition = i
objectives_recyclerview.layoutManager?.startSmoothScroll(smoothScroller) objectives_recyclerview.layoutManager?.startSmoothScroll(smoothScroller)
}
break break
} }
} }
@ -168,10 +165,17 @@ class ObjectivesFragment : Fragment() {
holder.progress.removeAllViews() holder.progress.removeAllViews()
for (task in objective.tasks) { for (task in objective.tasks) {
if (task.shouldBeIgnored()) continue if (task.shouldBeIgnored()) continue
// name
val name = TextView(holder.progress.context) val name = TextView(holder.progress.context)
name.text = MainApp.gs(task.task) + ":" name.text = MainApp.gs(task.task) + ":"
name.setTextColor(-0x1) name.setTextColor(-0x1)
holder.progress.addView(name, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT) holder.progress.addView(name, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)
// hint
task.hints.forEach { h ->
if (!task.isCompleted)
holder.progress.addView(h.generate(context))
}
// state
val state = TextView(holder.progress.context) val state = TextView(holder.progress.context)
state.setTextColor(-0x1) state.setTextColor(-0x1)
val basicHTML = "<font color=\"%1\$s\"><b>%2\$s</b></font>" val basicHTML = "<font color=\"%1\$s\"><b>%2\$s</b></font>"
@ -183,13 +187,14 @@ class ObjectivesFragment : Fragment() {
state.setOnClickListener { state.setOnClickListener {
val dialog = ObjectivesExamDialog() val dialog = ObjectivesExamDialog()
val bundle = Bundle() val bundle = Bundle()
val position = objective.tasks.indexOf(task) val taskPosition = objective.tasks.indexOf(task)
bundle.putInt("currentTask", position) bundle.putInt("currentTask", taskPosition)
dialog.arguments = bundle dialog.arguments = bundle
ObjectivesExamDialog.objective = objective ObjectivesExamDialog.objective = objective
fragmentManager?.let { dialog.show(it, "ObjectivesFragment") } fragmentManager?.let { dialog.show(it, "ObjectivesFragment") }
} }
} }
// horizontal line
val separator = View(holder.progress.context) val separator = View(holder.progress.context)
separator.setBackgroundColor(Color.DKGRAY) separator.setBackgroundColor(Color.DKGRAY)
holder.progress.addView(separator, LinearLayout.LayoutParams.MATCH_PARENT, 2) holder.progress.addView(separator, LinearLayout.LayoutParams.MATCH_PARENT, 2)
@ -198,16 +203,64 @@ class ObjectivesFragment : Fragment() {
holder.accomplished.text = MainApp.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn)) holder.accomplished.text = MainApp.gs(R.string.accomplished, DateUtil.dateAndTimeString(objective.accomplishedOn))
holder.accomplished.setTextColor(-0x3e3e3f) holder.accomplished.setTextColor(-0x3e3e3f)
holder.verify.setOnClickListener { holder.verify.setOnClickListener {
holder.verify.visibility = View.INVISIBLE
NetworkChangeReceiver.fetch()
if (objectives_fake.isChecked) {
objective.accomplishedOn = DateUtil.now() objective.accomplishedOn = DateUtil.now()
notifyDataSetChanged()
scrollToCurrentObjective() scrollToCurrentObjective()
startUpdateTimer() startUpdateTimer()
RxBus.send(EventObjectivesUpdateGui())
} else
SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() {
activity?.runOnUiThread {
holder.verify.visibility = View.VISIBLE
log.debug("NTP time: $time System time: ${DateUtil.now()}")
if (!networkConnected) {
ToastUtils.showToastInUiThread(context, R.string.notconnected)
} else if (success) {
if (objective.isCompleted(time)) {
objective.accomplishedOn = time
scrollToCurrentObjective()
startUpdateTimer()
RxBus.send(EventObjectivesUpdateGui())
} else {
ToastUtils.showToastInUiThread(context, R.string.requirementnotmet)
}
} else {
ToastUtils.showToastInUiThread(context, R.string.failedretrievetime)
}
}
}
}, NetworkChangeReceiver.isConnected())
} }
holder.start.setOnClickListener { holder.start.setOnClickListener {
holder.start.visibility = View.INVISIBLE
NetworkChangeReceiver.fetch()
if (objectives_fake.isChecked) {
objective.startedOn = DateUtil.now() objective.startedOn = DateUtil.now()
notifyDataSetChanged()
scrollToCurrentObjective() scrollToCurrentObjective()
startUpdateTimer() startUpdateTimer()
RxBus.send(EventObjectivesUpdateGui())
} else
SntpClient.ntpTime(object : SntpClient.Callback() {
override fun run() {
activity?.runOnUiThread {
holder.start.visibility = View.VISIBLE
log.debug("NTP time: $time System time: ${DateUtil.now()}")
if (!networkConnected) {
ToastUtils.showToastInUiThread(context, R.string.notconnected)
} else if (success) {
objective.startedOn = time
scrollToCurrentObjective()
startUpdateTimer()
RxBus.send(EventObjectivesUpdateGui())
} else {
ToastUtils.showToastInUiThread(context, R.string.failedretrievetime)
}
}
}
}, NetworkChangeReceiver.isConnected())
} }
holder.revert.setOnClickListener { holder.revert.setOnClickListener {
objective.accomplishedOn = 0 objective.accomplishedOn = 0
@ -216,8 +269,8 @@ class ObjectivesFragment : Fragment() {
val prevObj = ObjectivesPlugin.objectives[position - 1] val prevObj = ObjectivesPlugin.objectives[position - 1]
prevObj.accomplishedOn = 0 prevObj.accomplishedOn = 0
} }
notifyDataSetChanged()
scrollToCurrentObjective() scrollToCurrentObjective()
RxBus.send(EventObjectivesUpdateGui())
} }
if (objective.hasSpecialInput && !objective.isAccomplished && objective.isStarted) { if (objective.hasSpecialInput && !objective.isAccomplished && objective.isStarted) {
// generate random request code if none exists // generate random request code if none exists
@ -231,7 +284,7 @@ class ObjectivesFragment : Fragment() {
holder.enterButton.setOnClickListener { holder.enterButton.setOnClickListener {
val input = holder.input.text.toString() val input = holder.input.text.toString()
objective.specialAction(activity, input) objective.specialAction(activity, input)
notifyDataSetChanged() RxBus.send(EventObjectivesUpdateGui())
} }
} else { } else {
holder.enterButton.visibility = View.GONE holder.enterButton.visibility = View.GONE

View file

@ -21,8 +21,8 @@ import java.util.*
object ObjectivesPlugin : PluginBase(PluginDescription() object ObjectivesPlugin : PluginBase(PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
.fragmentClass(ObjectivesFragment::class.qualifiedName) .fragmentClass(ObjectivesFragment::class.qualifiedName)
.alwaysEnabled(!Config.NSCLIENT) .alwaysEnabled(Config.APS)
.showInList(!Config.NSCLIENT) .showInList(Config.APS)
.pluginName(R.string.objectives) .pluginName(R.string.objectives)
.shortName(R.string.objectives_shortname) .shortName(R.string.objectives_shortname)
.description(R.string.description_objectives)), ConstraintsInterface { .description(R.string.description_objectives)), ConstraintsInterface {
@ -64,7 +64,7 @@ object ObjectivesPlugin : PluginBase(PluginDescription()
private fun doConvertSP(number: Int, name: String) { private fun doConvertSP(number: Int, name: String) {
if (!SP.contains("Objectives_" + name + "_started")) { if (!SP.contains("Objectives_" + name + "_started")) {
SP.putLong("Objectives_" + name + "_started", SP.getLong("Objectives" + number + "accomplished", 0L)) SP.putLong("Objectives_" + name + "_started", SP.getLong("Objectives" + number + "started", 0L))
SP.putLong("Objectives_" + name + "_accomplished", SP.getLong("Objectives" + number + "accomplished", 0L)) SP.putLong("Objectives_" + name + "_accomplished", SP.getLong("Objectives" + number + "accomplished", 0L))
} }
// TODO: we can remove Objectives1accomplished sometimes later // TODO: we can remove Objectives1accomplished sometimes later

View file

@ -57,12 +57,11 @@ class ObjectivesExamDialog : DialogFragment() {
objectives_exam_question.setText(task.question) objectives_exam_question.setText(task.question)
// Options // Options
objectives_exam_options.removeAllViews() objectives_exam_options.removeAllViews()
for (o in task.options) { task.options.forEach {
val option: Option = o as Option; val cb = it.generate(context)
val cb = option.generate(context)
if (task.answered) { if (task.answered) {
cb.isEnabled = false cb.isEnabled = false
if (option.isCorrect) if (it.isCorrect)
cb.isChecked = true cb.isChecked = true
} }
objectives_exam_options.addView(cb) objectives_exam_options.addView(cb)
@ -70,8 +69,7 @@ class ObjectivesExamDialog : DialogFragment() {
// Hints // Hints
objectives_exam_hints.removeAllViews() objectives_exam_hints.removeAllViews()
for (h in task.hints) { for (h in task.hints) {
val hint: Hint = h as Hint; objectives_exam_hints.addView(h.generate(context))
objectives_exam_hints.addView(hint.generate(context))
} }
// Disabled to // Disabled to
objectives_exam_disabledto.text = MainApp.gs(R.string.answerdisabledto, DateUtil.timeString(task.disabledTo)) objectives_exam_disabledto.text = MainApp.gs(R.string.answerdisabledto, DateUtil.timeString(task.disabledTo))

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.TextView; import android.widget.TextView;
@ -36,6 +37,10 @@ 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.hours(3).msecs() || (startedOn - DateUtil.now()) > T.hours(3).msecs()) { // more than 3 hours in the future
startedOn = 0;
accomplishedOn = 0;
}
setupTasks(tasks); setupTasks(tasks);
for (Task task : tasks) task.objective = this; for (Task task : tasks) task.objective = this;
} }
@ -48,12 +53,20 @@ public abstract class Objective {
return true; return true;
} }
public boolean isCompleted(long trueTime) {
for (Task task : tasks) {
if (!task.shouldBeIgnored() && !task.isCompleted(trueTime))
return false;
}
return true;
}
public boolean isRevertable() { public boolean isRevertable() {
return false; return false;
} }
public boolean isAccomplished() { public boolean isAccomplished() {
return accomplishedOn != 0; return accomplishedOn != 0 && accomplishedOn < DateUtil.now();
} }
public boolean isStarted() { public boolean isStarted() {
@ -100,6 +113,7 @@ public abstract class Objective {
@StringRes @StringRes
private int task; private int task;
private Objective objective; private Objective objective;
ArrayList<Hint> hints = new ArrayList<>();
public Task(@StringRes int task) { public Task(@StringRes int task) {
this.task = task; this.task = task;
@ -114,11 +128,21 @@ public abstract class Objective {
} }
public abstract boolean isCompleted(); public abstract boolean isCompleted();
public boolean isCompleted(long trueTime) { return isCompleted(); };
public String getProgress() { public String getProgress() {
return MainApp.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet); return MainApp.gs(isCompleted() ? R.string.completed_well_done : R.string.not_completed_yet);
} }
Task hint(Hint hint) {
hints.add(hint);
return this;
}
public ArrayList<Hint> getHints() {
return hints;
}
public boolean shouldBeIgnored() { public boolean shouldBeIgnored() {
return false; return false;
} }
@ -138,6 +162,11 @@ public abstract class Objective {
return getObjective().isStarted() && System.currentTimeMillis() - getObjective().getStartedOn() >= minimumDuration; return getObjective().isStarted() && System.currentTimeMillis() - getObjective().getStartedOn() >= minimumDuration;
} }
@Override
public boolean isCompleted(long trueTime) {
return getObjective().isStarted() && trueTime - getObjective().getStartedOn() >= minimumDuration;
}
@Override @Override
public String getProgress() { public String getProgress() {
return getDurationText(System.currentTimeMillis() - getObjective().getStartedOn()) return getDurationText(System.currentTimeMillis() - getObjective().getStartedOn())
@ -157,8 +186,7 @@ public abstract class Objective {
public class ExamTask extends Task { public class ExamTask extends Task {
@StringRes @StringRes
int question; int question;
List hints = new ArrayList<>(); ArrayList<Option> options = new ArrayList<>();
List options = new ArrayList<>();
private String spIdentifier; private String spIdentifier;
private boolean answered; private boolean answered;
private long disabledTo; private long disabledTo;
@ -198,23 +226,14 @@ public abstract class Objective {
return this; return this;
} }
ExamTask hint(Hint hint) {
hints.add(hint);
return this;
}
public @StringRes int getQuestion() { public @StringRes int getQuestion() {
return question; return question;
} }
public List getOptions() { public List<Objective.Option> getOptions() {
return options; return options;
} }
public List getHints() {
return hints;
}
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
return answered; return answered;

View file

@ -4,7 +4,6 @@ import java.util.List;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin; import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
@ -28,36 +27,36 @@ public class Objective1 extends Objective {
public boolean isCompleted() { public boolean isCompleted() {
return SP.getBoolean(R.string.key_objectiveusedisconnect, false); return SP.getBoolean(R.string.key_objectiveusedisconnect, false);
} }
}); }.hint(new Hint(R.string.disconnectpump_hint)));
tasks.add(new Task(R.string.objectives_usereconnectpump) { tasks.add(new Task(R.string.objectives_usereconnectpump) {
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
return SP.getBoolean(R.string.key_objectiveusereconnect, false); return SP.getBoolean(R.string.key_objectiveusereconnect, false);
} }
}); }.hint(new Hint(R.string.disconnectpump_hint)));
tasks.add(new Task(R.string.objectives_usetemptarget) { tasks.add(new Task(R.string.objectives_usetemptarget) {
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
return SP.getBoolean(R.string.key_objectiveusetemptarget, false); return SP.getBoolean(R.string.key_objectiveusetemptarget, false);
} }
}); }.hint(new Hint(R.string.usetemptarget_hint)));
tasks.add(new Task(R.string.objectives_useactions) { tasks.add(new Task(R.string.objectives_useactions) {
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
return SP.getBoolean(R.string.key_objectiveuseactions, false) && ActionsPlugin.INSTANCE.isEnabled(PluginType.GENERAL) && ActionsPlugin.INSTANCE.isFragmentVisible(); return SP.getBoolean(R.string.key_objectiveuseactions, false) && ActionsPlugin.INSTANCE.isEnabled(PluginType.GENERAL) && ActionsPlugin.INSTANCE.isFragmentVisible();
} }
}); }.hint(new Hint(R.string.useaction_hint)));
tasks.add(new Task(R.string.objectives_useloop) { tasks.add(new Task(R.string.objectives_useloop) {
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
return SP.getBoolean(R.string.key_objectiveuseloop, false); return SP.getBoolean(R.string.key_objectiveuseloop, false);
} }
}); }.hint(new Hint(R.string.useaction_hint)));
tasks.add(new Task(R.string.objectives_usescale) { tasks.add(new Task(R.string.objectives_usescale) {
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
return SP.getBoolean(R.string.key_objectiveusescale, false); return SP.getBoolean(R.string.key_objectiveusescale, false);
} }
}); }.hint(new Hint(R.string.usescale_hint)));
} }
} }

View file

@ -26,7 +26,6 @@ public class Objective2 extends Objective {
); );
tasks.add(new ExamTask(R.string.hypott_label, R.string.hypott_whenhypott,"hypott") tasks.add(new ExamTask(R.string.hypott_label, R.string.hypott_whenhypott,"hypott")
.option(new Option(R.string.hypott_goinglow, false)) .option(new Option(R.string.hypott_goinglow, false))
.option(new Option(R.string.hypott_havinglow, false))
.option(new Option(R.string.hypott_preventoversmb, true)) .option(new Option(R.string.hypott_preventoversmb, true))
.hint(new Hint(R.string.hypott_hint1)) .hint(new Hint(R.string.hypott_hint1))
); );
@ -38,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))
); );
@ -46,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))
@ -66,7 +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_doitafterstart, false)) .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")
@ -79,6 +80,12 @@ public class Objective2 extends Objective {
.option(new Option(R.string.basaltest_havingregularhyper, true)) .option(new Option(R.string.basaltest_havingregularhyper, true))
.hint(new Hint(R.string.basaltest_hint1)) .hint(new Hint(R.string.basaltest_hint1))
); );
tasks.add(new ExamTask(R.string.basalhelp_label, R.string.basalhelp_where,"basalhelp")
.option(new Option(R.string.basalhelp_diabetesteam, true))
.option(new Option(R.string.basalhelp_google, false))
.option(new Option(R.string.basalhelp_facebook, false))
.hint(new Hint(R.string.basalhelp_hint1))
);
tasks.add(new ExamTask(R.string.prerequisites_label, R.string.prerequisites_what, "prerequisites") tasks.add(new ExamTask(R.string.prerequisites_label, R.string.prerequisites_what, "prerequisites")
.option(new Option(R.string.prerequisites_determinedcorrectprofile, true)) .option(new Option(R.string.prerequisites_determinedcorrectprofile, true))
.option(new Option(R.string.prerequisites_computer, true)) .option(new Option(R.string.prerequisites_computer, true))
@ -151,6 +158,7 @@ public class Objective2 extends Objective {
.option(new Option(R.string.nsclient_xdripfollower, true)) .option(new Option(R.string.nsclient_xdripfollower, true))
.option(new Option(R.string.nsclient_looponiphone, false)) .option(new Option(R.string.nsclient_looponiphone, false))
.option(new Option(R.string.nsclient_spikeiphone, true)) .option(new Option(R.string.nsclient_spikeiphone, true))
.hint(new Hint(R.string.nsclient_hint1))
); );
tasks.add(new ExamTask(R.string.isf_label, R.string.whatistrue,"isf") tasks.add(new ExamTask(R.string.isf_label, R.string.whatistrue,"isf")
.option(new Option(R.string.isf_increasingvalue, true)) .option(new Option(R.string.isf_increasingvalue, true))
@ -191,13 +199,13 @@ public class Objective2 extends Objective {
.hint(new Hint(R.string.profileswitchtime_hint1)) .hint(new Hint(R.string.profileswitchtime_hint1))
); );
tasks.add(new ExamTask(R.string.other_medication_label, R.string.other_medication_text,"otherMedicationWarning")
.option(new Option(R.string.yes, true))
.option(new Option(R.string.no, false))
);
for (Task task : tasks) for (Task task : tasks)
Collections.shuffle(((ExamTask)task).options); Collections.shuffle(((ExamTask)task).options);
} }
@Override
public boolean isRevertable() {
return true;
}
} }

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
@ -68,7 +69,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
if (!MainApp.isEngineeringModeOrRelease()) { if (!MainApp.isEngineeringModeOrRelease()) {
if (value.value()) { if (value.value()) {
Notification n = new Notification(Notification.TOAST_ALARM, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL); Notification n = new Notification(Notification.TOAST_ALARM, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(n)); RxBus.INSTANCE.send(new EventNewNotification(n));
} }
value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), this); value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), this);
} }
@ -125,6 +126,10 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
if (Config.APS) { if (Config.APS) {
double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d); double maxBasal = SP.getDouble(R.string.key_openapsma_max_basal, 1d);
if (maxBasal < profile.getMaxDailyBasal()) {
maxBasal = profile.getMaxDailyBasal();
absoluteRate.addReason(MainApp.gs(R.string.increasingmaxbasal), this);
}
absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxvalueinpreferences)), this); absoluteRate.setIfSmaller(maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), maxBasal, MainApp.gs(R.string.maxvalueinpreferences)), this);
// Check percentRate but absolute rate too, because we know real current basal in pump // Check percentRate but absolute rate too, because we know real current basal in pump

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.general.signatureVerifier; package info.nightscout.androidaps.plugins.constraints.signatureVerifier;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.Signature; import android.content.pm.Signature;
@ -32,6 +32,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.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
@ -41,23 +42,23 @@ import info.nightscout.androidaps.utils.SP;
* In case someone decides to leak a ready-to-use APK nonetheless, we can still disable it. * In case someone decides to leak a ready-to-use APK nonetheless, we can still disable it.
* Self-compiled APKs with privately held certificates cannot and will not be disabled. * Self-compiled APKs with privately held certificates cannot and will not be disabled.
*/ */
public class SignatureVerifier extends PluginBase implements ConstraintsInterface { public class SignatureVerifierPlugin extends PluginBase implements ConstraintsInterface {
private static final String REVOKED_CERTS_URL = "https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/src/main/assets/revoked_certs.txt"; private static final String REVOKED_CERTS_URL = "https://raw.githubusercontent.com/MilosKozak/AndroidAPS/master/app/src/main/assets/revoked_certs.txt";
private static final long UPDATE_INTERVAL = TimeUnit.DAYS.toMillis(1); private static final long UPDATE_INTERVAL = TimeUnit.DAYS.toMillis(1);
private static SignatureVerifier plugin = new SignatureVerifier(); private static SignatureVerifierPlugin plugin = new SignatureVerifierPlugin();
private Logger log = LoggerFactory.getLogger(L.CORE); private Logger log = LoggerFactory.getLogger(L.CORE);
private final Object $lock = new Object[0]; private final Object $lock = new Object[0];
private File revokedCertsFile; private File revokedCertsFile;
private List<byte[]> revokedCerts; private List<byte[]> revokedCerts;
public static SignatureVerifier getPlugin() { public static SignatureVerifierPlugin getPlugin() {
return plugin; return plugin;
} }
private SignatureVerifier() { private SignatureVerifierPlugin() {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.CONSTRAINTS) .mainType(PluginType.CONSTRAINTS)
.neverVisible(true) .neverVisible(true)
@ -103,7 +104,7 @@ public class SignatureVerifier extends PluginBase implements ConstraintsInterfac
private void showNotification() { private void showNotification() {
Notification notification = new Notification(Notification.INVALID_VERSION, MainApp.gs(R.string.running_invalid_version), Notification.URGENT); Notification notification = new Notification(Notification.INVALID_VERSION, MainApp.gs(R.string.running_invalid_version), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification)); RxBus.INSTANCE.send(new EventNewNotification(notification));
} }
private boolean hasIllegalSignature() { private boolean hasIllegalSignature() {
@ -123,14 +124,52 @@ public class SignatureVerifier extends PluginBase implements ConstraintsInterfac
} }
} }
} }
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
log.error("Error in SignatureVerifier", e); log.error("Error in SignatureVerifierPlugin", e);
} catch (NoSuchAlgorithmException e) {
log.error("Error in SignatureVerifier", e);
} }
return false; return false;
} }
public List<String> shortHashes() {
List<String> hashes = new ArrayList<>();
try {
Signature[] signatures = MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), PackageManager.GET_SIGNATURES).signatures;
if (signatures != null) {
for (Signature signature : signatures) {
MessageDigest digest = MessageDigest.getInstance("SHA256");
byte[] fingerprint = digest.digest(signature.toByteArray());
String hash = Hex.toHexString(fingerprint);
log.debug("Found signature: " + hash);
log.debug("Found signature (short): " + singleCharMap(fingerprint));
hashes.add(singleCharMap(fingerprint));
}
}
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
log.error("Error in SignatureVerifierPlugin", e);
}
return hashes;
}
String map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!\"§$%&/()=?,.-;:_<>|°^`´\\@€*'#+~{}[]¿¡áéíóúàèìòùöäü`ÁÉÍÓÚÀÈÌÒÙÖÄÜßÆÇÊËÎÏԌ۟æçêëîïôœûÿĆČĐŠŽćđšžñΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡ\u03A2ΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϨϩϪϫϬϭϮϯϰϱϲϳϴϵ϶ϷϸϹϺϻϼϽϾϿЀЁЂЃЄЅІЇЈЉЊЋЌЍЎЏАБВГДЕЖЗ";
private String singleCharMap(byte[] array) {
StringBuilder sb = new StringBuilder();
for (byte b : array) {
sb.append(map.charAt(b & 0xFF));
}
return sb.toString();
}
public String singleCharUnMap(String shortHash) {
byte[] array = new byte[shortHash.length()];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length; i++) {
if (i != 0) sb.append(":");
sb.append(String.format("%02X", 0xFF & map.charAt(map.indexOf(shortHash.charAt(i)))));
}
return sb.toString();
}
private boolean shouldDownloadCerts() { private boolean shouldDownloadCerts() {
return System.currentTimeMillis() - SP.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL; return System.currentTimeMillis() - SP.getLong(R.string.key_last_revoked_certs_check, 0L) >= UPDATE_INTERVAL;
} }
@ -152,7 +191,7 @@ public class SignatureVerifier extends PluginBase implements ConstraintsInterfac
this.revokedCerts = parseRevokedCertsFile(revokedCerts); this.revokedCerts = parseRevokedCertsFile(revokedCerts);
} }
} catch (IOException e) { } catch (IOException e) {
log.error("Error in SignatureVerifier", e); log.error("Error in SignatureVerifierPlugin", e);
} }
} }

Some files were not shown because too many files have changed in this diff Show more