Plugins refactor

This commit is contained in:
Milos Kozak 2018-03-31 00:36:03 +02:00
parent 259b5fa818
commit bcb733e42c
101 changed files with 1691 additions and 3363 deletions

View file

@ -63,7 +63,7 @@ android {
targetSdkVersion 23 targetSdkVersion 23
multiDexEnabled true multiDexEnabled true
versionCode 1500 versionCode 1500
version "1.60b-dev" version "1.60c-dev"
buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", generateGitBuild() buildConfigField "String", "BUILDVERSION", generateGitBuild()

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps; package info.nightscout.androidaps;
import info.nightscout.utils.T;
/** /**
* Created by mike on 07.06.2016. * Created by mike on 07.06.2016.
*/ */
@ -61,4 +63,7 @@ public class Constants {
// Pump // Pump
public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 120 - 1; public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 120 - 1;
public static final int MIN_WATCHDOG_INTERVAL_IN_SECONDS = 12 * 60; public static final int MIN_WATCHDOG_INTERVAL_IN_SECONDS = 12 * 60;
//SMS Communicator
public static final long SMS_CONFIRM_TIMEOUT = T.mins(5).msecs();
} }

View file

@ -27,8 +27,9 @@ import ch.qos.logback.classic.LoggerContext;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.ConstraintChecker; import info.nightscout.androidaps.data.ConstraintChecker;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Actions.ActionsFragment; import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
@ -66,11 +67,11 @@ import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
@ -110,6 +111,7 @@ public class MainApp extends Application {
sInstance = this; sInstance = this;
sResources = getResources(); sResources = getResources();
sConstraintsChecker = new ConstraintChecker(this); sConstraintsChecker = new ConstraintChecker(this);
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
try { try {
if (FabricPrivacy.fabricEnabled()) { if (FabricPrivacy.fabricEnabled()) {
@ -127,7 +129,7 @@ public class MainApp extends Application {
log.info("BuildVersion: " + BuildConfig.BUILDVERSION); log.info("BuildVersion: " + BuildConfig.BUILDVERSION);
String extFilesDir = this.getLogDirectory(); String extFilesDir = this.getLogDirectory();
File engineeringModeSemaphore = new File(extFilesDir,"engineering_mode"); File engineeringModeSemaphore = new File(extFilesDir, "engineering_mode");
engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile(); engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile();
devBranch = BuildConfig.VERSION.contains("dev"); devBranch = BuildConfig.VERSION.contains("dev");
@ -155,8 +157,10 @@ public class MainApp extends Application {
if (Config.HWPUMPS) pluginsList.add(DanaRv2Plugin.getPlugin()); if (Config.HWPUMPS) pluginsList.add(DanaRv2Plugin.getPlugin());
if (Config.HWPUMPS) pluginsList.add(DanaRSPlugin.getPlugin()); if (Config.HWPUMPS) pluginsList.add(DanaRSPlugin.getPlugin());
pluginsList.add(CareportalPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin());
if (Config.HWPUMPS && engineeringMode) pluginsList.add(InsightPlugin.getPlugin()); // <-- Enable Insight plugin here if (Config.HWPUMPS && engineeringMode)
if (Config.HWPUMPS && engineeringMode) pluginsList.add(ComboPlugin.getPlugin()); // <-- Enable Combo plugin here pluginsList.add(InsightPlugin.getPlugin()); // <-- Enable Insight plugin here
if (Config.HWPUMPS && engineeringMode)
pluginsList.add(ComboPlugin.getPlugin()); // <-- Enable Combo plugin here
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin()); if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin()); if (Config.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin());
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
@ -204,14 +208,14 @@ public class MainApp extends Application {
else else
FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop")); FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop"));
new Thread(new Runnable() { final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
@Override if (pump != null) {
public void run() { new Thread(() -> {
SystemClock.sleep(5000); SystemClock.sleep(5000);
ConfigBuilderPlugin.getCommandQueue().readStatus("Initialization", null); ConfigBuilderPlugin.getCommandQueue().readStatus("Initialization", null);
startKeepAliveService(); startKeepAliveService();
}
}).start(); }).start();
}
if (!isEngineeringModeOrRelease()) { if (!isEngineeringModeOrRelease()) {
Notification n = new Notification(Notification.TOAST_ALARM, gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL); Notification n = new Notification(Notification.TOAST_ALARM, gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL);
@ -303,7 +307,7 @@ public class MainApp extends Application {
return pluginsList; return pluginsList;
} }
public static ArrayList<PluginBase> getSpecificPluginsList(int type) { public static ArrayList<PluginBase> getSpecificPluginsList(PluginType type) {
ArrayList<PluginBase> newList = new ArrayList<>(); ArrayList<PluginBase> newList = new ArrayList<>();
if (pluginsList != null) { if (pluginsList != null) {
@ -317,11 +321,12 @@ public class MainApp extends Application {
return newList; return newList;
} }
/*
@Nullable @Nullable
public static InsulinInterface getInsulinIterfaceById(int id) { public static InsulinInterface getInsulinIterfaceById(int id) {
if (pluginsList != null) { if (pluginsList != null) {
for (PluginBase p : pluginsList) { for (PluginBase p : pluginsList) {
if (p.getType() == PluginBase.INSULIN && ((InsulinInterface) p).getId() == id) if (p.getType() == PluginType.INSULIN && ((InsulinInterface) p).getId() == id)
return (InsulinInterface) p; return (InsulinInterface) p;
} }
} else { } else {
@ -329,8 +334,9 @@ public class MainApp extends Application {
} }
return null; return null;
} }
*/
public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(int type) { public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(PluginType type) {
ArrayList<PluginBase> newList = new ArrayList<>(); ArrayList<PluginBase> newList = new ArrayList<>();
if (pluginsList != null) { if (pluginsList != null) {
@ -359,7 +365,7 @@ public class MainApp extends Application {
return newList; return newList;
} }
public static ArrayList<PluginBase> getSpecificPluginsVisibleInListByInterface(Class interfaceClass, int type) { public static ArrayList<PluginBase> getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type) {
ArrayList<PluginBase> newList = new ArrayList<>(); ArrayList<PluginBase> newList = new ArrayList<>();
if (pluginsList != null) { if (pluginsList != null) {

View file

@ -14,6 +14,7 @@ import android.text.TextUtils;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin; import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
@ -31,7 +32,7 @@ import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
import info.nightscout.utils.LocaleHelper; import info.nightscout.utils.LocaleHelper;
@ -111,7 +112,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
id = args.getInt("id"); id = args.getInt("id");
} }
void addPreferencesFromResourceIfEnabled(PluginBase p, int type) { void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) {
if (p.isEnabled(type) && p.getPreferencesId() != -1) if (p.isEnabled(type) && p.getPreferencesId() != -1)
addPreferencesFromResource(p.getPreferencesId()); addPreferencesFromResource(p.getPreferencesId());
} }
@ -139,50 +140,50 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
if (!Config.NSCLIENT && !Config.G5UPLOADER) { if (!Config.NSCLIENT && !Config.G5UPLOADER) {
addPreferencesFromResource(R.xml.pref_quickwizard); addPreferencesFromResource(R.xml.pref_quickwizard);
} }
addPreferencesFromResourceIfEnabled(SourceDexcomG5Plugin.getPlugin(), PluginBase.BGSOURCE); addPreferencesFromResourceIfEnabled(SourceDexcomG5Plugin.getPlugin(), PluginType.BGSOURCE);
addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL); addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginType.GENERAL);
addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS); addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginType.CONSTRAINTS);
if (Config.APS) { if (Config.APS) {
addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginBase.LOOP); addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginType.LOOP);
addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginBase.APS); addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginType.APS);
addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginBase.APS); addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginType.APS);
addPreferencesFromResourceIfEnabled(OpenAPSSMBPlugin.getPlugin(), PluginBase.APS); addPreferencesFromResourceIfEnabled(OpenAPSSMBPlugin.getPlugin(), PluginType.APS);
} }
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginBase.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginType.SENSITIVITY);
if (Config.HWPUMPS) { if (Config.HWPUMPS) {
addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginBase.PUMP); addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginType.PUMP);
addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginBase.PUMP); addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginType.PUMP);
addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginBase.PUMP); addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginType.PUMP);
addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginBase.PUMP); addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginType.PUMP);
if (DanaRPlugin.getPlugin().isEnabled(PluginBase.PROFILE) if (DanaRPlugin.getPlugin().isEnabled(PluginType.PROFILE)
|| DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PROFILE) || DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PROFILE)
|| DanaRv2Plugin.getPlugin().isEnabled(PluginBase.PROFILE) || DanaRv2Plugin.getPlugin().isEnabled(PluginType.PROFILE)
|| DanaRSPlugin.getPlugin().isEnabled(PluginBase.PROFILE)) { || DanaRSPlugin.getPlugin().isEnabled(PluginType.PROFILE)) {
addPreferencesFromResource(R.xml.pref_danarprofile); addPreferencesFromResource(R.xml.pref_danarprofile);
} }
} }
if (!Config.NSCLIENT && !Config.G5UPLOADER) { if (!Config.NSCLIENT && !Config.G5UPLOADER) {
addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginBase.PUMP); addPreferencesFromResourceIfEnabled(VirtualPumpPlugin.getPlugin(), PluginType.PUMP);
} }
addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginBase.INSULIN); addPreferencesFromResourceIfEnabled(InsulinOrefFreePeakPlugin.getPlugin(), PluginType.INSULIN);
addPreferencesFromResourceIfEnabled(NSClientPlugin.getPlugin(), PluginBase.GENERAL); addPreferencesFromResourceIfEnabled(NSClientPlugin.getPlugin(), PluginType.GENERAL);
addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL); addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginType.GENERAL);
if (!Config.NSCLIENT && !Config.G5UPLOADER) { if (!Config.NSCLIENT && !Config.G5UPLOADER) {
addPreferencesFromResource(R.xml.pref_others); addPreferencesFromResource(R.xml.pref_others);
} }
addPreferencesFromResource(R.xml.pref_advanced); addPreferencesFromResource(R.xml.pref_advanced);
addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginBase.GENERAL); addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginType.GENERAL);
addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginBase.GENERAL); addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginType.GENERAL);
} }
initSummary(getPreferenceScreen()); initSummary(getPreferenceScreen());

View file

@ -18,7 +18,6 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.events.EventNsFood;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
@ -34,11 +33,11 @@ import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI; import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync; import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.utils.BundleLogger; import info.nightscout.utils.BundleLogger;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
@ -63,8 +62,13 @@ public class DataService extends IntentService {
protected void onHandleIntent(final Intent intent) { protected void onHandleIntent(final Intent intent) {
if (Config.logFunctionCalls) if (Config.logFunctionCalls)
log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras())); log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras()));
if (ConfigBuilderPlugin.getPlugin().getActiveBgSource() == null) {
if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) { xDripEnabled = true;
nsClientEnabled = false;
mm640gEnabled = false;
glimpEnabled = false;
dexcomG5Enabled = false;
} else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) {
xDripEnabled = true; xDripEnabled = true;
nsClientEnabled = false; nsClientEnabled = false;
mm640gEnabled = false; mm640gEnabled = false;
@ -96,7 +100,7 @@ public class DataService extends IntentService {
dexcomG5Enabled = true; dexcomG5Enabled = true;
} }
boolean isNSProfile = MainApp.getConfigBuilder().getActiveProfileInterface().getClass().equals(NSProfilePlugin.class); boolean isNSProfile = MainApp.getConfigBuilder().getActiveProfileInterface() != null && MainApp.getConfigBuilder().getActiveProfileInterface().getClass().equals(NSProfilePlugin.class);
boolean acceptNSData = !SP.getBoolean(R.string.key_ns_upload_only, false); boolean acceptNSData = !SP.getBoolean(R.string.key_ns_upload_only, false);
Bundle bundles = intent.getExtras(); Bundle bundles = intent.getExtras();
@ -223,7 +227,7 @@ public class DataService extends IntentService {
try { try {
JSONArray jsonArray = new JSONArray(data); JSONArray jsonArray = new JSONArray(data);
log.debug("Received Dexcom Data size:" + jsonArray.length()); log.debug("Received Dexcom Data size:" + jsonArray.length());
for(int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
JSONObject json = jsonArray.getJSONObject(i); JSONObject json = jsonArray.getJSONObject(i);
bgReading.value = json.getInt("m_value"); bgReading.value = json.getInt("m_value");
bgReading.direction = json.getString("m_trend"); bgReading.direction = json.getString("m_trend");

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
/** /**
@ -73,7 +74,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p; ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constraint.isLoopInvokationAllowed(value); constraint.isLoopInvokationAllowed(value);
} }
return value; return value;
@ -85,7 +86,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p; ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constraint.isClosedLoopAllowed(value); constraint.isClosedLoopAllowed(value);
} }
return value; return value;
@ -97,7 +98,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p; ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constraint.isAutosensModeEnabled(value); constraint.isAutosensModeEnabled(value);
} }
return value; return value;
@ -109,7 +110,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.isAMAModeEnabled(value); constrain.isAMAModeEnabled(value);
} }
return value; return value;
@ -121,7 +122,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p; ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constraint.isSMBModeEnabled(value); constraint.isSMBModeEnabled(value);
} }
return value; return value;
@ -132,7 +133,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p; ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constraint.isAdvancedFilteringEnabled(value); constraint.isAdvancedFilteringEnabled(value);
} }
return value; return value;
@ -143,7 +144,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constraint = (ConstraintsInterface) p; ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constraint.applyBasalConstraints(absoluteRate, profile); constraint.applyBasalConstraints(absoluteRate, profile);
} }
return absoluteRate; return absoluteRate;
@ -154,7 +155,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.applyBasalPercentConstraints(percentRate, profile); constrain.applyBasalPercentConstraints(percentRate, profile);
} }
return percentRate; return percentRate;
@ -165,7 +166,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.applyBolusConstraints(insulin); constrain.applyBolusConstraints(insulin);
} }
return insulin; return insulin;
@ -176,7 +177,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.applyCarbsConstraints(carbs); constrain.applyCarbsConstraints(carbs);
} }
return carbs; return carbs;
@ -187,7 +188,7 @@ public class ConstraintChecker implements ConstraintsInterface {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
constrain.applyMaxIOBConstraints(maxIob); constrain.applyMaxIOBConstraints(maxIob);
} }
return maxIob; return maxIob;

View file

@ -1,34 +1,157 @@
package info.nightscout.androidaps.interfaces; package info.nightscout.androidaps.interfaces;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/** /**
* Created by mike on 09.06.2016. * Created by mike on 09.06.2016.
*/ */
public interface PluginBase { public abstract class PluginBase {
int GENERAL = 1; public enum State {
int TREATMENT = 2; NOT_INITIALIZED,
int SENSITIVITY = 3; ENABLED,
int PROFILE = 4; DISABLED
int APS = 5; }
int PUMP = 6;
int CONSTRAINTS = 7;
int LOOP = 8;
int BGSOURCE = 9;
int INSULIN = 10;
int LAST = 11; // keep always highest number
int getType(); State state = State.NOT_INITIALIZED;
String getFragmentClass(); boolean isFragmentVisible = false;
public PluginDescription pluginDescription;
String getName();
String getNameShort(); // Specific plugin with more Interfaces
boolean isEnabled(int type); protected boolean isProfileInterfaceEnabled = false;
boolean isVisibleInTabs(int type);
boolean canBeHidden(int type); public PluginBase(PluginDescription pluginDescription) {
boolean hasFragment(); this.pluginDescription = pluginDescription;
boolean showInList(int type); }
void setPluginEnabled(int type, boolean fragmentEnabled);
void setFragmentVisible(int type, boolean fragmentVisible); // public PluginType getType() {
int getPreferencesId(); // return mainType;
// }
// public String getFragmentClass() {
// return fragmentClass;
// }
public String getName() {
if (pluginDescription.pluginName == -1)
return "UKNOWN";
else
return MainApp.gs(pluginDescription.pluginName);
}
public String getNameShort() {
if (pluginDescription.shortName == -1)
return getName();
String name = MainApp.gs(pluginDescription.shortName);
if (!name.trim().isEmpty()) //only if translation exists
return name;
// use long name as fallback
return getName();
}
public PluginType getType() {
return pluginDescription.mainType;
}
public int getPreferencesId() {
return pluginDescription.preferencesId;
}
public int getAdvancedPreferencesId() {
return pluginDescription.advancedPreferencesId;
}
public boolean isEnabled(PluginType type) {
if (pluginDescription.alwaysEnabled && type == pluginDescription.mainType)
return true;
if (pluginDescription.mainType == PluginType.CONSTRAINTS && type == PluginType.CONSTRAINTS)
return true;
if (type == pluginDescription.mainType)
return state == State.ENABLED && specialEnableCondition();
if (type == PluginType.CONSTRAINTS && pluginDescription.mainType == PluginType.PUMP && isEnabled(PluginType.PUMP))
return true;
if (type == PluginType.PROFILE && pluginDescription.mainType == PluginType.PUMP)
return isProfileInterfaceEnabled;
return false;
}
public boolean canBeHidden(PluginType type) {
return pluginDescription.canBeHidden;
}
public boolean hasFragment() {
return pluginDescription.fragmentClass != null;
}
/**
* So far plugin can have it's main type + ConstraintInterface + ProfileInterface
* ConstraintInterface is enabled if main plugin is enabled
* ProfileInterface can be enabled only if main iterface is enable
*/
public void setPluginEnabled(PluginType type, boolean newState) {
if (type == pluginDescription.mainType) {
if (newState == true) { // enabling plugin
if (state != State.ENABLED) {
onStateChange(type, state, State.ENABLED);
state = State.ENABLED;
onStart();
}
} else { // disabling plugin
if (state == State.ENABLED) {
onStateChange(type, state, State.ENABLED);
state = State.DISABLED;
onStop();
}
}
} else if (type == PluginType.PROFILE) {
isProfileInterfaceEnabled = newState;
}
}
public void setFragmentVisible(PluginType type, boolean fragmentVisible) {
if (type == pluginDescription.mainType) {
isFragmentVisible = fragmentVisible && specialEnableCondition();
}
}
public boolean isFragmentVisible() {
if (pluginDescription.alwayVisible)
return true;
if (pluginDescription.neverVisible)
return false;
return isFragmentVisible;
}
public boolean showInList(PluginType type) {
if (pluginDescription.mainType == type)
return pluginDescription.showInList && specialShowInListCondition();
if (type == PluginType.PROFILE && pluginDescription.mainType == PluginType.PUMP)
return isEnabled(PluginType.PUMP);
return false;
}
public boolean specialEnableCondition() {
return true;
}
public boolean specialShowInListCondition() {
return true;
}
protected void onStart() {
}
protected void onStop() {
}
protected void onStateChange(PluginType type, State oldState, State newState) {
}
} }

View file

@ -0,0 +1,90 @@
package info.nightscout.androidaps.interfaces;
public class PluginDescription {
PluginType mainType = PluginType.GENERAL;
String fragmentClass = null;
boolean canBeHidden = true;
public boolean alwayVisible = false;
public boolean neverVisible = false;
public boolean alwaysEnabled = false;
boolean showInList = true;
int pluginName = -1;
int shortName = -1;
int preferencesId = -1;
int advancedPreferencesId = -1;
public boolean enableByDefault = false;
public boolean visibleByDefault = false;
public PluginDescription mainType(PluginType mainType) {
this.mainType = mainType;
return this;
}
public PluginDescription fragmentClass(String fragmentClass) {
this.fragmentClass = fragmentClass;
return this;
}
public PluginDescription canBeHidden(boolean canBeHidden) {
this.canBeHidden = canBeHidden;
return this;
}
public PluginDescription alwaysEnabled(boolean alwaysEnabled) {
this.alwaysEnabled = alwaysEnabled;
return this;
}
public PluginDescription alwayVisible(boolean alwayVisible) {
this.alwayVisible = alwayVisible;
return this;
}
public PluginDescription neverVisible(boolean neverVisible) {
this.neverVisible = neverVisible;
return this;
}
public PluginDescription showInList(boolean showInList) {
this.showInList = showInList;
return this;
}
public PluginDescription pluginName(int pluginName) {
this.pluginName = pluginName;
return this;
}
public PluginDescription shortName(int shortName) {
this.shortName = shortName;
return this;
}
public PluginDescription preferencesId(int preferencesId) {
this.preferencesId = preferencesId;
return this;
}
public PluginDescription advancedPreferencesId(int advancedPreferencesId) {
this.advancedPreferencesId = advancedPreferencesId;
return this;
}
public PluginDescription enableByDefault(boolean enableByDefault) {
this.enableByDefault = enableByDefault;
return this;
}
public PluginDescription visibleByDefault(boolean visibleByDefault) {
this.visibleByDefault = visibleByDefault;
return this;
}
public String getFragmentClass() {
return fragmentClass;
}
public PluginType getType() {
return mainType;
}
}

View file

@ -0,0 +1,14 @@
package info.nightscout.androidaps.interfaces;
public enum PluginType {
GENERAL,
TREATMENT,
SENSITIVITY,
PROFILE,
APS,
PUMP,
CONSTRAINTS,
LOOP,
BGSOURCE,
INSULIN
}

View file

@ -1,82 +1,22 @@
package info.nightscout.androidaps.plugins.Actions; package info.nightscout.androidaps.plugins.Actions;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/** /**
* Created by mike on 05.11.2016. * Created by mike on 05.11.2016.
*/ */
public class ActionsPlugin implements PluginBase { public class ActionsPlugin extends PluginBase {
private boolean fragmentEnabled = true; public ActionsPlugin() {
private boolean fragmentVisible = true; super(new PluginDescription()
.mainType(PluginType.GENERAL)
@Override .fragmentClass(ActionsFragment.class.getName())
public int getType() { .pluginName(R.string.actions)
return PluginBase.GENERAL; .shortName(R.string.actions_shortname)
);
} }
@Override
public String getFragmentClass() {
return ActionsFragment.class.getName();
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.actions);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.actions_shortname);
if (!name.trim().isEmpty()){
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == GENERAL) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
} }

View file

@ -1,14 +1,12 @@
package info.nightscout.androidaps.plugins.Careportal; package info.nightscout.androidaps.plugins.Careportal;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
public class CareportalPlugin implements PluginBase { public class CareportalPlugin extends PluginBase {
private boolean fragmentEnabled = true;
private boolean fragmentVisible = true;
static CareportalPlugin careportalPlugin; static CareportalPlugin careportalPlugin;
@ -19,70 +17,18 @@ public class CareportalPlugin implements PluginBase {
return careportalPlugin; return careportalPlugin;
} }
@Override public CareportalPlugin() {
public int getType() { super(new PluginDescription()
return PluginBase.GENERAL; .mainType(PluginType.GENERAL)
.fragmentClass(CareportalFragment.class.getName())
.pluginName(R.string.careportal)
.shortName(R.string.careportal_shortname)
);
} }
@Override @Override
public String getFragmentClass() { public boolean specialShowInListCondition() {
return CareportalFragment.class.getName();
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.careportal);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.careportal_shortname);
if (!name.trim().isEmpty()){
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return !Config.NSCLIENT && !Config.G5UPLOADER; return !Config.NSCLIENT && !Config.G5UPLOADER;
} }
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == GENERAL) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_careportal;
}
} }

View file

@ -34,6 +34,7 @@ import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; 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;
@ -131,48 +132,48 @@ public class ConfigBuilderFragment extends SubscriberFragment {
@Override @Override
protected void updateGUI() { protected void updateGUI() {
insulinDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginBase.INSULIN), PluginBase.INSULIN); insulinDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginType.INSULIN), PluginType.INSULIN);
insulinListView.setAdapter(insulinDataAdapter); insulinListView.setAdapter(insulinDataAdapter);
setListViewHeightBasedOnChildren(insulinListView); setListViewHeightBasedOnChildren(insulinListView);
bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginBase.BGSOURCE), PluginBase.BGSOURCE); bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginType.BGSOURCE), PluginType.BGSOURCE);
bgsourceListView.setAdapter(bgsourceDataAdapter); bgsourceListView.setAdapter(bgsourceDataAdapter);
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.BGSOURCE).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.BGSOURCE).size() == 0)
bgsourceLabel.setVisibility(View.GONE); bgsourceLabel.setVisibility(View.GONE);
setListViewHeightBasedOnChildren(bgsourceListView); setListViewHeightBasedOnChildren(bgsourceListView);
pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.PUMP), PluginBase.PUMP); pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP), PluginType.PUMP);
pumpListView.setAdapter(pumpDataAdapter); pumpListView.setAdapter(pumpDataAdapter);
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PUMP).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size() == 0)
pumpLabel.setVisibility(View.GONE); pumpLabel.setVisibility(View.GONE);
setListViewHeightBasedOnChildren(pumpListView); setListViewHeightBasedOnChildren(pumpListView);
loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP), PluginBase.LOOP); loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP), PluginType.LOOP);
loopListView.setAdapter(loopDataAdapter); loopListView.setAdapter(loopDataAdapter);
setListViewHeightBasedOnChildren(loopListView); setListViewHeightBasedOnChildren(loopListView);
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP).size() == 0)
loopLabel.setVisibility(View.GONE); loopLabel.setVisibility(View.GONE);
treatmentDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT), PluginBase.TREATMENT); treatmentDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT), PluginType.TREATMENT);
treatmentsListView.setAdapter(treatmentDataAdapter); treatmentsListView.setAdapter(treatmentDataAdapter);
setListViewHeightBasedOnChildren(treatmentsListView); setListViewHeightBasedOnChildren(treatmentsListView);
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT).size() == 0)
treatmentsLabel.setVisibility(View.GONE); treatmentsLabel.setVisibility(View.GONE);
profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginBase.PROFILE), PluginBase.PROFILE); profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginType.PROFILE), PluginType.PROFILE);
profileListView.setAdapter(profileDataAdapter); profileListView.setAdapter(profileDataAdapter);
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PROFILE).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.PROFILE).size() == 0)
profileLabel.setVisibility(View.GONE); profileLabel.setVisibility(View.GONE);
setListViewHeightBasedOnChildren(profileListView); setListViewHeightBasedOnChildren(profileListView);
apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.APS), PluginBase.APS); apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.APS), PluginType.APS);
apsListView.setAdapter(apsDataAdapter); apsListView.setAdapter(apsDataAdapter);
setListViewHeightBasedOnChildren(apsListView); setListViewHeightBasedOnChildren(apsListView);
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.APS).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.APS).size() == 0)
apsLabel.setVisibility(View.GONE); apsLabel.setVisibility(View.GONE);
sensivityDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginBase.SENSITIVITY), PluginBase.SENSITIVITY); sensivityDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginType.SENSITIVITY), PluginType.SENSITIVITY);
sensitivityListView.setAdapter(sensivityDataAdapter); sensitivityListView.setAdapter(sensivityDataAdapter);
setListViewHeightBasedOnChildren(sensitivityListView); setListViewHeightBasedOnChildren(sensitivityListView);
constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginBase.CONSTRAINTS), PluginBase.CONSTRAINTS); constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginType.CONSTRAINTS), PluginType.CONSTRAINTS);
constraintsListView.setAdapter(constraintsDataAdapter); constraintsListView.setAdapter(constraintsDataAdapter);
setListViewHeightBasedOnChildren(constraintsListView); setListViewHeightBasedOnChildren(constraintsListView);
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.CONSTRAINTS).size() == 0) if (MainApp.getSpecificPluginsVisibleInList(PluginType.CONSTRAINTS).size() == 0)
constraintsLabel.setVisibility(View.GONE); constraintsLabel.setVisibility(View.GONE);
generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.GENERAL), PluginBase.GENERAL); generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.GENERAL), PluginType.GENERAL);
generalListView.setAdapter(generalDataAdapter); generalListView.setAdapter(generalDataAdapter);
setListViewHeightBasedOnChildren(generalListView); setListViewHeightBasedOnChildren(generalListView);
} }
@ -184,10 +185,10 @@ public class ConfigBuilderFragment extends SubscriberFragment {
private class PluginCustomAdapter extends ArrayAdapter<PluginBase> { private class PluginCustomAdapter extends ArrayAdapter<PluginBase> {
private ArrayList<PluginBase> pluginList; private ArrayList<PluginBase> pluginList;
final private int type; final private PluginType type;
PluginCustomAdapter(Context context, int textViewResourceId, PluginCustomAdapter(Context context, int textViewResourceId,
ArrayList<PluginBase> pluginList, int type) { ArrayList<PluginBase> pluginList, PluginType type) {
super(context, textViewResourceId, pluginList); super(context, textViewResourceId, pluginList);
this.pluginList = new ArrayList<>(); this.pluginList = new ArrayList<>();
this.pluginList.addAll(pluginList); this.pluginList.addAll(pluginList);
@ -230,7 +231,7 @@ public class ConfigBuilderFragment extends SubscriberFragment {
plugin1.setPluginEnabled(type, cb.isChecked()); plugin1.setPluginEnabled(type, cb.isChecked());
plugin1.setFragmentVisible(type, cb.isChecked()); plugin1.setFragmentVisible(type, cb.isChecked());
onEnabledCategoryChanged(plugin1, type); onEnabledCategoryChanged(plugin1, type);
ConfigBuilderPlugin.getPlugin().storeSettings(); ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
MainApp.bus().post(new EventConfigBuilderChange()); MainApp.bus().post(new EventConfigBuilderChange());
ConfigBuilderPlugin.getPlugin().logPluginStatus(); ConfigBuilderPlugin.getPlugin().logPluginStatus();
@ -241,7 +242,7 @@ public class ConfigBuilderFragment extends SubscriberFragment {
CheckBox cb = (CheckBox) v; CheckBox cb = (CheckBox) v;
PluginBase plugin12 = (PluginBase) cb.getTag(); PluginBase plugin12 = (PluginBase) cb.getTag();
plugin12.setFragmentVisible(type, cb.isChecked()); plugin12.setFragmentVisible(type, cb.isChecked());
ConfigBuilderPlugin.getPlugin().storeSettings(); ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
ConfigBuilderPlugin.getPlugin().logPluginStatus(); ConfigBuilderPlugin.getPlugin().logPluginStatus();
}); });
@ -271,7 +272,7 @@ public class ConfigBuilderFragment extends SubscriberFragment {
holder.name.setText(plugin.getName()); holder.name.setText(plugin.getName());
holder.checkboxEnabled.setChecked(plugin.isEnabled(type)); holder.checkboxEnabled.setChecked(plugin.isEnabled(type));
holder.checkboxVisible.setChecked(plugin.isVisibleInTabs(type)); holder.checkboxVisible.setChecked(plugin.isFragmentVisible());
holder.name.setTag(plugin); holder.name.setTag(plugin);
holder.checkboxEnabled.setTag(plugin); holder.checkboxEnabled.setTag(plugin);
holder.checkboxVisible.setTag(plugin); holder.checkboxVisible.setTag(plugin);
@ -291,19 +292,19 @@ public class ConfigBuilderFragment extends SubscriberFragment {
} }
// Hide enabled control and force enabled plugin if there is only one plugin available // Hide enabled control and force enabled plugin if there is only one plugin available
if (type == PluginBase.INSULIN || type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.PROFILE || type == PluginBase.SENSITIVITY) if (type == PluginType.INSULIN || type == PluginType.PUMP || type == PluginType.SENSITIVITY)
if (pluginList.size() < 2) { if (pluginList.size() < 2) {
holder.checkboxEnabled.setEnabled(false); holder.checkboxEnabled.setEnabled(false);
plugin.setPluginEnabled(type, true); plugin.setPluginEnabled(type, true);
ConfigBuilderPlugin.getPlugin().storeSettings(); ConfigBuilderPlugin.getPlugin().storeSettings("ForceEnable");
} }
// Constraints cannot be disabled // Constraints cannot be disabled
if (type == PluginBase.CONSTRAINTS) if (type == PluginType.CONSTRAINTS)
holder.checkboxEnabled.setEnabled(false); holder.checkboxEnabled.setEnabled(false);
// Hide disabled profiles by default // Hide disabled profiles by default
if (type == PluginBase.PROFILE) { if (type == PluginType.PROFILE) {
if (!plugin.isEnabled(type)) { if (!plugin.isEnabled(type)) {
holder.checkboxVisible.setEnabled(false); holder.checkboxVisible.setEnabled(false);
holder.checkboxVisible.setChecked(false); holder.checkboxVisible.setChecked(false);
@ -313,9 +314,9 @@ public class ConfigBuilderFragment extends SubscriberFragment {
} }
// Disable profile control for pump profiles if pump is not enabled // Disable profile control for pump profiles if pump is not enabled
if (type == PluginBase.PROFILE) { if (type == PluginType.PROFILE) {
if (PumpInterface.class.isAssignableFrom(plugin.getClass())) { if (PumpInterface.class.isAssignableFrom(plugin.getClass())) {
if (!plugin.isEnabled(PluginBase.PUMP)) { if (!plugin.isEnabled(PluginType.PUMP)) {
holder.checkboxEnabled.setEnabled(false); holder.checkboxEnabled.setEnabled(false);
holder.checkboxEnabled.setChecked(false); holder.checkboxEnabled.setChecked(false);
} }
@ -332,32 +333,32 @@ public class ConfigBuilderFragment extends SubscriberFragment {
} }
void onEnabledCategoryChanged(PluginBase changedPlugin, int type) { void onEnabledCategoryChanged(PluginBase changedPlugin, PluginType type) {
ArrayList<PluginBase> pluginsInCategory = null; ArrayList<PluginBase> pluginsInCategory = null;
switch (type) { switch (type) {
// Multiple selection allowed // Multiple selection allowed
case PluginBase.GENERAL: case GENERAL:
case PluginBase.CONSTRAINTS: case CONSTRAINTS:
case PluginBase.LOOP: case LOOP:
break; break;
// Single selection allowed // Single selection allowed
case PluginBase.INSULIN: case INSULIN:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(InsulinInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(InsulinInterface.class);
break; break;
case PluginBase.SENSITIVITY: case SENSITIVITY:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(SensitivityInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(SensitivityInterface.class);
break; break;
case PluginBase.APS: case APS:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class);
break; break;
case PluginBase.PROFILE: case PROFILE:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class);
break; break;
case PluginBase.BGSOURCE: case BGSOURCE:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class);
break; break;
case PluginBase.TREATMENT: case TREATMENT:
case PluginBase.PUMP: case PUMP:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(PumpInterface.class); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(PumpInterface.class);
break; break;
} }
@ -373,13 +374,13 @@ public class ConfigBuilderFragment extends SubscriberFragment {
} }
} }
} else { // enable first plugin in list } else { // enable first plugin in list
if (type == PluginBase.PUMP) if (type == PluginType.PUMP)
VirtualPumpPlugin.getPlugin().setPluginEnabled(type, true); VirtualPumpPlugin.getPlugin().setPluginEnabled(type, true);
else if (type == PluginBase.INSULIN) else if (type == PluginType.INSULIN)
InsulinFastactingPlugin.getPlugin().setPluginEnabled(type, true); InsulinFastactingPlugin.getPlugin().setPluginEnabled(type, true);
else if (type == PluginBase.SENSITIVITY) else if (type == PluginType.SENSITIVITY)
SensitivityOref0Plugin.getPlugin().setPluginEnabled(type, true); SensitivityOref0Plugin.getPlugin().setPluginEnabled(type, true);
else if (type == PluginBase.PROFILE) else if (type == PluginType.PROFILE)
NSProfilePlugin.getPlugin().setPluginEnabled(type, true); NSProfilePlugin.getPlugin().setPluginEnabled(type, true);
else else
pluginsInCategory.get(0).setPluginEnabled(type, true); pluginsInCategory.get(0).setPluginEnabled(type, true);

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.ConfigBuilder; package info.nightscout.androidaps.plugins.ConfigBuilder;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.crashlytics.android.answers.CustomEvent; import com.crashlytics.android.answers.CustomEvent;
@ -38,25 +36,30 @@ import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; 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.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.SensitivityOref0.SensitivityOref0Plugin;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.CommandQueue; import info.nightscout.androidaps.queue.CommandQueue;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterface {
private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class); private static Logger log = LoggerFactory.getLogger(ConfigBuilderPlugin.class);
private static ConfigBuilderPlugin configBuilderPlugin; private static ConfigBuilderPlugin configBuilderPlugin;
@ -86,116 +89,159 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
private static CommandQueue commandQueue = new CommandQueue(); private static CommandQueue commandQueue = new CommandQueue();
public ConfigBuilderPlugin() { public ConfigBuilderPlugin() {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(ConfigBuilderFragment.class.getName())
.showInList(false)
.alwaysEnabled(true)
.alwayVisible(true)
.pluginName(R.string.configbuilder)
.shortName(R.string.configbuilder_shortname)
);
}
@Override
public void onStart() {
super.onStart();
MainApp.bus().register(this); MainApp.bus().register(this);
} }
@Override @Override
public int getType() { public void onStop() {
return PluginBase.GENERAL; super.onStop();
MainApp.bus().unregister(this);
} }
@Override
public String getFragmentClass() {
return ConfigBuilderFragment.class.getName();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.configbuilder);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.configbuilder_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL;
}
@Override
public boolean canBeHidden(int type) {
return false;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return false;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
// Always enabled
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
// Always visible
}
@Override
public int getPreferencesId() {
return -1;
}
public void initialize() { public void initialize() {
pluginList = MainApp.getPluginsList(); pluginList = MainApp.getPluginsList();
upgradeSettings();
loadSettings(); loadSettings();
MainApp.bus().post(new EventAppInitialized()); MainApp.bus().post(new EventAppInitialized());
} }
public void storeSettings() { public void storeSettings(String from) {
if (pluginList != null) { if (pluginList != null) {
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Storing settings"); log.debug("Storing settings from: " + from);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
SharedPreferences.Editor editor = settings.edit();
for (int type = 1; type < PluginBase.LAST; type++) {
for (PluginBase p : pluginList) { for (PluginBase p : pluginList) {
String settingEnabled = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Enabled"; PluginType type = p.getType();
String settingVisible = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Visible"; if (p.pluginDescription.alwaysEnabled && p.pluginDescription.alwayVisible)
editor.putBoolean(settingEnabled, p.isEnabled(type)); continue;
editor.putBoolean(settingVisible, p.isVisibleInTabs(type)); if (p.pluginDescription.alwaysEnabled && p.pluginDescription.neverVisible)
continue;
savePref(p, type, true);
if (type == PluginType.PUMP) {
if (p instanceof ProfileInterface) { // Store state of optional Profile interface
savePref(p, PluginType.PROFILE, false);
}
} }
} }
editor.apply();
verifySelectionInCategories(); verifySelectionInCategories();
} }
} }
private void savePref(PluginBase p, PluginType type, boolean storeVisible) {
String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
SP.putBoolean(settingEnabled, p.isEnabled(type));
log.debug("Storing: " + settingEnabled + ":" + p.isEnabled(type));
if (storeVisible) {
String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible";
SP.putBoolean(settingVisible, p.isFragmentVisible());
log.debug("Storing: " + settingVisible + ":" + p.isFragmentVisible());
}
}
private void loadSettings() { private void loadSettings() {
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Loading stored settings"); log.debug("Loading stored settings");
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
for (int type = 1; type < PluginBase.LAST; type++) {
for (PluginBase p : pluginList) { for (PluginBase p : pluginList) {
try { PluginType type = p.getType();
loadPref(p, type, true);
if (p.getType() == PluginType.PUMP) {
if (p instanceof ProfileInterface) {
loadPref(p, PluginType.PROFILE, false);
}
}
}
verifySelectionInCategories();
}
private void loadPref(PluginBase p, PluginType type, boolean loadVisible) {
String settingEnabled = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Enabled";
if (SP.contains(settingEnabled))
p.setPluginEnabled(type, SP.getBoolean(settingEnabled, false));
else if (p.getType() == type && p.pluginDescription.enableByDefault) {
p.setPluginEnabled(type, true);
}
log.debug("Loaded: " + settingEnabled + ":" + p.isEnabled(type));
if (loadVisible) {
String settingVisible = "ConfigBuilder_" + type.name() + "_" + p.getClass().getSimpleName() + "_Visible";
if (SP.contains(settingVisible))
p.setFragmentVisible(type, SP.getBoolean(settingVisible, false) && SP.getBoolean(settingEnabled, false));
else if (p.getType() == type && p.pluginDescription.visibleByDefault) {
p.setFragmentVisible(type, true);
}
log.debug("Loaded: " + settingVisible + ":" + p.isFragmentVisible());
}
}
private void upgradeSettings() {
if (!SP.contains("ConfigBuilder_1_NSProfilePlugin_Enabled"))
return;
if (Config.logPrefsChange)
log.debug("Upgrading stored settings");
for (PluginBase p : pluginList) {
for (int type = 1; type < 11; type++) {
PluginType newType;
switch (type) {
case 1:
newType = PluginType.GENERAL;
break;
case 2:
newType = PluginType.TREATMENT;
break;
case 3:
newType = PluginType.SENSITIVITY;
break;
case 4:
newType = PluginType.PROFILE;
break;
case 5:
newType = PluginType.APS;
break;
case 6:
newType = PluginType.PUMP;
break;
case 7:
newType = PluginType.CONSTRAINTS;
break;
case 8:
newType = PluginType.LOOP;
break;
case 9:
newType = PluginType.BGSOURCE;
break;
case 10:
newType = PluginType.INSULIN;
break;
default:
newType = PluginType.GENERAL;
break;
}
String settingEnabled = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Enabled"; String settingEnabled = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Enabled";
String settingVisible = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Visible"; String settingVisible = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Visible";
if (SP.contains(settingEnabled)) if (SP.contains(settingEnabled))
p.setPluginEnabled(type, SP.getBoolean(settingEnabled, true)); p.setPluginEnabled(newType, SP.getBoolean(settingEnabled, false));
if (SP.contains(settingVisible)) if (SP.contains(settingVisible))
p.setFragmentVisible(type, SP.getBoolean(settingVisible, true) && SP.getBoolean(settingEnabled, true)); p.setFragmentVisible(newType, SP.getBoolean(settingVisible, false) && SP.getBoolean(settingEnabled, false));
} catch (Exception e) { SP.remove(settingEnabled);
log.error("Unhandled exception", e); SP.remove(settingVisible);
if (newType == p.getType()) {
savePref(p, newType, true);
} else if (p.getType() == PluginType.PUMP && p instanceof ProfileInterface) {
savePref(p, PluginType.PROFILE, false);
} }
} }
} }
@ -237,16 +283,16 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
void logPluginStatus() { void logPluginStatus() {
for (PluginBase p : pluginList) { for (PluginBase p : pluginList) {
log.debug(p.getName() + ":" + log.debug(p.getName() + ":" +
(p.isEnabled(1) ? " GENERAL" : "") + (p.isEnabled(PluginType.GENERAL) ? " GENERAL" : "") +
(p.isEnabled(2) ? " TREATMENT" : "") + (p.isEnabled(PluginType.TREATMENT) ? " TREATMENT" : "") +
(p.isEnabled(3) ? " SENSITIVITY" : "") + (p.isEnabled(PluginType.SENSITIVITY) ? " SENSITIVITY" : "") +
(p.isEnabled(4) ? " PROFILE" : "") + (p.isEnabled(PluginType.PROFILE) ? " PROFILE" : "") +
(p.isEnabled(5) ? " APS" : "") + (p.isEnabled(PluginType.APS) ? " APS" : "") +
(p.isEnabled(6) ? " PUMP" : "") + (p.isEnabled(PluginType.PUMP) ? " PUMP" : "") +
(p.isEnabled(7) ? " CONSTRAINTS" : "") + (p.isEnabled(PluginType.CONSTRAINTS) ? " CONSTRAINTS" : "") +
(p.isEnabled(8) ? " LOOP" : "") + (p.isEnabled(PluginType.LOOP) ? " LOOP" : "") +
(p.isEnabled(9) ? " BGSOURCE" : "") + (p.isEnabled(PluginType.BGSOURCE) ? " BGSOURCE" : "") +
(p.isEnabled(10) ? " INSULIN" : "") (p.isEnabled(PluginType.INSULIN) ? " INSULIN" : "")
); );
} }
} }
@ -254,33 +300,47 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
private void verifySelectionInCategories() { private void verifySelectionInCategories() {
ArrayList<PluginBase> pluginsInCategory; ArrayList<PluginBase> pluginsInCategory;
// PluginBase.APS // PluginType.APS
activeAPS = this.determineActivePlugin(APSInterface.class, PluginBase.APS); activeAPS = this.determineActivePlugin(APSInterface.class, PluginType.APS);
// PluginBase.INSULIN // PluginType.INSULIN
activeInsulin = this.determineActivePlugin(InsulinInterface.class, PluginBase.INSULIN); pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.INSULIN);
activeInsulin = (InsulinInterface) getTheOneEnabledInArray(pluginsInCategory, PluginType.INSULIN);
if (activeInsulin == null) {
activeInsulin = InsulinOrefRapidActingPlugin.getPlugin();
InsulinOrefRapidActingPlugin.getPlugin().setPluginEnabled(PluginType.INSULIN, true);
}
this.setFragmentVisiblities(((PluginBase) activeInsulin).getName(), pluginsInCategory, PluginType.INSULIN);
// PluginBase.SENSITIVITY // PluginType.SENSITIVITY
activeSensitivity = this.determineActivePlugin(SensitivityInterface.class, PluginBase.SENSITIVITY); pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.SENSITIVITY);
activeSensitivity = (SensitivityInterface) getTheOneEnabledInArray(pluginsInCategory, PluginType.SENSITIVITY);
if (activeSensitivity == null) {
activeSensitivity = SensitivityOref0Plugin.getPlugin();
SensitivityOref0Plugin.getPlugin().setPluginEnabled(PluginType.SENSITIVITY, true);
}
this.setFragmentVisiblities(((PluginBase) activeSensitivity).getName(), pluginsInCategory, PluginType.SENSITIVITY);
// PluginBase.PROFILE // PluginType.PROFILE
activeProfile = this.determineActivePlugin(ProfileInterface.class, PluginBase.PROFILE); activeProfile = this.determineActivePlugin(ProfileInterface.class, PluginType.PROFILE);
// PluginBase.BGSOURCE // PluginType.BGSOURCE
activeBgSource = this.determineActivePlugin(BgSourceInterface.class, PluginBase.BGSOURCE); activeBgSource = this.determineActivePlugin(BgSourceInterface.class, PluginType.BGSOURCE);
// PluginBase.PUMP // PluginType.PUMP
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.PUMP); pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.PUMP);
activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP); activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginType.PUMP);
if (activePump == null) if (activePump == null) {
activePump = VirtualPumpPlugin.getPlugin(); // for NSClient build activePump = VirtualPumpPlugin.getPlugin();
this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginBase.PUMP); VirtualPumpPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, true);
}
this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginType.PUMP);
// PluginBase.LOOP // PluginType.LOOP
activeLoop = this.determineActivePlugin(PluginBase.LOOP); activeLoop = this.determineActivePlugin(PluginType.LOOP);
// PluginBase.TREATMENT // PluginType.TREATMENT
activeTreatments = this.determineActivePlugin(PluginBase.TREATMENT); activeTreatments = this.determineActivePlugin(PluginType.TREATMENT);
} }
/** /**
@ -292,14 +352,14 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
* @param <T> * @param <T>
* @return * @return
*/ */
private <T> T determineActivePlugin(Class<T> pluginInterface, int pluginType) { private <T> T determineActivePlugin(Class<T> pluginInterface, PluginType pluginType) {
ArrayList<PluginBase> pluginsInCategory; ArrayList<PluginBase> pluginsInCategory;
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(pluginInterface); pluginsInCategory = MainApp.getSpecificPluginsListByInterface(pluginInterface);
return this.determineActivePlugin(pluginsInCategory, pluginType); return this.determineActivePlugin(pluginsInCategory, pluginType);
} }
private <T> T determineActivePlugin(int pluginType) { private <T> T determineActivePlugin(PluginType pluginType) {
ArrayList<PluginBase> pluginsInCategory; ArrayList<PluginBase> pluginsInCategory;
pluginsInCategory = MainApp.getSpecificPluginsList(pluginType); pluginsInCategory = MainApp.getSpecificPluginsList(pluginType);
@ -321,7 +381,7 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
* @return * @return
*/ */
private <T> T determineActivePlugin(ArrayList<PluginBase> pluginsInCategory, private <T> T determineActivePlugin(ArrayList<PluginBase> pluginsInCategory,
int pluginType) { PluginType pluginType) {
T activePlugin = (T) getTheOneEnabledInArray(pluginsInCategory, pluginType); T activePlugin = (T) getTheOneEnabledInArray(pluginsInCategory, pluginType);
if (activePlugin != null) { if (activePlugin != null) {
@ -333,7 +393,7 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
} }
private void setFragmentVisiblities(String activePluginName, ArrayList<PluginBase> pluginsInCategory, private void setFragmentVisiblities(String activePluginName, ArrayList<PluginBase> pluginsInCategory,
int pluginType) { PluginType pluginType) {
if (Config.logConfigBuilder) if (Config.logConfigBuilder)
log.debug("Selected interface: " + activePluginName); log.debug("Selected interface: " + activePluginName);
for (PluginBase p : pluginsInCategory) { for (PluginBase p : pluginsInCategory) {
@ -344,7 +404,7 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
} }
@Nullable @Nullable
private PluginBase getTheOneEnabledInArray(ArrayList<PluginBase> pluginsInCategory, int type) { private PluginBase getTheOneEnabledInArray(ArrayList<PluginBase> pluginsInCategory, PluginType type) {
PluginBase found = null; PluginBase found = null;
for (PluginBase p : pluginsInCategory) { for (PluginBase p : pluginsInCategory) {
if (p.isEnabled(type) && found == null) { if (p.isEnabled(type) && found == null) {
@ -355,8 +415,8 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface {
} }
} }
// If none enabled, enable first one // If none enabled, enable first one
if (found == null && pluginsInCategory.size() > 0) //if (found == null && pluginsInCategory.size() > 0)
found = pluginsInCategory.get(0); // found = pluginsInCategory.get(0);
return found; return found;
} }

View file

@ -24,9 +24,10 @@ import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
public class ObjectivesFragment extends Fragment { public class ObjectivesFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class); private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class);
RecyclerView recyclerView; RecyclerView recyclerView;
@ -214,15 +215,13 @@ public class ObjectivesFragment extends Fragment {
return null; return null;
} }
void updateGUI() { @Override
public void updateGUI() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) if (activity != null)
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> {
@Override
public void run() {
RecyclerViewAdapter adapter = new RecyclerViewAdapter(ObjectivesPlugin.objectives); RecyclerViewAdapter adapter = new RecyclerViewAdapter(ObjectivesPlugin.objectives);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
}
}); });
} }

View file

@ -18,6 +18,9 @@ import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
@ -28,7 +31,7 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface {
private static Logger log = LoggerFactory.getLogger(ObjectivesPlugin.class); private static Logger log = LoggerFactory.getLogger(ObjectivesPlugin.class);
private static ObjectivesPlugin objectivesPlugin; private static ObjectivesPlugin objectivesPlugin;
@ -42,77 +45,27 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
public static List<Objective> objectives; public static List<Objective> objectives;
private boolean fragmentVisible = true;
private ObjectivesPlugin() { private ObjectivesPlugin() {
super(new PluginDescription()
.mainType(PluginType.CONSTRAINTS)
.fragmentClass(ObjectivesFragment.class.getName())
.alwaysEnabled(true)
.pluginName(R.string.objectives)
.shortName(R.string.objectives_shortname)
);
initializeData(); initializeData();
loadProgress(); loadProgress();
MainApp.bus().register(this);
} }
@Override @Override
public String getFragmentClass() { public boolean specialEnableCondition() {
return ObjectivesFragment.class.getName(); PumpInterface pump = ConfigBuilderPlugin.getActivePump();
return pump == null || pump.getPumpDescription().isTempBasalCapable;
} }
@Override @Override
public int getType() { public boolean specialShowInListCondition() {
return PluginBase.CONSTRAINTS; return !Config.NSCLIENT && !Config.G5UPLOADER;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.objectives);
}
@Override
public String getNameShort() {
String name = MainApp.gs(R.string.objectives_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == CONSTRAINTS && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == CONSTRAINTS && fragmentVisible && !Config.NSCLIENT && !Config.G5UPLOADER;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == CONSTRAINTS) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
} }
public class Objective { public class Objective {
@ -170,23 +123,23 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
RequirementResult requirementsMet(Integer objNum) { RequirementResult requirementsMet(Integer objNum) {
switch (objNum) { switch (objNum) {
case 0: case 0:
boolean isVirtualPump = VirtualPumpPlugin.getPlugin().isEnabled(PluginBase.PUMP); boolean isVirtualPump = VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP);
boolean vpUploadEnabled = SP.getBoolean("virtualpump_uploadstatus", false); boolean vpUploadEnabled = SP.getBoolean("virtualpump_uploadstatus", false);
boolean vpUploadNeeded = !isVirtualPump || vpUploadEnabled; boolean vpUploadNeeded = !isVirtualPump || vpUploadEnabled;
boolean hasBGData = DatabaseHelper.lastBg() != null; boolean hasBGData = DatabaseHelper.lastBg() != null;
boolean apsEnabled = false; boolean apsEnabled = false;
APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS(); APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS();
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginType.APS))
apsEnabled = true; apsEnabled = true;
return new RequirementResult(hasBGData && bgIsAvailableInNS && pumpStatusIsAvailableInNS && NSClientPlugin.getPlugin().hasWritePermission() && LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP) && apsEnabled && vpUploadNeeded, return new RequirementResult(hasBGData && bgIsAvailableInNS && pumpStatusIsAvailableInNS && NSClientPlugin.getPlugin().hasWritePermission() && LoopPlugin.getPlugin().isEnabled(PluginType.LOOP) && apsEnabled && vpUploadNeeded,
MainApp.gs(R.string.objectives_bgavailableinns) + ": " + yesOrNo(bgIsAvailableInNS) MainApp.gs(R.string.objectives_bgavailableinns) + ": " + yesOrNo(bgIsAvailableInNS)
+ "\n" + MainApp.gs(R.string.nsclienthaswritepermission) + ": " + yesOrNo(NSClientPlugin.getPlugin().hasWritePermission()) + "\n" + MainApp.gs(R.string.nsclienthaswritepermission) + ": " + yesOrNo(NSClientPlugin.getPlugin().hasWritePermission())
+ (isVirtualPump ? "\n" + MainApp.gs(R.string.virtualpump_uploadstatus_title) + ": " + yesOrNo(vpUploadEnabled) : "") + (isVirtualPump ? "\n" + MainApp.gs(R.string.virtualpump_uploadstatus_title) + ": " + yesOrNo(vpUploadEnabled) : "")
+ "\n" + MainApp.gs(R.string.objectives_pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS) + "\n" + MainApp.gs(R.string.objectives_pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS)
+ "\n" + MainApp.gs(R.string.hasbgdata) + ": " + yesOrNo(hasBGData) + "\n" + MainApp.gs(R.string.hasbgdata) + ": " + yesOrNo(hasBGData)
+ "\n" + MainApp.gs(R.string.loopenabled) + ": " + yesOrNo(LoopPlugin.getPlugin().isEnabled(PluginBase.LOOP)) + "\n" + MainApp.gs(R.string.loopenabled) + ": " + yesOrNo(LoopPlugin.getPlugin().isEnabled(PluginType.LOOP))
+ "\n" + MainApp.gs(R.string.apsselected) + ": " + yesOrNo(apsEnabled) + "\n" + MainApp.gs(R.string.apsselected) + ": " + yesOrNo(apsEnabled)
); );
case 1: case 1:

View file

@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.ConstraintsSafety; package info.nightscout.androidaps.plugins.ConstraintsSafety;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ConstraintChecker; import info.nightscout.androidaps.data.ConstraintChecker;
@ -11,6 +8,8 @@ import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
@ -23,8 +22,7 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class SafetyPlugin implements PluginBase, ConstraintsInterface { public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
private static Logger log = LoggerFactory.getLogger(SafetyPlugin.class);
static SafetyPlugin plugin = null; static SafetyPlugin plugin = null;
@ -34,64 +32,15 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
return plugin; return plugin;
} }
@Override public SafetyPlugin() {
public String getFragmentClass() { super(new PluginDescription()
return null; .mainType(PluginType.CONSTRAINTS)
} .neverVisible(true)
.alwaysEnabled(true)
@Override .showInList(false)
public int getType() { .pluginName(R.string.safety)
return PluginBase.CONSTRAINTS; .preferencesId(R.xml.pref_safety)
} );
@Override
public String getName() {
return MainApp.instance().getString(R.string.safety);
}
@Override
public String getNameShort() {
// use long name as fallback (no tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == CONSTRAINTS;
}
@Override
public boolean isVisibleInTabs(int type) {
return false;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return false;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
}
@Override
public int getPreferencesId() {
return R.xml.pref_safety;
} }
/** /**
@ -215,11 +164,11 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
double maxIobPref = SP.getDouble(R.string.key_openapsma_max_iob, 1.5d); double maxIobPref = SP.getDouble(R.string.key_openapsma_max_iob, 1.5d);
maxIob.setIfSmaller(maxIobPref, String.format(MainApp.gs(R.string.limitingiob), maxIobPref, MainApp.gs(R.string.maxvalueinpreferences)), this); maxIob.setIfSmaller(maxIobPref, String.format(MainApp.gs(R.string.limitingiob), maxIobPref, MainApp.gs(R.string.maxvalueinpreferences)), this);
if (OpenAPSMAPlugin.getPlugin().isEnabled(PluginBase.APS)) if (OpenAPSMAPlugin.getPlugin().isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this); maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this);
if (OpenAPSAMAPlugin.getPlugin().isEnabled(PluginBase.APS)) if (OpenAPSAMAPlugin.getPlugin().isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this); maxIob.setIfSmaller(HardLimits.maxIobAMA(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobAMA(), MainApp.gs(R.string.hardlimit)), this);
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginBase.APS)) if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS))
maxIob.setIfSmaller(HardLimits.maxIobSMB(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobSMB(), MainApp.gs(R.string.hardlimit)), this); maxIob.setIfSmaller(HardLimits.maxIobSMB(), String.format(MainApp.gs(R.string.limitingiob), HardLimits.maxIobSMB(), MainApp.gs(R.string.hardlimit)), this);
return maxIob; return maxIob;
} }

View file

@ -1,90 +1,33 @@
package info.nightscout.androidaps.plugins.Food; package info.nightscout.androidaps.plugins.Food;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class FoodPlugin implements PluginBase { public class FoodPlugin extends PluginBase {
private boolean fragmentEnabled = true;
private boolean fragmentVisible = false;
private static FoodPlugin plugin = null; private static FoodPlugin plugin = null;
private FoodService service;
private FoodPlugin() {
this.service = new FoodService();
}
public static FoodPlugin getPlugin() { public static FoodPlugin getPlugin() {
if (plugin == null) if (plugin == null)
plugin = new FoodPlugin(); plugin = new FoodPlugin();
return plugin; return plugin;
} }
@Override private FoodService service;
public String getFragmentClass() {
return FoodFragment.class.getName();
}
@Override private FoodPlugin() {
public int getType() { super(new PluginDescription()
return PluginBase.GENERAL; .mainType(PluginType.GENERAL)
} .fragmentClass(FoodFragment.class.getName())
.pluginName(R.string.food)
@Override .shortName(R.string.food_short)
public String getName() { );
return MainApp.instance().getString(R.string.food); this.service = new FoodService();
}
@Override
public String getNameShort() {
// use long name as fallback (not visible in tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == GENERAL) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
} }
public FoodService getService() { public FoodService getService() {

View file

@ -7,15 +7,14 @@ import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/** /**
* Created by mike on 17.04.2017. * Created by mike on 17.04.2017.
*/ */
public class InsulinFastactingPlugin implements PluginBase, InsulinInterface { public class InsulinFastactingPlugin extends PluginBase implements InsulinInterface {
private boolean fragmentEnabled = true;
private boolean fragmentVisible = false;
private static InsulinFastactingPlugin plugin = null; private static InsulinFastactingPlugin plugin = null;
@ -25,64 +24,13 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
return plugin; return plugin;
} }
@Override public InsulinFastactingPlugin() {
public int getType() { super(new PluginDescription()
return INSULIN; .mainType(PluginType.INSULIN)
} .fragmentClass(InsulinFragment.class.getName())
.pluginName(R.string.fastactinginsulin)
@Override .shortName(R.string.insulin_shortname)
public String getFragmentClass() { );
return InsulinFragment.class.getName();
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.fastactinginsulin);
}
@Override
public String getNameShort() {
return MainApp.sResources.getString(R.string.insulin_shortname);
}
@Override
public boolean isEnabled(int type) {
return type == INSULIN && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == INSULIN && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
} }
// Insulin interface // Insulin interface

View file

@ -8,15 +8,14 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/** /**
* Created by mike on 17.04.2017. * Created by mike on 17.04.2017.
*/ */
public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInterface { public class InsulinFastactingProlongedPlugin extends PluginBase implements InsulinInterface {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static InsulinFastactingProlongedPlugin plugin = null; private static InsulinFastactingProlongedPlugin plugin = null;
@ -26,64 +25,13 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte
return plugin; return plugin;
} }
@Override public InsulinFastactingProlongedPlugin() {
public int getType() { super(new PluginDescription()
return INSULIN; .mainType(PluginType.INSULIN)
} .fragmentClass(InsulinFragment.class.getName())
.pluginName(R.string.fastactinginsulinprolonged)
@Override .shortName(R.string.insulin_shortname)
public String getFragmentClass() { );
return InsulinFragment.class.getName();
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.fastactinginsulinprolonged);
}
@Override
public String getNameShort() {
return MainApp.sResources.getString(R.string.insulin_shortname);
}
@Override
public boolean isEnabled(int type) {
return type == INSULIN && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == INSULIN && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
} }
// Insulin interface // Insulin interface

View file

@ -8,42 +8,28 @@ import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
/** /**
* Created by adrian on 13.08.2017. * Created by adrian on 13.08.2017.
*/ */
public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterface { public abstract class InsulinOrefBasePlugin extends PluginBase implements InsulinInterface {
public static double MIN_DIA = 5; public static double MIN_DIA = 5;
long lastWarned = 0; long lastWarned = 0;
@Override public InsulinOrefBasePlugin() {
public int getType() { super(new PluginDescription()
return INSULIN; .mainType(PluginType.INSULIN)
} .fragmentClass(InsulinFragment.class.getName())
.pluginName(R.string.fastactinginsulin)
@Override .shortName(R.string.insulin_shortname)
public String getNameShort() { );
return MainApp.sResources.getString(R.string.insulin_shortname);
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
} }
public Bus getBus() { public Bus getBus() {
@ -53,7 +39,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf
@Override @Override
public double getDia() { public double getDia() {
double dia = getUserDefinedDia(); double dia = getUserDefinedDia();
if(dia >= MIN_DIA){ if (dia >= MIN_DIA) {
return dia; return dia;
} else { } else {
sendShortDiaNotification(dia); sendShortDiaNotification(dia);
@ -62,7 +48,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf
} }
void sendShortDiaNotification(double dia) { void sendShortDiaNotification(double dia) {
if((System.currentTimeMillis() - lastWarned) > 60*1000) { if ((System.currentTimeMillis() - lastWarned) > 60 * 1000) {
lastWarned = System.currentTimeMillis(); lastWarned = System.currentTimeMillis();
Notification notification = new Notification(Notification.SHORT_DIA, String.format(this.getNotificationPattern(), dia, MIN_DIA), Notification.URGENT); Notification notification = new Notification(Notification.SHORT_DIA, String.format(this.getNotificationPattern(), dia, MIN_DIA), Notification.URGENT);
this.getBus().post(new EventNewNotification(notification)); this.getBus().post(new EventNewNotification(notification));
@ -92,7 +78,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf
long bolusTime = treatment.date; long bolusTime = treatment.date;
double t = (time - bolusTime) / 1000d / 60d; double t = (time - bolusTime) / 1000d / 60d;
double td = getDia()*60; //getDIA() always >= MIN_DIA double td = getDia() * 60; //getDIA() always >= MIN_DIA
double tp = peak; double tp = peak;
// force the IOB to 0 if over DIA hours have passed // force the IOB to 0 if over DIA hours have passed
@ -111,7 +97,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf
public String getComment() { public String getComment() {
String comment = commentStandardText(); String comment = commentStandardText();
double userDia = getUserDefinedDia(); double userDia = getUserDefinedDia();
if(userDia < MIN_DIA){ if (userDia < MIN_DIA) {
comment += "\n" + String.format(MainApp.sResources.getString(R.string.dia_too_short), userDia, MIN_DIA); comment += "\n" + String.format(MainApp.sResources.getString(R.string.dia_too_short), userDia, MIN_DIA);
} }
return comment; return comment;

View file

@ -10,9 +10,6 @@ import info.nightscout.utils.SP;
public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin { public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static InsulinOrefFreePeakPlugin plugin = null; private static InsulinOrefFreePeakPlugin plugin = null;
public static InsulinOrefFreePeakPlugin getPlugin() { public static InsulinOrefFreePeakPlugin getPlugin() {
@ -21,24 +18,20 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin {
return plugin; return plugin;
} }
public static final int DEFAULT_PEAK = 75; private static final int DEFAULT_PEAK = 75;
private InsulinOrefFreePeakPlugin() {
super();
pluginDescription
.pluginName(R.string.free_peak_oref)
.preferencesId(R.xml.pref_insulinoreffreepeak);
}
@Override @Override
public int getId() { public int getId() {
return OREF_FREE_PEAK; return OREF_FREE_PEAK;
} }
@Override
public String getName() {
return MainApp.sResources.getString(R.string.free_peak_oref);
}
@Override
public String getFragmentClass() {
return InsulinFragment.class.getName();
}
@Override
public String getFriendlyName() { public String getFriendlyName() {
return MainApp.sResources.getString(R.string.free_peak_oref); return MainApp.sResources.getString(R.string.free_peak_oref);
} }
@ -48,31 +41,6 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin {
return MainApp.sResources.getString(R.string.insulin_peak_time) + ": " + getPeak(); return MainApp.sResources.getString(R.string.insulin_peak_time) + ": " + getPeak();
} }
@Override
public boolean isEnabled(int type) {
return type == INSULIN && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == INSULIN && fragmentVisible;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_insulinoreffreepeak;
}
@Override @Override
int getPeak() { int getPeak() {
return SP.getInt(R.string.key_insulin_oref_peak, DEFAULT_PEAK); return SP.getInt(R.string.key_insulin_oref_peak, DEFAULT_PEAK);

View file

@ -9,9 +9,6 @@ import info.nightscout.androidaps.R;
public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin { public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static InsulinOrefRapidActingPlugin plugin = null; private static InsulinOrefRapidActingPlugin plugin = null;
public static InsulinOrefRapidActingPlugin getPlugin() { public static InsulinOrefRapidActingPlugin getPlugin() {
@ -20,23 +17,19 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
return plugin; return plugin;
} }
public static final int PEAK = 75; private static final int PEAK = 75;
private InsulinOrefRapidActingPlugin() {
super();
pluginDescription
.pluginName(R.string.rapid_acting_oref);
}
@Override @Override
public int getId() { public int getId() {
return OREF_RAPID_ACTING; return OREF_RAPID_ACTING;
} }
@Override
public String getName() {
return MainApp.sResources.getString(R.string.rapid_acting_oref);
}
@Override
public String getFragmentClass() {
return InsulinFragment.class.getName();
}
@Override @Override
public String getFriendlyName() { public String getFriendlyName() {
return MainApp.sResources.getString(R.string.rapid_acting_oref); return MainApp.sResources.getString(R.string.rapid_acting_oref);
@ -47,31 +40,6 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
return MainApp.sResources.getString(R.string.fastactinginsulincomment); return MainApp.sResources.getString(R.string.fastactinginsulincomment);
} }
@Override
public boolean isEnabled(int type) {
return type == INSULIN && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == INSULIN && fragmentVisible;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override @Override
int getPeak() { int getPeak() {
return PEAK; return PEAK;

View file

@ -9,9 +9,6 @@ import info.nightscout.androidaps.R;
public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static InsulinOrefUltraRapidActingPlugin plugin = null; private static InsulinOrefUltraRapidActingPlugin plugin = null;
public static InsulinOrefUltraRapidActingPlugin getPlugin() { public static InsulinOrefUltraRapidActingPlugin getPlugin() {
@ -20,7 +17,13 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
return plugin; return plugin;
} }
public static final int PEAK = 55; private static final int PEAK = 55;
private InsulinOrefUltraRapidActingPlugin() {
super();
pluginDescription
.pluginName(R.string.ultrarapid_oref);
}
@Override @Override
public int getId() { public int getId() {
@ -32,11 +35,6 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
return MainApp.sResources.getString(R.string.ultrarapid_oref); return MainApp.sResources.getString(R.string.ultrarapid_oref);
} }
@Override
public String getFragmentClass() {
return InsulinFragment.class.getName();
}
@Override @Override
public String getFriendlyName() { public String getFriendlyName() {
return MainApp.sResources.getString(R.string.ultrarapid_oref); return MainApp.sResources.getString(R.string.ultrarapid_oref);
@ -47,31 +45,6 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
return MainApp.sResources.getString(R.string.ultrafastactinginsulincomment); return MainApp.sResources.getString(R.string.ultrafastactinginsulincomment);
} }
@Override
public boolean isEnabled(int type) {
return type == INSULIN && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == INSULIN && fragmentVisible;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override @Override
int getPeak() { int getPeak() {
return PEAK; return PEAK;

View file

@ -12,6 +12,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -33,7 +34,7 @@ public class AutosensData {
time = t.date; time = t.date;
carbs = t.carbs; carbs = t.carbs;
remaining = t.carbs; remaining = t.carbs;
if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginBase.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginBase.SENSITIVITY)) { if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) {
double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, 4d); double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, 4d);
Profile profile = MainApp.getConfigBuilder().getProfile(t.date); Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits()); double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits());

View file

@ -29,6 +29,8 @@ import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin;
@ -38,8 +40,16 @@ import info.nightscout.utils.DateUtil;
* Created by mike on 24.04.2017. * Created by mike on 24.04.2017.
*/ */
public class IobCobCalculatorPlugin implements PluginBase { public class IobCobCalculatorPlugin extends PluginBase {
private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class); private Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class);
private static IobCobCalculatorPlugin plugin = null;
public static IobCobCalculatorPlugin getPlugin() {
if (plugin == null)
plugin = new IobCobCalculatorPlugin();
return plugin;
}
private LongSparseArray<IobTotal> iobTable = new LongSparseArray<>(); // oldest at index 0 private LongSparseArray<IobTotal> iobTable = new LongSparseArray<>(); // oldest at index 0
private LongSparseArray<AutosensData> autosensDataTable = new LongSparseArray<>(); // oldest at index 0 private LongSparseArray<AutosensData> autosensDataTable = new LongSparseArray<>(); // oldest at index 0
@ -55,12 +65,26 @@ public class IobCobCalculatorPlugin implements PluginBase {
boolean stopCalculationTrigger = false; boolean stopCalculationTrigger = false;
private IobCobThread thread = null; private IobCobThread thread = null;
private static IobCobCalculatorPlugin plugin = null; public IobCobCalculatorPlugin() {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
.pluginName(R.string.iobcobcalculator)
.showInList(false)
.neverVisible(true)
.alwaysEnabled(true)
);
}
public static IobCobCalculatorPlugin getPlugin() { @Override
if (plugin == null) public void onStart() {
plugin = new IobCobCalculatorPlugin(); super.onStart();
return plugin; MainApp.bus().register(this);
}
@Override
public void onStop() {
super.onStop();
MainApp.bus().unregister(this);
} }
public LongSparseArray<AutosensData> getAutosensDataTable() { public LongSparseArray<AutosensData> getAutosensDataTable() {
@ -71,70 +95,6 @@ public class IobCobCalculatorPlugin implements PluginBase {
return bucketed_data; return bucketed_data;
} }
@Override
public int getType() {
return GENERAL;
}
@Override
public String getFragmentClass() {
return null;
}
@Override
public String getName() {
return "IOB COB Calculator";
}
@Override
public String getNameShort() {
return "IOC";
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL;
}
@Override
public boolean isVisibleInTabs(int type) {
return false;
}
@Override
public boolean canBeHidden(int type) {
return false;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return false;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
}
@Override
public int getPreferencesId() {
return -1;
}
public IobCobCalculatorPlugin() {
MainApp.bus().register(this);
}
@Nullable @Nullable
public List<BgReading> getBucketedData(long fromTime) { public List<BgReading> getBucketedData(long fromTime) {
//log.debug("Locking getBucketedData"); //log.debug("Locking getBucketedData");
@ -323,7 +283,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
log.debug("Bucketed data created. Size: " + bucketed_data.size()); log.debug("Bucketed data created. Size: " + bucketed_data.size());
} }
public static long oldestDataAvailable() { public long oldestDataAvailable() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable(); long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable();
@ -349,7 +309,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
} }
IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round(); IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round();
IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round(); IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round();
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginBase.APS)) { if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) {
// Add expected zere temp basal for next 240 mins // Add expected zere temp basal for next 240 mins
IobTotal basalIobWithZeroTemp = basalIob.copy(); IobTotal basalIobWithZeroTemp = basalIob.copy();
TemporaryBasal t = new TemporaryBasal() TemporaryBasal t = new TemporaryBasal()
@ -447,7 +407,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
log.debug("AUTOSENSDATA null: autosensDataTable empty (" + reason + ")"); log.debug("AUTOSENSDATA null: autosensDataTable empty (" + reason + ")");
return null; return null;
} }
AutosensData data = null; AutosensData data;
try { try {
data = autosensDataTable.valueAt(autosensDataTable.size() - 1); data = autosensDataTable.valueAt(autosensDataTable.size() - 1);
} catch (Exception e) { } catch (Exception e) {
@ -461,8 +421,6 @@ public class IobCobCalculatorPlugin implements PluginBase {
log.debug("AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time)); log.debug("AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time));
return null; return null;
} else { } else {
if (data == null)
log.debug("AUTOSENSDATA null: data == null (" + " " + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time));
return data; return data;
} }
} }

View file

@ -26,9 +26,11 @@ import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
@ -43,7 +45,7 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class LoopPlugin implements PluginBase { public class LoopPlugin extends PluginBase {
private static Logger log = LoggerFactory.getLogger(LoopPlugin.class); private static Logger log = LoggerFactory.getLogger(LoopPlugin.class);
protected static LoopPlugin loopPlugin; protected static LoopPlugin loopPlugin;
@ -55,9 +57,6 @@ public class LoopPlugin implements PluginBase {
return loopPlugin; return loopPlugin;
} }
private boolean pluginEnabled = false;
private boolean fragmentVisible = false;
private long loopSuspendedTill = 0L; // end of manual loop suspend private long loopSuspendedTill = 0L; // end of manual loop suspend
private boolean isSuperBolus = false; private boolean isSuperBolus = false;
private boolean isDisconnected = false; private boolean isDisconnected = false;
@ -76,78 +75,34 @@ public class LoopPlugin implements PluginBase {
static public LastRun lastRun = null; static public LastRun lastRun = null;
public LoopPlugin() { public LoopPlugin() {
MainApp.bus().register(this); super(new PluginDescription()
.mainType(PluginType.LOOP)
.fragmentClass(LoopFragment.class.getName())
.pluginName(R.string.loop)
.shortName(R.string.loop_shortname)
.preferencesId(R.xml.pref_closedmode)
);
loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L); loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L);
isSuperBolus = SP.getBoolean("isSuperBolus", false); isSuperBolus = SP.getBoolean("isSuperBolus", false);
isDisconnected = SP.getBoolean("isDisconnected", false); isDisconnected = SP.getBoolean("isDisconnected", false);
} }
@Override @Override
public String getFragmentClass() { protected void onStart() {
return LoopFragment.class.getName(); super.onStart();
MainApp.bus().register(this);
} }
@Override @Override
public int getType() { protected void onStop() {
return PluginBase.LOOP; super.onStop();
MainApp.bus().unregister(this);
} }
@Override @Override
public String getName() { public boolean specialEnableCondition() {
return MainApp.instance().gs(R.string.loop); PumpInterface pump = ConfigBuilderPlugin.getActivePump();
} return pump == null || pump.getPumpDescription().isTempBasalCapable;
@Override
public String getNameShort() {
String name = MainApp.gs(R.string.loop_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
return type == LOOP && pluginEnabled && pumpCapable;
}
@Override
public boolean isVisibleInTabs(int type) {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
return type == LOOP && fragmentVisible && pumpCapable;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean pluginEnabled) {
if (type == LOOP) this.pluginEnabled = pluginEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == LOOP) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_closedmode;
} }
@Subscribe @Subscribe
@ -266,7 +221,7 @@ public class LoopPlugin implements PluginBase {
final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
APSResult result = null; APSResult result = null;
if (!isEnabled(PluginBase.LOOP)) if (!isEnabled(PluginType.LOOP))
return; return;
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
@ -281,7 +236,7 @@ public class LoopPlugin implements PluginBase {
if (pump.getBaseBasalRate() < 0.01d) return; if (pump.getBaseBasalRate() < 0.01d) return;
APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS(); APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS();
if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) { if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginType.APS)) {
usedAPS.invoke(initiator); usedAPS.invoke(initiator);
result = usedAPS.getLastAPSResult(); result = usedAPS.getLastAPSResult();
} }

View file

@ -24,6 +24,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientNewLog;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientUpdateGUI;
@ -31,7 +33,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientServ
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
public class NSClientPlugin implements PluginBase { public class NSClientPlugin extends PluginBase {
private static Logger log = LoggerFactory.getLogger(NSClientPlugin.class); private static Logger log = LoggerFactory.getLogger(NSClientPlugin.class);
static NSClientPlugin nsClientPlugin; static NSClientPlugin nsClientPlugin;
@ -43,9 +45,6 @@ public class NSClientPlugin implements PluginBase {
return nsClientPlugin; return nsClientPlugin;
} }
private boolean fragmentEnabled = true;
private boolean fragmentVisible = true;
public Handler handler; public Handler handler;
private final List<EventNSClientNewLog> listLog = new ArrayList<>(); private final List<EventNSClientNewLog> listLog = new ArrayList<>();
@ -58,8 +57,14 @@ public class NSClientPlugin implements PluginBase {
public NSClientService nsClientService = null; public NSClientService nsClientService = null;
NSClientPlugin() { public NSClientPlugin() {
MainApp.bus().register(this); super(new PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(NSClientFragment.class.getName())
.pluginName(R.string.nsclientinternal)
.shortName(R.string.nsclientinternal_shortname)
.preferencesId(R.xml.pref_nsclientinternal)
);
paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false); paused = SP.getBoolean(R.string.key_nsclientinternal_paused, false);
autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true); autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true);
@ -68,78 +73,28 @@ public class NSClientPlugin implements PluginBase {
handlerThread.start(); handlerThread.start();
handler = new Handler(handlerThread.getLooper()); handler = new Handler(handlerThread.getLooper());
} }
}
@Override
protected void onStart() {
MainApp.bus().register(this);
Context context = MainApp.instance().getApplicationContext(); Context context = MainApp.instance().getApplicationContext();
Intent intent = new Intent(context, NSClientService.class); Intent intent = new Intent(context, NSClientService.class);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
} }
@Override @Override
public int getType() { protected void onStop() {
return PluginBase.GENERAL; MainApp.bus().unregister(this);
Context context = MainApp.instance().getApplicationContext();
context.unbindService(mConnection);
} }
@Override @Override
public String getFragmentClass() { public boolean specialShowInListCondition() {
return NSClientFragment.class.getName();
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.nsclientinternal);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.nsclientinternal_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return !Config.NSCLIENT && !Config.G5UPLOADER; return !Config.NSCLIENT && !Config.G5UPLOADER;
} }
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == GENERAL) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_nsclientinternal;
}
private ServiceConnection mConnection = new ServiceConnection() { private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {

View file

@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck; import info.nightscout.androidaps.plugins.NSClientInternal.data.AlarmAck;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
@ -27,7 +28,7 @@ public class AckAlarmReceiver extends BroadcastReceiver {
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
AckAlarmReceiver.class.getSimpleName()); AckAlarmReceiver.class.getSimpleName());
NSClientPlugin nsClientPlugin = MainApp.getSpecificPlugin(NSClientPlugin.class); NSClientPlugin nsClientPlugin = MainApp.getSpecificPlugin(NSClientPlugin.class);
if (!nsClientPlugin.isEnabled(PluginBase.GENERAL)) { if (!nsClientPlugin.isEnabled(PluginType.GENERAL)) {
return; return;
} }
if (SP.getBoolean(R.string.key_ns_noupload, false)) { if (SP.getBoolean(R.string.key_ns_noupload, false)) {

View file

@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DbRequest; import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment; import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment;
@ -106,7 +106,7 @@ public class DBAccessReceiver extends BroadcastReceiver {
public boolean shouldUpload() { public boolean shouldUpload() {
NSClientPlugin nsClientPlugin = MainApp.getSpecificPlugin(NSClientPlugin.class); NSClientPlugin nsClientPlugin = MainApp.getSpecificPlugin(NSClientPlugin.class);
return nsClientPlugin.isEnabled(PluginBase.GENERAL) && !SP.getBoolean(R.string.key_ns_noupload, false); return nsClientPlugin.isEnabled(PluginType.GENERAL) && !SP.getBoolean(R.string.key_ns_noupload, false);
} }
public void genereateTreatmentOfflineBroadcast(DbRequest request) { public void genereateTreatmentOfflineBroadcast(DbRequest request) {

View file

@ -34,6 +34,7 @@ import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventConfigBuilderChange;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue; import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck; import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck;
@ -180,7 +181,7 @@ public class NSClientService extends Service {
@Subscribe @Subscribe
public void onStatusEvent(EventConfigBuilderChange ev) { public void onStatusEvent(EventConfigBuilderChange ev) {
if (nsEnabled != MainApp.getSpecificPlugin(NSClientPlugin.class).isEnabled(PluginBase.GENERAL)) { if (nsEnabled != MainApp.getSpecificPlugin(NSClientPlugin.class).isEnabled(PluginType.GENERAL)) {
latestDateInReceivedData = 0; latestDateInReceivedData = 0;
destroy(); destroy();
initialize(); initialize();
@ -313,7 +314,7 @@ public class NSClientService extends Service {
} }
public void readPreferences() { public void readPreferences() {
nsEnabled = MainApp.getSpecificPlugin(NSClientPlugin.class).isEnabled(PluginBase.GENERAL); nsEnabled = MainApp.getSpecificPlugin(NSClientPlugin.class).isEnabled(PluginType.GENERAL);
nsURL = SP.getString(R.string.key_nsclientinternal_url, ""); nsURL = SP.getString(R.string.key_nsclientinternal_url, "");
nsAPISecret = SP.getString(R.string.key_nsclientinternal_api_secret, ""); nsAPISecret = SP.getString(R.string.key_nsclientinternal_api_secret, "");
nsDevice = SP.getString("careportal_enteredby", ""); nsDevice = SP.getString("careportal_enteredby", "");

View file

@ -8,7 +8,6 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.GlucoseStatus;
@ -18,8 +17,9 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
@ -32,12 +32,11 @@ import info.nightscout.utils.DateUtil;
import info.nightscout.utils.HardLimits; import info.nightscout.utils.HardLimits;
import info.nightscout.utils.Profiler; import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class OpenAPSAMAPlugin implements PluginBase, APSInterface { public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAPlugin.class); private static Logger log = LoggerFactory.getLogger(OpenAPSAMAPlugin.class);
private static OpenAPSAMAPlugin openAPSAMAPlugin; private static OpenAPSAMAPlugin openAPSAMAPlugin;
@ -55,75 +54,26 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
DetermineBasalResultAMA lastAPSResult = null; DetermineBasalResultAMA lastAPSResult = null;
AutosensResult lastAutosensResult = null; AutosensResult lastAutosensResult = null;
private boolean fragmentEnabled = false; public OpenAPSAMAPlugin() {
private boolean fragmentVisible = false; super(new PluginDescription()
.mainType(PluginType.APS)
@Override .fragmentClass(OpenAPSAMAFragment.class.getName())
public String getName() { .pluginName(R.string.openapsama)
return MainApp.instance().getString(R.string.openapsama); .shortName(R.string.oaps_shortname)
.preferencesId(R.xml.pref_openapsama)
);
} }
@Override @Override
public String getNameShort() { public boolean specialEnableCondition() {
String name = MainApp.sResources.getString(R.string.oaps_shortname); PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (!name.trim().isEmpty()) { return pump == null || pump.getPumpDescription().isTempBasalCapable;
//only if translation exists
return name;
}
// use long name as fallback
return getName();
} }
@Override @Override
public boolean isEnabled(int type) { public boolean specialShowInListCondition() {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump() != null && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable; PumpInterface pump = ConfigBuilderPlugin.getActivePump();
return type == APS && fragmentEnabled && pumpCapable; return pump == null || pump.getPumpDescription().isTempBasalCapable;
}
@Override
public boolean isVisibleInTabs(int type) {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
return type == APS && fragmentVisible && pumpCapable;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == APS) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_openapsama;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == APS) this.fragmentEnabled = fragmentEnabled;
}
@Override
public int getType() {
return PluginBase.APS;
}
@Override
public String getFragmentClass() {
return OpenAPSAMAFragment.class.getName();
} }
@Override @Override
@ -159,7 +109,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
return; return;
} }
if (!isEnabled(PluginBase.APS)) { if (!isEnabled(PluginType.APS)) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled))); MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled)));
if (Config.logAPSResult) if (Config.logAPSResult)
log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); log.debug(MainApp.instance().getString(R.string.openapsma_disabled));
@ -221,7 +171,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
startPart = new Date(); startPart = new Date();
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis()); lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis());
} else { } else {
lastAutosensResult = new AutosensResult(); lastAutosensResult = new AutosensResult();
} }

View file

@ -8,7 +8,6 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.GlucoseStatus;
@ -18,8 +17,9 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
@ -30,7 +30,6 @@ import info.nightscout.utils.DateUtil;
import info.nightscout.utils.HardLimits; import info.nightscout.utils.HardLimits;
import info.nightscout.utils.Profiler; import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
import info.nightscout.utils.SP;
import static info.nightscout.utils.HardLimits.checkOnlyHardLimits; import static info.nightscout.utils.HardLimits.checkOnlyHardLimits;
import static info.nightscout.utils.HardLimits.verifyHardLimits; import static info.nightscout.utils.HardLimits.verifyHardLimits;
@ -38,7 +37,7 @@ import static info.nightscout.utils.HardLimits.verifyHardLimits;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class OpenAPSMAPlugin implements PluginBase, APSInterface { public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSMAPlugin.class); private static Logger log = LoggerFactory.getLogger(OpenAPSMAPlugin.class);
private static OpenAPSMAPlugin openAPSMAPlugin; private static OpenAPSMAPlugin openAPSMAPlugin;
@ -55,75 +54,26 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
Date lastAPSRun = null; Date lastAPSRun = null;
DetermineBasalResultMA lastAPSResult = null; DetermineBasalResultMA lastAPSResult = null;
private boolean fragmentEnabled = false; public OpenAPSMAPlugin() {
private boolean fragmentVisible = false; super(new PluginDescription()
.mainType(PluginType.APS)
@Override .fragmentClass(OpenAPSMAFragment.class.getName())
public String getName() { .pluginName(R.string.openapsma)
return MainApp.instance().getString(R.string.openapsma); .shortName(R.string.oaps_shortname)
.preferencesId(R.xml.pref_openapsma)
);
} }
@Override @Override
public String getNameShort() { public boolean specialEnableCondition() {
String name = MainApp.sResources.getString(R.string.oaps_shortname); PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (!name.trim().isEmpty()) { return pump == null || pump.getPumpDescription().isTempBasalCapable;
//only if translation exists
return name;
}
// use long name as fallback
return getName();
} }
@Override @Override
public boolean isEnabled(int type) { public boolean specialShowInListCondition() {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump() != null && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable; PumpInterface pump = ConfigBuilderPlugin.getActivePump();
return type == APS && fragmentEnabled && pumpCapable; return pump == null || pump.getPumpDescription().isTempBasalCapable;
}
@Override
public boolean isVisibleInTabs(int type) {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump() != null && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
return type == APS && fragmentVisible && pumpCapable;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == APS) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_openapsma;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == APS) this.fragmentEnabled = fragmentEnabled;
}
@Override
public int getType() {
return PluginBase.APS;
}
@Override
public String getFragmentClass() {
return OpenAPSMAFragment.class.getName();
} }
@Override @Override
@ -159,7 +109,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
return; return;
} }
if (!isEnabled(PluginBase.APS)) { if (!isEnabled(PluginType.APS)) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled))); MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled)));
if (Config.logAPSResult) if (Config.logAPSResult)
log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); log.debug(MainApp.instance().getString(R.string.openapsma_disabled));

View file

@ -8,7 +8,6 @@ import java.io.IOException;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.GlucoseStatus;
@ -20,6 +19,8 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
@ -33,29 +34,16 @@ import info.nightscout.utils.HardLimits;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
import info.nightscout.utils.Profiler; import info.nightscout.utils.Profiler;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class OpenAPSSMBPlugin implements PluginBase, APSInterface { public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSSMBPlugin.class); private static Logger log = LoggerFactory.getLogger(OpenAPSSMBPlugin.class);
// last values
DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null;
Date lastAPSRun = null;
DetermineBasalResultSMB lastAPSResult = null;
AutosensResult lastAutosensResult = null;
boolean fragmentEnabled = false;
boolean fragmentVisible = true;
private static OpenAPSSMBPlugin openAPSSMBPlugin; private static OpenAPSSMBPlugin openAPSSMBPlugin;
private OpenAPSSMBPlugin() {
}
public static OpenAPSSMBPlugin getPlugin() { public static OpenAPSSMBPlugin getPlugin() {
if (openAPSSMBPlugin == null) { if (openAPSSMBPlugin == null) {
openAPSSMBPlugin = new OpenAPSSMBPlugin(); openAPSSMBPlugin = new OpenAPSSMBPlugin();
@ -63,72 +51,32 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
return openAPSSMBPlugin; return openAPSSMBPlugin;
} }
@Override // last values
public String getName() { DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null;
return MainApp.instance().getString(R.string.openapssmb); Date lastAPSRun = null;
DetermineBasalResultSMB lastAPSResult = null;
AutosensResult lastAutosensResult = null;
private OpenAPSSMBPlugin() {
super(new PluginDescription()
.mainType(PluginType.APS)
.fragmentClass(OpenAPSSMBFragment.class.getName())
.pluginName(R.string.openapssmb)
.shortName(R.string.smb_shortname)
.preferencesId(R.xml.pref_openapssmb)
);
} }
@Override @Override
public String getNameShort() { public boolean specialEnableCondition() {
String name = MainApp.sResources.getString(R.string.smb_shortname); PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (!name.trim().isEmpty()) { return pump == null || pump.getPumpDescription().isTempBasalCapable;
//only if translation exists
return name;
}
// use long name as fallback
return getName();
} }
@Override @Override
public boolean isEnabled(int type) { public boolean specialShowInListCondition() {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump() != null && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable; PumpInterface pump = ConfigBuilderPlugin.getActivePump();
return type == APS && fragmentEnabled && pumpCapable; return pump == null || pump.getPumpDescription().isTempBasalCapable;
}
@Override
public boolean isVisibleInTabs(int type) {
boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable;
return type == APS && fragmentVisible && pumpCapable;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == APS) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_openapssmb;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == APS) this.fragmentEnabled = fragmentEnabled;
}
@Override
public int getType() {
return PluginBase.APS;
}
@Override
public String getFragmentClass() {
return OpenAPSSMBFragment.class.getName();
} }
@Override @Override
@ -164,7 +112,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
return; return;
} }
if (!isEnabled(PluginBase.APS)) { if (!isEnabled(PluginType.APS)) {
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled))); MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled)));
if (Config.logAPSResult) if (Config.logAPSResult)
log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); log.debug(MainApp.instance().getString(R.string.openapsma_disabled));
@ -217,17 +165,20 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
} }
if (!checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA)) return; if (!checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA))
return;
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC)) if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
return; return;
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF))
return; return;
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.05, HardLimits.maxBasal())) return; if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.05, HardLimits.maxBasal()))
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return; return;
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal()))
return;
startPart = new Date(); startPart = new Date();
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis()); lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis());
} else { } else {
lastAutosensResult = new AutosensResult(); lastAutosensResult = new AutosensResult();
} }

View file

@ -84,7 +84,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
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.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
@ -112,8 +112,8 @@ import info.nightscout.androidaps.plugins.Overview.events.EventSetWakeLock;
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData; import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.BolusWizard; import info.nightscout.utils.BolusWizard;
@ -458,7 +458,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation"))
return; return;
menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop)); menu.setHeaderTitle(MainApp.sResources.getString(R.string.loop));
if (activeloop.isEnabled(PluginBase.LOOP)) { if (activeloop.isEnabled(PluginType.LOOP)) {
menu.add(MainApp.sResources.getString(R.string.disableloop)); menu.add(MainApp.sResources.getString(R.string.disableloop));
if (!activeloop.isSuspended()) { if (!activeloop.isSuspended()) {
menu.add(MainApp.sResources.getString(R.string.suspendloopfor1h)); menu.add(MainApp.sResources.getString(R.string.suspendloopfor1h));
@ -476,7 +476,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
menu.add(MainApp.sResources.getString(R.string.resume)); menu.add(MainApp.sResources.getString(R.string.resume));
} }
} }
if (!activeloop.isEnabled(PluginBase.LOOP)) if (!activeloop.isEnabled(PluginType.LOOP))
menu.add(MainApp.sResources.getString(R.string.enableloop)); menu.add(MainApp.sResources.getString(R.string.enableloop));
} else if (v == activeProfileView) { } else if (v == activeProfileView) {
menu.setHeaderTitle(MainApp.sResources.getString(R.string.profile)); menu.setHeaderTitle(MainApp.sResources.getString(R.string.profile));
@ -494,9 +494,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
return true; return true;
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (item.getTitle().equals(MainApp.sResources.getString(R.string.disableloop))) { if (item.getTitle().equals(MainApp.sResources.getString(R.string.disableloop))) {
activeloop.setPluginEnabled(PluginBase.LOOP, false); activeloop.setPluginEnabled(PluginType.LOOP, false);
activeloop.setFragmentVisible(PluginBase.LOOP, false); activeloop.setFragmentVisible(PluginType.LOOP, false);
MainApp.getConfigBuilder().storeSettings(); MainApp.getConfigBuilder().storeSettings("DisablingLoop");
updateGUI("suspendmenu"); updateGUI("suspendmenu");
MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() { MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
@ -509,9 +509,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration NSUpload.uploadOpenAPSOffline(24 * 60); // upload 24h, we don't know real duration
return true; return true;
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) { } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) {
activeloop.setPluginEnabled(PluginBase.LOOP, true); activeloop.setPluginEnabled(PluginType.LOOP, true);
activeloop.setFragmentVisible(PluginBase.LOOP, true); activeloop.setFragmentVisible(PluginType.LOOP, true);
MainApp.getConfigBuilder().storeSettings(); MainApp.getConfigBuilder().storeSettings("EnablingLoop");
updateGUI("suspendmenu"); updateGUI("suspendmenu");
NSUpload.uploadOpenAPSOffline(0); NSUpload.uploadOpenAPSOffline(0);
return true; return true;
@ -581,8 +581,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
@Override @Override
public void onClick(View v) { public void onClick(View v) {
boolean xdrip = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginBase.BGSOURCE); boolean xdrip = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginType.BGSOURCE);
boolean g5 = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class).isEnabled(PluginBase.BGSOURCE); boolean g5 = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class).isEnabled(PluginType.BGSOURCE);
String units = MainApp.getConfigBuilder().getProfileUnits(); String units = MainApp.getConfigBuilder().getProfileUnits();
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
@ -1101,8 +1101,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
// **** Calibration & CGM buttons **** // **** Calibration & CGM buttons ****
boolean xDripIsBgSource = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginBase.BGSOURCE); boolean xDripIsBgSource = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginType.BGSOURCE);
boolean g5IsBgSource = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class).isEnabled(PluginBase.BGSOURCE); boolean g5IsBgSource = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class).isEnabled(PluginType.BGSOURCE);
boolean bgAvailable = DatabaseHelper.actualBg() != null; boolean bgAvailable = DatabaseHelper.actualBg() != null;
if (calibrationButton != null) { if (calibrationButton != null) {
if ((xDripIsBgSource || g5IsBgSource) && bgAvailable && SP.getBoolean(R.string.key_show_calibration_button, true)) { if ((xDripIsBgSource || g5IsBgSource) && bgAvailable && SP.getBoolean(R.string.key_show_calibration_button, true)) {

View file

@ -13,6 +13,8 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.QuickWizard; import info.nightscout.androidaps.data.QuickWizard;
import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore;
@ -21,7 +23,7 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class OverviewPlugin implements PluginBase { public class OverviewPlugin extends PluginBase {
private static Logger log = LoggerFactory.getLogger(OverviewPlugin.class); private static Logger log = LoggerFactory.getLogger(OverviewPlugin.class);
private static OverviewPlugin overviewPlugin = new OverviewPlugin(); private static OverviewPlugin overviewPlugin = new OverviewPlugin();
@ -40,82 +42,34 @@ public class OverviewPlugin implements PluginBase {
public NotificationStore notificationStore = new NotificationStore(); public NotificationStore notificationStore = new NotificationStore();
public OverviewPlugin() { public OverviewPlugin() {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(OverviewFragment.class.getName())
.canBeHidden(false)
.alwayVisible(true)
.alwaysEnabled(true)
.pluginName(R.string.overview)
.shortName(R.string.overview_shortname)
.preferencesId(R.xml.pref_overview)
);
String storedData = SP.getString("QuickWizard", "[]"); String storedData = SP.getString("QuickWizard", "[]");
try { try {
quickWizard.setData(new JSONArray(storedData)); quickWizard.setData(new JSONArray(storedData));
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
}
@Override
public void onStart() {
MainApp.bus().register(this); MainApp.bus().register(this);
} }
@Override @Override
public String getFragmentClass() { public void onStop() {
return OverviewFragment.class.getName(); MainApp.bus().unregister(this);
} }
@Override
public String getName() {
return MainApp.instance().getString(R.string.overview);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.overview_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL;
}
@Override
public boolean isVisibleInTabs(int type) {
return true;
}
@Override
public boolean canBeHidden(int type) {
return false;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
// Always enabled
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
// Always visible
}
@Override
public int getPreferencesId() {
return R.xml.pref_overview;
}
@Override
public int getType() {
return PluginBase.GENERAL;
}
@Subscribe @Subscribe
public void onStatusEvent(final EventNewNotification n) { public void onStatusEvent(final EventNewNotification n) {
notificationStore.add(n.notification); notificationStore.add(n.notification);
@ -128,14 +82,6 @@ public class OverviewPlugin implements PluginBase {
MainApp.bus().post(new EventRefreshOverview("EventDismissNotification")); MainApp.bus().post(new EventRefreshOverview("EventDismissNotification"));
} }
public double determineHighLine() {
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) {
return bgTargetHigh;
}
return determineHighLine(profile.getUnits());
}
public double determineHighLine(String units) { public double determineHighLine(String units) {
double highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units)); double highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units));
if (highLineSetting < 1) if (highLineSetting < 1)

View file

@ -6,8 +6,8 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.support.v4.app.TaskStackBuilder;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
@ -29,6 +29,8 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@ -36,84 +38,37 @@ import info.nightscout.utils.DecimalFormatter;
* Created by adrian on 23/12/16. * Created by adrian on 23/12/16.
*/ */
public class PersistentNotificationPlugin implements PluginBase { public class PersistentNotificationPlugin extends PluginBase {
private static final int ONGOING_NOTIFICATION_ID = 4711; private static final int ONGOING_NOTIFICATION_ID = 4711;
private boolean fragmentEnabled = true;
private final Context ctx; private final Context ctx;
public PersistentNotificationPlugin(Context ctx) { public PersistentNotificationPlugin(Context ctx) {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
.neverVisible(true)
.pluginName(R.string.ongoingnotificaction)
.enableByDefault(true)
);
this.ctx = ctx; this.ctx = ctx;
} }
@Override @Override
public int getType() { protected void onStart() {
return GENERAL; MainApp.bus().register(this);
updateNotification();
} }
@Override @Override
public String getFragmentClass() { protected void onStop() {
return null; MainApp.bus().unregister(this);
}
@Override
public String getName() {
return ctx.getString(R.string.ongoingnotificaction);
}
@Override
public String getNameShort() {
// use long name as fallback (not visible in tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return false;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (getType() == type) {
this.fragmentEnabled = fragmentEnabled;
enableDisableNotification(fragmentEnabled);
checkBusRegistration();
}
}
private void enableDisableNotification(boolean fragmentEnabled) {
if (!fragmentEnabled) {
NotificationManager mNotificationManager = NotificationManager mNotificationManager =
(NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(ONGOING_NOTIFICATION_ID); mNotificationManager.cancel(ONGOING_NOTIFICATION_ID);
} else {
updateNotification();
}
} }
private void updateNotification() { private void updateNotification() {
if (!fragmentEnabled) { if (!isEnabled(PluginType.GENERAL)) {
return; return;
} }
@ -190,32 +145,6 @@ public class PersistentNotificationPlugin implements PluginBase {
} }
private void checkBusRegistration() {
if (fragmentEnabled) {
try {
MainApp.bus().register(this);
} catch (IllegalArgumentException e) {
// already registered
}
} else {
try {
MainApp.bus().unregister(this);
} catch (IllegalArgumentException e) {
// already unregistered
}
}
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
//no visible fragment
}
@Override
public int getPreferencesId() {
return -1;
}
private String deltastring(double deltaMGDL, double deltaMMOL, String units) { private String deltastring(double deltaMGDL, double deltaMMOL, String units) {
String deltastring = ""; String deltastring = "";
if (deltaMGDL >= 0) { if (deltaMGDL >= 0) {

View file

@ -15,6 +15,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -22,7 +24,7 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class LocalProfilePlugin implements PluginBase, ProfileInterface { public class LocalProfilePlugin extends PluginBase implements ProfileInterface {
public static final String LOCAL_PROFILE = "LocalProfile"; public static final String LOCAL_PROFILE = "LocalProfile";
private static Logger log = LoggerFactory.getLogger(LocalProfilePlugin.class); private static Logger log = LoggerFactory.getLogger(LocalProfilePlugin.class);
@ -34,13 +36,9 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
return localProfilePlugin; return localProfilePlugin;
} }
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private ProfileStore convertedProfile = null; private ProfileStore convertedProfile = null;
private String convertedProfileName = null;
public static final String DEFAULTARRAY = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]"; private static final String DEFAULTARRAY = "[{\"time\":\"00:00\",\"timeAsSeconds\":0,\"value\":0}]";
boolean mgdl; boolean mgdl;
boolean mmol; boolean mmol;
@ -52,75 +50,15 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
JSONArray targetHigh; JSONArray targetHigh;
public LocalProfilePlugin() { public LocalProfilePlugin() {
super(new PluginDescription()
.mainType(PluginType.PROFILE)
.fragmentClass(LocalProfileFragment.class.getName())
.pluginName(R.string.localprofile)
.shortName(R.string.localprofile_shortname)
);
loadSettings(); loadSettings();
} }
@Override
public String getFragmentClass() {
return LocalProfileFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.PROFILE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.localprofile);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.localprofile_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == PROFILE && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PROFILE && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PROFILE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PROFILE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
public void storeSettings() { public void storeSettings() {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
@ -246,7 +184,6 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
convertedProfile = new ProfileStore(json); convertedProfile = new ProfileStore(json);
convertedProfileName = LOCAL_PROFILE;
} }
@Override @Override

View file

@ -17,17 +17,16 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI; import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class NSProfilePlugin implements PluginBase, ProfileInterface { public class NSProfilePlugin extends PluginBase implements ProfileInterface {
private static Logger log = LoggerFactory.getLogger(NSProfilePlugin.class); private static Logger log = LoggerFactory.getLogger(NSProfilePlugin.class);
private static NSProfilePlugin nsProfilePlugin; private static NSProfilePlugin nsProfilePlugin;
@ -38,83 +37,33 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface {
return nsProfilePlugin; return nsProfilePlugin;
} }
@Override
public String getFragmentClass() {
return NSProfileFragment.class.getName();
}
private boolean fragmentEnabled = true;
private boolean fragmentVisible = true;
private ProfileStore profile = null; private ProfileStore profile = null;
private NSProfilePlugin() { private NSProfilePlugin() {
MainApp.bus().register(this); super(new PluginDescription()
.mainType(PluginType.PROFILE)
.fragmentClass(NSProfileFragment.class.getName())
.pluginName(R.string.profileviewer)
.shortName(R.string.profileviewer_shortname)
);
loadNSProfile(); loadNSProfile();
} }
@Override @Override
public String getName() { protected void onStart() {
return MainApp.instance().getString(R.string.profileviewer); MainApp.bus().register(this);
} }
@Override @Override
public String getNameShort() { protected void onStop() {
String name = MainApp.sResources.getString(R.string.profileviewer_shortname); MainApp.bus().unregister(this);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
} }
@Override @Override
public boolean isEnabled(int type) { public boolean specialShowInListCondition() {
return type == PROFILE && (Config.NSCLIENT || Config.G5UPLOADER|| fragmentEnabled);
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PROFILE && (Config.NSCLIENT || Config.G5UPLOADER|| fragmentVisible);
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return !Config.NSCLIENT && !Config.G5UPLOADER; return !Config.NSCLIENT && !Config.G5UPLOADER;
} }
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PROFILE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PROFILE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public int getType() {
return PluginBase.PROFILE;
}
@Subscribe @Subscribe
public void storeNewProfile(ProfileStore newProfile) { public void storeNewProfile(ProfileStore newProfile) {
profile = new ProfileStore(newProfile.getData()); profile = new ProfileStore(newProfile.getData());

View file

@ -15,13 +15,15 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class SimpleProfilePlugin implements PluginBase, ProfileInterface { public class SimpleProfilePlugin extends PluginBase implements ProfileInterface {
private static Logger log = LoggerFactory.getLogger(SimpleProfilePlugin.class); private static Logger log = LoggerFactory.getLogger(SimpleProfilePlugin.class);
private static SimpleProfilePlugin simpleProfilePlugin; private static SimpleProfilePlugin simpleProfilePlugin;
@ -32,9 +34,6 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
return simpleProfilePlugin; return simpleProfilePlugin;
} }
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static ProfileStore convertedProfile = null; private static ProfileStore convertedProfile = null;
boolean mgdl; boolean mgdl;
@ -47,75 +46,15 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
Double targetHigh; Double targetHigh;
private SimpleProfilePlugin() { private SimpleProfilePlugin() {
super(new PluginDescription()
.mainType(PluginType.PROFILE)
.fragmentClass(SimpleProfileFragment.class.getName())
.pluginName(R.string.simpleprofile)
.shortName(R.string.simpleprofile_shortname)
);
loadSettings(); loadSettings();
} }
@Override
public String getFragmentClass() {
return SimpleProfileFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.PROFILE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.simpleprofile);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.simpleprofile_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == PROFILE && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PROFILE && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PROFILE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PROFILE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
public void storeSettings() { public void storeSettings() {
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Storing settings"); log.debug("Storing settings");

View file

@ -31,11 +31,13 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
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.interfaces.Constraint;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
@ -63,14 +65,18 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterface { public class ComboPlugin extends PluginBase implements PumpInterface, ConstraintsInterface {
private static final Logger log = LoggerFactory.getLogger(ComboPlugin.class); private static final Logger log = LoggerFactory.getLogger(ComboPlugin.class);
public static final String COMBO_TBRS_SET = "combo_tbrs_set"; public static final String COMBO_TBRS_SET = "combo_tbrs_set";
public static final String COMBO_BOLUSES_DELIVERED = "combo_boluses_delivered"; public static final String COMBO_BOLUSES_DELIVERED = "combo_boluses_delivered";
private static ComboPlugin plugin = null; private static ComboPlugin plugin = null;
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false; public static ComboPlugin getPlugin() {
if (plugin == null)
plugin = new ComboPlugin();
return plugin;
}
private final static PumpDescription pumpDescription = new PumpDescription(); private final static PumpDescription pumpDescription = new PumpDescription();
@ -147,16 +153,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
*/ */
private volatile List<Bolus> recentBoluses = new ArrayList<>(0); private volatile List<Bolus> recentBoluses = new ArrayList<>(0);
public static ComboPlugin getPlugin() {
if (plugin == null)
plugin = new ComboPlugin();
return plugin;
}
private static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult() private static final PumpEnactResult OPERATION_NOT_SUPPORTED = new PumpEnactResult()
.success(false).enacted(false).comment(MainApp.gs(R.string.combo_pump_unsupported_operation)); .success(false).enacted(false).comment(MainApp.gs(R.string.combo_pump_unsupported_operation));
private ComboPlugin() { private ComboPlugin() {
super(new PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(ComboFragment.class.getName())
.pluginName(R.string.combopump)
.shortName(R.string.combopump_shortname)
);
ruffyScripter = new RuffyScripter(MainApp.instance().getApplicationContext()); ruffyScripter = new RuffyScripter(MainApp.instance().getApplicationContext());
} }
@ -164,27 +170,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return pump; return pump;
} }
@Override
public String getFragmentClass() {
return ComboFragment.class.getName();
}
@Override
public String getName() {
return MainApp.gs(R.string.combopump);
}
@Override
public String getNameShort() {
String name = MainApp.gs(R.string.combopump_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
String getStateSummary() { String getStateSummary() {
PumpState ps = pump.state; PumpState ps = pump.state;
if (ps.activeAlert != null) { if (ps.activeAlert != null) {
@ -203,53 +188,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
return MainApp.gs(R.string.combo_pump_state_running); return MainApp.gs(R.string.combo_pump_state_running);
} }
@Override
public boolean isEnabled(int type) {
if (type == PluginBase.PUMP) return fragmentEnabled;
else if (type == PluginBase.CONSTRAINTS) return fragmentEnabled;
return false;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PUMP && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return type == PUMP;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PUMP) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PUMP) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override @Override
public boolean isInitialized() { public boolean isInitialized() {
return pump.initialized; return pump.initialized;
@ -1448,8 +1386,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
HashMap<Long, TDD> map = new HashMap<>(); HashMap<Long, TDD> map = new HashMap<>();
for (int i = 0; i < tdds.size(); i++) { for (int i = 0; i < tdds.size(); i++) {
Tdd currTdd = tdds.get(i); Tdd currTdd = tdds.get(i);
if(currTdd.total < 1) continue; //cases where dummy days are introduced (e.g. Battery change with date loss) if (currTdd.total < 1)
if(map.containsKey(currTdd.timestamp)){ continue; //cases where dummy days are introduced (e.g. Battery change with date loss)
if (map.containsKey(currTdd.timestamp)) {
//duplicate days on time changes //duplicate days on time changes
TDD existing = map.get(currTdd.timestamp); TDD existing = map.get(currTdd.timestamp);
existing.total += currTdd.total; existing.total += currTdd.total;
@ -1460,7 +1399,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
Collection<TDD> uniqueColl = map.values(); Collection<TDD> uniqueColl = map.values();
for (TDD currTdd: uniqueColl) { for (TDD currTdd : uniqueColl) {
MainApp.getDbHelper().createOrUpdateTDD(currTdd); MainApp.getDbHelper().createOrUpdateTDD(currTdd);
} }
} }

View file

@ -21,6 +21,8 @@ import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.DanaRInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
@ -39,13 +41,9 @@ import info.nightscout.utils.SP;
* Created by mike on 28.01.2018. * Created by mike on 28.01.2018.
*/ */
public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface { public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface {
protected Logger log; protected Logger log;
protected boolean mPluginPumpEnabled = false;
protected boolean mPluginProfileEnabled = false;
protected boolean mFragmentPumpVisible = true;
protected AbstractDanaRExecutionService sExecutionService; protected AbstractDanaRExecutionService sExecutionService;
protected DanaRPump pump = DanaRPump.getInstance(); protected DanaRPump pump = DanaRPump.getInstance();
@ -53,79 +51,26 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
public PumpDescription pumpDescription = new PumpDescription(); public PumpDescription pumpDescription = new PumpDescription();
@Override protected AbstractDanaRPlugin() {
public String getFragmentClass() { super(new PluginDescription()
return DanaRFragment.class.getName(); .mainType(PluginType.PUMP)
} .fragmentClass(DanaRFragment.class.getName())
.pluginName(R.string.danarspump)
// Plugin base interface .shortName(R.string.danarpump_shortname)
@Override .preferencesId(R.xml.pref_danars)
public int getType() { );
return PluginBase.PUMP;
} }
@Override @Override
public String getNameShort() { public void onStateChange(PluginType type, State oldState, State newState) {
String name = MainApp.sResources.getString(R.string.danarpump_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
if (type == PluginBase.PROFILE) return mPluginProfileEnabled && mPluginPumpEnabled;
else if (type == PluginBase.PUMP) return mPluginPumpEnabled;
else if (type == PluginBase.CONSTRAINTS) return mPluginPumpEnabled;
return false;
}
@Override
public boolean isVisibleInTabs(int type) {
if (type == PluginBase.PROFILE || type == PluginBase.CONSTRAINTS) return false;
else if (type == PluginBase.PUMP) return mFragmentPumpVisible;
return false;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return type == PUMP;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PluginBase.PROFILE)
mPluginProfileEnabled = fragmentEnabled;
else if (type == PluginBase.PUMP)
mPluginPumpEnabled = fragmentEnabled;
// if pump profile was enabled need to switch to another too // if pump profile was enabled need to switch to another too
if (type == PluginBase.PUMP && !fragmentEnabled && mPluginProfileEnabled) { if (type == PluginType.PUMP && newState == State.DISABLED && isProfileInterfaceEnabled) {
setPluginEnabled(PluginBase.PROFILE, false); setPluginEnabled(PluginType.PROFILE, false);
setFragmentVisible(PluginBase.PROFILE, false); NSProfilePlugin.getPlugin().setPluginEnabled(PluginType.PROFILE, true);
NSProfilePlugin.getPlugin().setPluginEnabled(PluginBase.PROFILE, true); NSProfilePlugin.getPlugin().setFragmentVisible(PluginType.PROFILE, true);
NSProfilePlugin.getPlugin().setFragmentVisible(PluginBase.PROFILE, true);
} }
} }
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PluginBase.PUMP)
mFragmentPumpVisible = fragmentVisible;
}
@Override @Override
public boolean isSuspended() { public boolean isSuspended() {
return pump.pumpSuspended; return pump.pumpSuspended;
@ -183,7 +128,7 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60; int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) { for (int h = 0; h < basalValues; h++) {
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h]; Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
Double profileValue = profile.getBasalTimeFromMidnight((Integer) (h * basalIncrement)); Double profileValue = profile.getBasalTimeFromMidnight(h * basalIncrement);
if (profileValue == null) return true; if (profileValue == null) return true;
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) { if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue); log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);
@ -396,7 +341,7 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
extended.put("BaseBasalRate", getBaseBasalRate()); extended.put("BaseBasalRate", getBaseBasalRate());
try { try {
extended.put("ActiveProfile", profilename); extended.put("ActiveProfile", profilename);
} catch (Exception e) { } catch (Exception ignored) {
} }
pumpjson.put("battery", battery); pumpjson.put("battery", battery);

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
import info.nightscout.utils.Round; import info.nightscout.utils.Round;
@ -41,6 +42,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
} }
public DanaRPlugin() { public DanaRPlugin() {
super();
log = LoggerFactory.getLogger(DanaRPlugin.class); log = LoggerFactory.getLogger(DanaRPlugin.class);
useExtendedBoluses = SP.getBoolean("danar_useextended", false); useExtendedBoluses = SP.getBoolean("danar_useextended", false);
@ -98,7 +100,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
@Subscribe @Subscribe
public void onStatusEvent(final EventPreferenceChange s) { public void onStatusEvent(final EventPreferenceChange s) {
if (isEnabled(PUMP)) { if (isEnabled(PluginType.PUMP)) {
boolean previousValue = useExtendedBoluses; boolean previousValue = useExtendedBoluses;
useExtendedBoluses = SP.getBoolean("danar_useextended", false); useExtendedBoluses = SP.getBoolean("danar_useextended", false);

View file

@ -1,14 +1,9 @@
package info.nightscout.androidaps.plugins.PumpDanaR.activities; package info.nightscout.androidaps.plugins.PumpDanaR.activities;
import android.app.Activity; import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.os.IBinder;
import android.support.v7.widget.CardView; import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -32,14 +27,11 @@ import java.util.List;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.events.EventPumpStatusChanged; import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.DanaRInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus; import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
@ -124,8 +116,8 @@ public class DanaRHistoryActivity extends Activity {
statusView.setVisibility(View.GONE); statusView.setVisibility(View.GONE);
boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP); boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PUMP);
boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginBase.PUMP); boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.class).isEnabled(PluginType.PUMP);
// Types // Types

View file

@ -9,10 +9,10 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
@ -31,20 +31,20 @@ public class MsgInitConnStatusTime extends MessageBase {
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model"); MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
log.debug("Wrong model selected. Switching to Korean DanaR"); log.debug("Wrong model selected. Switching to Korean DanaR");
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginBase.PUMP, true); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, true);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginType.PUMP, true);
MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginBase.PUMP, false); MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginType.PUMP, false);
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false); MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginType.PUMP, false);
DanaRPump.reset(); // mark not initialized DanaRPump.reset(); // mark not initialized
//If profile coming from pump, switch it as well //If profile coming from pump, switch it as well
if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){ if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginType.PROFILE)){
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, false); (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, false);
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginType.PROFILE, true);
} }
MainApp.getConfigBuilder().storeSettings(); MainApp.getConfigBuilder().storeSettings("ChangingDanaDriver");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return; return;

View file

@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
@ -43,7 +43,7 @@ public class MsgSettingMeal extends MessageBase {
} }
// DanaRKorean is not possible to set to 0.01 but it works when controlled from AAPS // DanaRKorean is not possible to set to 0.01 but it works when controlled from AAPS
if (DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PUMP)) { if (DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PUMP)) {
pump.basalStep = 0.01d; pump.basalStep = 0.01d;
} }

View file

@ -22,6 +22,7 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService;
@ -42,6 +43,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
} }
public DanaRKoreanPlugin() { public DanaRKoreanPlugin() {
super();
log = LoggerFactory.getLogger(DanaRKoreanPlugin.class); log = LoggerFactory.getLogger(DanaRKoreanPlugin.class);
useExtendedBoluses = SP.getBoolean("danar_useextended", false); useExtendedBoluses = SP.getBoolean("danar_useextended", false);
@ -99,7 +101,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
@Subscribe @Subscribe
public void onStatusEvent(final EventPreferenceChange s) { public void onStatusEvent(final EventPreferenceChange s) {
if (isEnabled(PUMP)) { if (isEnabled(PluginType.PUMP)) {
boolean previousValue = useExtendedBoluses; boolean previousValue = useExtendedBoluses;
useExtendedBoluses = SP.getBoolean("danar_useextended", false); useExtendedBoluses = SP.getBoolean("danar_useextended", false);
@ -138,7 +140,8 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
Treatment t = new Treatment(); Treatment t = new Treatment();
t.isSMB = detailedBolusInfo.isSMB; t.isSMB = detailedBolusInfo.isSMB;
boolean connectionOK = false; boolean connectionOK = false;
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0) connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t); if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK; result.success = connectionOK;
result.bolusDelivered = t.insulin; result.bolusDelivered = t.insulin;
@ -250,7 +253,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
// Convert duration from minutes to hours // Convert duration from minutes to hours
if (Config.logPumpActions) if (Config.logPumpActions)
log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)"); log.debug("setTempBasalAbsolute: Setting temp basal " + percentRate + "% for " + durationInMinutes + " mins (doLowTemp || doHighTemp)");
return setTempBasalPercent(percentRate, durationInMinutes, profile,false); return setTempBasalPercent(percentRate, durationInMinutes, profile, false);
} }
if (doExtendedTemp) { if (doExtendedTemp) {
// Check if some temp is already in progress // Check if some temp is already in progress

View file

@ -9,10 +9,10 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
@ -33,20 +33,20 @@ public class MsgInitConnStatusTime_k extends MessageBase {
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model"); DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
log.debug("Wrong model selected. Switching to export DanaR"); log.debug("Wrong model selected. Switching to export DanaR");
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginBase.PUMP, false); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, false);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, false); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginType.PUMP, false);
MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginBase.PUMP, true); MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginType.PUMP, true);
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, true); MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginType.PUMP, true);
DanaRPump.reset(); // mark not initialized DanaRPump.reset(); // mark not initialized
//If profile coming from pump, switch it as well //If profile coming from pump, switch it as well
if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)) { if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PROFILE)) {
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginBase.PROFILE, false); (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginType.PROFILE, false);
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, true);
} }
MainApp.getConfigBuilder().storeSettings(); MainApp.getConfigBuilder().storeSettings("ChangingKoreanDanaDriver");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return; return;

View file

@ -32,6 +32,8 @@ import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.DanaRInterface; import info.nightscout.androidaps.interfaces.DanaRInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
@ -54,103 +56,9 @@ import info.nightscout.utils.SP;
* Created by mike on 03.09.2017. * Created by mike on 03.09.2017.
*/ */
public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface { public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInterface, ConstraintsInterface, ProfileInterface {
private static Logger log = LoggerFactory.getLogger(DanaRSPlugin.class); private static Logger log = LoggerFactory.getLogger(DanaRSPlugin.class);
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override
public String getFragmentClass() {
return DanaRFragment.class.getName();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.danarspump);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.danarspump_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
if (type == PluginBase.PROFILE) return fragmentProfileEnabled && fragmentPumpEnabled;
else if (type == PluginBase.PUMP) return fragmentPumpEnabled;
else if (type == PluginBase.CONSTRAINTS) return fragmentPumpEnabled;
return false;
}
@Override
public boolean isVisibleInTabs(int type) {
if (type == PluginBase.PROFILE || type == PluginBase.CONSTRAINTS) return false;
else if (type == PluginBase.PUMP) return fragmentPumpVisible;
return false;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return type == PUMP;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PluginBase.PROFILE)
this.fragmentProfileEnabled = fragmentEnabled;
else if (type == PluginBase.PUMP)
this.fragmentPumpEnabled = fragmentEnabled;
// if pump profile was enabled need to switch to another too
if (type == PluginBase.PUMP && !fragmentEnabled && this.fragmentProfileEnabled) {
setPluginEnabled(PluginBase.PROFILE, false);
setFragmentVisible(PluginBase.PROFILE, false);
MainApp.getSpecificPlugin(NSProfilePlugin.class).setPluginEnabled(PluginBase.PROFILE, true);
MainApp.getSpecificPlugin(NSProfilePlugin.class).setFragmentVisible(PluginBase.PROFILE, true);
}
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PluginBase.PUMP)
this.fragmentPumpVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_danars;
}
static boolean fragmentPumpEnabled = false;
static boolean fragmentProfileEnabled = false;
static boolean fragmentPumpVisible = false;
public static DanaRSService danaRSService;
public static String mDeviceAddress = "";
public static String mDeviceName = "";
private static DanaRSPlugin plugin = null; private static DanaRSPlugin plugin = null;
private static DanaRPump pump = DanaRPump.getInstance();
public static PumpDescription pumpDescription = new PumpDescription();
public static DanaRSPlugin getPlugin() { public static DanaRSPlugin getPlugin() {
if (plugin == null) if (plugin == null)
@ -158,12 +66,22 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
return plugin; return plugin;
} }
public static DanaRSService danaRSService;
public static String mDeviceAddress = "";
public static String mDeviceName = "";
private static DanaRPump pump = DanaRPump.getInstance();
public static PumpDescription pumpDescription = new PumpDescription();
DanaRSPlugin() { DanaRSPlugin() {
Context context = MainApp.instance().getApplicationContext(); super(new PluginDescription()
Intent intent = new Intent(context, DanaRSService.class); .mainType(PluginType.PUMP)
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); .fragmentClass(DanaRFragment.class.getName())
MainApp.bus().register(this); .pluginName(R.string.danarspump)
onStatusEvent(new EventDanaRSDeviceChange()); // load device name .shortName(R.string.danarspump_shortname)
.preferencesId(R.xml.pref_danars)
);
pumpDescription.isBolusCapable = true; pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.05d; pumpDescription.bolusStep = 0.05d;
@ -194,6 +112,34 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
pumpDescription.storesCarbInfo = true; pumpDescription.storesCarbInfo = true;
} }
@Override
public void onStateChange(PluginType type, State oldState, State newState) {
// if pump profile was enabled need to switch to another too
if (type == PluginType.PUMP && newState == State.DISABLED && isProfileInterfaceEnabled) {
setPluginEnabled(PluginType.PROFILE, false);
NSProfilePlugin.getPlugin().setPluginEnabled(PluginType.PROFILE, true);
NSProfilePlugin.getPlugin().setFragmentVisible(PluginType.PROFILE, true);
}
}
@Override
protected void onStart() {
Context context = MainApp.instance().getApplicationContext();
Intent intent = new Intent(context, DanaRSService.class);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
MainApp.bus().register(this);
onStatusEvent(new EventDanaRSDeviceChange()); // load device name
}
@Override
protected void onStop() {
Context context = MainApp.instance().getApplicationContext();
context.unbindService(mConnection);
MainApp.bus().unregister(this);
}
private ServiceConnection mConnection = new ServiceConnection() { private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {

View file

@ -7,10 +7,10 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
@ -43,20 +43,20 @@ public class MsgCheckValue_v2 extends MessageBase {
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model"); MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model");
log.debug("Wrong model selected. Switching to Korean DanaR"); log.debug("Wrong model selected. Switching to Korean DanaR");
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginBase.PUMP, true); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, true);
MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true); MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginType.PUMP, true);
MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginBase.PUMP, false); MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginType.PUMP, false);
MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false); MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginType.PUMP, false);
DanaRPump.reset(); // mark not initialized DanaRPump.reset(); // mark not initialized
//If profile coming from pump, switch it as well //If profile coming from pump, switch it as well
if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){ if (MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginType.PROFILE)) {
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, false); (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, false);
(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginType.PROFILE, true);
} }
MainApp.getConfigBuilder().storeSettings(); MainApp.getConfigBuilder().storeSettings("ChangingDanaRv2Driver");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return; return;
@ -68,18 +68,18 @@ public class MsgCheckValue_v2 extends MessageBase {
MainApp.bus().post(new EventNewNotification(notification)); MainApp.bus().post(new EventNewNotification(notification));
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model"); DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
log.debug("Wrong model selected. Switching to non APS DanaR"); log.debug("Wrong model selected. Switching to non APS DanaR");
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginBase.PUMP, false); (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginType.PUMP, false);
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentVisible(PluginBase.PUMP, false); (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentVisible(PluginType.PUMP, false);
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PUMP, true); (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PUMP, true);
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentVisible(PluginBase.PUMP, true); (MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentVisible(PluginType.PUMP, true);
//If profile coming from pump, switch it as well //If profile coming from pump, switch it as well
if(MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginBase.PROFILE)){ if (MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PROFILE)) {
(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginBase.PROFILE, false); (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginType.PROFILE, false);
(MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, true);
} }
MainApp.getConfigBuilder().storeSettings(); MainApp.getConfigBuilder().storeSettings("ChangingDanaRv2Driver");
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return; return;

View file

@ -25,6 +25,8 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
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.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
@ -74,21 +76,27 @@ import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache
*/ */
@SuppressWarnings("AccessStaticViaInstance") @SuppressWarnings("AccessStaticViaInstance")
public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInterface { public class InsightPlugin extends PluginBase implements PumpInterface, ConstraintsInterface {
private static volatile InsightPlugin plugin;
public static InsightPlugin getPlugin() {
if (plugin == null) {
plugin = new InsightPlugin();
}
return plugin;
}
private static final long BUSY_WAIT_TIME = 20000; private static final long BUSY_WAIT_TIME = 20000;
static Integer batteryPercent = 0; private static Integer batteryPercent = 0;
static Integer reservoirInUnits = 0; private static Integer reservoirInUnits = 0;
static boolean initialized = false; private static boolean initialized = false;
private static volatile boolean update_pending = false; private static volatile boolean update_pending = false;
private static Logger log = LoggerFactory.getLogger(InsightPlugin.class); private static Logger log = LoggerFactory.getLogger(InsightPlugin.class);
private static volatile InsightPlugin plugin;
private final InsightAsyncAdapter async = new InsightAsyncAdapter(); private final InsightAsyncAdapter async = new InsightAsyncAdapter();
private StatusTaskRunner.Result statusResult; private StatusTaskRunner.Result statusResult;
private long statusResultTime = -1; private long statusResultTime = -1;
private Date lastDataTime = new Date(0); private Date lastDataTime = new Date(0);
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private boolean fauxTBRcancel = true; private boolean fauxTBRcancel = true;
private PumpDescription pumpDescription = new PumpDescription(); private PumpDescription pumpDescription = new PumpDescription();
private double basalRate = 0; private double basalRate = 0;
@ -97,6 +105,13 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte
private List<BRProfileBlock.ProfileBlock> profileBlocks; private List<BRProfileBlock.ProfileBlock> profileBlocks;
private InsightPlugin() { private InsightPlugin() {
super(new PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(InsightFragment.class.getName())
.pluginName(R.string.insightpump)
.shortName(R.string.insightpump_shortname)
.preferencesId(R.xml.pref_insightpump)
);
log("InsightPlugin instantiated"); log("InsightPlugin instantiated");
pumpDescription.isBolusCapable = true; pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.05d; // specification says 0.05U up to 2U then 0.1U @ 2-5U 0.2U @ 10-20U 0.5U 10-20U (are these just UI restrictions?) pumpDescription.bolusStep = 0.05d; // specification says 0.05U up to 2U then 0.1U @ 2-5U 0.2U @ 10-20U 0.5U 10-20U (are these just UI restrictions?)
@ -129,20 +144,6 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte
} }
public static InsightPlugin getPlugin() {
if (plugin == null) {
createInstance();
}
return plugin;
}
private static synchronized void createInstance() {
if (plugin == null) {
log("creating instance");
plugin = new InsightPlugin();
}
}
// just log during debugging // just log during debugging
private static void log(String msg) { private static void log(String msg) {
android.util.Log.e("INSIGHTPUMP", msg); android.util.Log.e("INSIGHTPUMP", msg);
@ -157,7 +158,8 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte
MainApp.bus().post(e); MainApp.bus().post(e);
} }
private void enableConnector() { @Override
protected void onStart() {
if (!connector_enabled) { if (!connector_enabled) {
synchronized (this) { synchronized (this) {
if (!connector_enabled) { if (!connector_enabled) {
@ -170,7 +172,7 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte
} }
} }
private void disableConnector() { protected void onStop() {
if (connector_enabled) { if (connector_enabled) {
synchronized (this) { synchronized (this) {
if (connector_enabled) { if (connector_enabled) {
@ -182,81 +184,6 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte
} }
} }
@Override
public String getFragmentClass() {
return InsightFragment.class.getName();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.insightpump);
}
@Override
public String getNameShort() {
String name = MainApp.instance().getString(R.string.insightpump_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
if (type == PluginBase.PUMP) return fragmentEnabled;
else if (type == PluginBase.CONSTRAINTS) return fragmentEnabled;
return false;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PUMP && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return type == PUMP;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PUMP) {
if (fragmentEnabled) {
enableConnector();
} else {
disableConnector();
}
this.fragmentEnabled = fragmentEnabled;
}
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PUMP) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_insightpump;
}
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override @Override
public boolean isFakingTempsByExtendedBoluses() { public boolean isFakingTempsByExtendedBoluses() {
return false; return false;
@ -593,7 +520,6 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte
PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(true).duration(durationInMinutes); PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(true).duration(durationInMinutes);
pumpEnactResult.percent = percent_amount; pumpEnactResult.percent = percent_amount;
pumpEnactResult.success = ms.success(); pumpEnactResult.success = ms.success();
pumpEnactResult.isTempCancel = percent_amount == 100; // 100% temp basal is a cancellation
pumpEnactResult.comment = ms.getCommandComment(); pumpEnactResult.comment = ms.getCommandComment();
@ -644,7 +570,6 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte
PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(true).duration(durationInMinutes); PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(true).duration(durationInMinutes);
pumpEnactResult.percent = percent; pumpEnactResult.percent = percent;
pumpEnactResult.success = ms.success(); pumpEnactResult.success = ms.success();
pumpEnactResult.isTempCancel = percent == 100; // 100% temp basal is a cancellation
pumpEnactResult.comment = ms.getCommandComment(); pumpEnactResult.comment = ms.getCommandComment();
if (pumpEnactResult.success) { if (pumpEnactResult.success) {

View file

@ -15,6 +15,8 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
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.utils.DateUtil; import info.nightscout.utils.DateUtil;
@ -22,14 +24,9 @@ import info.nightscout.utils.DateUtil;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class MDIPlugin implements PluginBase, PumpInterface { public class MDIPlugin extends PluginBase implements PumpInterface {
private static Logger log = LoggerFactory.getLogger(MDIPlugin.class); private static Logger log = LoggerFactory.getLogger(MDIPlugin.class);
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private PumpDescription pumpDescription = new PumpDescription();
private static MDIPlugin plugin = null; private static MDIPlugin plugin = null;
public static MDIPlugin getPlugin() { public static MDIPlugin getPlugin() {
@ -38,7 +35,13 @@ public class MDIPlugin implements PluginBase, PumpInterface {
return plugin; return plugin;
} }
private PumpDescription pumpDescription = new PumpDescription();
private MDIPlugin() { private MDIPlugin() {
super(new PluginDescription()
.mainType(PluginType.PUMP)
.pluginName(R.string.mdi)
);
pumpDescription.isBolusCapable = true; pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.5d; pumpDescription.bolusStep = 0.5d;
@ -48,67 +51,6 @@ public class MDIPlugin implements PluginBase, PumpInterface {
pumpDescription.isRefillingCapable = false; pumpDescription.isRefillingCapable = false;
} }
@Override
public String getFragmentClass() {
return null;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.mdi);
}
@Override
public String getNameShort() {
// use long name as fallback (not visible in tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == PUMP && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return false;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PUMP) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PUMP) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override @Override
public boolean isFakingTempsByExtendedBoluses() { public boolean isFakingTempsByExtendedBoluses() {
return false; return false;

View file

@ -20,6 +20,8 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
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.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
@ -34,19 +36,23 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class VirtualPumpPlugin implements PluginBase, PumpInterface { public class VirtualPumpPlugin extends PluginBase implements PumpInterface {
private static Logger log = LoggerFactory.getLogger(VirtualPumpPlugin.class); private static Logger log = LoggerFactory.getLogger(VirtualPumpPlugin.class);
public static Double defaultBasalValue = 0.2d; private static VirtualPumpPlugin plugin = null;
public static VirtualPumpPlugin getPlugin() {
loadFakingStatus();
if (plugin == null)
plugin = new VirtualPumpPlugin();
return plugin;
}
static Integer batteryPercent = 50; static Integer batteryPercent = 50;
static Integer reservoirInUnits = 50; static Integer reservoirInUnits = 50;
private Date lastDataTime = new Date(0); private Date lastDataTime = new Date(0);
private boolean fragmentEnabled = true;
private boolean fragmentVisible = true;
private static boolean fromNSAreCommingFakedExtendedBoluses = false; private static boolean fromNSAreCommingFakedExtendedBoluses = false;
private PumpDescription pumpDescription = new PumpDescription(); private PumpDescription pumpDescription = new PumpDescription();
@ -64,16 +70,14 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
return fromNSAreCommingFakedExtendedBoluses; return fromNSAreCommingFakedExtendedBoluses;
} }
private static VirtualPumpPlugin plugin = null;
public static VirtualPumpPlugin getPlugin() {
loadFakingStatus();
if (plugin == null)
plugin = new VirtualPumpPlugin();
return plugin;
}
public VirtualPumpPlugin() { public VirtualPumpPlugin() {
super(new PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(VirtualPumpFragment.class.getName())
.pluginName(R.string.virtualpump)
.shortName(R.string.virtualpump_shortname)
.preferencesId(R.xml.pref_virtualpump)
);
pumpDescription.isBolusCapable = true; pumpDescription.isBolusCapable = true;
pumpDescription.bolusStep = 0.1d; pumpDescription.bolusStep = 0.1d;
@ -104,72 +108,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
pumpDescription.is30minBasalRatesCapable = true; pumpDescription.is30minBasalRatesCapable = true;
} }
@Override
public String getFragmentClass() {
return VirtualPumpFragment.class.getName();
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.virtualpump);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.virtualpump_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == PUMP && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == PUMP && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == PUMP) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == PUMP) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_virtualpump;
}
@Override
public int getType() {
return PluginBase.PUMP;
}
@Override @Override
public boolean isFakingTempsByExtendedBoluses() { public boolean isFakingTempsByExtendedBoluses() {
return (Config.NSCLIENT || Config.G5UPLOADER) && fromNSAreCommingFakedExtendedBoluses; return (Config.NSCLIENT || Config.G5UPLOADER) && fromNSAreCommingFakedExtendedBoluses;

View file

@ -16,6 +16,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
@ -28,12 +30,9 @@ import info.nightscout.utils.SafeParse;
* Created by mike on 24.06.2017. * Created by mike on 24.06.2017.
*/ */
public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{ public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInterface{
private static Logger log = LoggerFactory.getLogger(SensitivityAAPSPlugin.class); private static Logger log = LoggerFactory.getLogger(SensitivityAAPSPlugin.class);
private boolean fragmentEnabled = true;
private boolean fragmentVisible = false;
static SensitivityAAPSPlugin plugin = null; static SensitivityAAPSPlugin plugin = null;
public static SensitivityAAPSPlugin getPlugin() { public static SensitivityAAPSPlugin getPlugin() {
@ -42,67 +41,15 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{
return plugin; return plugin;
} }
@Override public SensitivityAAPSPlugin() {
public int getType() { super(new PluginDescription()
return SENSITIVITY; .mainType(PluginType.SENSITIVITY)
.pluginName(R.string.sensitivityaaps)
.shortName(R.string.sensitivity_shortname)
.preferencesId(R.xml.pref_absorption_aaps)
);
} }
@Override
public String getFragmentClass() {
return null;
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.sensitivityaaps);
}
@Override
public String getNameShort() {
return MainApp.sResources.getString(R.string.sensitivity_shortname);
}
@Override
public boolean isEnabled(int type) {
return type == SENSITIVITY && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == SENSITIVITY && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == SENSITIVITY) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_absorption_aaps;
}
@Override @Override
public AutosensResult detectSensitivity(long fromTime, long toTime) { public AutosensResult detectSensitivity(long fromTime, long toTime) {
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable();

View file

@ -15,6 +15,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
@ -27,12 +29,9 @@ import info.nightscout.utils.SafeParse;
* Created by mike on 24.06.2017. * Created by mike on 24.06.2017.
*/ */
public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface { public class SensitivityOref0Plugin extends PluginBase implements SensitivityInterface {
private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class); private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class);
private boolean fragmentEnabled = true;
private boolean fragmentVisible = false;
static SensitivityOref0Plugin plugin = null; static SensitivityOref0Plugin plugin = null;
public static SensitivityOref0Plugin getPlugin() { public static SensitivityOref0Plugin getPlugin() {
@ -41,76 +40,24 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface
return plugin; return plugin;
} }
@Override public SensitivityOref0Plugin() {
public int getType() { super(new PluginDescription()
return SENSITIVITY; .mainType(PluginType.SENSITIVITY)
.pluginName(R.string.sensitivityoref0)
.shortName(R.string.sensitivity_shortname)
.preferencesId(R.xml.pref_absorption_oref0)
);
} }
@Override
public String getFragmentClass() {
return null;
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.sensitivityoref0);
}
@Override
public String getNameShort() {
return MainApp.sResources.getString(R.string.sensitivity_shortname);
}
@Override
public boolean isEnabled(int type) {
return type == SENSITIVITY && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == SENSITIVITY && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == SENSITIVITY) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_absorption_oref0;
}
@Override @Override
public AutosensResult detectSensitivity(long fromTime, long toTime) { public AutosensResult detectSensitivity(long fromTime, long toTime) {
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable();
String age = SP.getString(R.string.key_age, ""); String age = SP.getString(R.string.key_age, "");
int defaultHours = 24; int defaultHours = 24;
if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; if (age.equals(MainApp.gs(R.string.key_adult))) defaultHours = 24;
if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 24; if (age.equals(MainApp.gs(R.string.key_teenage))) defaultHours = 24;
if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 24; if (age.equals(MainApp.gs(R.string.key_child))) defaultHours = 24;
int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();

View file

@ -12,6 +12,8 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.SensitivityInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
@ -24,12 +26,9 @@ import info.nightscout.utils.SafeParse;
* Created by mike on 24.06.2017. * Created by mike on 24.06.2017.
*/ */
public class SensitivityWeightedAveragePlugin implements PluginBase, SensitivityInterface { public class SensitivityWeightedAveragePlugin extends PluginBase implements SensitivityInterface {
private static Logger log = LoggerFactory.getLogger(SensitivityWeightedAveragePlugin.class); private static Logger log = LoggerFactory.getLogger(SensitivityWeightedAveragePlugin.class);
private boolean fragmentEnabled = true;
private boolean fragmentVisible = false;
private static SensitivityWeightedAveragePlugin plugin = null; private static SensitivityWeightedAveragePlugin plugin = null;
public static SensitivityWeightedAveragePlugin getPlugin() { public static SensitivityWeightedAveragePlugin getPlugin() {
@ -38,67 +37,15 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
return plugin; return plugin;
} }
@Override public SensitivityWeightedAveragePlugin() {
public int getType() { super(new PluginDescription()
return SENSITIVITY; .mainType(PluginType.SENSITIVITY)
.pluginName(R.string.sensitivityweightedaverage)
.shortName(R.string.sensitivity_shortname)
.preferencesId(R.xml.pref_absorption_aaps)
);
} }
@Override
public String getFragmentClass() {
return null;
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.sensitivityweightedaverage);
}
@Override
public String getNameShort() {
return MainApp.sResources.getString(R.string.sensitivity_shortname);
}
@Override
public boolean isEnabled(int type) {
return type == SENSITIVITY && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == SENSITIVITY && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == SENSITIVITY) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == SENSITIVITY) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_absorption_aaps;
}
@Override @Override
public AutosensResult detectSensitivity(long fromTime, long toTime) { public AutosensResult detectSensitivity(long fromTime, long toTime) {
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable();

View file

@ -31,6 +31,8 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
@ -49,7 +51,7 @@ import info.nightscout.utils.XdripCalibrations;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class SmsCommunicatorPlugin implements PluginBase { public class SmsCommunicatorPlugin extends PluginBase {
private static Logger log = LoggerFactory.getLogger(SmsCommunicatorPlugin.class); private static Logger log = LoggerFactory.getLogger(SmsCommunicatorPlugin.class);
private static SmsCommunicatorPlugin smsCommunicatorPlugin; private static SmsCommunicatorPlugin smsCommunicatorPlugin;
@ -62,11 +64,6 @@ public class SmsCommunicatorPlugin implements PluginBase {
return smsCommunicatorPlugin; return smsCommunicatorPlugin;
} }
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private final long CONFIRM_TIMEOUT = 5 * 60 * 1000L;
private List<String> allowedNumbers = new ArrayList<>(); private List<String> allowedNumbers = new ArrayList<>();
class Sms { class Sms {
@ -120,78 +117,28 @@ public class SmsCommunicatorPlugin implements PluginBase {
ArrayList<Sms> messages = new ArrayList<>(); ArrayList<Sms> messages = new ArrayList<>();
private SmsCommunicatorPlugin() { private SmsCommunicatorPlugin() {
MainApp.bus().register(this); super(new PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(SmsCommunicatorFragment.class.getName())
.pluginName(R.string.smscommunicator)
.shortName(R.string.smscommunicator_shortname)
.preferencesId(R.xml.pref_smscommunicator)
);
processSettings(null); processSettings(null);
} }
@Override @Override
public String getFragmentClass() { protected void onStart() {
return SmsCommunicatorFragment.class.getName(); MainApp.bus().register(this);
} }
@Override @Override
public int getType() { protected void onStop() {
return PluginBase.GENERAL; MainApp.bus().unregister(this);
}
@Override
public String getName() {
return MainApp.sResources.getString(R.string.smscommunicator);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.smscommunicator_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == GENERAL) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_smscommunicator;
} }
@Subscribe @Subscribe
public void processSettings(final EventPreferenceChange ev) { private void processSettings(final EventPreferenceChange ev) {
if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) { if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, ""); String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");
@ -217,15 +164,17 @@ public class SmsCommunicatorPlugin implements PluginBase {
public void onStatusEvent(final EventNewSMS ev) { public void onStatusEvent(final EventNewSMS ev) {
Object[] pdus = (Object[]) ev.bundle.get("pdus"); Object[] pdus = (Object[]) ev.bundle.get("pdus");
if (pdus != null) {
// For every SMS message received // For every SMS message received
for (Object pdu : pdus) { for (Object pdu : pdus) {
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu); SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu);
processSms(new Sms(message)); processSms(new Sms(message));
} }
} }
}
private void processSms(final Sms receivedSms) { private void processSms(final Sms receivedSms) {
if (!isEnabled(PluginBase.GENERAL)) { if (!isEnabled(PluginType.GENERAL)) {
log.debug("Ignoring SMS. Plugin disabled."); log.debug("Ignoring SMS. Plugin disabled.");
return; return;
} }
@ -240,10 +189,10 @@ public class SmsCommunicatorPlugin implements PluginBase {
log.debug(receivedSms.toString()); log.debug(receivedSms.toString());
String[] splited = receivedSms.text.split("\\s+"); String[] splited = receivedSms.text.split("\\s+");
Double amount = 0d; Double amount;
Double tempBasal = 0d; Double tempBasal;
int duration = 0; int duration = 0;
String passCode = ""; String passCode;
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
if (splited.length > 0) { if (splited.length > 0) {
@ -284,8 +233,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
case "DISABLE": case "DISABLE":
case "STOP": case "STOP":
LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) { if (loopPlugin != null && loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.setPluginEnabled(PluginBase.LOOP, false); loopPlugin.setPluginEnabled(PluginType.LOOP, false);
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
public void run() { public void run() {
@ -302,8 +251,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
case "ENABLE": case "ENABLE":
case "START": case "START":
loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
if (loopPlugin != null && !loopPlugin.isEnabled(PluginBase.LOOP)) { if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.setPluginEnabled(PluginBase.LOOP, true); loopPlugin.setPluginEnabled(PluginType.LOOP, true);
reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeenenabled); reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeenenabled);
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START")); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START"));
@ -314,7 +263,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
case "STATUS": case "STATUS":
loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
if (loopPlugin != null) { if (loopPlugin != null) {
if (loopPlugin.isEnabled(PluginBase.LOOP)) { if (loopPlugin.isEnabled(PluginType.LOOP)) {
if (loopPlugin.isSuspended()) if (loopPlugin.isSuspended())
reply = String.format(MainApp.sResources.getString(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()); reply = String.format(MainApp.sResources.getString(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend());
else else
@ -489,7 +438,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
break; break;
default: // expect passCode here default: // expect passCode here
if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed && if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed &&
bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - bolusWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) {
bolusWaitingForConfirmation.processed = true; bolusWaitingForConfirmation.processed = true;
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested; detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested;
@ -513,7 +462,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
} }
}); });
} else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed && } else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed &&
tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - tempBasalWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) {
tempBasalWaitingForConfirmation.processed = true; tempBasalWaitingForConfirmation.processed = true;
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile != null) if (profile != null)
@ -532,7 +481,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
} }
}); });
} else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed && } else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed &&
cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - cancelTempBasalWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) {
cancelTempBasalWaitingForConfirmation.processed = true; cancelTempBasalWaitingForConfirmation.processed = true;
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override
@ -549,7 +498,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
} }
}); });
} else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed && } else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed &&
calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - calibrationWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) {
calibrationWaitingForConfirmation.processed = true; calibrationWaitingForConfirmation.processed = true;
boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested); boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested);
if (result) { if (result) {
@ -560,7 +509,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
} }
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed && } else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && System.currentTimeMillis() - suspendWaitingForConfirmation.date.getTime() < Constants.SMS_CONFIRM_TIMEOUT) {
suspendWaitingForConfirmation.processed = true; suspendWaitingForConfirmation.processed = true;
ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() {
@Override @Override

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.SourceDexcomG5; package info.nightscout.androidaps.plugins.Source;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -25,8 +25,6 @@ import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.UploadQueue;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;

View file

@ -0,0 +1,43 @@
package info.nightscout.androidaps.plugins.Source;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/**
* Created by mike on 28.11.2017.
*/
public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterface {
private static SourceDexcomG5Plugin plugin = null;
public static SourceDexcomG5Plugin getPlugin() {
if (plugin == null)
plugin = new SourceDexcomG5Plugin();
return plugin;
}
private SourceDexcomG5Plugin() {
super(new PluginDescription()
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.DexcomG5)
.shortName(R.string.dexcomG5_shortname)
.preferencesId(R.xml.pref_dexcomg5)
);
}
@Override
public boolean specialShowInListCondition() {
return !Config.G5UPLOADER;
}
@Override
public boolean advancedFilteringSupported() {
return true;
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.Source;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/**
* Created by mike on 05.08.2016.
*/
public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface {
private static SourceGlimpPlugin plugin = null;
public static SourceGlimpPlugin getPlugin() {
if (plugin == null)
plugin = new SourceGlimpPlugin();
return plugin;
}
private SourceGlimpPlugin() {
super(new PluginDescription()
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.Glimp)
);
}
@Override
public boolean advancedFilteringSupported() {
return false;
}
}

View file

@ -0,0 +1,33 @@
package info.nightscout.androidaps.plugins.Source;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/**
* Created by mike on 05.08.2016.
*/
public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface {
private static SourceMM640gPlugin plugin = null;
public static SourceMM640gPlugin getPlugin() {
if (plugin == null)
plugin = new SourceMM640gPlugin();
return plugin;
}
private SourceMM640gPlugin() {
super(new PluginDescription()
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.MM640g)
);
}
@Override
public boolean advancedFilteringSupported() {
return false;
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.Source;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/**
* Created by mike on 05.08.2016.
*/
public class SourceNSClientPlugin extends PluginBase implements BgSourceInterface {
private static SourceNSClientPlugin plugin = null;
public static SourceNSClientPlugin getPlugin() {
if (plugin == null)
plugin = new SourceNSClientPlugin();
return plugin;
}
private SourceNSClientPlugin() {
super(new PluginDescription()
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.nsclientbg)
);
}
@Override
public boolean advancedFilteringSupported() {
return true;
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.Source;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
/**
* Created by mike on 05.08.2016.
*/
public class SourceXdripPlugin extends PluginBase implements BgSourceInterface {
private static SourceXdripPlugin plugin = null;
public static SourceXdripPlugin getPlugin() {
if (plugin == null)
plugin = new SourceXdripPlugin();
return plugin;
}
private SourceXdripPlugin() {
super(new PluginDescription()
.mainType(PluginType.BGSOURCE)
.fragmentClass(BGSourceFragment.class.getName())
.pluginName(R.string.xdrip)
);
}
@Override
public boolean advancedFilteringSupported() {
return false;
}
}

View file

@ -1,89 +0,0 @@
package info.nightscout.androidaps.plugins.SourceDexcomG5;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
/**
* Created by mike on 28.11.2017.
*/
public class SourceDexcomG5Plugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceDexcomG5Plugin plugin = null;
public static SourceDexcomG5Plugin getPlugin() {
if (plugin == null)
plugin = new SourceDexcomG5Plugin();
return plugin;
}
@Override
public String getFragmentClass() {
return BGSourceFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.BGSOURCE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.DexcomG5);
}
@Override
public String getNameShort() {
return MainApp.gs(R.string.dexcomG5_shortname);
}
@Override
public boolean isEnabled(int type) {
return Config.G5UPLOADER || type == BGSOURCE && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return Config.G5UPLOADER || type == BGSOURCE && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return !Config.G5UPLOADER;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return R.xml.pref_dexcomg5;
}
@Override
public boolean advancedFilteringSupported() {
return true;
}
}

View file

@ -1,90 +0,0 @@
package info.nightscout.androidaps.plugins.SourceGlimp;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/**
* Created by mike on 05.08.2016.
*/
public class SourceGlimpPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceGlimpPlugin plugin = null;
public static SourceGlimpPlugin getPlugin() {
if (plugin == null)
plugin = new SourceGlimpPlugin();
return plugin;
}
@Override
public String getFragmentClass() {
return BGSourceFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.BGSOURCE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.Glimp);
}
@Override
public String getNameShort() {
// use long name as fallback (no tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == BGSOURCE && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == BGSOURCE && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public boolean advancedFilteringSupported() {
return false;
}
}

View file

@ -1,90 +0,0 @@
package info.nightscout.androidaps.plugins.SourceMM640g;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/**
* Created by mike on 05.08.2016.
*/
public class SourceMM640gPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceMM640gPlugin plugin = null;
public static SourceMM640gPlugin getPlugin() {
if (plugin == null)
plugin = new SourceMM640gPlugin();
return plugin;
}
@Override
public String getFragmentClass() {
return BGSourceFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.BGSOURCE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.MM640g);
}
@Override
public String getNameShort() {
// use long name as fallback (no tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == BGSOURCE && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == BGSOURCE && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public boolean advancedFilteringSupported() {
return false;
}
}

View file

@ -1,92 +0,0 @@
package info.nightscout.androidaps.plugins.SourceNSClient;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/**
* Created by mike on 05.08.2016.
*/
public class SourceNSClientPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = true;
private boolean fragmentVisible = false;
private static SourceNSClientPlugin plugin = null;
public static SourceNSClientPlugin getPlugin() {
if (plugin == null)
plugin = new SourceNSClientPlugin();
return plugin;
}
@Override
public String getFragmentClass() {
return BGSourceFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.BGSOURCE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.nsclientbg);
}
@Override
public String getNameShort() {
// use long name as fallback (not visible in tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return Config.NSCLIENT || type == BGSOURCE && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == BGSOURCE && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return !Config.NSCLIENT;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public boolean advancedFilteringSupported() {
return true;
}
}

View file

@ -1,91 +0,0 @@
package info.nightscout.androidaps.plugins.SourceXdrip;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.BgSourceInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment;
/**
* Created by mike on 05.08.2016.
*/
public class SourceXdripPlugin implements PluginBase, BgSourceInterface {
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
private static SourceXdripPlugin plugin = null;
public static SourceXdripPlugin getPlugin() {
if (plugin == null)
plugin = new SourceXdripPlugin();
return plugin;
}
@Override
public String getFragmentClass() {
return BGSourceFragment.class.getName();
}
@Override
public int getType() {
return PluginBase.BGSOURCE;
}
@Override
public String getName() {
return MainApp.instance().getString(R.string.xdrip);
}
@Override
public String getNameShort() {
// use long name as fallback (no tabs)
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == BGSOURCE && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == BGSOURCE && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == BGSOURCE) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == BGSOURCE) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public boolean advancedFilteringSupported() {
return false;
}
}

View file

@ -34,6 +34,8 @@ import info.nightscout.androidaps.events.EventReloadTempBasalData;
import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventReloadTreatmentData;
import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.events.EventTempTargetChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
@ -43,7 +45,7 @@ import info.nightscout.utils.SP;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
*/ */
public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface {
private static Logger log = LoggerFactory.getLogger(TreatmentsPlugin.class); private static Logger log = LoggerFactory.getLogger(TreatmentsPlugin.class);
private static TreatmentsPlugin treatmentsPlugin; private static TreatmentsPlugin treatmentsPlugin;
@ -63,76 +65,24 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
private final static Intervals<TempTarget> tempTargets = new OverlappingIntervals<>(); private final static Intervals<TempTarget> tempTargets = new OverlappingIntervals<>();
private final static ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>(); private final static ProfileIntervals<ProfileSwitch> profiles = new ProfileIntervals<>();
private boolean fragmentEnabled = true; public TreatmentsPlugin() {
private boolean fragmentVisible = true; super(new PluginDescription()
.mainType(PluginType.TREATMENT)
@Override .fragmentClass(TreatmentsFragment.class.getName())
public String getFragmentClass() { .pluginName(R.string.treatments)
return TreatmentsFragment.class.getName(); .shortName(R.string.treatments_shortname)
.preferencesId(R.xml.pref_absorption_oref0)
.alwaysEnabled(true)
);
} }
@Override @Override
public String getName() { public boolean specialShowInListCondition() {
return MainApp.instance().getString(R.string.treatments);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.treatments_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == TREATMENT && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == TREATMENT && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return !Config.NSCLIENT && !Config.G5UPLOADER; return !Config.NSCLIENT && !Config.G5UPLOADER;
} }
@Override @Override
public void setPluginEnabled(int type, boolean fragmentEnabled) { protected void onStart() {
if (type == TREATMENT) this.fragmentEnabled = fragmentEnabled;
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
if (type == TREATMENT) this.fragmentVisible = fragmentVisible;
}
@Override
public int getPreferencesId() {
return -1;
}
@Override
public int getType() {
return PluginBase.TREATMENT;
}
private TreatmentsPlugin() {
MainApp.bus().register(this); MainApp.bus().register(this);
initializeTempBasalData(); initializeTempBasalData();
initializeTreatmentData(); initializeTreatmentData();
@ -141,6 +91,11 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
initializeProfileSwitchData(); initializeProfileSwitchData();
} }
@Override
protected void onStop() {
MainApp.bus().register(this);
}
private static void initializeTreatmentData() { private static void initializeTreatmentData() {
double dia = Constants.defaultDIA; double dia = Constants.defaultDIA;
if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null) if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null)

View file

@ -5,12 +5,10 @@ import android.content.Intent;
import com.squareup.otto.Subscribe; import com.squareup.otto.Subscribe;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.events.EventBolusRequested;
import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventLoop;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
@ -18,6 +16,8 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
@ -29,7 +29,7 @@ import info.nightscout.utils.SP;
* Created by adrian on 17/11/16. * Created by adrian on 17/11/16.
*/ */
public class WearPlugin implements PluginBase { public class WearPlugin extends PluginBase {
private static boolean fragmentEnabled = false; private static boolean fragmentEnabled = false;
private boolean fragmentVisible = false; private boolean fragmentVisible = false;
@ -41,6 +41,7 @@ public class WearPlugin implements PluginBase {
public static WearPlugin getPlugin() { public static WearPlugin getPlugin() {
return wearPlugin; return wearPlugin;
} }
public static WearPlugin initPlugin(Context ctx) { public static WearPlugin initPlugin(Context ctx) {
if (wearPlugin == null) { if (wearPlugin == null) {
@ -51,79 +52,27 @@ public class WearPlugin implements PluginBase {
} }
WearPlugin(Context ctx) { WearPlugin(Context ctx) {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(WearFragment.class.getName())
.pluginName(R.string.wear)
.shortName(R.string.wear_shortname)
.preferencesId(R.xml.pref_wear)
);
this.ctx = ctx; this.ctx = ctx;
}
@Override
protected void onStart() {
MainApp.bus().register(this); MainApp.bus().register(this);
}
@Override
public int getType() {
return PluginBase.GENERAL;
}
@Override
public String getFragmentClass() {
return WearFragment.class.getName();
}
@Override
public String getName() {
return ctx.getString(R.string.wear);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.wear_shortname);
if (!name.trim().isEmpty()){
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return type == GENERAL && fragmentVisible;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return true;
}
@Override
public boolean showInList(int type) {
return true;
}
@Override
public void setPluginEnabled(int type, boolean fragmentEnabled) {
if (type == GENERAL) {
this.fragmentEnabled = fragmentEnabled;
if (watchUS != null) { if (watchUS != null) {
watchUS.setSettings(); watchUS.setSettings();
} }
} }
}
@Override @Override
public void setFragmentVisible(int type, boolean fragmentVisible) { protected void onStop() {
if (type == GENERAL) this.fragmentVisible = fragmentVisible; MainApp.bus().unregister(this);
}
@Override
public int getPreferencesId() {
return R.xml.pref_wear;
} }
private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) { private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) {
@ -171,7 +120,7 @@ public class WearPlugin implements PluginBase {
} }
@Subscribe @Subscribe
public void onStatusEvent(final EventOpenAPSUpdateGui ev){ public void onStatusEvent(final EventOpenAPSUpdateGui ev) {
sendDataToWatch(true, true, false); sendDataToWatch(true, true, false);
} }
@ -196,7 +145,7 @@ public class WearPlugin implements PluginBase {
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
if (activeloop == null) return; if (activeloop == null) return;
if(WatchUpdaterService.shouldReportLoopStatus(activeloop.isEnabled(PluginBase.LOOP))) { if (WatchUpdaterService.shouldReportLoopStatus(activeloop.isEnabled(PluginType.LOOP))) {
sendDataToWatch(true, false, false); sendDataToWatch(true, false, false);
} }
} }
@ -204,7 +153,7 @@ public class WearPlugin implements PluginBase {
@Subscribe @Subscribe
public void onStatusEvent(final EventOverviewBolusProgress ev) { public void onStatusEvent(final EventOverviewBolusProgress ev) {
if(!ev.isSMB()||SP.getBoolean("wear_notifySMB", true)) { if (!ev.isSMB() || SP.getBoolean("wear_notifySMB", true)) {
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS); Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_BOLUSPROGRESS);
intent.putExtra("progresspercent", ev.percent); intent.putExtra("progresspercent", ev.percent);
intent.putExtra("progressstatus", ev.status); intent.putExtra("progressstatus", ev.status);
@ -224,10 +173,10 @@ public class WearPlugin implements PluginBase {
@Subscribe @Subscribe
public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) {
if(ev.result == null) return; if (ev.result == null) return;
String status; String status;
if(ev.result.success){ if (ev.result.success) {
status = MainApp.sResources.getString(R.string.success); status = MainApp.sResources.getString(R.string.success);
} else { } else {
status = MainApp.sResources.getString(R.string.nosuccess); status = MainApp.sResources.getString(R.string.nosuccess);
@ -238,7 +187,7 @@ public class WearPlugin implements PluginBase {
ctx.startService(intent); ctx.startService(intent);
} }
public void requestActionConfirmation(String title, String message, String actionstring){ public void requestActionConfirmation(String title, String message, String actionstring) {
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_ACTIONCONFIRMATIONREQUEST); Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_ACTIONCONFIRMATIONREQUEST);
intent.putExtra("title", title); intent.putExtra("title", title);

View file

@ -21,15 +21,11 @@ import com.google.android.gms.wearable.PutDataRequest;
import com.google.android.gms.wearable.Wearable; import com.google.android.gms.wearable.Wearable;
import com.google.android.gms.wearable.WearableListenerService; import com.google.android.gms.wearable.WearableListenerService;
import org.mozilla.javascript.tools.jsc.Main;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
@ -42,11 +38,11 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSDeviceStatus;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
@ -290,7 +286,7 @@ public class WatchUpdaterService extends WearableListenerService implements
deltastring += DecimalFormatter.to0Decimal(Math.abs(deltaMGDL)); deltastring += DecimalFormatter.to0Decimal(Math.abs(deltaMGDL));
} }
} else { } else {
if (detailed){ if (detailed) {
deltastring += DecimalFormatter.to2Decimal(Math.abs(deltaMMOL)); deltastring += DecimalFormatter.to2Decimal(Math.abs(deltaMMOL));
} else { } else {
deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMMOL)); deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMMOL));
@ -366,8 +362,6 @@ public class WatchUpdaterService extends WearableListenerService implements
ArrayList<DataMap> predictions = new ArrayList<>(); ArrayList<DataMap> predictions = new ArrayList<>();
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) { if (profile == null) {
@ -469,15 +463,15 @@ public class WatchUpdaterService extends WearableListenerService implements
} }
List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory(); List<Treatment> treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory();
for (Treatment treatment:treatments) { for (Treatment treatment : treatments) {
if(treatment.date > startTimeWindow){ if (treatment.date > startTimeWindow) {
boluses.add(treatmentMap(treatment.date, treatment.insulin, treatment.carbs, treatment.isSMB, treatment.isValid)); boluses.add(treatmentMap(treatment.date, treatment.insulin, treatment.carbs, treatment.isSMB, treatment.isValid));
} }
} }
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
if(SP.getBoolean("wear_predictions", true) && finalLastRun != null && finalLastRun.request.hasPredictions && finalLastRun.constraintsProcessed != null){ if (SP.getBoolean("wear_predictions", true) && finalLastRun != null && finalLastRun.request.hasPredictions && finalLastRun.constraintsProcessed != null) {
List<BgReading> predArray = finalLastRun.constraintsProcessed.getPredictions(); List<BgReading> predArray = finalLastRun.constraintsProcessed.getPredictions();
if (!predArray.isEmpty()) { if (!predArray.isEmpty()) {
@ -587,7 +581,7 @@ public class WatchUpdaterService extends WearableListenerService implements
String status = MainApp.instance().getString(R.string.noprofile); String status = MainApp.instance().getString(R.string.noprofile);
String iobSum, iobDetail, cobString, currentBasal, bgiString; String iobSum, iobDetail, cobString, currentBasal, bgiString;
iobSum = iobDetail = cobString = currentBasal = bgiString = ""; iobSum = iobDetail = cobString = currentBasal = bgiString = "";
if(profile!=null) { if (profile != null) {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
treatmentsInterface.updateTotalIOBTreatments(); treatmentsInterface.updateTotalIOBTreatments();
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round(); IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
@ -605,7 +599,7 @@ public class WatchUpdaterService extends WearableListenerService implements
double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf(); double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf();
bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to1Decimal(bgi); bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to1Decimal(bgi);
status = generateStatusString(profile, currentBasal,iobSum, iobDetail, bgiString); status = generateStatusString(profile, currentBasal, iobSum, iobDetail, bgiString);
} }
@ -616,9 +610,9 @@ public class WatchUpdaterService extends WearableListenerService implements
long openApsStatus = -1; long openApsStatus = -1;
//OpenAPS status //OpenAPS status
if(Config.APS){ if (Config.APS) {
//we are AndroidAPS //we are AndroidAPS
openApsStatus = LoopPlugin.lastRun != null && LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.getTime(): -1; openApsStatus = LoopPlugin.lastRun != null && LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.getTime() : -1;
} else { } else {
//NSClient or remote //NSClient or remote
openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); openApsStatus = NSDeviceStatus.getOpenApsTimestamp();
@ -673,10 +667,10 @@ public class WatchUpdaterService extends WearableListenerService implements
LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) { if (activeloop != null && !activeloop.isEnabled(PluginType.LOOP)) {
status += getString(R.string.disabledloop) + "\n"; status += getString(R.string.disabledloop) + "\n";
lastLoopStatus = false; lastLoopStatus = false;
} else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) { } else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) {
lastLoopStatus = true; lastLoopStatus = true;
} }

View file

@ -22,6 +22,8 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
@ -31,19 +33,7 @@ import info.nightscout.utils.DecimalFormatter;
* Created by adrian on 17/11/16. * Created by adrian on 17/11/16.
*/ */
public class StatuslinePlugin implements PluginBase { public class StatuslinePlugin extends PluginBase {
//broadcast related constants
private static final String EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline";
private static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline";
private static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE";
private boolean fragmentEnabled = false;
private boolean lastLoopStatus;
private final Context ctx;
private SharedPreferences mPrefs;
private static StatuslinePlugin statuslinePlugin; private static StatuslinePlugin statuslinePlugin;
@ -51,8 +41,19 @@ public class StatuslinePlugin implements PluginBase {
return statuslinePlugin; return statuslinePlugin;
} }
public static StatuslinePlugin initPlugin(Context ctx) { //broadcast related constants
private static final String EXTRA_STATUSLINE = "com.eveningoutpost.dexdrip.Extras.Statusline";
private static final String ACTION_NEW_EXTERNAL_STATUSLINE = "com.eveningoutpost.dexdrip.ExternalStatusline";
private static final String RECEIVER_PERMISSION = "com.eveningoutpost.dexdrip.permissions.RECEIVE_EXTERNAL_STATUSLINE";
private boolean lastLoopStatus;
private final Context ctx;
private SharedPreferences mPrefs;
public static StatuslinePlugin initPlugin(Context ctx) {
if (statuslinePlugin == null) { if (statuslinePlugin == null) {
statuslinePlugin = new StatuslinePlugin(ctx); statuslinePlugin = new StatuslinePlugin(ctx);
} }
@ -60,100 +61,43 @@ public class StatuslinePlugin implements PluginBase {
return statuslinePlugin; return statuslinePlugin;
} }
private StatuslinePlugin(Context ctx) { public StatuslinePlugin(Context ctx) {
super(new PluginDescription()
.mainType(PluginType.GENERAL)
.pluginName(R.string.xdripstatus)
.shortName(R.string.xdripstatus_shortname)
.neverVisible(true)
.preferencesId(R.xml.pref_xdripstatus)
);
this.ctx = ctx; this.ctx = ctx;
this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
} }
@Override @Override
public int getType() { public boolean specialShowInListCondition() {
return PluginBase.GENERAL;
}
@Override
public String getFragmentClass() {
return null;
}
@Override
public String getName() {
return ctx.getString(R.string.xdripstatus);
}
@Override
public String getNameShort() {
String name = MainApp.sResources.getString(R.string.xdripstatus_shortname);
if (!name.trim().isEmpty()) {
//only if translation exists
return name;
}
// use long name as fallback
return getName();
}
@Override
public boolean isEnabled(int type) {
return type == GENERAL && fragmentEnabled;
}
@Override
public boolean isVisibleInTabs(int type) {
return false;
}
@Override
public boolean canBeHidden(int type) {
return true;
}
@Override
public boolean hasFragment() {
return false;
}
@Override
public boolean showInList(int type) {
return !Config.NSCLIENT && !Config.G5UPLOADER; return !Config.NSCLIENT && !Config.G5UPLOADER;
} }
@Override @Override
public void setPluginEnabled(int type, boolean fragmentEnabled) { public void onStart() {
if (type == GENERAL) { super.onStart();
this.fragmentEnabled = fragmentEnabled;
if (fragmentEnabled) {
try {
MainApp.bus().register(this); MainApp.bus().register(this);
} catch (Exception e) {
}
sendStatus(); sendStatus();
} else { }
try {
@Override
public void onStop() {
super.onStop();
MainApp.bus().unregister(this); MainApp.bus().unregister(this);
} catch (Exception e) {
}
sendStatus(); sendStatus();
} }
}
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
// do nothing, no gui
}
@Override
public int getPreferencesId() {
return R.xml.pref_xdripstatus;
}
private void sendStatus() { private void sendStatus() {
String status = ""; // sent once on disable String status = ""; // sent once on disable
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (fragmentEnabled && profile != null) { if (isEnabled(PluginType.GENERAL) && profile != null) {
status = buildStatusString(profile); status = buildStatusString(profile);
} }
@ -171,10 +115,10 @@ public class StatuslinePlugin implements PluginBase {
String status = ""; String status = "";
LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) { if (activeloop != null && !activeloop.isEnabled(PluginType.LOOP)) {
status += ctx.getString(R.string.disabledloop) + "\n"; status += ctx.getString(R.string.disabledloop) + "\n";
lastLoopStatus = false; lastLoopStatus = false;
} else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) { } else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) {
lastLoopStatus = true; lastLoopStatus = true;
} }
@ -246,14 +190,9 @@ public class StatuslinePlugin implements PluginBase {
LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
if (activeloop == null) return; if (activeloop == null) return;
if ((lastLoopStatus != activeloop.isEnabled(PluginBase.LOOP))) { if ((lastLoopStatus != activeloop.isEnabled(PluginType.LOOP))) {
sendStatus(); sendStatus();
} }
} }
public boolean isEnabled() {
return fragmentEnabled;
}
} }

View file

@ -7,6 +7,7 @@ import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
@ -34,7 +35,7 @@ public class CommandSetProfile extends Command {
ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis()); ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis());
if (r.enacted && profileSwitch.source == Source.NIGHTSCOUT) { if (r.enacted && profileSwitch.source == Source.NIGHTSCOUT) {
SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class); SmsCommunicatorPlugin smsCommunicatorPlugin = MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) { if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginType.GENERAL)) {
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok)); smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
} }
} }

View file

@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
/** /**
@ -37,7 +36,7 @@ public class TabPageAdapter extends FragmentStatePagerAdapter {
@Nullable @Nullable
public Fragment getItem(int position) { public Fragment getItem(int position) {
//Fragment fragment = (Fragment) visibleFragmentList.get(position); //Fragment fragment = (Fragment) visibleFragmentList.get(position);
return Fragment.instantiate(context, visibleFragmentList.get(position).getFragmentClass()); return Fragment.instantiate(context, visibleFragmentList.get(position).pluginDescription.getFragmentClass());
} }
@Override @Override
@ -67,7 +66,7 @@ public class TabPageAdapter extends FragmentStatePagerAdapter {
} }
public void registerNewFragment(PluginBase plugin) { public void registerNewFragment(PluginBase plugin) {
if (plugin.hasFragment() && plugin.isVisibleInTabs(plugin.getType())) { if (plugin.hasFragment() && plugin.isFragmentVisible()) {
visibleFragmentList.add(plugin); visibleFragmentList.add(plugin);
notifyDataSetChanged(); notifyDataSetChanged();
} }

View file

@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment"> tools:context="info.nightscout.androidaps.plugins.Source.BGSourceFragment">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -586,7 +586,7 @@
<string name="careportal_newnstreatment_duration_min_label">Продължителност [мин.]</string> <string name="careportal_newnstreatment_duration_min_label">Продължителност [мин.]</string>
<string name="careportal_pump_label">ПОМПА</string> <string name="careportal_pump_label">ПОМПА</string>
<string name="date">Дата</string> <string name="date">Дата</string>
<string name="dia_too_short" formatted="false">DIA от %s е твърде кратка - използвай %s вместо това!</string> <string name="dia_too_short" formatted="false">DIA от %f е твърде кратка - използвай %f вместо това!</string>
<string name="free_peak_oref">Със свободен пик по Oref</string> <string name="free_peak_oref">Със свободен пик по Oref</string>
<string name="insulin_oref_peak">Пик на кривата на IOB</string> <string name="insulin_oref_peak">Пик на кривата на IOB</string>
<string name="insulin_peak_time">Време на пик [мин.]</string> <string name="insulin_peak_time">Време на пик [мин.]</string>

View file

@ -573,7 +573,7 @@
<string name="activate_profile">AKTIVOVAT PROFIL</string> <string name="activate_profile">AKTIVOVAT PROFIL</string>
<string name="danar_visualizeextendedaspercentage_title">Zobrazovat prodloužený bolus v %</string> <string name="danar_visualizeextendedaspercentage_title">Zobrazovat prodloužený bolus v %</string>
<string name="date">Datum</string> <string name="date">Datum</string>
<string name="dia_too_short" formatted="false">DIA %s je příliž krátké - použito %s !</string> <string name="dia_too_short" formatted="false">DIA %f je příliž krátké - použito %f !</string>
<string name="insulin_oref_peak">Čas vrcholu IOB křivky</string> <string name="insulin_oref_peak">Čas vrcholu IOB křivky</string>
<string name="insulin_peak_time">Vrchol křivky [min]</string> <string name="insulin_peak_time">Vrchol křivky [min]</string>
<string name="invalid">NEPLATNÝ</string> <string name="invalid">NEPLATNÝ</string>

View file

@ -564,7 +564,7 @@
<string name="insulin_peak_time">Peak Time [min]</string> <string name="insulin_peak_time">Peak Time [min]</string>
<string name="insulin_oref_peak">IOB Curve Peak Time</string> <string name="insulin_oref_peak">IOB Curve Peak Time</string>
<string name="free_peak_oref">Free-Peak Oref</string> <string name="free_peak_oref">Free-Peak Oref</string>
<string formatted="false" name="dia_too_short">DIA von %s ist zu kurz - AAPS nutzt stattdessen %s!</string> <string formatted="false" name="dia_too_short">DIA von %f ist zu kurz - AAPS nutzt stattdessen %f!</string>
<string name="danar_stats_warning_Message">Möglicherweise ungenau, wenn zum Befüllen ein Bolus verwendet wurde!</string> <string name="danar_stats_warning_Message">Möglicherweise ungenau, wenn zum Befüllen ein Bolus verwendet wurde!</string>
<string name="danar_stats_ratio">Verhältnis</string> <string name="danar_stats_ratio">Verhältnis</string>
<string name="activate_profile">AKTIVIERE PROFIL</string> <string name="activate_profile">AKTIVIERE PROFIL</string>

View file

@ -580,7 +580,7 @@
<string name="free_peak_oref">Free-Peak Oref</string> <string name="free_peak_oref">Free-Peak Oref</string>
<string name="rapid_acting_oref">Γρήγορη δράση - Oref</string> <string name="rapid_acting_oref">Γρήγορη δράση - Oref</string>
<string name="ultrarapid_oref">Έξτρα Γρήγορη δράση - Oref</string> <string name="ultrarapid_oref">Έξτρα Γρήγορη δράση - Oref</string>
<string name="dia_too_short" formatted="false">"DIA για %s πολύ μικρή - χρησιμοποιήστε %s! "</string> <string name="dia_too_short" formatted="false">"DIA για %f πολύ μικρή - χρησιμοποιήστε %f! "</string>
<string name="activate_profile">ΕΝΕΡΓΟΠΟΙΗΣΗ ΠΡΟΦΙΛ</string> <string name="activate_profile">ΕΝΕΡΓΟΠΟΙΗΣΗ ΠΡΟΦΙΛ</string>
<string name="date">Ημερομηνία</string> <string name="date">Ημερομηνία</string>
<string name="invalid">ΜΗ ΕΓΚΥΡΟ</string> <string name="invalid">ΜΗ ΕΓΚΥΡΟ</string>

View file

@ -585,7 +585,7 @@
<string name="free_peak_oref">Free-Peak Oref</string> <string name="free_peak_oref">Free-Peak Oref</string>
<string name="rapid_acting_oref">Rapid-Acting Oref</string> <string name="rapid_acting_oref">Rapid-Acting Oref</string>
<string name="ultrarapid_oref">Ultra-Rapid Oref</string> <string name="ultrarapid_oref">Ultra-Rapid Oref</string>
<string name="dia_too_short" formatted="false">DIA de %s demasiado corto - usando %s!</string> <string name="dia_too_short" formatted="false">DIA de %f demasiado corto - usando %f!</string>
<string name="activate_profile">ACTIVAR PERFIL</string> <string name="activate_profile">ACTIVAR PERFIL</string>
<string name="date">Fecha</string> <string name="date">Fecha</string>
<string name="invalid">INVALIDO</string> <string name="invalid">INVALIDO</string>

View file

@ -579,7 +579,7 @@
<string name="insulin_peak_time">"Durée du Pic [min] "</string> <string name="insulin_peak_time">"Durée du Pic [min] "</string>
<string name="rapid_acting_oref">"Insuline à Action Rapide Oref "</string> <string name="rapid_acting_oref">"Insuline à Action Rapide Oref "</string>
<string name="ultrarapid_oref">Insuline à Action Ultra Rapide Oref</string> <string name="ultrarapid_oref">Insuline à Action Ultra Rapide Oref</string>
<string name="dia_too_short" formatted="false">Durée dAction pour %s trop courte - utiliser %s à la place!</string> <string name="dia_too_short" formatted="false">Durée dAction pour %f trop courte - utiliser %f à la place!</string>
<string name="activate_profile">ACTIVER LE PROFIL</string> <string name="activate_profile">ACTIVER LE PROFIL</string>
<string name="date">" Date"</string> <string name="date">" Date"</string>
<string name="invalid">INVALID</string> <string name="invalid">INVALID</string>

View file

@ -591,7 +591,7 @@
<string name="free_peak_oref">Free-Peak Oref</string> <string name="free_peak_oref">Free-Peak Oref</string>
<string name="rapid_acting_oref">Rapid-Acting Oref</string> <string name="rapid_acting_oref">Rapid-Acting Oref</string>
<string name="ultrarapid_oref">Ultra-Rapid Oref</string> <string name="ultrarapid_oref">Ultra-Rapid Oref</string>
<string name="dia_too_short" formatted="false">"DIA %s는 너무 짧습니다. 대신 %s을 사용하세요!"</string> <string name="dia_too_short" formatted="false">"DIA %f는 너무 짧습니다. 대신 %f을 사용하세요!"</string>
<string name="activate_profile">프로파일 활성화하기</string> <string name="activate_profile">프로파일 활성화하기</string>
<string name="date">Date</string> <string name="date">Date</string>
<string name="invalid">INVALID</string> <string name="invalid">INVALID</string>

View file

@ -587,7 +587,7 @@
<string name="activate_profile">Activeer profiel</string> <string name="activate_profile">Activeer profiel</string>
<string name="date">Datum</string> <string name="date">Datum</string>
<string name="free_peak_oref">Free-Peak Oref</string> <string name="free_peak_oref">Free-Peak Oref</string>
<string name="dia_too_short" formatted="false">DIA van %s te kort - %s wordt inplaats gebruikt!\"</string> <string name="dia_too_short" formatted="false">DIA van %f te kort - %f wordt inplaats gebruikt!\"</string>
<string name="insulin_oref_peak">IOB curve piek tijd</string> <string name="insulin_oref_peak">IOB curve piek tijd</string>
<string name="insulin_peak_time">Piek tijd [min]</string> <string name="insulin_peak_time">Piek tijd [min]</string>
<string name="invalid">Ongeldig</string> <string name="invalid">Ongeldig</string>

View file

@ -547,7 +547,7 @@
<string name="danar_visualizeextendedaspercentage_title">Просмотреть расширенный болюс %</string> <string name="danar_visualizeextendedaspercentage_title">Просмотреть расширенный болюс %</string>
<string name="danarv2pump">DanaRv2</string> <string name="danarv2pump">DanaRv2</string>
<string name="date">дата</string> <string name="date">дата</string>
<string name="dia_too_short" formatted="false">ачение длительности работы инс %s слишком мало - применено %s</string> <string name="dia_too_short" formatted="false">ачение длительности работы инс %f слишком мало - применено %f</string>
<string name="extendedbolus">расширенный болюс</string> <string name="extendedbolus">расширенный болюс</string>
<string name="free_peak_oref">Акуу-Зуфл Щкуа</string> <string name="free_peak_oref">Акуу-Зуфл Щкуа</string>
<string name="hours">час</string> <string name="hours">час</string>

View file

@ -663,7 +663,7 @@
<string name="free_peak_oref">Free-Peak Oref</string> <string name="free_peak_oref">Free-Peak Oref</string>
<string name="rapid_acting_oref">Rapid-Acting Oref</string> <string name="rapid_acting_oref">Rapid-Acting Oref</string>
<string name="ultrarapid_oref">Ultra-Rapid Oref</string> <string name="ultrarapid_oref">Ultra-Rapid Oref</string>
<string name="dia_too_short" formatted="false">DIA of %s too short - using %s instead!</string> <string name="dia_too_short" formatted="false">DIA of %f too short - using %f instead!</string>
<string name="activate_profile">ACTIVATE PROFILE</string> <string name="activate_profile">ACTIVATE PROFILE</string>
<string name="date">Date</string> <string name="date">Date</string>
<string name="invalid">INVALID</string> <string name="invalid">INVALID</string>
@ -994,5 +994,7 @@
<string name="record_insulin_cartridge_change">Record insulin cartridge change</string> <string name="record_insulin_cartridge_change">Record insulin cartridge change</string>
<string name="smbalwaysdisabled">SMB always and after carbs disabled because active BG source doesn\'t support advanced filtering</string> <string name="smbalwaysdisabled">SMB always and after carbs disabled because active BG source doesn\'t support advanced filtering</string>
<string name="smbnotallowedinopenloopmode">SMB not allowed in open loop mode</string> <string name="smbnotallowedinopenloopmode">SMB not allowed in open loop mode</string>
<string name="food_short">Food</string>
<string name="iobcobcalculator" translatable="false">IobCobCalculator</string>
</resources> </resources>

View file

@ -30,8 +30,8 @@ import static org.mockito.Mockito.when;
*/ */
public class AAPSMocker { public class AAPSMocker {
static String validProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"; private static String validProfile = "{\"dia\":\"3\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"100\"},{\"time\":\"2:00\",\"value\":\"110\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}";
static Profile profile; private static Profile profile;
public static void mockStrings() { public static void mockStrings() {
Locale.setDefault(new Locale("en", "US")); Locale.setDefault(new Locale("en", "US"));
@ -112,7 +112,7 @@ public class AAPSMocker {
try { try {
if (profile == null) if (profile == null)
profile = new Profile(new JSONObject(validProfile), Constants.MGDL); profile = new Profile(new JSONObject(validProfile), Constants.MGDL);
} catch (JSONException e) {} } catch (JSONException ignored) {}
return profile; return profile;
} }
} }

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -36,8 +36,8 @@ public class DanaRPluginTest {
@Test @Test
public void basalRateShouldBeLimited() throws Exception { public void basalRateShouldBeLimited() throws Exception {
danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
DanaRPump.getInstance().maxBasal = 0.8d; DanaRPump.getInstance().maxBasal = 0.8d;
Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE); Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE);
@ -49,8 +49,8 @@ public class DanaRPluginTest {
@Test @Test
public void percentBasalRateShouldBeLimited() throws Exception { public void percentBasalRateShouldBeLimited() throws Exception {
danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
DanaRPump.getInstance().maxBasal = 0.8d; DanaRPump.getInstance().maxBasal = 0.8d;
Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE); Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE);

View file

@ -34,7 +34,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner; import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -64,7 +64,7 @@ public class ConstraintsCheckerTest {
@Test @Test
public void isLoopInvokationAllowedTest() throws Exception { public void isLoopInvokationAllowedTest() throws Exception {
comboPlugin.setPluginEnabled(PluginBase.PUMP, true); comboPlugin.setPluginEnabled(PluginType.PUMP, true);
comboPlugin.setValidBasalRateProfileSelectedOnPump(false); comboPlugin.setValidBasalRateProfileSelectedOnPump(false);
Constraint<Boolean> c = constraintChecker.isLoopInvokationAllowed(); Constraint<Boolean> c = constraintChecker.isLoopInvokationAllowed();
@ -137,12 +137,12 @@ public class ConstraintsCheckerTest {
@Test @Test
public void basalRateShouldBeLimited() throws Exception { public void basalRateShouldBeLimited() throws Exception {
// DanaR, RS // DanaR, RS
danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRSPlugin.setPluginEnabled(PluginType.PUMP, true);
DanaRPump.getInstance().maxBasal = 0.8d; DanaRPump.getInstance().maxBasal = 0.8d;
// Insight // Insight
insightPlugin.setPluginEnabled(PluginBase.PUMP, true); insightPlugin.setPluginEnabled(PluginType.PUMP, true);
StatusTaskRunner.Result result = new StatusTaskRunner.Result(); StatusTaskRunner.Result result = new StatusTaskRunner.Result();
result.maximumBasalAmount = 1.1d; result.maximumBasalAmount = 1.1d;
insightPlugin.setStatusResult(result); insightPlugin.setStatusResult(result);
@ -164,12 +164,12 @@ public class ConstraintsCheckerTest {
@Test @Test
public void percentBasalRateShouldBeLimited() throws Exception { public void percentBasalRateShouldBeLimited() throws Exception {
// DanaR, RS // DanaR, RS
danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRSPlugin.setPluginEnabled(PluginType.PUMP, true);
DanaRPump.getInstance().maxBasal = 0.8d; DanaRPump.getInstance().maxBasal = 0.8d;
// Insight // Insight
insightPlugin.setPluginEnabled(PluginBase.PUMP, true); insightPlugin.setPluginEnabled(PluginType.PUMP, true);
StatusTaskRunner.Result result = new StatusTaskRunner.Result(); StatusTaskRunner.Result result = new StatusTaskRunner.Result();
result.maximumBasalAmount = 1.1d; result.maximumBasalAmount = 1.1d;
insightPlugin.setStatusResult(result); insightPlugin.setStatusResult(result);
@ -192,12 +192,12 @@ public class ConstraintsCheckerTest {
@Test @Test
public void bolusAmountShouldBeLimited() throws Exception { public void bolusAmountShouldBeLimited() throws Exception {
// DanaR, RS // DanaR, RS
danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRSPlugin.setPluginEnabled(PluginType.PUMP, true);
DanaRPump.getInstance().maxBolus = 6d; DanaRPump.getInstance().maxBolus = 6d;
// Insight // Insight
insightPlugin.setPluginEnabled(PluginBase.PUMP, true); insightPlugin.setPluginEnabled(PluginType.PUMP, true);
StatusTaskRunner.Result result = new StatusTaskRunner.Result(); StatusTaskRunner.Result result = new StatusTaskRunner.Result();
result.maximumBolusAmount = 7d; result.maximumBolusAmount = 7d;
insightPlugin.setStatusResult(result); insightPlugin.setStatusResult(result);
@ -233,9 +233,9 @@ public class ConstraintsCheckerTest {
// No limit by default // No limit by default
when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d); when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d);
when(SP.getString(R.string.key_age, "")).thenReturn("teenage"); when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
// Apply all limits // Apply all limits
Constraint<Double> d = constraintChecker.getMaxIOBAllowed(); Constraint<Double> d = constraintChecker.getMaxIOBAllowed();

View file

@ -0,0 +1,19 @@
package info.nightscout.androidaps.plugins.ConfigBuilder;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.*;
@RunWith(PowerMockRunner.class)
public class ConfigBuilderPluginTest {
@Test
public void getPluginTest() {
ConfigBuilderPlugin configBuilderPlugin = ConfigBuilderPlugin.getPlugin();
Assert.assertNotNull(configBuilderPlugin);
}
}

View file

@ -13,6 +13,7 @@ import java.util.Date;
import info.AAPSMocker; import info.AAPSMocker;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;

View file

@ -15,13 +15,13 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -208,9 +208,9 @@ public class SafetyPluginTest {
public void iobShouldBeLimited() throws Exception { public void iobShouldBeLimited() throws Exception {
when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d); when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d);
when(SP.getString(R.string.key_age, "")).thenReturn("teenage"); when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
// Apply all limits // Apply all limits
Constraint<Double> d = new Constraint<>(Constants.REALLYHIGHIOB); Constraint<Double> d = new Constraint<>(Constants.REALLYHIGHIOB);
@ -232,7 +232,6 @@ public class SafetyPluginTest {
AAPSMocker.mockStrings(); AAPSMocker.mockStrings();
when(MainApp.getConfigBuilder().getActivePump()).thenReturn(pump); when(MainApp.getConfigBuilder().getActivePump()).thenReturn(pump);
safetyPlugin = SafetyPlugin.getPlugin(); safetyPlugin = SafetyPlugin.getPlugin();

View file

@ -99,55 +99,21 @@ public class InsulinOrefBasePluginTest extends InsulinOrefBasePlugin {
this.shortDiaNotificationSend = true; this.shortDiaNotificationSend = true;
} }
// the following methods are implemented, but not needed...
@Override
String commentStandardText() {
return null;
}
@Override
public String getFragmentClass() {
return null;
}
@Override @Override
public int getId() { public int getId() {
return 0; return 0;
} }
@Override
public String getName() {
return null;
}
@Override @Override
public String getFriendlyName() { public String getFriendlyName() {
return null; return null;
} }
@Override @Override
public boolean isEnabled(int type) { String commentStandardText() {
return false; return null;
} }
@Override
public boolean isVisibleInTabs(int type) {
return false;
}
@Override // the following methods are implemented, but not needed...
public void setPluginEnabled(int type, boolean fragmentEnabled) {
}
@Override
public void setFragmentVisible(int type, boolean fragmentVisible) {
}
@Override
public int getPreferencesId() {
return 0;
}
} }

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -37,30 +38,30 @@ public class LoopPluginTest {
@Test @Test
public void testPluginInterface() { public void testPluginInterface() {
Assert.assertEquals(LoopFragment.class.getName(), loopPlugin.getFragmentClass()); Assert.assertEquals(LoopFragment.class.getName(), loopPlugin.pluginDescription.getFragmentClass());
Assert.assertEquals(PluginBase.LOOP, loopPlugin.getType()); Assert.assertEquals(PluginType.LOOP, loopPlugin.getType());
Assert.assertEquals("Loop", loopPlugin.getName()); Assert.assertEquals("Loop", loopPlugin.getName());
Assert.assertEquals("LOOP", loopPlugin.getNameShort()); Assert.assertEquals("LOOP", loopPlugin.getNameShort());
Assert.assertEquals(true, loopPlugin.canBeHidden(PluginBase.LOOP)); Assert.assertEquals(true, loopPlugin.canBeHidden(PluginType.LOOP));
Assert.assertEquals(true, loopPlugin.hasFragment()); Assert.assertEquals(true, loopPlugin.hasFragment());
Assert.assertEquals(true, loopPlugin.showInList(PluginBase.LOOP)); Assert.assertEquals(true, loopPlugin.showInList(PluginType.LOOP));
Assert.assertEquals(R.xml.pref_closedmode, loopPlugin.getPreferencesId()); Assert.assertEquals(R.xml.pref_closedmode, loopPlugin.getPreferencesId());
// Plugin is disabled by default // Plugin is disabled by default
Assert.assertEquals(false, loopPlugin.isEnabled(PluginBase.LOOP)); Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP));
loopPlugin.setPluginEnabled(PluginBase.LOOP, true); loopPlugin.setPluginEnabled(PluginType.LOOP, true);
Assert.assertEquals(true, loopPlugin.isEnabled(PluginBase.LOOP)); Assert.assertEquals(true, loopPlugin.isEnabled(PluginType.LOOP));
// No temp basal capable pump should disable plugin // No temp basal capable pump should disable plugin
virtualPumpPlugin.getPumpDescription().isTempBasalCapable = false; virtualPumpPlugin.getPumpDescription().isTempBasalCapable = false;
Assert.assertEquals(false, loopPlugin.isEnabled(PluginBase.LOOP)); Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP));
virtualPumpPlugin.getPumpDescription().isTempBasalCapable = true; virtualPumpPlugin.getPumpDescription().isTempBasalCapable = true;
// Fragment is hidden by default // Fragment is hidden by default
Assert.assertEquals(false, loopPlugin.isVisibleInTabs(PluginBase.LOOP)); Assert.assertEquals(false, loopPlugin.isFragmentVisible());
loopPlugin.setFragmentVisible(PluginBase.LOOP, true); loopPlugin.setFragmentVisible(PluginType.LOOP, true);
Assert.assertEquals(true, loopPlugin.isVisibleInTabs(PluginBase.LOOP)); Assert.assertEquals(true, loopPlugin.isFragmentVisible());
} }

View file

@ -12,7 +12,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker; import info.AAPSMocker;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
@ -27,14 +27,14 @@ public class ComboPluginTest {
@Test @Test
public void invalidBasalRateOnComboPumpShouldLimitLoopInvokation() throws Exception { public void invalidBasalRateOnComboPumpShouldLimitLoopInvokation() throws Exception {
comboPlugin.setPluginEnabled(PluginBase.PUMP, true); comboPlugin.setPluginEnabled(PluginType.PUMP, true);
comboPlugin.setValidBasalRateProfileSelectedOnPump(false); comboPlugin.setValidBasalRateProfileSelectedOnPump(false);
Constraint<Boolean> c = new Constraint<>(true); Constraint<Boolean> c = new Constraint<>(true);
c = comboPlugin.isLoopInvokationAllowed(c); c = comboPlugin.isLoopInvokationAllowed(c);
Assert.assertEquals("Combo: No valid basal rate read from pump", c.getReasons()); Assert.assertEquals("Combo: No valid basal rate read from pump", c.getReasons());
Assert.assertEquals(Boolean.FALSE, c.value()); Assert.assertEquals(Boolean.FALSE, c.value());
comboPlugin.setPluginEnabled(PluginBase.PUMP, false); comboPlugin.setPluginEnabled(PluginType.PUMP, false);
} }
@Test @Test

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -35,8 +35,8 @@ public class DanaRSPluginTest {
@Test @Test
public void basalRateShouldBeLimited() throws Exception { public void basalRateShouldBeLimited() throws Exception {
danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRSPlugin.setPluginEnabled(PluginType.PUMP, true);
danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRSPlugin.setPluginEnabled(PluginType.PUMP, true);
DanaRPump.getInstance().maxBasal = 0.8d; DanaRPump.getInstance().maxBasal = 0.8d;
Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE); Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE);
@ -48,8 +48,8 @@ public class DanaRSPluginTest {
@Test @Test
public void percentBasalRateShouldBeLimited() throws Exception { public void percentBasalRateShouldBeLimited() throws Exception {
danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRSPlugin.setPluginEnabled(PluginType.PUMP, true);
danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); danaRSPlugin.setPluginEnabled(PluginType.PUMP, true);
DanaRPump.getInstance().maxBasal = 0.8d; DanaRPump.getInstance().maxBasal = 0.8d;
Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE); Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE);

View file

@ -14,7 +14,7 @@ import info.AAPSMocker;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner; import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
@ -31,7 +31,7 @@ public class InsightPluginTest {
@Test @Test
public void basalRateShouldBeLimited() throws Exception { public void basalRateShouldBeLimited() throws Exception {
insightPlugin.setPluginEnabled(PluginBase.PUMP, true); insightPlugin.setPluginEnabled(PluginType.PUMP, true);
StatusTaskRunner.Result result = new StatusTaskRunner.Result(); StatusTaskRunner.Result result = new StatusTaskRunner.Result();
result.maximumBasalAmount = 1.1d; result.maximumBasalAmount = 1.1d;
insightPlugin.setStatusResult(result); insightPlugin.setStatusResult(result);

View file

@ -0,0 +1,27 @@
package info.nightscout.androidaps.plugins.Source;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.Config;
@RunWith(PowerMockRunner.class)
public class SourceDexcomG5PluginTest {
@Test
public void getPlugin() {
Assert.assertNotEquals(null, SourceDexcomG5Plugin.getPlugin());
}
@Test
public void specialShowInListCondition() {
Assert.assertEquals(!Config.G5UPLOADER, SourceDexcomG5Plugin.getPlugin().specialShowInListCondition());
}
@Test
public void advancedFilteringSupported() {
Assert.assertEquals(true, SourceDexcomG5Plugin.getPlugin().advancedFilteringSupported());
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.Source;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin;
@RunWith(PowerMockRunner.class)
public class SourceGlimpPluginTest {
@Test
public void getPlugin() {
Assert.assertNotEquals(null, SourceGlimpPlugin.getPlugin());
}
@Test
public void advancedFilteringSupported() {
Assert.assertEquals(false, SourceGlimpPlugin.getPlugin().advancedFilteringSupported());
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.Source;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin;
@RunWith(PowerMockRunner.class)
public class SourceMM640gPluginTest {
@Test
public void getPlugin() {
Assert.assertNotEquals(null, SourceMM640gPlugin.getPlugin());
}
@Test
public void advancedFilteringSupported() {
Assert.assertEquals(false, SourceMM640gPlugin.getPlugin().advancedFilteringSupported());
}
}

View file

@ -0,0 +1,20 @@
package info.nightscout.androidaps.plugins.Source;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
public class SourceNSClientPluginTest {
@Test
public void getPlugin() {
Assert.assertNotEquals(null, SourceNSClientPlugin.getPlugin());
}
@Test
public void advancedFilteringSupported() {
Assert.assertEquals(true, SourceNSClientPlugin.getPlugin().advancedFilteringSupported());
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.Source;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
@RunWith(PowerMockRunner.class)
public class SourceXdripPluginTest {
@Test
public void getPlugin() {
Assert.assertNotEquals(null, SourceXdripPlugin.getPlugin());
}
@Test
public void advancedFilteringSupported() {
Assert.assertEquals(false, SourceXdripPlugin.getPlugin().advancedFilteringSupported());
}
}

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