From bcb733e42ce7a2fa3feedfc93eb7d5d6a4d47b55 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 31 Mar 2018 00:36:03 +0200 Subject: [PATCH 1/5] Plugins refactor --- app/build.gradle | 2 +- .../info/nightscout/androidaps/Constants.java | 5 + .../info/nightscout/androidaps/MainApp.java | 42 ++- .../androidaps/PreferencesActivity.java | 53 +-- .../androidaps/Services/DataService.java | 26 +- .../androidaps/data/ConstraintChecker.java | 23 +- .../androidaps/interfaces/PluginBase.java | 171 ++++++++-- .../interfaces/PluginDescription.java | 90 +++++ .../androidaps/interfaces/PluginType.java | 14 + .../plugins/Actions/ActionsPlugin.java | 80 +---- .../plugins/Careportal/CareportalPlugin.java | 76 +---- .../ConfigBuilder/ConfigBuilderFragment.java | 87 ++--- .../ConfigBuilder/ConfigBuilderPlugin.java | 310 +++++++++++------- .../ObjectivesFragment.java | 15 +- .../ObjectivesPlugin.java | 91 ++--- .../ConstraintsSafety/SafetyPlugin.java | 81 +---- .../androidaps/plugins/Food/FoodPlugin.java | 81 +---- .../Insulin/InsulinFastactingPlugin.java | 72 +--- .../InsulinFastactingProlongedPlugin.java | 72 +--- .../Insulin/InsulinOrefBasePlugin.java | 46 +-- .../Insulin/InsulinOrefFreePeakPlugin.java | 48 +-- .../Insulin/InsulinOrefRapidActingPlugin.java | 46 +-- .../InsulinOrefUltraRapidActingPlugin.java | 41 +-- .../IobCobCalculator/AutosensData.java | 3 +- .../IobCobCalculatorPlugin.java | 110 ++----- .../androidaps/plugins/Loop/LoopPlugin.java | 91 ++--- .../NSClientInternal/NSClientPlugin.java | 85 ++--- .../receivers/AckAlarmReceiver.java | 3 +- .../receivers/DBAccessReceiver.java | 4 +- .../services/NSClientService.java | 5 +- .../plugins/OpenAPSAMA/OpenAPSAMAPlugin.java | 90 ++--- .../plugins/OpenAPSMA/OpenAPSMAPlugin.java | 90 ++--- .../plugins/OpenAPSSMB/OpenAPSSMBPlugin.java | 115 ++----- .../plugins/Overview/OverviewFragment.java | 30 +- .../plugins/Overview/OverviewPlugin.java | 92 ++---- .../PersistentNotificationPlugin.java | 109 ++---- .../ProfileLocal/LocalProfilePlugin.java | 83 +---- .../plugins/ProfileNS/NSProfilePlugin.java | 79 +---- .../ProfileSimple/SimpleProfilePlugin.java | 79 +---- .../plugins/PumpCombo/ComboPlugin.java | 111 ++----- .../PumpDanaR/AbstractDanaRPlugin.java | 91 +---- .../plugins/PumpDanaR/DanaRPlugin.java | 4 +- .../activities/DanaRHistoryActivity.java | 16 +- .../PumpDanaR/comm/MsgInitConnStatusTime.java | 20 +- .../PumpDanaR/comm/MsgSettingMeal.java | 4 +- .../PumpDanaRKorean/DanaRKoreanPlugin.java | 11 +- .../comm/MsgInitConnStatusTime_k.java | 22 +- .../plugins/PumpDanaRS/DanaRSPlugin.java | 146 +++------ .../PumpDanaRv2/comm/MsgCheckValue_v2.java | 40 +-- .../plugins/PumpInsight/InsightPlugin.java | 125 ++----- .../androidaps/plugins/PumpMDI/MDIPlugin.java | 76 +---- .../PumpVirtual/VirtualPumpPlugin.java | 98 +----- .../SensitivityAAPSPlugin.java | 73 +---- .../SensitivityOref0Plugin.java | 79 +---- .../SensitivityWeightedAveragePlugin.java | 73 +---- .../SmsCommunicatorPlugin.java | 121 ++----- .../BGSourceFragment.java | 4 +- .../plugins/Source/SourceDexcomG5Plugin.java | 43 +++ .../plugins/Source/SourceGlimpPlugin.java | 34 ++ .../plugins/Source/SourceMM640gPlugin.java | 33 ++ .../plugins/Source/SourceNSClientPlugin.java | 34 ++ .../plugins/Source/SourceXdripPlugin.java | 34 ++ .../SourceDexcomG5/SourceDexcomG5Plugin.java | 89 ----- .../SourceGlimp/SourceGlimpPlugin.java | 90 ----- .../SourceMM640g/SourceMM640gPlugin.java | 90 ----- .../SourceNSClient/SourceNSClientPlugin.java | 92 ------ .../SourceXdrip/SourceXdripPlugin.java | 91 ----- .../plugins/Treatments/TreatmentsPlugin.java | 83 ++--- .../androidaps/plugins/Wear/WearPlugin.java | 101 ++---- .../wearintegration/WatchUpdaterService.java | 32 +- .../XDripStatusline/StatuslinePlugin.java | 133 ++------ .../queue/commands/CommandSetProfile.java | 3 +- .../androidaps/tabs/TabPageAdapter.java | 5 +- app/src/main/res/layout/bgsource_fragment.xml | 2 +- app/src/main/res/values-bg/strings.xml | 2 +- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-el/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-ko/strings.xml | 2 +- app/src/main/res/values-nl/strings.xml | 2 +- app/src/main/res/values-ru/strings.xml | 2 +- app/src/main/res/values/strings.xml | 4 +- app/src/test/java/info/AAPSMocker.java | 6 +- .../androidaps/PumpDanaR/DanaRPluginTest.java | 10 +- .../interfaces/ConstraintsCheckerTest.java | 28 +- .../ConfigBuilderPluginTest.java | 19 ++ .../ObjectivesPluginTest.java | 1 + .../ConstraintsSafety/SafetyPluginTest.java | 11 +- .../Insulin/InsulinOrefBasePluginTest.java | 42 +-- .../plugins/Loop/LoopPluginTest.java | 23 +- .../plugins/PumpCombo/ComboPluginTest.java | 6 +- .../plugins/PumpDanaRS/DanaRSPluginTest.java | 10 +- .../PumpInsight/InsightPluginTest.java | 4 +- .../Source/SourceDexcomG5PluginTest.java | 27 ++ .../plugins/Source/SourceGlimpPluginTest.java | 22 ++ .../Source/SourceMM640gPluginTest.java | 22 ++ .../Source/SourceNSClientPluginTest.java | 20 ++ .../plugins/Source/SourceXdripPluginTest.java | 22 ++ .../watchfaces/CircleWatchface.java | 16 +- 101 files changed, 1691 insertions(+), 3363 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java create mode 100644 app/src/main/java/info/nightscout/androidaps/interfaces/PluginType.java rename app/src/main/java/info/nightscout/androidaps/plugins/{SourceDexcomG5 => Source}/BGSourceFragment.java (97%) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceDexcomG5/SourceDexcomG5Plugin.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5PluginTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPluginTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPluginTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPluginTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java diff --git a/app/build.gradle b/app/build.gradle index 53928d4c0d..b398132004 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -63,7 +63,7 @@ android { targetSdkVersion 23 multiDexEnabled true versionCode 1500 - version "1.60b-dev" + version "1.60c-dev" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", generateGitBuild() diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index 1fe9431397..cd645abd9a 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps; +import info.nightscout.utils.T; + /** * Created by mike on 07.06.2016. */ @@ -61,4 +63,7 @@ public class Constants { // Pump public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 120 - 1; public static final int MIN_WATCHDOG_INTERVAL_IN_SECONDS = 12 * 60; + + //SMS Communicator + public static final long SMS_CONFIRM_TIMEOUT = T.mins(5).msecs(); } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 089ffa255e..60989800b6 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -27,8 +27,9 @@ import ch.qos.logback.classic.LoggerContext; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.ConstraintChecker; import info.nightscout.androidaps.db.DatabaseHelper; -import info.nightscout.androidaps.interfaces.InsulinInterface; 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.Careportal.CareportalPlugin; 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.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; -import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; -import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; -import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; -import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; -import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin; +import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin; +import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin; +import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; @@ -110,6 +111,7 @@ public class MainApp extends Application { sInstance = this; sResources = getResources(); sConstraintsChecker = new ConstraintChecker(this); + sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class); try { if (FabricPrivacy.fabricEnabled()) { @@ -127,7 +129,7 @@ public class MainApp extends Application { log.info("BuildVersion: " + BuildConfig.BUILDVERSION); String extFilesDir = this.getLogDirectory(); - File engineeringModeSemaphore = new File(extFilesDir,"engineering_mode"); + File engineeringModeSemaphore = new File(extFilesDir, "engineering_mode"); engineeringMode = engineeringModeSemaphore.exists() && engineeringModeSemaphore.isFile(); 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(DanaRSPlugin.getPlugin()); pluginsList.add(CareportalPlugin.getPlugin()); - if (Config.HWPUMPS && engineeringMode) pluginsList.add(InsightPlugin.getPlugin()); // <-- Enable Insight plugin here - if (Config.HWPUMPS && engineeringMode) pluginsList.add(ComboPlugin.getPlugin()); // <-- Enable Combo plugin here + if (Config.HWPUMPS && engineeringMode) + 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.VIRTUALPUMP) pluginsList.add(VirtualPumpPlugin.getPlugin()); if (Config.APS) pluginsList.add(LoopPlugin.getPlugin()); @@ -204,14 +208,14 @@ public class MainApp extends Application { else FabricPrivacy.getInstance().logCustom(new CustomEvent("AppStart-OpenLoop")); - new Thread(new Runnable() { - @Override - public void run() { + final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + if (pump != null) { + new Thread(() -> { SystemClock.sleep(5000); ConfigBuilderPlugin.getCommandQueue().readStatus("Initialization", null); startKeepAliveService(); - } - }).start(); + }).start(); + } if (!isEngineeringModeOrRelease()) { 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; } - public static ArrayList getSpecificPluginsList(int type) { + public static ArrayList getSpecificPluginsList(PluginType type) { ArrayList newList = new ArrayList<>(); if (pluginsList != null) { @@ -317,11 +321,12 @@ public class MainApp extends Application { return newList; } + /* @Nullable public static InsulinInterface getInsulinIterfaceById(int id) { if (pluginsList != null) { 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; } } else { @@ -329,8 +334,9 @@ public class MainApp extends Application { } return null; } + */ - public static ArrayList getSpecificPluginsVisibleInList(int type) { + public static ArrayList getSpecificPluginsVisibleInList(PluginType type) { ArrayList newList = new ArrayList<>(); if (pluginsList != null) { @@ -359,7 +365,7 @@ public class MainApp extends Application { return newList; } - public static ArrayList getSpecificPluginsVisibleInListByInterface(Class interfaceClass, int type) { + public static ArrayList getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type) { ArrayList newList = new ArrayList<>(); if (pluginsList != null) { diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java index 3d445dca7b..b6b117381f 100644 --- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java @@ -14,6 +14,7 @@ import android.text.TextUtils; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.Careportal.CareportalPlugin; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; 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.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; 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.XDripStatusline.StatuslinePlugin; import info.nightscout.utils.LocaleHelper; @@ -111,7 +112,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre id = args.getInt("id"); } - void addPreferencesFromResourceIfEnabled(PluginBase p, int type) { + void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) { if (p.isEnabled(type) && p.getPreferencesId() != -1) addPreferencesFromResource(p.getPreferencesId()); } @@ -139,50 +140,50 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre if (!Config.NSCLIENT && !Config.G5UPLOADER) { addPreferencesFromResource(R.xml.pref_quickwizard); } - addPreferencesFromResourceIfEnabled(SourceDexcomG5Plugin.getPlugin(), PluginBase.BGSOURCE); - addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginBase.GENERAL); - addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginBase.CONSTRAINTS); + addPreferencesFromResourceIfEnabled(SourceDexcomG5Plugin.getPlugin(), PluginType.BGSOURCE); + addPreferencesFromResourceIfEnabled(CareportalPlugin.getPlugin(), PluginType.GENERAL); + addPreferencesFromResourceIfEnabled(SafetyPlugin.getPlugin(), PluginType.CONSTRAINTS); if (Config.APS) { - addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginBase.LOOP); - addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginBase.APS); - addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginBase.APS); - addPreferencesFromResourceIfEnabled(OpenAPSSMBPlugin.getPlugin(), PluginBase.APS); + addPreferencesFromResourceIfEnabled(LoopPlugin.getPlugin(), PluginType.LOOP); + addPreferencesFromResourceIfEnabled(OpenAPSMAPlugin.getPlugin(), PluginType.APS); + addPreferencesFromResourceIfEnabled(OpenAPSAMAPlugin.getPlugin(), PluginType.APS); + addPreferencesFromResourceIfEnabled(OpenAPSSMBPlugin.getPlugin(), PluginType.APS); } - addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginBase.SENSITIVITY); - addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginBase.SENSITIVITY); - addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginBase.SENSITIVITY); + addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY); + addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginType.SENSITIVITY); + addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginType.SENSITIVITY); if (Config.HWPUMPS) { - addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginBase.PUMP); - addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginBase.PUMP); - addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginBase.PUMP); - addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginBase.PUMP); + addPreferencesFromResourceIfEnabled(DanaRPlugin.getPlugin(), PluginType.PUMP); + addPreferencesFromResourceIfEnabled(DanaRKoreanPlugin.getPlugin(), PluginType.PUMP); + addPreferencesFromResourceIfEnabled(DanaRv2Plugin.getPlugin(), PluginType.PUMP); + addPreferencesFromResourceIfEnabled(DanaRSPlugin.getPlugin(), PluginType.PUMP); - if (DanaRPlugin.getPlugin().isEnabled(PluginBase.PROFILE) - || DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PROFILE) - || DanaRv2Plugin.getPlugin().isEnabled(PluginBase.PROFILE) - || DanaRSPlugin.getPlugin().isEnabled(PluginBase.PROFILE)) { + if (DanaRPlugin.getPlugin().isEnabled(PluginType.PROFILE) + || DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PROFILE) + || DanaRv2Plugin.getPlugin().isEnabled(PluginType.PROFILE) + || DanaRSPlugin.getPlugin().isEnabled(PluginType.PROFILE)) { addPreferencesFromResource(R.xml.pref_danarprofile); } } 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(SmsCommunicatorPlugin.getPlugin(), PluginBase.GENERAL); + addPreferencesFromResourceIfEnabled(NSClientPlugin.getPlugin(), PluginType.GENERAL); + addPreferencesFromResourceIfEnabled(SmsCommunicatorPlugin.getPlugin(), PluginType.GENERAL); if (!Config.NSCLIENT && !Config.G5UPLOADER) { addPreferencesFromResource(R.xml.pref_others); } addPreferencesFromResource(R.xml.pref_advanced); - addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginBase.GENERAL); - addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginBase.GENERAL); + addPreferencesFromResourceIfEnabled(WearPlugin.getPlugin(), PluginType.GENERAL); + addPreferencesFromResourceIfEnabled(StatuslinePlugin.getPlugin(), PluginType.GENERAL); } initSummary(getPreferenceScreen()); diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java index a9df24798e..7a0193d65c 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -18,7 +18,6 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.CareportalEvent; -import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventNsFood; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; 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.PumpDanaR.activities.DanaRNSHistorySync; import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS; -import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; -import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpPlugin; -import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gPlugin; -import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin; -import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.Source.SourceGlimpPlugin; +import info.nightscout.androidaps.plugins.Source.SourceMM640gPlugin; +import info.nightscout.androidaps.plugins.Source.SourceNSClientPlugin; +import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.utils.BundleLogger; import info.nightscout.utils.NSUpload; @@ -63,8 +62,13 @@ public class DataService extends IntentService { protected void onHandleIntent(final Intent intent) { if (Config.logFunctionCalls) log.debug("onHandleIntent " + BundleLogger.log(intent.getExtras())); - - if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) { + if (ConfigBuilderPlugin.getPlugin().getActiveBgSource() == null) { + xDripEnabled = true; + nsClientEnabled = false; + mm640gEnabled = false; + glimpEnabled = false; + dexcomG5Enabled = false; + } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) { xDripEnabled = true; nsClientEnabled = false; mm640gEnabled = false; @@ -96,7 +100,7 @@ public class DataService extends IntentService { 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); Bundle bundles = intent.getExtras(); @@ -223,7 +227,7 @@ public class DataService extends IntentService { try { JSONArray jsonArray = new JSONArray(data); 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); bgReading.value = json.getInt("m_value"); bgReading.direction = json.getString("m_trend"); @@ -474,7 +478,7 @@ public class DataService extends IntentService { if (intent.getAction().equals(Intents.ACTION_NEW_FOOD) || intent.getAction().equals(Intents.ACTION_CHANGED_FOOD)) { - int mode = Intents.ACTION_NEW_FOOD.equals(intent.getAction()) ? EventNsFood.ADD : EventNsFood.UPDATE; + int mode = Intents.ACTION_NEW_FOOD.equals(intent.getAction()) ? EventNsFood.ADD : EventNsFood.UPDATE; EventNsFood evt = new EventNsFood(mode, bundles); MainApp.bus().post(evt); } diff --git a/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java b/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java index 6c13075a3c..3161cb19f3 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java +++ b/app/src/main/java/info/nightscout/androidaps/data/ConstraintChecker.java @@ -8,6 +8,7 @@ import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; /** @@ -73,7 +74,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isLoopInvokationAllowed(value); } return value; @@ -85,7 +86,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isClosedLoopAllowed(value); } return value; @@ -97,7 +98,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isAutosensModeEnabled(value); } return value; @@ -109,7 +110,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.isAMAModeEnabled(value); } return value; @@ -121,7 +122,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isSMBModeEnabled(value); } return value; @@ -132,7 +133,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.isAdvancedFilteringEnabled(value); } return value; @@ -143,7 +144,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constraint = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constraint.applyBasalConstraints(absoluteRate, profile); } return absoluteRate; @@ -154,7 +155,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyBasalPercentConstraints(percentRate, profile); } return percentRate; @@ -165,7 +166,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyBolusConstraints(insulin); } return insulin; @@ -176,7 +177,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyCarbsConstraints(carbs); } return carbs; @@ -187,7 +188,7 @@ public class ConstraintChecker implements ConstraintsInterface { ArrayList constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; + if (!p.isEnabled(PluginType.CONSTRAINTS)) continue; constrain.applyMaxIOBConstraints(maxIob); } return maxIob; diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java index 75101b2413..3bcb240fb4 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -1,34 +1,157 @@ package info.nightscout.androidaps.interfaces; 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. */ -public interface PluginBase { - int GENERAL = 1; - int TREATMENT = 2; - int SENSITIVITY = 3; - int PROFILE = 4; - 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 +public abstract class PluginBase { + public enum State { + NOT_INITIALIZED, + ENABLED, + DISABLED + } - int getType(); - String getFragmentClass(); + State state = State.NOT_INITIALIZED; + boolean isFragmentVisible = false; + public PluginDescription pluginDescription; - String getName(); - String getNameShort(); - boolean isEnabled(int type); - boolean isVisibleInTabs(int type); - boolean canBeHidden(int type); - boolean hasFragment(); - boolean showInList(int type); - void setPluginEnabled(int type, boolean fragmentEnabled); - void setFragmentVisible(int type, boolean fragmentVisible); - int getPreferencesId(); + + // Specific plugin with more Interfaces + protected boolean isProfileInterfaceEnabled = false; + + public PluginBase(PluginDescription pluginDescription) { + this.pluginDescription = pluginDescription; + } + +// public PluginType getType() { +// 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) { + } } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java new file mode 100644 index 0000000000..296c882755 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java @@ -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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginType.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginType.java new file mode 100644 index 0000000000..1e5685f2ac --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginType.java @@ -0,0 +1,14 @@ +package info.nightscout.androidaps.interfaces; + +public enum PluginType { + GENERAL, + TREATMENT, + SENSITIVITY, + PROFILE, + APS, + PUMP, + CONSTRAINTS, + LOOP, + BGSOURCE, + INSULIN +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java index 3de3acbf18..2397410693 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsPlugin.java @@ -1,82 +1,22 @@ package info.nightscout.androidaps.plugins.Actions; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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. */ -public class ActionsPlugin implements PluginBase { +public class ActionsPlugin extends PluginBase { - private boolean fragmentEnabled = true; - private boolean fragmentVisible = true; - - @Override - public int getType() { - return PluginBase.GENERAL; + public ActionsPlugin() { + super(new PluginDescription() + .mainType(PluginType.GENERAL) + .fragmentClass(ActionsFragment.class.getName()) + .pluginName(R.string.actions) + .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; - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java index 1cfd5822ab..a7de76ce85 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalPlugin.java @@ -1,14 +1,12 @@ package info.nightscout.androidaps.plugins.Careportal; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginDescription; +import info.nightscout.androidaps.interfaces.PluginType; -public class CareportalPlugin implements PluginBase { - - private boolean fragmentEnabled = true; - private boolean fragmentVisible = true; +public class CareportalPlugin extends PluginBase { static CareportalPlugin careportalPlugin; @@ -19,70 +17,18 @@ public class CareportalPlugin implements PluginBase { return careportalPlugin; } - @Override - public int getType() { - return PluginBase.GENERAL; + public CareportalPlugin() { + super(new PluginDescription() + .mainType(PluginType.GENERAL) + .fragmentClass(CareportalFragment.class.getName()) + .pluginName(R.string.careportal) + .shortName(R.string.careportal_shortname) + ); } @Override - public String getFragmentClass() { - 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) { + public boolean specialShowInListCondition() { 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; - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java index da3dba05a7..355b0bc758 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderFragment.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.interfaces.BgSourceInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface; @@ -131,48 +132,48 @@ public class ConfigBuilderFragment extends SubscriberFragment { @Override 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); 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); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.BGSOURCE).size() == 0) + if (MainApp.getSpecificPluginsVisibleInList(PluginType.BGSOURCE).size() == 0) bgsourceLabel.setVisibility(View.GONE); 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); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PUMP).size() == 0) + if (MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size() == 0) pumpLabel.setVisibility(View.GONE); 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); setListViewHeightBasedOnChildren(loopListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.LOOP).size() == 0) + if (MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP).size() == 0) 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); setListViewHeightBasedOnChildren(treatmentsListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT).size() == 0) + if (MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT).size() == 0) 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); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.PROFILE).size() == 0) + if (MainApp.getSpecificPluginsVisibleInList(PluginType.PROFILE).size() == 0) profileLabel.setVisibility(View.GONE); 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); setListViewHeightBasedOnChildren(apsListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.APS).size() == 0) + if (MainApp.getSpecificPluginsVisibleInList(PluginType.APS).size() == 0) 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); 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); setListViewHeightBasedOnChildren(constraintsListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginBase.CONSTRAINTS).size() == 0) + if (MainApp.getSpecificPluginsVisibleInList(PluginType.CONSTRAINTS).size() == 0) 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); setListViewHeightBasedOnChildren(generalListView); } @@ -184,10 +185,10 @@ public class ConfigBuilderFragment extends SubscriberFragment { private class PluginCustomAdapter extends ArrayAdapter { private ArrayList pluginList; - final private int type; + final private PluginType type; PluginCustomAdapter(Context context, int textViewResourceId, - ArrayList pluginList, int type) { + ArrayList pluginList, PluginType type) { super(context, textViewResourceId, pluginList); this.pluginList = new ArrayList<>(); this.pluginList.addAll(pluginList); @@ -230,7 +231,7 @@ public class ConfigBuilderFragment extends SubscriberFragment { plugin1.setPluginEnabled(type, cb.isChecked()); plugin1.setFragmentVisible(type, cb.isChecked()); onEnabledCategoryChanged(plugin1, type); - ConfigBuilderPlugin.getPlugin().storeSettings(); + ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled"); MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventConfigBuilderChange()); ConfigBuilderPlugin.getPlugin().logPluginStatus(); @@ -241,7 +242,7 @@ public class ConfigBuilderFragment extends SubscriberFragment { CheckBox cb = (CheckBox) v; PluginBase plugin12 = (PluginBase) cb.getTag(); plugin12.setFragmentVisible(type, cb.isChecked()); - ConfigBuilderPlugin.getPlugin().storeSettings(); + ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible"); MainApp.bus().post(new EventRefreshGui()); ConfigBuilderPlugin.getPlugin().logPluginStatus(); }); @@ -271,7 +272,7 @@ public class ConfigBuilderFragment extends SubscriberFragment { holder.name.setText(plugin.getName()); holder.checkboxEnabled.setChecked(plugin.isEnabled(type)); - holder.checkboxVisible.setChecked(plugin.isVisibleInTabs(type)); + holder.checkboxVisible.setChecked(plugin.isFragmentVisible()); holder.name.setTag(plugin); holder.checkboxEnabled.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 - 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) { holder.checkboxEnabled.setEnabled(false); plugin.setPluginEnabled(type, true); - ConfigBuilderPlugin.getPlugin().storeSettings(); + ConfigBuilderPlugin.getPlugin().storeSettings("ForceEnable"); } // Constraints cannot be disabled - if (type == PluginBase.CONSTRAINTS) + if (type == PluginType.CONSTRAINTS) holder.checkboxEnabled.setEnabled(false); // Hide disabled profiles by default - if (type == PluginBase.PROFILE) { + if (type == PluginType.PROFILE) { if (!plugin.isEnabled(type)) { holder.checkboxVisible.setEnabled(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 - if (type == PluginBase.PROFILE) { + if (type == PluginType.PROFILE) { if (PumpInterface.class.isAssignableFrom(plugin.getClass())) { - if (!plugin.isEnabled(PluginBase.PUMP)) { + if (!plugin.isEnabled(PluginType.PUMP)) { holder.checkboxEnabled.setEnabled(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 pluginsInCategory = null; switch (type) { // Multiple selection allowed - case PluginBase.GENERAL: - case PluginBase.CONSTRAINTS: - case PluginBase.LOOP: + case GENERAL: + case CONSTRAINTS: + case LOOP: break; // Single selection allowed - case PluginBase.INSULIN: + case INSULIN: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(InsulinInterface.class); break; - case PluginBase.SENSITIVITY: + case SENSITIVITY: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(SensitivityInterface.class); break; - case PluginBase.APS: + case APS: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(APSInterface.class); break; - case PluginBase.PROFILE: + case PROFILE: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(ProfileInterface.class); break; - case PluginBase.BGSOURCE: + case BGSOURCE: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class); break; - case PluginBase.TREATMENT: - case PluginBase.PUMP: + case TREATMENT: + case PUMP: pluginsInCategory = MainApp.getSpecificPluginsListByInterface(PumpInterface.class); break; } @@ -373,13 +374,13 @@ public class ConfigBuilderFragment extends SubscriberFragment { } } } else { // enable first plugin in list - if (type == PluginBase.PUMP) + if (type == PluginType.PUMP) VirtualPumpPlugin.getPlugin().setPluginEnabled(type, true); - else if (type == PluginBase.INSULIN) + else if (type == PluginType.INSULIN) InsulinFastactingPlugin.getPlugin().setPluginEnabled(type, true); - else if (type == PluginBase.SENSITIVITY) + else if (type == PluginType.SENSITIVITY) SensitivityOref0Plugin.getPlugin().setPluginEnabled(type, true); - else if (type == PluginBase.PROFILE) + else if (type == PluginType.PROFILE) NSProfilePlugin.getPlugin().setPluginEnabled(type, true); else pluginsInCategory.get(0).setPluginEnabled(type, true); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 51d91732ca..f0250e1050 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.ConfigBuilder; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import android.support.annotation.Nullable; 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.InsulinInterface; 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.PumpInterface; import info.nightscout.androidaps.interfaces.SensitivityInterface; 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.LoopPlugin; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; 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.CommandQueue; import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.NSUpload; +import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; /** * 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 ConfigBuilderPlugin configBuilderPlugin; @@ -86,116 +89,159 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { private static CommandQueue commandQueue = new CommandQueue(); 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); } @Override - public int getType() { - return PluginBase.GENERAL; + public void onStop() { + 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() { pluginList = MainApp.getPluginsList(); + upgradeSettings(); loadSettings(); MainApp.bus().post(new EventAppInitialized()); } - public void storeSettings() { + public void storeSettings(String from) { if (pluginList != null) { if (Config.logPrefsChange) - log.debug("Storing settings"); - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - SharedPreferences.Editor editor = settings.edit(); + log.debug("Storing settings from: " + from); - for (int type = 1; type < PluginBase.LAST; type++) { - for (PluginBase p : pluginList) { - String settingEnabled = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Enabled"; - String settingVisible = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Visible"; - editor.putBoolean(settingEnabled, p.isEnabled(type)); - editor.putBoolean(settingVisible, p.isVisibleInTabs(type)); + for (PluginBase p : pluginList) { + PluginType type = p.getType(); + if (p.pluginDescription.alwaysEnabled && p.pluginDescription.alwayVisible) + continue; + 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(); } } + 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() { if (Config.logPrefsChange) log.debug("Loading stored settings"); - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - for (int type = 1; type < PluginBase.LAST; type++) { - for (PluginBase p : pluginList) { - try { - String settingEnabled = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Enabled"; - String settingVisible = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Visible"; - if (SP.contains(settingEnabled)) - p.setPluginEnabled(type, SP.getBoolean(settingEnabled, true)); - if (SP.contains(settingVisible)) - p.setFragmentVisible(type, SP.getBoolean(settingVisible, true) && SP.getBoolean(settingEnabled, true)); - } catch (Exception e) { - log.error("Unhandled exception", e); + for (PluginBase p : pluginList) { + 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 settingVisible = "ConfigBuilder_" + type + "_" + p.getClass().getSimpleName() + "_Visible"; + if (SP.contains(settingEnabled)) + p.setPluginEnabled(newType, SP.getBoolean(settingEnabled, false)); + if (SP.contains(settingVisible)) + p.setFragmentVisible(newType, SP.getBoolean(settingVisible, false) && SP.getBoolean(settingEnabled, false)); + SP.remove(settingEnabled); + 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() { for (PluginBase p : pluginList) { log.debug(p.getName() + ":" + - (p.isEnabled(1) ? " GENERAL" : "") + - (p.isEnabled(2) ? " TREATMENT" : "") + - (p.isEnabled(3) ? " SENSITIVITY" : "") + - (p.isEnabled(4) ? " PROFILE" : "") + - (p.isEnabled(5) ? " APS" : "") + - (p.isEnabled(6) ? " PUMP" : "") + - (p.isEnabled(7) ? " CONSTRAINTS" : "") + - (p.isEnabled(8) ? " LOOP" : "") + - (p.isEnabled(9) ? " BGSOURCE" : "") + - (p.isEnabled(10) ? " INSULIN" : "") + (p.isEnabled(PluginType.GENERAL) ? " GENERAL" : "") + + (p.isEnabled(PluginType.TREATMENT) ? " TREATMENT" : "") + + (p.isEnabled(PluginType.SENSITIVITY) ? " SENSITIVITY" : "") + + (p.isEnabled(PluginType.PROFILE) ? " PROFILE" : "") + + (p.isEnabled(PluginType.APS) ? " APS" : "") + + (p.isEnabled(PluginType.PUMP) ? " PUMP" : "") + + (p.isEnabled(PluginType.CONSTRAINTS) ? " CONSTRAINTS" : "") + + (p.isEnabled(PluginType.LOOP) ? " LOOP" : "") + + (p.isEnabled(PluginType.BGSOURCE) ? " BGSOURCE" : "") + + (p.isEnabled(PluginType.INSULIN) ? " INSULIN" : "") ); } } @@ -254,33 +300,47 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { private void verifySelectionInCategories() { ArrayList pluginsInCategory; - // PluginBase.APS - activeAPS = this.determineActivePlugin(APSInterface.class, PluginBase.APS); + // PluginType.APS + activeAPS = this.determineActivePlugin(APSInterface.class, PluginType.APS); - // PluginBase.INSULIN - activeInsulin = this.determineActivePlugin(InsulinInterface.class, PluginBase.INSULIN); + // PluginType.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 - activeSensitivity = this.determineActivePlugin(SensitivityInterface.class, PluginBase.SENSITIVITY); + // PluginType.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 - activeProfile = this.determineActivePlugin(ProfileInterface.class, PluginBase.PROFILE); + // PluginType.PROFILE + activeProfile = this.determineActivePlugin(ProfileInterface.class, PluginType.PROFILE); - // PluginBase.BGSOURCE - activeBgSource = this.determineActivePlugin(BgSourceInterface.class, PluginBase.BGSOURCE); + // PluginType.BGSOURCE + activeBgSource = this.determineActivePlugin(BgSourceInterface.class, PluginType.BGSOURCE); - // PluginBase.PUMP - pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.PUMP); - activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP); - if (activePump == null) - activePump = VirtualPumpPlugin.getPlugin(); // for NSClient build - this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginBase.PUMP); + // PluginType.PUMP + pluginsInCategory = MainApp.getSpecificPluginsList(PluginType.PUMP); + activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginType.PUMP); + if (activePump == null) { + activePump = VirtualPumpPlugin.getPlugin(); + VirtualPumpPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, true); + } + this.setFragmentVisiblities(((PluginBase) activePump).getName(), pluginsInCategory, PluginType.PUMP); - // PluginBase.LOOP - activeLoop = this.determineActivePlugin(PluginBase.LOOP); + // PluginType.LOOP + activeLoop = this.determineActivePlugin(PluginType.LOOP); - // PluginBase.TREATMENT - activeTreatments = this.determineActivePlugin(PluginBase.TREATMENT); + // PluginType.TREATMENT + activeTreatments = this.determineActivePlugin(PluginType.TREATMENT); } /** @@ -292,14 +352,14 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { * @param * @return */ - private T determineActivePlugin(Class pluginInterface, int pluginType) { + private T determineActivePlugin(Class pluginInterface, PluginType pluginType) { ArrayList pluginsInCategory; pluginsInCategory = MainApp.getSpecificPluginsListByInterface(pluginInterface); return this.determineActivePlugin(pluginsInCategory, pluginType); } - private T determineActivePlugin(int pluginType) { + private T determineActivePlugin(PluginType pluginType) { ArrayList pluginsInCategory; pluginsInCategory = MainApp.getSpecificPluginsList(pluginType); @@ -321,7 +381,7 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { * @return */ private T determineActivePlugin(ArrayList pluginsInCategory, - int pluginType) { + PluginType pluginType) { T activePlugin = (T) getTheOneEnabledInArray(pluginsInCategory, pluginType); if (activePlugin != null) { @@ -333,7 +393,7 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { } private void setFragmentVisiblities(String activePluginName, ArrayList pluginsInCategory, - int pluginType) { + PluginType pluginType) { if (Config.logConfigBuilder) log.debug("Selected interface: " + activePluginName); for (PluginBase p : pluginsInCategory) { @@ -344,7 +404,7 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { } @Nullable - private PluginBase getTheOneEnabledInArray(ArrayList pluginsInCategory, int type) { + private PluginBase getTheOneEnabledInArray(ArrayList pluginsInCategory, PluginType type) { PluginBase found = null; for (PluginBase p : pluginsInCategory) { if (p.isEnabled(type) && found == null) { @@ -355,8 +415,8 @@ public class ConfigBuilderPlugin implements PluginBase, TreatmentsInterface { } } // If none enabled, enable first one - if (found == null && pluginsInCategory.size() > 0) - found = pluginsInCategory.get(0); + //if (found == null && pluginsInCategory.size() > 0) + // found = pluginsInCategory.get(0); return found; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java index 14255a28e1..23f5cb1fb8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java @@ -24,9 +24,10 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.utils.FabricPrivacy; -public class ObjectivesFragment extends Fragment { +public class ObjectivesFragment extends SubscriberFragment { private static Logger log = LoggerFactory.getLogger(ObjectivesFragment.class); RecyclerView recyclerView; @@ -214,15 +215,13 @@ public class ObjectivesFragment extends Fragment { return null; } - void updateGUI() { + @Override + public void updateGUI() { Activity activity = getActivity(); if (activity != null) - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - RecyclerViewAdapter adapter = new RecyclerViewAdapter(ObjectivesPlugin.objectives); - recyclerView.setAdapter(adapter); - } + activity.runOnUiThread(() -> { + RecyclerViewAdapter adapter = new RecyclerViewAdapter(ObjectivesPlugin.objectives); + recyclerView.setAdapter(adapter); }); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index e031d16976..76caf3d306 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -18,6 +18,9 @@ import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; 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.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; @@ -28,7 +31,7 @@ import info.nightscout.utils.SP; /** * 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 ObjectivesPlugin objectivesPlugin; @@ -42,77 +45,27 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { public static List objectives; - private boolean fragmentVisible = true; - private ObjectivesPlugin() { + super(new PluginDescription() + .mainType(PluginType.CONSTRAINTS) + .fragmentClass(ObjectivesFragment.class.getName()) + .alwaysEnabled(true) + .pluginName(R.string.objectives) + .shortName(R.string.objectives_shortname) + ); initializeData(); loadProgress(); - MainApp.bus().register(this); } @Override - public String getFragmentClass() { - return ObjectivesFragment.class.getName(); + public boolean specialEnableCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Override - public int getType() { - return PluginBase.CONSTRAINTS; - } - - @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 boolean specialShowInListCondition() { + return !Config.NSCLIENT && !Config.G5UPLOADER; } public class Objective { @@ -170,23 +123,23 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { RequirementResult requirementsMet(Integer objNum) { switch (objNum) { case 0: - boolean isVirtualPump = VirtualPumpPlugin.getPlugin().isEnabled(PluginBase.PUMP); + boolean isVirtualPump = VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP); boolean vpUploadEnabled = SP.getBoolean("virtualpump_uploadstatus", false); boolean vpUploadNeeded = !isVirtualPump || vpUploadEnabled; boolean hasBGData = DatabaseHelper.lastBg() != null; boolean apsEnabled = false; APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS(); - if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) + if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginType.APS)) 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) + "\n" + MainApp.gs(R.string.nsclienthaswritepermission) + ": " + yesOrNo(NSClientPlugin.getPlugin().hasWritePermission()) + (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.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) ); case 1: @@ -328,14 +281,14 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface { } @Override - public Constraint isAMAModeEnabled(Constraint value) { + public Constraint isAMAModeEnabled(Constraint value) { if (!objectives.get(6).isStarted()) value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7), this); return value; } @Override - public Constraint isSMBModeEnabled(Constraint value) { + public Constraint isSMBModeEnabled(Constraint value) { if (!objectives.get(7).isStarted()) value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8), this); return value; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java index e76be9a32c..a3e27e1662 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java @@ -1,8 +1,5 @@ package info.nightscout.androidaps.plugins.ConstraintsSafety; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.ConstraintsInterface; 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.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; @@ -23,8 +22,7 @@ import info.nightscout.utils.SP; /** * Created by mike on 05.08.2016. */ -public class SafetyPlugin implements PluginBase, ConstraintsInterface { - private static Logger log = LoggerFactory.getLogger(SafetyPlugin.class); +public class SafetyPlugin extends PluginBase implements ConstraintsInterface { static SafetyPlugin plugin = null; @@ -34,64 +32,15 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface { return plugin; } - @Override - public String getFragmentClass() { - return null; - } - - @Override - public int getType() { - return PluginBase.CONSTRAINTS; - } - - @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; + public SafetyPlugin() { + super(new PluginDescription() + .mainType(PluginType.CONSTRAINTS) + .neverVisible(true) + .alwaysEnabled(true) + .showInList(false) + .pluginName(R.string.safety) + .preferencesId(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); 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); - 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); - 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); return maxIob; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java index 2f7337566e..14eb318af4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Food/FoodPlugin.java @@ -1,90 +1,33 @@ package info.nightscout.androidaps.plugins.Food; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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 FoodPlugin implements PluginBase { - private boolean fragmentEnabled = true; - private boolean fragmentVisible = false; +public class FoodPlugin extends PluginBase { private static FoodPlugin plugin = null; - private FoodService service; - - private FoodPlugin() { - this.service = new FoodService(); - } - public static FoodPlugin getPlugin() { if (plugin == null) plugin = new FoodPlugin(); return plugin; } - @Override - public String getFragmentClass() { - return FoodFragment.class.getName(); - } + private FoodService service; - @Override - public int getType() { - return PluginBase.GENERAL; - } - - @Override - public String getName() { - return MainApp.instance().getString(R.string.food); - } - - @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; + private FoodPlugin() { + super(new PluginDescription() + .mainType(PluginType.GENERAL) + .fragmentClass(FoodFragment.class.getName()) + .pluginName(R.string.food) + .shortName(R.string.food_short) + ); + this.service = new FoodService(); } public FoodService getService() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java index bb9c035115..0fc5220044 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingPlugin.java @@ -7,15 +7,14 @@ import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; 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. */ -public class InsulinFastactingPlugin implements PluginBase, InsulinInterface { - - private boolean fragmentEnabled = true; - private boolean fragmentVisible = false; +public class InsulinFastactingPlugin extends PluginBase implements InsulinInterface { private static InsulinFastactingPlugin plugin = null; @@ -25,64 +24,13 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface { return plugin; } - @Override - public int getType() { - return INSULIN; - } - - @Override - 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; + public InsulinFastactingPlugin() { + super(new PluginDescription() + .mainType(PluginType.INSULIN) + .fragmentClass(InsulinFragment.class.getName()) + .pluginName(R.string.fastactinginsulin) + .shortName(R.string.insulin_shortname) + ); } // Insulin interface diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java index 6afb867ec9..d6a41add4c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinFastactingProlongedPlugin.java @@ -8,15 +8,14 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; 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. */ -public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInterface { - - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; +public class InsulinFastactingProlongedPlugin extends PluginBase implements InsulinInterface { private static InsulinFastactingProlongedPlugin plugin = null; @@ -26,64 +25,13 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte return plugin; } - @Override - public int getType() { - return INSULIN; - } - - @Override - 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; + public InsulinFastactingProlongedPlugin() { + super(new PluginDescription() + .mainType(PluginType.INSULIN) + .fragmentClass(InsulinFragment.class.getName()) + .pluginName(R.string.fastactinginsulinprolonged) + .shortName(R.string.insulin_shortname) + ); } // Insulin interface diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java index b91eefdc9c..cf56452bcc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePlugin.java @@ -8,42 +8,28 @@ import info.nightscout.androidaps.data.Iob; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.interfaces.InsulinInterface; 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.notifications.Notification; /** * 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; long lastWarned = 0; - @Override - public int getType() { - return INSULIN; - } - - @Override - 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 InsulinOrefBasePlugin() { + super(new PluginDescription() + .mainType(PluginType.INSULIN) + .fragmentClass(InsulinFragment.class.getName()) + .pluginName(R.string.fastactinginsulin) + .shortName(R.string.insulin_shortname) + ); } public Bus getBus() { @@ -53,7 +39,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf @Override public double getDia() { double dia = getUserDefinedDia(); - if(dia >= MIN_DIA){ + if (dia >= MIN_DIA) { return dia; } else { sendShortDiaNotification(dia); @@ -62,7 +48,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf } void sendShortDiaNotification(double dia) { - if((System.currentTimeMillis() - lastWarned) > 60*1000) { + if ((System.currentTimeMillis() - lastWarned) > 60 * 1000) { lastWarned = System.currentTimeMillis(); Notification notification = new Notification(Notification.SHORT_DIA, String.format(this.getNotificationPattern(), dia, MIN_DIA), Notification.URGENT); this.getBus().post(new EventNewNotification(notification)); @@ -92,7 +78,7 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf long bolusTime = treatment.date; 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; // force the IOB to 0 if over DIA hours have passed @@ -109,9 +95,9 @@ public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterf @Override public String getComment() { - String comment = commentStandardText(); + String comment = commentStandardText(); 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); } return comment; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java index 76667d3ad7..3a19573d71 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefFreePeakPlugin.java @@ -10,9 +10,6 @@ import info.nightscout.utils.SP; public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin { - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - private static InsulinOrefFreePeakPlugin plugin = null; public static InsulinOrefFreePeakPlugin getPlugin() { @@ -21,24 +18,20 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin { 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 public int getId() { 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() { 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(); } - @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 int getPeak() { return SP.getInt(R.string.key_insulin_oref_peak, DEFAULT_PEAK); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java index 86af7f8130..cd7769b55b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefRapidActingPlugin.java @@ -9,9 +9,6 @@ import info.nightscout.androidaps.R; public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin { - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - private static InsulinOrefRapidActingPlugin plugin = null; public static InsulinOrefRapidActingPlugin getPlugin() { @@ -20,23 +17,19 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin { 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 public int getId() { 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 public String getFriendlyName() { 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); } - @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 int getPeak() { return PEAK; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java index 0c24bb1034..0e20f8dd42 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefUltraRapidActingPlugin.java @@ -9,9 +9,6 @@ import info.nightscout.androidaps.R; public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - private static InsulinOrefUltraRapidActingPlugin plugin = null; public static InsulinOrefUltraRapidActingPlugin getPlugin() { @@ -20,7 +17,13 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { return plugin; } - public static final int PEAK = 55; + private static final int PEAK = 55; + + private InsulinOrefUltraRapidActingPlugin() { + super(); + pluginDescription + .pluginName(R.string.ultrarapid_oref); + } @Override public int getId() { @@ -32,11 +35,6 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { return MainApp.sResources.getString(R.string.ultrarapid_oref); } - @Override - public String getFragmentClass() { - return InsulinFragment.class.getName(); - } - @Override public String getFriendlyName() { return MainApp.sResources.getString(R.string.ultrarapid_oref); @@ -47,31 +45,6 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { 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 int getPeak() { return PEAK; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 7a79b62c3a..42a2b35490 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -12,6 +12,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.utils.SP; @@ -33,7 +34,7 @@ public class AutosensData { time = t.date; carbs = 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); Profile profile = MainApp.getConfigBuilder().getProfile(t.date); double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 6128dffadd..21dcefdb1b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -29,6 +29,8 @@ import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; import info.nightscout.androidaps.events.EventPreferenceChange; 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.IobCobCalculator.events.EventNewHistoryData; import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; @@ -38,8 +40,16 @@ import info.nightscout.utils.DateUtil; * Created by mike on 24.04.2017. */ -public class IobCobCalculatorPlugin implements PluginBase { - private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class); +public class IobCobCalculatorPlugin extends PluginBase { + 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 iobTable = new LongSparseArray<>(); // oldest at index 0 private LongSparseArray autosensDataTable = new LongSparseArray<>(); // oldest at index 0 @@ -55,12 +65,26 @@ public class IobCobCalculatorPlugin implements PluginBase { boolean stopCalculationTrigger = false; 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() { - if (plugin == null) - plugin = new IobCobCalculatorPlugin(); - return plugin; + @Override + public void onStart() { + super.onStart(); + MainApp.bus().register(this); + } + + @Override + public void onStop() { + super.onStop(); + MainApp.bus().unregister(this); } public LongSparseArray getAutosensDataTable() { @@ -71,70 +95,6 @@ public class IobCobCalculatorPlugin implements PluginBase { 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 public List getBucketedData(long fromTime) { //log.debug("Locking getBucketedData"); @@ -323,7 +283,7 @@ public class IobCobCalculatorPlugin implements PluginBase { log.debug("Bucketed data created. Size: " + bucketed_data.size()); } - public static long oldestDataAvailable() { + public long oldestDataAvailable() { long now = System.currentTimeMillis(); long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable(); @@ -349,7 +309,7 @@ public class IobCobCalculatorPlugin implements PluginBase { } IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(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 IobTotal basalIobWithZeroTemp = basalIob.copy(); TemporaryBasal t = new TemporaryBasal() @@ -447,7 +407,7 @@ public class IobCobCalculatorPlugin implements PluginBase { log.debug("AUTOSENSDATA null: autosensDataTable empty (" + reason + ")"); return null; } - AutosensData data = null; + AutosensData data; try { data = autosensDataTable.valueAt(autosensDataTable.size() - 1); } 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)); return null; } else { - if (data == null) - log.debug("AUTOSENSDATA null: data == null (" + " " + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time)); return data; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index c2f765e47e..9f34def4c9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -26,9 +26,11 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventTreatmentChange; 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.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.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui; @@ -43,7 +45,7 @@ import info.nightscout.utils.SP; /** * 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); protected static LoopPlugin loopPlugin; @@ -55,9 +57,6 @@ public class LoopPlugin implements PluginBase { return loopPlugin; } - private boolean pluginEnabled = false; - private boolean fragmentVisible = false; - private long loopSuspendedTill = 0L; // end of manual loop suspend private boolean isSuperBolus = false; private boolean isDisconnected = false; @@ -76,78 +75,34 @@ public class LoopPlugin implements PluginBase { static public LastRun lastRun = null; 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); isSuperBolus = SP.getBoolean("isSuperBolus", false); isDisconnected = SP.getBoolean("isDisconnected", false); } @Override - public String getFragmentClass() { - return LoopFragment.class.getName(); + protected void onStart() { + super.onStart(); + MainApp.bus().register(this); } @Override - public int getType() { - return PluginBase.LOOP; + protected void onStop() { + super.onStop(); + MainApp.bus().unregister(this); } @Override - public String getName() { - return MainApp.instance().gs(R.string.loop); - } - - @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; + public boolean specialEnableCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Subscribe @@ -266,7 +221,7 @@ public class LoopPlugin implements PluginBase { final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); APSResult result = null; - if (!isEnabled(PluginBase.LOOP)) + if (!isEnabled(PluginType.LOOP)) return; Profile profile = MainApp.getConfigBuilder().getProfile(); @@ -281,7 +236,7 @@ public class LoopPlugin implements PluginBase { if (pump.getBaseBasalRate() < 0.01d) return; APSInterface usedAPS = ConfigBuilderPlugin.getActiveAPS(); - if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginBase.APS)) { + if (usedAPS != null && ((PluginBase) usedAPS).isEnabled(PluginType.APS)) { usedAPS.invoke(initiator); result = usedAPS.getLastAPSResult(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java index cf33e9dc41..018fc73cb9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/NSClientPlugin.java @@ -24,6 +24,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventAppExit; 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.EventNSClientStatus; 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.ToastUtils; -public class NSClientPlugin implements PluginBase { +public class NSClientPlugin extends PluginBase { private static Logger log = LoggerFactory.getLogger(NSClientPlugin.class); static NSClientPlugin nsClientPlugin; @@ -43,9 +45,6 @@ public class NSClientPlugin implements PluginBase { return nsClientPlugin; } - private boolean fragmentEnabled = true; - private boolean fragmentVisible = true; - public Handler handler; private final List listLog = new ArrayList<>(); @@ -58,8 +57,14 @@ public class NSClientPlugin implements PluginBase { public NSClientService nsClientService = null; - NSClientPlugin() { - MainApp.bus().register(this); + public NSClientPlugin() { + 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); autoscroll = SP.getBoolean(R.string.key_nsclientinternal_autoscroll, true); @@ -68,78 +73,28 @@ public class NSClientPlugin implements PluginBase { handlerThread.start(); handler = new Handler(handlerThread.getLooper()); } + } + @Override + protected void onStart() { + MainApp.bus().register(this); Context context = MainApp.instance().getApplicationContext(); Intent intent = new Intent(context, NSClientService.class); context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Override - public int getType() { - return PluginBase.GENERAL; + protected void onStop() { + MainApp.bus().unregister(this); + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(mConnection); } @Override - public String getFragmentClass() { - 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) { + public boolean specialShowInListCondition() { 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() { public void onServiceDisconnected(ComponentName name) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java index a07ae3db39..2aae41538a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/AckAlarmReceiver.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.data.AlarmAck; 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, AckAlarmReceiver.class.getSimpleName()); NSClientPlugin nsClientPlugin = MainApp.getSpecificPlugin(NSClientPlugin.class); - if (!nsClientPlugin.isEnabled(PluginBase.GENERAL)) { + if (!nsClientPlugin.isEnabled(PluginType.GENERAL)) { return; } if (SP.getBoolean(R.string.key_ns_noupload, false)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java index 4ebd36c31a..31dff0985e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/receivers/DBAccessReceiver.java @@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.UploadQueue; import info.nightscout.androidaps.plugins.NSClientInternal.broadcasts.BroadcastTreatment; @@ -106,7 +106,7 @@ public class DBAccessReceiver extends BroadcastReceiver { public boolean shouldUpload() { 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) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index c2c2348610..1d9d832837 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -34,6 +34,7 @@ import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventConfigBuilderChange; import info.nightscout.androidaps.events.EventPreferenceChange; 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.UploadQueue; import info.nightscout.androidaps.plugins.NSClientInternal.acks.NSAddAck; @@ -180,7 +181,7 @@ public class NSClientService extends Service { @Subscribe 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; destroy(); initialize(); @@ -313,7 +314,7 @@ public class NSClientService extends Service { } 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, ""); nsAPISecret = SP.getString(R.string.key_nsclientinternal_api_secret, ""); nsDevice = SP.getString("careportal_enteredby", ""); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java index 4c69a347b4..4f7edc7559 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/OpenAPSAMAPlugin.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; -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.IobCobCalculator.AutosensResult; @@ -32,12 +32,11 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.HardLimits; import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; -import info.nightscout.utils.SP; /** * 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 OpenAPSAMAPlugin openAPSAMAPlugin; @@ -55,75 +54,26 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { DetermineBasalResultAMA lastAPSResult = null; AutosensResult lastAutosensResult = null; - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - - @Override - public String getName() { - return MainApp.instance().getString(R.string.openapsama); + public OpenAPSAMAPlugin() { + super(new PluginDescription() + .mainType(PluginType.APS) + .fragmentClass(OpenAPSAMAFragment.class.getName()) + .pluginName(R.string.openapsama) + .shortName(R.string.oaps_shortname) + .preferencesId(R.xml.pref_openapsama) + ); } @Override - public String getNameShort() { - String name = MainApp.sResources.getString(R.string.oaps_shortname); - if (!name.trim().isEmpty()) { - //only if translation exists - return name; - } - // use long name as fallback - return getName(); + public boolean specialEnableCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Override - public boolean isEnabled(int type) { - boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump() != null && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable; - return type == APS && fragmentEnabled && pumpCapable; - } - - @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(); + public boolean specialShowInListCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Override @@ -159,7 +109,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { return; } - if (!isEnabled(PluginBase.APS)) { + if (!isEnabled(PluginType.APS)) { MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled))); if (Config.logAPSResult) log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); @@ -192,7 +142,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { MealData mealData = MainApp.getConfigBuilder().getMealData(); Profiler.log(log, "getMealData()", startPart); - double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); + double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); minBg = HardLimits.verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]); maxBg = HardLimits.verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]); @@ -221,7 +171,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface { startPart = new Date(); if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { - lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis()); + lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis()); } else { lastAutosensResult = new AutosensResult(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java index 7fb7a3e207..c8372641b1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAPlugin.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.TemporaryBasal; import info.nightscout.androidaps.interfaces.APSInterface; -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.Loop.APSResult; @@ -30,7 +30,6 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.HardLimits; import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; -import info.nightscout.utils.SP; import static info.nightscout.utils.HardLimits.checkOnlyHardLimits; 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. */ -public class OpenAPSMAPlugin implements PluginBase, APSInterface { +public class OpenAPSMAPlugin extends PluginBase implements APSInterface { private static Logger log = LoggerFactory.getLogger(OpenAPSMAPlugin.class); private static OpenAPSMAPlugin openAPSMAPlugin; @@ -55,75 +54,26 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { Date lastAPSRun = null; DetermineBasalResultMA lastAPSResult = null; - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - - @Override - public String getName() { - return MainApp.instance().getString(R.string.openapsma); + public OpenAPSMAPlugin() { + super(new PluginDescription() + .mainType(PluginType.APS) + .fragmentClass(OpenAPSMAFragment.class.getName()) + .pluginName(R.string.openapsma) + .shortName(R.string.oaps_shortname) + .preferencesId(R.xml.pref_openapsma) + ); } @Override - public String getNameShort() { - String name = MainApp.sResources.getString(R.string.oaps_shortname); - if (!name.trim().isEmpty()) { - //only if translation exists - return name; - } - // use long name as fallback - return getName(); + public boolean specialEnableCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Override - public boolean isEnabled(int type) { - boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump() != null && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable; - return type == APS && fragmentEnabled && pumpCapable; - } - - @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(); + public boolean specialShowInListCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Override @@ -159,7 +109,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { return; } - if (!isEnabled(PluginBase.APS)) { + if (!isEnabled(PluginType.APS)) { MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled))); if (Config.logAPSResult) log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); @@ -194,7 +144,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { MealData mealData = MainApp.getConfigBuilder().getMealData(); - double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); + double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); Profiler.log(log, "MA data gathering", start); minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]); @@ -237,7 +187,7 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface { // limit requests on openloop mode if (!MainApp.getConstraintChecker().isClosedLoopAllowed().value()) { TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); - if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) { + if (activeTemp != null && determineBasalResultMA.rate == 0 && determineBasalResultMA.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultMA.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { determineBasalResultMA.tempBasalRequested = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java index 2f50d72335..8fe5f0a673 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/OpenAPSSMBPlugin.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.util.Date; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.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.IobCobCalculator.AutosensResult; @@ -33,29 +34,16 @@ import info.nightscout.utils.HardLimits; import info.nightscout.utils.NSUpload; import info.nightscout.utils.Profiler; import info.nightscout.utils.Round; -import info.nightscout.utils.SP; import info.nightscout.utils.ToastUtils; /** * 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); - // 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 OpenAPSSMBPlugin() { - } - public static OpenAPSSMBPlugin getPlugin() { if (openAPSSMBPlugin == null) { openAPSSMBPlugin = new OpenAPSSMBPlugin(); @@ -63,72 +51,32 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { return openAPSSMBPlugin; } - @Override - public String getName() { - return MainApp.instance().getString(R.string.openapssmb); + // last values + DetermineBasalAdapterSMBJS lastDetermineBasalAdapterSMBJS = null; + 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 - public String getNameShort() { - String name = MainApp.sResources.getString(R.string.smb_shortname); - if (!name.trim().isEmpty()) { - //only if translation exists - return name; - } - // use long name as fallback - return getName(); + public boolean specialEnableCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Override - public boolean isEnabled(int type) { - boolean pumpCapable = ConfigBuilderPlugin.getActivePump() == null || ConfigBuilderPlugin.getActivePump() != null && ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable; - return type == APS && fragmentEnabled && pumpCapable; - } - - @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(); + public boolean specialShowInListCondition() { + PumpInterface pump = ConfigBuilderPlugin.getActivePump(); + return pump == null || pump.getPumpDescription().isTempBasalCapable; } @Override @@ -164,7 +112,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { return; } - if (!isEnabled(PluginBase.APS)) { + if (!isEnabled(PluginType.APS)) { MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.instance().getString(R.string.openapsma_disabled))); if (Config.logAPSResult) log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); @@ -201,7 +149,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { MealData mealData = MainApp.getConfigBuilder().getMealData(); Profiler.log(log, "getMealData()", startPart); - double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); + double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value(); minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]); maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]); @@ -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)) return; if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF)) return; - if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.05, HardLimits.maxBasal())) return; - if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) return; + if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.05, HardLimits.maxBasal())) + return; + if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, HardLimits.maxBasal())) + return; startPart = new Date(); if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { - lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis()); + lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis()); } else { lastAutosensResult = new AutosensResult(); } @@ -267,7 +218,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface { // limit requests on openloop mode if (!MainApp.getConstraintChecker().isClosedLoopAllowed().value()) { TemporaryBasal activeTemp = MainApp.getConfigBuilder().getTempBasalFromHistory(now); - if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) { + if (activeTemp != null && determineBasalResultSMB.rate == 0 && determineBasalResultSMB.duration == 0) { // going to cancel } else if (activeTemp != null && Math.abs(determineBasalResultSMB.rate - activeTemp.tempBasalConvertedToAbsolute(now, profile)) < 0.1) { determineBasalResultSMB.tempBasalRequested = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java index e6f4772d7a..e08dd6ba0d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java @@ -84,7 +84,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempTargetChange; 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.PumpInterface; 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.notifications.Notification; import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; -import info.nightscout.androidaps.plugins.SourceDexcomG5.SourceDexcomG5Plugin; -import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin; +import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.BolusWizard; @@ -458,7 +458,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, if (activeloop == null || !MainApp.getConfigBuilder().isProfileValid("ContexMenuCreation")) return; 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)); if (!activeloop.isSuspended()) { 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)); } } - if (!activeloop.isEnabled(PluginBase.LOOP)) + if (!activeloop.isEnabled(PluginType.LOOP)) menu.add(MainApp.sResources.getString(R.string.enableloop)); } else if (v == activeProfileView) { menu.setHeaderTitle(MainApp.sResources.getString(R.string.profile)); @@ -494,9 +494,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, return true; final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); if (item.getTitle().equals(MainApp.sResources.getString(R.string.disableloop))) { - activeloop.setPluginEnabled(PluginBase.LOOP, false); - activeloop.setFragmentVisible(PluginBase.LOOP, false); - MainApp.getConfigBuilder().storeSettings(); + activeloop.setPluginEnabled(PluginType.LOOP, false); + activeloop.setFragmentVisible(PluginType.LOOP, false); + MainApp.getConfigBuilder().storeSettings("DisablingLoop"); updateGUI("suspendmenu"); MainApp.getConfigBuilder().getCommandQueue().cancelTempBasal(true, new Callback() { @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 return true; } else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) { - activeloop.setPluginEnabled(PluginBase.LOOP, true); - activeloop.setFragmentVisible(PluginBase.LOOP, true); - MainApp.getConfigBuilder().storeSettings(); + activeloop.setPluginEnabled(PluginType.LOOP, true); + activeloop.setFragmentVisible(PluginType.LOOP, true); + MainApp.getConfigBuilder().storeSettings("EnablingLoop"); updateGUI("suspendmenu"); NSUpload.uploadOpenAPSOffline(0); return true; @@ -581,8 +581,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, @Override public void onClick(View v) { - boolean xdrip = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginBase.BGSOURCE); - boolean g5 = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.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(PluginType.BGSOURCE); String units = MainApp.getConfigBuilder().getProfileUnits(); FragmentManager manager = getFragmentManager(); @@ -1101,8 +1101,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, } // **** Calibration & CGM buttons **** - boolean xDripIsBgSource = MainApp.getSpecificPlugin(SourceXdripPlugin.class) != null && MainApp.getSpecificPlugin(SourceXdripPlugin.class).isEnabled(PluginBase.BGSOURCE); - boolean g5IsBgSource = MainApp.getSpecificPlugin(SourceDexcomG5Plugin.class) != null && MainApp.getSpecificPlugin(SourceDexcomG5Plugin.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(PluginType.BGSOURCE); boolean bgAvailable = DatabaseHelper.actualBg() != null; if (calibrationButton != null) { if ((xDripIsBgSource || g5IsBgSource) && bgAvailable && SP.getBoolean(R.string.key_show_calibration_button, true)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java index 376ee9ca87..bc219d6f32 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java @@ -13,6 +13,8 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.QuickWizard; import info.nightscout.androidaps.events.EventRefreshOverview; 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.EventNewNotification; import info.nightscout.androidaps.plugins.Overview.notifications.NotificationStore; @@ -21,7 +23,7 @@ import info.nightscout.utils.SP; /** * 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 OverviewPlugin overviewPlugin = new OverviewPlugin(); @@ -40,82 +42,34 @@ public class OverviewPlugin implements PluginBase { public NotificationStore notificationStore = new NotificationStore(); 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", "[]"); try { quickWizard.setData(new JSONArray(storedData)); } catch (JSONException e) { log.error("Unhandled exception", e); } + } + + @Override + public void onStart() { MainApp.bus().register(this); } @Override - public String getFragmentClass() { - return OverviewFragment.class.getName(); + public void onStop() { + 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 public void onStatusEvent(final EventNewNotification n) { notificationStore.add(n.notification); @@ -128,14 +82,6 @@ public class OverviewPlugin implements PluginBase { 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) { double highLineSetting = SP.getDouble("high_mark", Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units)); if (highLineSetting < 1) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java index 282b3e16a7..60c18d6018 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Persistentnotification/PersistentNotificationPlugin.java @@ -6,8 +6,8 @@ import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.support.v4.app.TaskStackBuilder; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.TaskStackBuilder; 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.EventTreatmentChange; 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.utils.DecimalFormatter; @@ -36,84 +38,37 @@ import info.nightscout.utils.DecimalFormatter; * 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 boolean fragmentEnabled = true; private final Context ctx; public PersistentNotificationPlugin(Context ctx) { + super(new PluginDescription() + .mainType(PluginType.GENERAL) + .neverVisible(true) + .pluginName(R.string.ongoingnotificaction) + .enableByDefault(true) + ); this.ctx = ctx; } - @Override - public int getType() { - return GENERAL; + protected void onStart() { + MainApp.bus().register(this); + updateNotification(); } @Override - public String getFragmentClass() { - return null; - } - - @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) ctx.getSystemService(Context.NOTIFICATION_SERVICE); - mNotificationManager.cancel(ONGOING_NOTIFICATION_ID); - } else { - updateNotification(); - } + protected void onStop() { + MainApp.bus().unregister(this); + NotificationManager mNotificationManager = + (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); + mNotificationManager.cancel(ONGOING_NOTIFICATION_ID); } private void updateNotification() { - if (!fragmentEnabled) { + if (!isEnabled(PluginType.GENERAL)) { 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) { String deltastring = ""; if (deltaMGDL >= 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java index c59537ad6b..512d452289 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfilePlugin.java @@ -15,6 +15,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ProfileStore; 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.utils.DecimalFormatter; import info.nightscout.utils.SP; @@ -22,7 +24,7 @@ import info.nightscout.utils.SP; /** * 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"; private static Logger log = LoggerFactory.getLogger(LocalProfilePlugin.class); @@ -34,13 +36,9 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface { return localProfilePlugin; } - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - 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 mmol; @@ -52,75 +50,15 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface { JSONArray targetHigh; public LocalProfilePlugin() { + super(new PluginDescription() + .mainType(PluginType.PROFILE) + .fragmentClass(LocalProfileFragment.class.getName()) + .pluginName(R.string.localprofile) + .shortName(R.string.localprofile_shortname) + ); 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() { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences.Editor editor = settings.edit(); @@ -246,7 +184,6 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface { log.error("Unhandled exception", e); } convertedProfile = new ProfileStore(json); - convertedProfileName = LOCAL_PROFILE; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java index a50e47b998..72eca4545f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfilePlugin.java @@ -17,17 +17,16 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.data.ProfileStore; 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.plugins.ConfigBuilder.ConfigBuilderPlugin; 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; /** * 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 NSProfilePlugin nsProfilePlugin; @@ -38,83 +37,33 @@ public class NSProfilePlugin implements PluginBase, ProfileInterface { return nsProfilePlugin; } - @Override - public String getFragmentClass() { - return NSProfileFragment.class.getName(); - } - - private boolean fragmentEnabled = true; - private boolean fragmentVisible = true; - private ProfileStore profile = null; 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(); - } @Override - public String getName() { - return MainApp.instance().getString(R.string.profileviewer); + protected void onStart() { + MainApp.bus().register(this); } @Override - public String getNameShort() { - String name = MainApp.sResources.getString(R.string.profileviewer_shortname); - if (!name.trim().isEmpty()) { - //only if translation exists - return name; - } - // use long name as fallback - return getName(); + protected void onStop() { + MainApp.bus().unregister(this); } @Override - public boolean isEnabled(int type) { - 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) { + public boolean specialShowInListCondition() { 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 public void storeNewProfile(ProfileStore newProfile) { profile = new ProfileStore(newProfile.getData()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java index 92f810c3a0..adff378819 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileSimple/SimpleProfilePlugin.java @@ -15,13 +15,15 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.ProfileStore; 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.utils.SP; /** * 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 SimpleProfilePlugin simpleProfilePlugin; @@ -32,9 +34,6 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface { return simpleProfilePlugin; } - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - private static ProfileStore convertedProfile = null; boolean mgdl; @@ -47,75 +46,15 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface { Double targetHigh; private SimpleProfilePlugin() { + super(new PluginDescription() + .mainType(PluginType.PROFILE) + .fragmentClass(SimpleProfileFragment.class.getName()) + .pluginName(R.string.simpleprofile) + .shortName(R.string.simpleprofile_shortname) + ); 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() { if (Config.logPrefsChange) log.debug("Storing settings"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java index e09eb87547..d60279d648 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPlugin.java @@ -31,11 +31,13 @@ import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.events.EventRefreshOverview; +import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; 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.PumpInterface; -import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification; @@ -63,14 +65,18 @@ import info.nightscout.utils.SP; /** * 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); public static final String COMBO_TBRS_SET = "combo_tbrs_set"; public static final String COMBO_BOLUSES_DELIVERED = "combo_boluses_delivered"; 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(); @@ -147,16 +153,16 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf */ private volatile List 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() .success(false).enacted(false).comment(MainApp.gs(R.string.combo_pump_unsupported_operation)); 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()); } @@ -164,27 +170,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf 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() { PumpState ps = pump.state; if (ps.activeAlert != null) { @@ -203,53 +188,6 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf 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 public boolean isInitialized() { return pump.initialized; @@ -360,9 +298,9 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf double rate = profile.getBasalTimeFromMidnight(i * 60 * 60); /*The Combo pump does hava a different granularity for basal rate: - * 0.01 - if below 1U/h - * 0.05 - if above 1U/h - * */ + * 0.01 - if below 1U/h + * 0.05 - if above 1U/h + * */ if (rate < 1) { //round to 0.01 granularity; @@ -1439,7 +1377,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf @Override public PumpEnactResult loadTDDs() { - + PumpEnactResult result = new PumpEnactResult(); result.success = readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL)); if (result.success) { @@ -1447,9 +1385,10 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf if (tdds != null) { HashMap map = new HashMap<>(); for (int i = 0; i < tdds.size(); 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(map.containsKey(currTdd.timestamp)){ + Tdd currTdd = tdds.get(i); + if (currTdd.total < 1) + continue; //cases where dummy days are introduced (e.g. Battery change with date loss) + if (map.containsKey(currTdd.timestamp)) { //duplicate days on time changes TDD existing = map.get(currTdd.timestamp); existing.total += currTdd.total; @@ -1460,7 +1399,7 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf Collection uniqueColl = map.values(); - for (TDD currTdd: uniqueColl) { + for (TDD currTdd : uniqueColl) { MainApp.getDbHelper().createOrUpdateTDD(currTdd); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index 3ac2ab65a9..12ec4dfca7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java @@ -21,6 +21,8 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.DanaRInterface; 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.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; @@ -39,13 +41,9 @@ import info.nightscout.utils.SP; * 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 boolean mPluginPumpEnabled = false; - protected boolean mPluginProfileEnabled = false; - protected boolean mFragmentPumpVisible = true; - protected AbstractDanaRExecutionService sExecutionService; protected DanaRPump pump = DanaRPump.getInstance(); @@ -53,79 +51,26 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface, public PumpDescription pumpDescription = new PumpDescription(); - @Override - public String getFragmentClass() { - return DanaRFragment.class.getName(); - } - - // Plugin base interface - @Override - public int getType() { - return PluginBase.PUMP; + protected AbstractDanaRPlugin() { + super(new PluginDescription() + .mainType(PluginType.PUMP) + .fragmentClass(DanaRFragment.class.getName()) + .pluginName(R.string.danarspump) + .shortName(R.string.danarpump_shortname) + .preferencesId(R.xml.pref_danars) + ); } @Override - public String getNameShort() { - 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; + public void onStateChange(PluginType type, State oldState, State newState) { // if pump profile was enabled need to switch to another too - if (type == PluginBase.PUMP && !fragmentEnabled && mPluginProfileEnabled) { - setPluginEnabled(PluginBase.PROFILE, false); - setFragmentVisible(PluginBase.PROFILE, false); - NSProfilePlugin.getPlugin().setPluginEnabled(PluginBase.PROFILE, true); - NSProfilePlugin.getPlugin().setFragmentVisible(PluginBase.PROFILE, true); + 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 - public void setFragmentVisible(int type, boolean fragmentVisible) { - if (type == PluginBase.PUMP) - mFragmentPumpVisible = fragmentVisible; - } - @Override public boolean isSuspended() { return pump.pumpSuspended; @@ -183,7 +128,7 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface, int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60; for (int h = 0; h < basalValues; 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 (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) { 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()); try { extended.put("ActiveProfile", profilename); - } catch (Exception e) { + } catch (Exception ignored) { } pumpjson.put("battery", battery); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index ce1a5c392c..0e118df96a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.PumpDanaR.services.DanaRExecutionService; import info.nightscout.utils.Round; @@ -41,6 +42,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { } public DanaRPlugin() { + super(); log = LoggerFactory.getLogger(DanaRPlugin.class); useExtendedBoluses = SP.getBoolean("danar_useextended", false); @@ -98,7 +100,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin { @Subscribe public void onStatusEvent(final EventPreferenceChange s) { - if (isEnabled(PUMP)) { + if (isEnabled(PluginType.PUMP)) { boolean previousValue = useExtendedBoluses; useExtendedBoluses = SP.getBoolean("danar_useextended", false); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java index 583a0b68c2..7f90fb190b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRHistoryActivity.java @@ -1,14 +1,9 @@ package info.nightscout.androidaps.plugins.PumpDanaR.activities; 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.Handler; import android.os.HandlerThread; -import android.os.IBinder; import android.support.v7.widget.CardView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -32,14 +27,11 @@ import java.util.List; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.DanaRHistoryRecord; import info.nightscout.androidaps.events.EventPumpStatusChanged; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.interfaces.DanaRInterface; -import info.nightscout.androidaps.interfaces.PluginBase; -import info.nightscout.androidaps.interfaces.PumpInterface; +import info.nightscout.androidaps.interfaces.PluginType; 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.events.EventDanaRSyncStatus; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; @@ -124,8 +116,8 @@ public class DanaRHistoryActivity extends Activity { statusView.setVisibility(View.GONE); - boolean isKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class) != null && MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PUMP); - boolean isRS = MainApp.getSpecificPlugin(DanaRSPlugin.class) != null && MainApp.getSpecificPlugin(DanaRSPlugin.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(PluginType.PUMP); // Types diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java index 93f66aa200..642f539f6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java @@ -9,10 +9,10 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.Overview.notifications.Notification; 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.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; @@ -31,20 +31,20 @@ public class MsgInitConnStatusTime extends MessageBase { MainApp.bus().post(new EventNewNotification(notification)); MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model"); log.debug("Wrong model selected. Switching to Korean DanaR"); - MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginBase.PUMP, true); - MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true); - MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginBase.PUMP, false); - MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false); + MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, true); + MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginType.PUMP, true); + MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginType.PUMP, false); + MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginType.PUMP, false); DanaRPump.reset(); // mark not initialized //If profile coming from pump, switch it as well - if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){ - (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, false); - (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); + if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginType.PROFILE)){ + (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, false); + (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginType.PROFILE, true); } - MainApp.getConfigBuilder().storeSettings(); + MainApp.getConfigBuilder().storeSettings("ChangingDanaDriver"); MainApp.bus().post(new EventRefreshGui()); ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java index 5d7b4b65ac..6f87803868 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMeal.java @@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; 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.EventNewNotification; 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 - if (DanaRKoreanPlugin.getPlugin().isEnabled(PluginBase.PUMP)) { + if (DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PUMP)) { pump.basalStep = 0.01d; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 6462afbe79..94adcc6f82 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; @@ -42,6 +43,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { } public DanaRKoreanPlugin() { + super(); log = LoggerFactory.getLogger(DanaRKoreanPlugin.class); useExtendedBoluses = SP.getBoolean("danar_useextended", false); @@ -99,7 +101,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { @Subscribe public void onStatusEvent(final EventPreferenceChange s) { - if (isEnabled(PUMP)) { + if (isEnabled(PluginType.PUMP)) { boolean previousValue = useExtendedBoluses; useExtendedBoluses = SP.getBoolean("danar_useextended", false); @@ -138,7 +140,8 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { Treatment t = new Treatment(); t.isSMB = detailedBolusInfo.isSMB; 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(); result.success = connectionOK; result.bolusDelivered = t.insulin; @@ -250,7 +253,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { // Convert duration from minutes to hours if (Config.logPumpActions) 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) { // Check if some temp is already in progress @@ -331,7 +334,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { public PumpEnactResult cancelRealTempBasal() { PumpEnactResult result = new PumpEnactResult(); - TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); + TemporaryBasal runningTB = MainApp.getConfigBuilder().getTempBasalFromHistory(System.currentTimeMillis()); if (runningTB != null) { sExecutionService.tempBasalStop(); result.enacted = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java index 6e2b66d2d0..2028411791 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/comm/MsgInitConnStatusTime_k.java @@ -9,10 +9,10 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.Overview.notifications.Notification; 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.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; @@ -29,24 +29,24 @@ public class MsgInitConnStatusTime_k extends MessageBase { public void handleMessage(byte[] bytes) { if (bytes.length - 10 < 10) { - Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL); + Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL); MainApp.bus().post(new EventNewNotification(notification)); DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model"); log.debug("Wrong model selected. Switching to export DanaR"); - MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginBase.PUMP, false); - MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, false); - MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginBase.PUMP, true); - MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, true); + MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, false); + MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginType.PUMP, false); + MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginType.PUMP, true); + MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginType.PUMP, true); DanaRPump.reset(); // mark not initialized //If profile coming from pump, switch it as well - if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginBase.PROFILE)) { - (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginBase.PROFILE, false); - (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); + if (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).isEnabled(PluginType.PROFILE)) { + (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginType.PROFILE, false); + (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, true); } - MainApp.getConfigBuilder().storeSettings(); + MainApp.getConfigBuilder().storeSettings("ChangingKoreanDanaDriver"); MainApp.bus().post(new EventRefreshGui()); ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java index 238a5777c2..af7ee06800 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPlugin.java @@ -32,6 +32,8 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.DanaRInterface; 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.PumpDescription; import info.nightscout.androidaps.interfaces.PumpInterface; @@ -54,103 +56,9 @@ import info.nightscout.utils.SP; * 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); - - @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 DanaRPump pump = DanaRPump.getInstance(); - public static PumpDescription pumpDescription = new PumpDescription(); public static DanaRSPlugin getPlugin() { if (plugin == null) @@ -158,12 +66,22 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, 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() { - 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 + super(new PluginDescription() + .mainType(PluginType.PUMP) + .fragmentClass(DanaRFragment.class.getName()) + .pluginName(R.string.danarspump) + .shortName(R.string.danarspump_shortname) + .preferencesId(R.xml.pref_danars) + ); pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.05d; @@ -194,6 +112,34 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface, 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() { public void onServiceDisconnected(ComponentName name) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java index fe84ea8114..9117ad1c98 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MsgCheckValue_v2.java @@ -7,10 +7,10 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.Overview.notifications.Notification; 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.DanaRPump; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase; @@ -39,24 +39,24 @@ public class MsgCheckValue_v2 extends MessageBase { pump.productCode = intFromBuff(bytes, 2, 1); if (pump.model != DanaRPump.EXPORT_MODEL) { pump.lastConnection = 0; - Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL); + Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL); MainApp.bus().post(new EventNewNotification(notification)); MainApp.getSpecificPlugin(DanaRPlugin.class).disconnect("Wrong Model"); log.debug("Wrong model selected. Switching to Korean DanaR"); - MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginBase.PUMP, true); - MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginBase.PUMP, true); - MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginBase.PUMP, false); - MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginBase.PUMP, false); + MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setPluginEnabled(PluginType.PUMP, true); + MainApp.getSpecificPlugin(DanaRKoreanPlugin.class).setFragmentVisible(PluginType.PUMP, true); + MainApp.getSpecificPlugin(DanaRPlugin.class).setPluginEnabled(PluginType.PUMP, false); + MainApp.getSpecificPlugin(DanaRPlugin.class).setFragmentVisible(PluginType.PUMP, false); DanaRPump.reset(); // mark not initialized //If profile coming from pump, switch it as well - if(MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginBase.PROFILE)){ - (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, false); - (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); + if (MainApp.getSpecificPlugin(DanaRPlugin.class).isEnabled(PluginType.PROFILE)) { + (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, false); + (MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).setPluginEnabled(PluginType.PROFILE, true); } - MainApp.getConfigBuilder().storeSettings(); + MainApp.getConfigBuilder().storeSettings("ChangingDanaRv2Driver"); MainApp.bus().post(new EventRefreshGui()); ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection return; @@ -64,22 +64,22 @@ public class MsgCheckValue_v2 extends MessageBase { if (pump.protocol != 2) { pump.lastConnection = 0; - Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL); + Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.sResources.getString(R.string.pumpdrivercorrected), Notification.NORMAL); MainApp.bus().post(new EventNewNotification(notification)); DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model"); log.debug("Wrong model selected. Switching to non APS DanaR"); - (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginBase.PUMP, false); - (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentVisible(PluginBase.PUMP, false); - (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PUMP, true); - (MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentVisible(PluginBase.PUMP, true); + (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginType.PUMP, false); + (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setFragmentVisible(PluginType.PUMP, false); + (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PUMP, true); + (MainApp.getSpecificPlugin(DanaRPlugin.class)).setFragmentVisible(PluginType.PUMP, true); //If profile coming from pump, switch it as well - if(MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginBase.PROFILE)){ - (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginBase.PROFILE, false); - (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginBase.PROFILE, true); + if (MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PROFILE)) { + (MainApp.getSpecificPlugin(DanaRv2Plugin.class)).setPluginEnabled(PluginType.PROFILE, false); + (MainApp.getSpecificPlugin(DanaRPlugin.class)).setPluginEnabled(PluginType.PROFILE, true); } - MainApp.getConfigBuilder().storeSettings(); + MainApp.getConfigBuilder().storeSettings("ChangingDanaRv2Driver"); MainApp.bus().post(new EventRefreshGui()); ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection return; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java index a2f2fea425..25338db4a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPlugin.java @@ -25,6 +25,8 @@ import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.ConstraintsInterface; 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.PumpInterface; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; @@ -74,21 +76,27 @@ import static info.nightscout.androidaps.plugins.PumpInsight.history.PumpIdCache */ @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; - static Integer batteryPercent = 0; - static Integer reservoirInUnits = 0; - static boolean initialized = false; + private static Integer batteryPercent = 0; + private static Integer reservoirInUnits = 0; + private static boolean initialized = false; private static volatile boolean update_pending = false; private static Logger log = LoggerFactory.getLogger(InsightPlugin.class); - private static volatile InsightPlugin plugin; private final InsightAsyncAdapter async = new InsightAsyncAdapter(); private StatusTaskRunner.Result statusResult; private long statusResultTime = -1; private Date lastDataTime = new Date(0); - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; private boolean fauxTBRcancel = true; private PumpDescription pumpDescription = new PumpDescription(); private double basalRate = 0; @@ -97,6 +105,13 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte private List profileBlocks; 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"); 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?) @@ -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 private static void log(String msg) { android.util.Log.e("INSIGHTPUMP", msg); @@ -157,7 +158,8 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte MainApp.bus().post(e); } - private void enableConnector() { + @Override + protected void onStart() { if (!connector_enabled) { synchronized (this) { if (!connector_enabled) { @@ -170,7 +172,7 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte } } - private void disableConnector() { + protected void onStop() { if (connector_enabled) { synchronized (this) { 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 public boolean isFakingTempsByExtendedBoluses() { return false; @@ -593,7 +520,6 @@ public class InsightPlugin implements PluginBase, PumpInterface, ConstraintsInte PumpEnactResult pumpEnactResult = new PumpEnactResult().enacted(true).isPercent(true).duration(durationInMinutes); pumpEnactResult.percent = percent_amount; pumpEnactResult.success = ms.success(); - pumpEnactResult.isTempCancel = percent_amount == 100; // 100% temp basal is a cancellation 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.percent = percent; pumpEnactResult.success = ms.success(); - pumpEnactResult.isTempCancel = percent == 100; // 100% temp basal is a cancellation pumpEnactResult.comment = ms.getCommandComment(); if (pumpEnactResult.success) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java index a7edff8c52..0e12428967 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpMDI/MDIPlugin.java @@ -15,6 +15,8 @@ import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; 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.PumpInterface; import info.nightscout.utils.DateUtil; @@ -22,14 +24,9 @@ import info.nightscout.utils.DateUtil; /** * 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 boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - - private PumpDescription pumpDescription = new PumpDescription(); - private static MDIPlugin plugin = null; public static MDIPlugin getPlugin() { @@ -38,7 +35,13 @@ public class MDIPlugin implements PluginBase, PumpInterface { return plugin; } + private PumpDescription pumpDescription = new PumpDescription(); + private MDIPlugin() { + super(new PluginDescription() + .mainType(PluginType.PUMP) + .pluginName(R.string.mdi) + ); pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.5d; @@ -48,67 +51,6 @@ public class MDIPlugin implements PluginBase, PumpInterface { 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 public boolean isFakingTempsByExtendedBoluses() { return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java index 607c5b8184..d0bd8ebd0b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpVirtual/VirtualPumpPlugin.java @@ -20,6 +20,8 @@ import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; 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.PumpInterface; import info.nightscout.androidaps.interfaces.TreatmentsInterface; @@ -34,19 +36,23 @@ import info.nightscout.utils.SP; /** * 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); - 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 reservoirInUnits = 50; private Date lastDataTime = new Date(0); - private boolean fragmentEnabled = true; - private boolean fragmentVisible = true; - private static boolean fromNSAreCommingFakedExtendedBoluses = false; private PumpDescription pumpDescription = new PumpDescription(); @@ -64,16 +70,14 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { return fromNSAreCommingFakedExtendedBoluses; } - private static VirtualPumpPlugin plugin = null; - - public static VirtualPumpPlugin getPlugin() { - loadFakingStatus(); - if (plugin == null) - plugin = new VirtualPumpPlugin(); - return plugin; - } - 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.bolusStep = 0.1d; @@ -104,72 +108,6 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface { 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 public boolean isFakingTempsByExtendedBoluses() { return (Config.NSCLIENT || Config.G5UPLOADER) && fromNSAreCommingFakedExtendedBoluses; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java index e321e98f1e..6b072a3a17 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java @@ -16,6 +16,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; 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.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; @@ -28,12 +30,9 @@ import info.nightscout.utils.SafeParse; * 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 boolean fragmentEnabled = true; - private boolean fragmentVisible = false; - static SensitivityAAPSPlugin plugin = null; public static SensitivityAAPSPlugin getPlugin() { @@ -42,67 +41,15 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{ return plugin; } - @Override - public int getType() { - return SENSITIVITY; + public SensitivityAAPSPlugin() { + super(new PluginDescription() + .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 public AutosensResult detectSensitivity(long fromTime, long toTime) { LongSparseArray autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java index bcac02f51c..46e00427bf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityOref0/SensitivityOref0Plugin.java @@ -15,6 +15,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; 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.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; @@ -27,12 +29,9 @@ import info.nightscout.utils.SafeParse; * 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 boolean fragmentEnabled = true; - private boolean fragmentVisible = false; - static SensitivityOref0Plugin plugin = null; public static SensitivityOref0Plugin getPlugin() { @@ -41,76 +40,24 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface return plugin; } - @Override - public int getType() { - return SENSITIVITY; + public SensitivityOref0Plugin() { + super(new PluginDescription() + .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 public AutosensResult detectSensitivity(long fromTime, long toTime) { LongSparseArray autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); String age = SP.getString(R.string.key_age, ""); int defaultHours = 24; - if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24; - if (age.equals(MainApp.sResources.getString(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_adult))) defaultHours = 24; + if (age.equals(MainApp.gs(R.string.key_teenage))) defaultHours = 24; + if (age.equals(MainApp.gs(R.string.key_child))) defaultHours = 24; int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours); long now = System.currentTimeMillis(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java index 7b2592c7e8..4066b1edfb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java @@ -12,6 +12,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; 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.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; @@ -24,12 +26,9 @@ import info.nightscout.utils.SafeParse; * 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 boolean fragmentEnabled = true; - private boolean fragmentVisible = false; - private static SensitivityWeightedAveragePlugin plugin = null; public static SensitivityWeightedAveragePlugin getPlugin() { @@ -38,67 +37,15 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity return plugin; } - @Override - public int getType() { - return SENSITIVITY; + public SensitivityWeightedAveragePlugin() { + super(new PluginDescription() + .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 public AutosensResult detectSensitivity(long fromTime, long toTime) { LongSparseArray autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index 1ba525a489..19550fc534 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -31,6 +31,8 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshOverview; 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.Loop.LoopPlugin; @@ -49,7 +51,7 @@ import info.nightscout.utils.XdripCalibrations; /** * 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 SmsCommunicatorPlugin smsCommunicatorPlugin; @@ -62,11 +64,6 @@ public class SmsCommunicatorPlugin implements PluginBase { return smsCommunicatorPlugin; } - private boolean fragmentEnabled = false; - private boolean fragmentVisible = false; - - private final long CONFIRM_TIMEOUT = 5 * 60 * 1000L; - private List allowedNumbers = new ArrayList<>(); class Sms { @@ -120,78 +117,28 @@ public class SmsCommunicatorPlugin implements PluginBase { ArrayList messages = new ArrayList<>(); 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); } @Override - public String getFragmentClass() { - return SmsCommunicatorFragment.class.getName(); + protected void onStart() { + MainApp.bus().register(this); } @Override - public int getType() { - return PluginBase.GENERAL; - } - - @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; + protected void onStop() { + MainApp.bus().unregister(this); } @Subscribe - public void processSettings(final EventPreferenceChange ev) { + private void processSettings(final EventPreferenceChange ev) { if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) { String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, ""); @@ -217,15 +164,17 @@ public class SmsCommunicatorPlugin implements PluginBase { public void onStatusEvent(final EventNewSMS ev) { Object[] pdus = (Object[]) ev.bundle.get("pdus"); - // For every SMS message received - for (Object pdu : pdus) { - SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu); - processSms(new Sms(message)); + if (pdus != null) { + // For every SMS message received + for (Object pdu : pdus) { + SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu); + processSms(new Sms(message)); + } } } private void processSms(final Sms receivedSms) { - if (!isEnabled(PluginBase.GENERAL)) { + if (!isEnabled(PluginType.GENERAL)) { log.debug("Ignoring SMS. Plugin disabled."); return; } @@ -240,10 +189,10 @@ public class SmsCommunicatorPlugin implements PluginBase { log.debug(receivedSms.toString()); String[] splited = receivedSms.text.split("\\s+"); - Double amount = 0d; - Double tempBasal = 0d; + Double amount; + Double tempBasal; int duration = 0; - String passCode = ""; + String passCode; boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false); if (splited.length > 0) { @@ -284,8 +233,8 @@ public class SmsCommunicatorPlugin implements PluginBase { case "DISABLE": case "STOP": LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); - if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) { - loopPlugin.setPluginEnabled(PluginBase.LOOP, false); + if (loopPlugin != null && loopPlugin.isEnabled(PluginType.LOOP)) { + loopPlugin.setPluginEnabled(PluginType.LOOP, false); ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override public void run() { @@ -302,8 +251,8 @@ public class SmsCommunicatorPlugin implements PluginBase { case "ENABLE": case "START": loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); - if (loopPlugin != null && !loopPlugin.isEnabled(PluginBase.LOOP)) { - loopPlugin.setPluginEnabled(PluginBase.LOOP, true); + if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) { + loopPlugin.setPluginEnabled(PluginType.LOOP, true); reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeenenabled); sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START")); @@ -314,7 +263,7 @@ public class SmsCommunicatorPlugin implements PluginBase { case "STATUS": loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class); if (loopPlugin != null) { - if (loopPlugin.isEnabled(PluginBase.LOOP)) { + if (loopPlugin.isEnabled(PluginType.LOOP)) { if (loopPlugin.isSuspended()) reply = String.format(MainApp.sResources.getString(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()); else @@ -489,7 +438,7 @@ public class SmsCommunicatorPlugin implements PluginBase { break; default: // expect passCode here 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; DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo.insulin = bolusWaitingForConfirmation.bolusRequested; @@ -513,7 +462,7 @@ public class SmsCommunicatorPlugin implements PluginBase { } }); } 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; Profile profile = MainApp.getConfigBuilder().getProfile(); if (profile != null) @@ -532,7 +481,7 @@ public class SmsCommunicatorPlugin implements PluginBase { } }); } 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; ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override @@ -549,7 +498,7 @@ public class SmsCommunicatorPlugin implements PluginBase { } }); } 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; boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested); if (result) { @@ -560,7 +509,7 @@ public class SmsCommunicatorPlugin implements PluginBase { sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); } } 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; ConfigBuilderPlugin.getCommandQueue().cancelTempBasal(true, new Callback() { @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceDexcomG5/BGSourceFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/BGSourceFragment.java similarity index 97% rename from app/src/main/java/info/nightscout/androidaps/plugins/SourceDexcomG5/BGSourceFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/Source/BGSourceFragment.java index ef5c4bce5b..7e959b78d4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceDexcomG5/BGSourceFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/BGSourceFragment.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.plugins.SourceDexcomG5; +package info.nightscout.androidaps.plugins.Source; import android.app.Activity; import android.content.DialogInterface; @@ -25,8 +25,6 @@ import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.events.EventNewBG; 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.FabricPrivacy; import info.nightscout.utils.NSUpload; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java new file mode 100644 index 0000000000..be4514a366 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java @@ -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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java new file mode 100644 index 0000000000..0846885df7 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java @@ -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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java new file mode 100644 index 0000000000..8df63df1e6 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java @@ -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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java new file mode 100644 index 0000000000..025e059d67 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java @@ -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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java new file mode 100644 index 0000000000..0d33f529b3 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java @@ -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; + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceDexcomG5/SourceDexcomG5Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceDexcomG5/SourceDexcomG5Plugin.java deleted file mode 100644 index 719b2eb1f4..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceDexcomG5/SourceDexcomG5Plugin.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java deleted file mode 100644 index 719a4b3059..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceGlimp/SourceGlimpPlugin.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java deleted file mode 100644 index 38b787d750..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceMM640g/SourceMM640gPlugin.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java deleted file mode 100644 index bbc1759735..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientPlugin.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java deleted file mode 100644 index 66e8d470fd..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripPlugin.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 829ded4c46..dcbbbe6ce0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -34,6 +34,8 @@ import info.nightscout.androidaps.events.EventReloadTempBasalData; import info.nightscout.androidaps.events.EventReloadTreatmentData; import info.nightscout.androidaps.events.EventTempTargetChange; 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.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; @@ -43,7 +45,7 @@ import info.nightscout.utils.SP; /** * 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 TreatmentsPlugin treatmentsPlugin; @@ -63,76 +65,24 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { private final static Intervals tempTargets = new OverlappingIntervals<>(); private final static ProfileIntervals profiles = new ProfileIntervals<>(); - private boolean fragmentEnabled = true; - private boolean fragmentVisible = true; - - @Override - public String getFragmentClass() { - return TreatmentsFragment.class.getName(); + public TreatmentsPlugin() { + super(new PluginDescription() + .mainType(PluginType.TREATMENT) + .fragmentClass(TreatmentsFragment.class.getName()) + .pluginName(R.string.treatments) + .shortName(R.string.treatments_shortname) + .preferencesId(R.xml.pref_absorption_oref0) + .alwaysEnabled(true) + ); } @Override - public String getName() { - 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) { + public boolean specialShowInListCondition() { return !Config.NSCLIENT && !Config.G5UPLOADER; } @Override - public void setPluginEnabled(int type, boolean fragmentEnabled) { - 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() { + protected void onStart() { MainApp.bus().register(this); initializeTempBasalData(); initializeTreatmentData(); @@ -141,6 +91,11 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface { initializeProfileSwitchData(); } + @Override + protected void onStop() { + MainApp.bus().register(this); + } + private static void initializeTreatmentData() { double dia = Constants.defaultDIA; if (MainApp.getConfigBuilder() != null && MainApp.getConfigBuilder().getProfile() != null) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java index f37effebe3..59adb1ecc0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/WearPlugin.java @@ -5,12 +5,10 @@ import android.content.Intent; import com.squareup.otto.Subscribe; -import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventBolusRequested; import info.nightscout.androidaps.events.EventExtendedBolusChange; -import info.nightscout.androidaps.events.EventLoop; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBasalProfile; 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.EventTreatmentChange; 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.OpenAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning; @@ -29,7 +29,7 @@ import info.nightscout.utils.SP; * Created by adrian on 17/11/16. */ -public class WearPlugin implements PluginBase { +public class WearPlugin extends PluginBase { private static boolean fragmentEnabled = false; private boolean fragmentVisible = false; @@ -41,6 +41,7 @@ public class WearPlugin implements PluginBase { public static WearPlugin getPlugin() { return wearPlugin; } + public static WearPlugin initPlugin(Context ctx) { if (wearPlugin == null) { @@ -51,79 +52,27 @@ public class WearPlugin implements PluginBase { } 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; + } + + @Override + protected void onStart() { 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) { - watchUS.setSettings(); - } + if (watchUS != null) { + watchUS.setSettings(); } } @Override - public void setFragmentVisible(int type, boolean fragmentVisible) { - if (type == GENERAL) this.fragmentVisible = fragmentVisible; - } - - @Override - public int getPreferencesId() { - return R.xml.pref_wear; + protected void onStop() { + MainApp.bus().unregister(this); } private void sendDataToWatch(boolean status, boolean basals, boolean bgValue) { @@ -171,7 +120,7 @@ public class WearPlugin implements PluginBase { } @Subscribe - public void onStatusEvent(final EventOpenAPSUpdateGui ev){ + public void onStatusEvent(final EventOpenAPSUpdateGui ev) { sendDataToWatch(true, true, false); } @@ -196,7 +145,7 @@ public class WearPlugin implements PluginBase { LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); if (activeloop == null) return; - if(WatchUpdaterService.shouldReportLoopStatus(activeloop.isEnabled(PluginBase.LOOP))) { + if (WatchUpdaterService.shouldReportLoopStatus(activeloop.isEnabled(PluginType.LOOP))) { sendDataToWatch(true, false, false); } } @@ -204,7 +153,7 @@ public class WearPlugin implements PluginBase { @Subscribe 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.putExtra("progresspercent", ev.percent); intent.putExtra("progressstatus", ev.status); @@ -224,10 +173,10 @@ public class WearPlugin implements PluginBase { @Subscribe public void onStatusEvent(final EventDismissBolusprogressIfRunning ev) { - if(ev.result == null) return; + if (ev.result == null) return; String status; - if(ev.result.success){ + if (ev.result.success) { status = MainApp.sResources.getString(R.string.success); } else { status = MainApp.sResources.getString(R.string.nosuccess); @@ -238,7 +187,7 @@ public class WearPlugin implements PluginBase { 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.putExtra("title", title); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index 7813e02506..7acfc27a93 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -21,15 +21,11 @@ import com.google.android.gms.wearable.PutDataRequest; import com.google.android.gms.wearable.Wearable; import com.google.android.gms.wearable.WearableListenerService; -import org.mozilla.javascript.tools.jsc.Main; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; import java.util.List; -import java.util.stream.Collectors; import info.nightscout.androidaps.Config; 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.TemporaryBasal; 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.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; 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.NSClientInternal.data.NSDeviceStatus; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; @@ -290,7 +286,7 @@ public class WatchUpdaterService extends WearableListenerService implements deltastring += DecimalFormatter.to0Decimal(Math.abs(deltaMGDL)); } } else { - if (detailed){ + if (detailed) { deltastring += DecimalFormatter.to2Decimal(Math.abs(deltaMMOL)); } else { deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMMOL)); @@ -366,8 +362,6 @@ public class WatchUpdaterService extends WearableListenerService implements ArrayList predictions = new ArrayList<>(); - - Profile profile = MainApp.getConfigBuilder().getProfile(); if (profile == null) { @@ -469,15 +463,15 @@ public class WatchUpdaterService extends WearableListenerService implements } List treatments = MainApp.getConfigBuilder().getTreatmentsFromHistory(); - for (Treatment treatment:treatments) { - if(treatment.date > startTimeWindow){ + for (Treatment treatment : treatments) { + if (treatment.date > startTimeWindow) { boluses.add(treatmentMap(treatment.date, treatment.insulin, treatment.carbs, treatment.isSMB, treatment.isValid)); } } 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 predArray = finalLastRun.constraintsProcessed.getPredictions(); if (!predArray.isEmpty()) { @@ -586,8 +580,8 @@ public class WatchUpdaterService extends WearableListenerService implements Profile profile = MainApp.getConfigBuilder().getProfile(); String status = MainApp.instance().getString(R.string.noprofile); String iobSum, iobDetail, cobString, currentBasal, bgiString; - iobSum = iobDetail = cobString = currentBasal = bgiString = ""; - if(profile!=null) { + iobSum = iobDetail = cobString = currentBasal = bgiString = ""; + if (profile != null) { TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder(); treatmentsInterface.updateTotalIOBTreatments(); IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round(); @@ -605,7 +599,7 @@ public class WatchUpdaterService extends WearableListenerService implements double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf(); 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; //OpenAPS status - if(Config.APS){ + if (Config.APS) { //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 { //NSClient or remote openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); @@ -673,10 +667,10 @@ public class WatchUpdaterService extends WearableListenerService implements 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"; lastLoopStatus = false; - } else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) { + } else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) { lastLoopStatus = true; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index d2df702cd4..b7cd680859 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -22,6 +22,8 @@ import info.nightscout.androidaps.events.EventRefreshOverview; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTreatmentChange; 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.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; @@ -31,19 +33,7 @@ import info.nightscout.utils.DecimalFormatter; * Created by adrian on 17/11/16. */ -public class StatuslinePlugin implements 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; +public class StatuslinePlugin extends PluginBase { private static StatuslinePlugin statuslinePlugin; @@ -51,8 +41,19 @@ public class StatuslinePlugin implements PluginBase { 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) { statuslinePlugin = new StatuslinePlugin(ctx); } @@ -60,100 +61,43 @@ public class StatuslinePlugin implements PluginBase { 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.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); } @Override - public int getType() { - 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) { + public boolean specialShowInListCondition() { return !Config.NSCLIENT && !Config.G5UPLOADER; } @Override - public void setPluginEnabled(int type, boolean fragmentEnabled) { - if (type == GENERAL) { - this.fragmentEnabled = fragmentEnabled; - - if (fragmentEnabled) { - try { - MainApp.bus().register(this); - } catch (Exception e) { - } - sendStatus(); - } else { - try { - MainApp.bus().unregister(this); - } catch (Exception e) { - } - sendStatus(); - } - } + public void onStart() { + super.onStart(); + MainApp.bus().register(this); + sendStatus(); } @Override - public void setFragmentVisible(int type, boolean fragmentVisible) { - // do nothing, no gui + public void onStop() { + super.onStop(); + MainApp.bus().unregister(this); + sendStatus(); } - @Override - public int getPreferencesId() { - return R.xml.pref_xdripstatus; - } - - private void sendStatus() { String status = ""; // sent once on disable Profile profile = MainApp.getConfigBuilder().getProfile(); - if (fragmentEnabled && profile != null) { + if (isEnabled(PluginType.GENERAL) && profile != null) { status = buildStatusString(profile); } @@ -171,10 +115,10 @@ public class StatuslinePlugin implements PluginBase { String status = ""; 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"; lastLoopStatus = false; - } else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) { + } else if (activeloop != null && activeloop.isEnabled(PluginType.LOOP)) { lastLoopStatus = true; } @@ -246,14 +190,9 @@ public class StatuslinePlugin implements PluginBase { LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop(); if (activeloop == null) return; - if ((lastLoopStatus != activeloop.isEnabled(PluginBase.LOOP))) { + if ((lastLoopStatus != activeloop.isEnabled(PluginType.LOOP))) { sendStatus(); } } - - public boolean isEnabled() { - return fragmentEnabled; - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java index 8b2437fdc3..867d118428 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandSetProfile.java @@ -7,6 +7,7 @@ import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.db.ProfileSwitch; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.queue.Callback; @@ -34,7 +35,7 @@ public class CommandSetProfile extends Command { ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(System.currentTimeMillis()); if (r.enacted && profileSwitch.source == Source.NIGHTSCOUT) { 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)); } } diff --git a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java index b5ed76af02..8397da97aa 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; -import info.nightscout.androidaps.MainActivity; import info.nightscout.androidaps.interfaces.PluginBase; /** @@ -37,7 +36,7 @@ public class TabPageAdapter extends FragmentStatePagerAdapter { @Nullable public Fragment getItem(int 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 @@ -67,7 +66,7 @@ public class TabPageAdapter extends FragmentStatePagerAdapter { } public void registerNewFragment(PluginBase plugin) { - if (plugin.hasFragment() && plugin.isVisibleInTabs(plugin.getType())) { + if (plugin.hasFragment() && plugin.isFragmentVisible()) { visibleFragmentList.add(plugin); notifyDataSetChanged(); } diff --git a/app/src/main/res/layout/bgsource_fragment.xml b/app/src/main/res/layout/bgsource_fragment.xml index dbd0ea4e67..316bc8e049 100644 --- a/app/src/main/res/layout/bgsource_fragment.xml +++ b/app/src/main/res/layout/bgsource_fragment.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="info.nightscout.androidaps.plugins.SourceDexcomG5.BGSourceFragment"> + tools:context="info.nightscout.androidaps.plugins.Source.BGSourceFragment"> Продължителност [мин.] ПОМПА Дата - DIA от %s е твърде кратка - използвай %s вместо това! + DIA от %f е твърде кратка - използвай %f вместо това! Със свободен пик по Oref Пик на кривата на IOB Време на пик [мин.] diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index da46f60698..c2014a9082 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -573,7 +573,7 @@ AKTIVOVAT PROFIL Zobrazovat prodloužený bolus v % Datum - DIA %s je příliž krátké - použito %s ! + DIA %f je příliž krátké - použito %f ! Čas vrcholu IOB křivky Vrchol křivky [min] NEPLATNÝ diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0bad8b97e0..90cf07d5fd 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -564,7 +564,7 @@ Peak Time [min] IOB Curve Peak Time Free-Peak Oref - DIA von %s ist zu kurz - AAPS nutzt stattdessen %s! + DIA von %f ist zu kurz - AAPS nutzt stattdessen %f! Möglicherweise ungenau, wenn zum Befüllen ein Bolus verwendet wurde! Verhältnis AKTIVIERE PROFIL diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index d071fa7f8e..6cb7a1a252 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -580,7 +580,7 @@ Free-Peak Oref Γρήγορη δράση - Oref Έξτρα Γρήγορη δράση - Oref - "DIA για %s πολύ μικρή - χρησιμοποιήστε %s! " + "DIA για %f πολύ μικρή - χρησιμοποιήστε %f! " ΕΝΕΡΓΟΠΟΙΗΣΗ ΠΡΟΦΙΛ Ημερομηνία ΜΗ ΕΓΚΥΡΟ diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index a29ce984df..f29b7855da 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -585,7 +585,7 @@ Free-Peak Oref Rapid-Acting Oref Ultra-Rapid Oref - DIA de %s demasiado corto - usando %s! + DIA de %f demasiado corto - usando %f! ACTIVAR PERFIL Fecha INVALIDO diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 2d0d2ff32d..084d6c8609 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -579,7 +579,7 @@ "Durée du Pic [min] " "Insuline à Action Rapide Oref " Insuline à Action Ultra Rapide Oref - Durée d’Action pour %s trop courte - utiliser %s à la place! + Durée d’Action pour %f trop courte - utiliser %f à la place! ACTIVER LE PROFIL " Date" INVALID diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 89d0dca30d..0906a208c4 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -591,7 +591,7 @@ Free-Peak Oref Rapid-Acting Oref Ultra-Rapid Oref - "DIA %s는 너무 짧습니다. 대신 %s을 사용하세요!" + "DIA %f는 너무 짧습니다. 대신 %f을 사용하세요!" 프로파일 활성화하기 Date INVALID diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 86cab639c4..94bbbe2e8d 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -587,7 +587,7 @@ Activeer profiel Datum Free-Peak Oref - DIA van %s te kort - %s wordt inplaats gebruikt!\" + DIA van %f te kort - %f wordt inplaats gebruikt!\" IOB curve piek tijd Piek tijd [min] Ongeldig diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 8f0c0162ca..d04b486b95 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -547,7 +547,7 @@ Просмотреть расширенный болюс % DanaRv2 дата - pначение длительности работы инс %s слишком мало - применено %s + pначение длительности работы инс %f слишком мало - применено %f расширенный болюс Акуу-Зуфл Щкуа час diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a84d66fad0..3475ee7432 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -663,7 +663,7 @@ Free-Peak Oref Rapid-Acting Oref Ultra-Rapid Oref - DIA of %s too short - using %s instead! + DIA of %f too short - using %f instead! ACTIVATE PROFILE Date INVALID @@ -994,5 +994,7 @@ Record insulin cartridge change SMB always and after carbs disabled because active BG source doesn\'t support advanced filtering SMB not allowed in open loop mode + Food + IobCobCalculator diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index b407bc360f..6e13fdc17a 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -30,8 +30,8 @@ import static org.mockito.Mockito.when; */ 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\"}"; - static Profile profile; + 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\"}"; + private static Profile profile; public static void mockStrings() { Locale.setDefault(new Locale("en", "US")); @@ -112,7 +112,7 @@ public class AAPSMocker { try { if (profile == null) profile = new Profile(new JSONObject(validProfile), Constants.MGDL); - } catch (JSONException e) {} + } catch (JSONException ignored) {} return profile; } } diff --git a/app/src/test/java/info/nightscout/androidaps/PumpDanaR/DanaRPluginTest.java b/app/src/test/java/info/nightscout/androidaps/PumpDanaR/DanaRPluginTest.java index 33b5dad925..86681bd3ec 100644 --- a/app/src/test/java/info/nightscout/androidaps/PumpDanaR/DanaRPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/PumpDanaR/DanaRPluginTest.java @@ -15,7 +15,7 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; @@ -36,8 +36,8 @@ public class DanaRPluginTest { @Test public void basalRateShouldBeLimited() throws Exception { - danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); - danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); + danaRPlugin.setPluginEnabled(PluginType.PUMP, true); + danaRPlugin.setPluginEnabled(PluginType.PUMP, true); DanaRPump.getInstance().maxBasal = 0.8d; Constraint c = new Constraint<>(Constants.REALLYHIGHBASALRATE); @@ -49,8 +49,8 @@ public class DanaRPluginTest { @Test public void percentBasalRateShouldBeLimited() throws Exception { - danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); - danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); + danaRPlugin.setPluginEnabled(PluginType.PUMP, true); + danaRPlugin.setPluginEnabled(PluginType.PUMP, true); DanaRPump.getInstance().maxBasal = 0.8d; Constraint c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE); diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java index dd2459d9d7..e1204c104b 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java @@ -34,7 +34,7 @@ import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; import info.nightscout.androidaps.plugins.PumpInsight.connector.StatusTaskRunner; 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.SP; @@ -64,7 +64,7 @@ public class ConstraintsCheckerTest { @Test public void isLoopInvokationAllowedTest() throws Exception { - comboPlugin.setPluginEnabled(PluginBase.PUMP, true); + comboPlugin.setPluginEnabled(PluginType.PUMP, true); comboPlugin.setValidBasalRateProfileSelectedOnPump(false); Constraint c = constraintChecker.isLoopInvokationAllowed(); @@ -137,12 +137,12 @@ public class ConstraintsCheckerTest { @Test public void basalRateShouldBeLimited() throws Exception { // DanaR, RS - danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); - danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); + danaRPlugin.setPluginEnabled(PluginType.PUMP, true); + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); DanaRPump.getInstance().maxBasal = 0.8d; // Insight - insightPlugin.setPluginEnabled(PluginBase.PUMP, true); + insightPlugin.setPluginEnabled(PluginType.PUMP, true); StatusTaskRunner.Result result = new StatusTaskRunner.Result(); result.maximumBasalAmount = 1.1d; insightPlugin.setStatusResult(result); @@ -164,12 +164,12 @@ public class ConstraintsCheckerTest { @Test public void percentBasalRateShouldBeLimited() throws Exception { // DanaR, RS - danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); - danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); + danaRPlugin.setPluginEnabled(PluginType.PUMP, true); + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); DanaRPump.getInstance().maxBasal = 0.8d; // Insight - insightPlugin.setPluginEnabled(PluginBase.PUMP, true); + insightPlugin.setPluginEnabled(PluginType.PUMP, true); StatusTaskRunner.Result result = new StatusTaskRunner.Result(); result.maximumBasalAmount = 1.1d; insightPlugin.setStatusResult(result); @@ -192,12 +192,12 @@ public class ConstraintsCheckerTest { @Test public void bolusAmountShouldBeLimited() throws Exception { // DanaR, RS - danaRPlugin.setPluginEnabled(PluginBase.PUMP, true); - danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); + danaRPlugin.setPluginEnabled(PluginType.PUMP, true); + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); DanaRPump.getInstance().maxBolus = 6d; // Insight - insightPlugin.setPluginEnabled(PluginBase.PUMP, true); + insightPlugin.setPluginEnabled(PluginType.PUMP, true); StatusTaskRunner.Result result = new StatusTaskRunner.Result(); result.maximumBolusAmount = 7d; insightPlugin.setStatusResult(result); @@ -233,9 +233,9 @@ public class ConstraintsCheckerTest { // No limit by default when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d); when(SP.getString(R.string.key_age, "")).thenReturn("teenage"); - OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); - OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); - OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); + OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true); + OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true); + OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true); // Apply all limits Constraint d = constraintChecker.getMaxIOBAllowed(); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java new file mode 100644 index 0000000000..68193f7b94 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java @@ -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); + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPluginTest.java index 116fd3fee6..0b682b3164 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPluginTest.java @@ -13,6 +13,7 @@ import java.util.Date; import info.AAPSMocker; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.interfaces.Constraint; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.utils.SP; diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java index 2ae35de4ae..bfe430ccf5 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java @@ -15,13 +15,13 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSSMB.OpenAPSSMBPlugin; 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 static org.mockito.Mockito.when; @@ -208,9 +208,9 @@ public class SafetyPluginTest { public void iobShouldBeLimited() throws Exception { when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d); when(SP.getString(R.string.key_age, "")).thenReturn("teenage"); - OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); - OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); - OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginBase.APS, true); + OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true); + OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true); + OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true); // Apply all limits Constraint d = new Constraint<>(Constants.REALLYHIGHIOB); @@ -232,7 +232,6 @@ public class SafetyPluginTest { AAPSMocker.mockStrings(); - when(MainApp.getConfigBuilder().getActivePump()).thenReturn(pump); safetyPlugin = SafetyPlugin.getPlugin(); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePluginTest.java index 7dd40883fa..d362937b82 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Insulin/InsulinOrefBasePluginTest.java @@ -86,7 +86,7 @@ public class InsulinOrefBasePluginTest extends InsulinOrefBasePlugin { return this.peak; } - /** + /** * Userdefined Dia is implemented to allow tests of the getDia method * * @return @@ -99,55 +99,21 @@ public class InsulinOrefBasePluginTest extends InsulinOrefBasePlugin { this.shortDiaNotificationSend = true; } - - // the following methods are implemented, but not needed... - @Override - String commentStandardText() { - return null; - } - - @Override - public String getFragmentClass() { - return null; - } - @Override public int getId() { return 0; } - @Override - public String getName() { - return null; - } - @Override public String getFriendlyName() { return null; } @Override - public boolean isEnabled(int type) { - return false; + String commentStandardText() { + return null; } - @Override - public boolean isVisibleInTabs(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 0; - } + // the following methods are implemented, but not needed... } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java index d533782f13..396ffc52b2 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java @@ -17,6 +17,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.utils.SP; @@ -37,30 +38,30 @@ public class LoopPluginTest { @Test public void testPluginInterface() { - Assert.assertEquals(LoopFragment.class.getName(), loopPlugin.getFragmentClass()); - Assert.assertEquals(PluginBase.LOOP, loopPlugin.getType()); + Assert.assertEquals(LoopFragment.class.getName(), loopPlugin.pluginDescription.getFragmentClass()); + Assert.assertEquals(PluginType.LOOP, loopPlugin.getType()); Assert.assertEquals("Loop", loopPlugin.getName()); 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.showInList(PluginBase.LOOP)); + Assert.assertEquals(true, loopPlugin.showInList(PluginType.LOOP)); Assert.assertEquals(R.xml.pref_closedmode, loopPlugin.getPreferencesId()); // Plugin is disabled by default - Assert.assertEquals(false, loopPlugin.isEnabled(PluginBase.LOOP)); - loopPlugin.setPluginEnabled(PluginBase.LOOP, true); - Assert.assertEquals(true, loopPlugin.isEnabled(PluginBase.LOOP)); + Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP)); + loopPlugin.setPluginEnabled(PluginType.LOOP, true); + Assert.assertEquals(true, loopPlugin.isEnabled(PluginType.LOOP)); // No temp basal capable pump should disable plugin virtualPumpPlugin.getPumpDescription().isTempBasalCapable = false; - Assert.assertEquals(false, loopPlugin.isEnabled(PluginBase.LOOP)); + Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP)); virtualPumpPlugin.getPumpDescription().isTempBasalCapable = true; // Fragment is hidden by default - Assert.assertEquals(false, loopPlugin.isVisibleInTabs(PluginBase.LOOP)); - loopPlugin.setFragmentVisible(PluginBase.LOOP, true); - Assert.assertEquals(true, loopPlugin.isVisibleInTabs(PluginBase.LOOP)); + Assert.assertEquals(false, loopPlugin.isFragmentVisible()); + loopPlugin.setFragmentVisible(PluginType.LOOP, true); + Assert.assertEquals(true, loopPlugin.isFragmentVisible()); } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPluginTest.java index 2e856029f9..ff558bff2c 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpCombo/ComboPluginTest.java @@ -12,7 +12,7 @@ import org.powermock.modules.junit4.PowerMockRunner; import info.AAPSMocker; import info.nightscout.androidaps.MainApp; 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.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.utils.ToastUtils; @@ -27,14 +27,14 @@ public class ComboPluginTest { @Test public void invalidBasalRateOnComboPumpShouldLimitLoopInvokation() throws Exception { - comboPlugin.setPluginEnabled(PluginBase.PUMP, true); + comboPlugin.setPluginEnabled(PluginType.PUMP, true); comboPlugin.setValidBasalRateProfileSelectedOnPump(false); Constraint c = new Constraint<>(true); c = comboPlugin.isLoopInvokationAllowed(c); Assert.assertEquals("Combo: No valid basal rate read from pump", c.getReasons()); Assert.assertEquals(Boolean.FALSE, c.value()); - comboPlugin.setPluginEnabled(PluginBase.PUMP, false); + comboPlugin.setPluginEnabled(PluginType.PUMP, false); } @Test diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPluginTest.java index 1b88e7d025..902a3eb682 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaRS/DanaRSPluginTest.java @@ -15,7 +15,7 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; 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.PumpDanaR.DanaRPump; import info.nightscout.utils.SP; @@ -35,8 +35,8 @@ public class DanaRSPluginTest { @Test public void basalRateShouldBeLimited() throws Exception { - danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); - danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); DanaRPump.getInstance().maxBasal = 0.8d; Constraint c = new Constraint<>(Constants.REALLYHIGHBASALRATE); @@ -48,8 +48,8 @@ public class DanaRSPluginTest { @Test public void percentBasalRateShouldBeLimited() throws Exception { - danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); - danaRSPlugin.setPluginEnabled(PluginBase.PUMP, true); + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); DanaRPump.getInstance().maxBasal = 0.8d; Constraint c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPluginTest.java index a93757af87..47595c929b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpInsight/InsightPluginTest.java @@ -14,7 +14,7 @@ import info.AAPSMocker; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; 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.PumpInsight.connector.StatusTaskRunner; import info.nightscout.utils.ToastUtils; @@ -31,7 +31,7 @@ public class InsightPluginTest { @Test public void basalRateShouldBeLimited() throws Exception { - insightPlugin.setPluginEnabled(PluginBase.PUMP, true); + insightPlugin.setPluginEnabled(PluginType.PUMP, true); StatusTaskRunner.Result result = new StatusTaskRunner.Result(); result.maximumBasalAmount = 1.1d; insightPlugin.setStatusResult(result); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5PluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5PluginTest.java new file mode 100644 index 0000000000..e7dce0b254 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5PluginTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPluginTest.java new file mode 100644 index 0000000000..045552c8da --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPluginTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPluginTest.java new file mode 100644 index 0000000000..9bbe86da40 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPluginTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPluginTest.java new file mode 100644 index 0000000000..f37307992e --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPluginTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java new file mode 100644 index 0000000000..f85719dc47 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Source/SourceXdripPluginTest.java @@ -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()); + } +} \ No newline at end of file diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java index 7c62ba6b0f..3c479f3f86 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java @@ -28,17 +28,16 @@ import android.view.WindowManager; import android.widget.TextView; import com.google.android.gms.wearable.DataMap; -import com.ustwo.clockwise.wearable.WatchFace; import com.ustwo.clockwise.common.WatchFaceTime; +import com.ustwo.clockwise.wearable.WatchFace; import java.util.ArrayList; import java.util.Calendar; -import java.util.Date; import java.util.HashSet; import java.util.TreeSet; -import info.nightscout.androidaps.data.BgWatchData; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.BgWatchData; import info.nightscout.androidaps.interaction.menus.MainMenuActivity; @@ -77,9 +76,8 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh private String direction = ""; private String delta = ""; private String avgDelta = ""; - public TreeSet bgDataList = new TreeSet(); + public TreeSet bgDataList = new TreeSet<>(); - private View layoutView; private int specW; private int specH; private View myLayout; @@ -151,7 +149,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh // prepare fields - TextView textView = null; + TextView textView; mSgv = (TextView) myLayout.findViewById(R.id.sgvString); textView = (TextView) myLayout.findViewById(R.id.sgvString); if (sharedPrefs.getBoolean("showBG", true)) { @@ -298,10 +296,8 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh removePaint.setAntiAlias(true); removePaint.setColor(getBackgroundColor()); - ; - - rect = new RectF(PADDING, PADDING, (float) (displaySize.x - PADDING), (float) (displaySize.y - PADDING)); - rectDelete = new RectF(PADDING - CIRCLE_WIDTH / 2, PADDING - CIRCLE_WIDTH / 2, (float) (displaySize.x - PADDING + CIRCLE_WIDTH / 2), (float) (displaySize.y - PADDING + CIRCLE_WIDTH / 2)); + rect = new RectF(PADDING, PADDING, displaySize.x - PADDING, displaySize.y - PADDING); + rectDelete = new RectF(PADDING - CIRCLE_WIDTH / 2, PADDING - CIRCLE_WIDTH / 2, displaySize.x - PADDING + CIRCLE_WIDTH / 2, displaySize.y - PADDING + CIRCLE_WIDTH / 2); overlapping = ALWAYS_HIGHLIGT_SMALL || areOverlapping(angleSMALL, angleSMALL + SMALL_HAND_WIDTH + NEAR, angleBig, angleBig + BIG_HAND_WIDTH + NEAR); Log.d("CircleWatchface", "end prepareDrawTime"); From a30334f5d53d8a1109a77bd1dfd49adfef86e080 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 31 Mar 2018 10:09:29 +0200 Subject: [PATCH 2/5] PluginDescriptionTest --- .../interfaces/PluginDescriptionTest.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 app/src/test/java/info/nightscout/androidaps/interfaces/PluginDescriptionTest.java diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/PluginDescriptionTest.java b/app/src/test/java/info/nightscout/androidaps/interfaces/PluginDescriptionTest.java new file mode 100644 index 0000000000..9e885a784d --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/PluginDescriptionTest.java @@ -0,0 +1,95 @@ +package info.nightscout.androidaps.interfaces; + +import net.bytebuddy.build.Plugin; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.nightscout.androidaps.plugins.ProfileNS.NSProfileFragment; + +import static org.junit.Assert.*; + +@RunWith(PowerMockRunner.class) +public class PluginDescriptionTest { + + @Test + public void mainTypeTest() { + PluginDescription pluginDescription = new PluginDescription().mainType(PluginType.PUMP); + Assert.assertEquals(PluginType.PUMP, pluginDescription.getType()); + } + + @Test + public void fragmentClassTest() { + PluginDescription pluginDescription = new PluginDescription().fragmentClass(NSProfileFragment.class.getName()); + Assert.assertEquals(NSProfileFragment.class.getName(), pluginDescription.getFragmentClass()); + } + + @Test + public void canBeHiddenTest() { + PluginDescription pluginDescription = new PluginDescription().canBeHidden(false); + Assert.assertEquals(false, pluginDescription.canBeHidden); + } + + @Test + public void alwaysEnabledTest() { + PluginDescription pluginDescription = new PluginDescription().alwaysEnabled(true); + Assert.assertEquals(true, pluginDescription.alwaysEnabled); + } + + @Test + public void alwayVisibleTest() { + PluginDescription pluginDescription = new PluginDescription().alwayVisible(true); + Assert.assertEquals(true, pluginDescription.alwayVisible); + } + + @Test + public void neverVisibleTest() { + PluginDescription pluginDescription = new PluginDescription().neverVisible(true); + Assert.assertEquals(true, pluginDescription.neverVisible); + } + + @Test + public void showInListTest() { + PluginDescription pluginDescription = new PluginDescription().showInList(false); + Assert.assertEquals(false, pluginDescription.showInList); + } + + @Test + public void pluginName() { + PluginDescription pluginDescription = new PluginDescription().pluginName(10); + Assert.assertEquals(10, pluginDescription.pluginName); + } + + @Test + public void shortNameTest() { + PluginDescription pluginDescription = new PluginDescription().shortName(10); + Assert.assertEquals(10, pluginDescription.shortName); + } + + @Test + public void preferencesIdTest() { + PluginDescription pluginDescription = new PluginDescription().preferencesId(10); + Assert.assertEquals(10, pluginDescription.preferencesId); + } + + @Test + public void advancedPreferencesIdTest() { + PluginDescription pluginDescription = new PluginDescription().advancedPreferencesId(10); + Assert.assertEquals(10, pluginDescription.advancedPreferencesId); + } + + @Test + public void enableByDefault() { + PluginDescription pluginDescription = new PluginDescription().enableByDefault(true); + Assert.assertEquals(true, pluginDescription.enableByDefault); + } + + @Test + public void visibleByDefault() { + PluginDescription pluginDescription = new PluginDescription().visibleByDefault(true); + Assert.assertEquals(true, pluginDescription.visibleByDefault); + } + +} \ No newline at end of file From 1c6c5f85f73382b3b8bb3220aa213a95ec4ed7c0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 31 Mar 2018 10:36:57 +0200 Subject: [PATCH 3/5] DanaR pumps lifecycle --- .../PumpDanaR/AbstractDanaRPlugin.java | 2 +- .../plugins/PumpDanaR/DanaRPlugin.java | 21 ++++++++++++---- .../PumpDanaRKorean/DanaRKoreanPlugin.java | 23 ++++++++++++++---- .../plugins/PumpDanaRv2/DanaRv2Plugin.java | 24 +++++++++++++++---- 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java index 12ec4dfca7..07c4655de7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/AbstractDanaRPlugin.java @@ -64,7 +64,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte @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) { + if (type == PluginType.PUMP && newState == State.ENABLED && newState == State.DISABLED && isProfileInterfaceEnabled) { setPluginEnabled(PluginType.PROFILE, false); NSProfilePlugin.getPlugin().setPluginEnabled(PluginType.PROFILE, true); NSProfilePlugin.getPlugin().setFragmentVisible(PluginType.PROFILE, true); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java index 0e118df96a..f90d529987 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRPlugin.java @@ -46,11 +46,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin { log = LoggerFactory.getLogger(DanaRPlugin.class); useExtendedBoluses = SP.getBoolean("danar_useextended", false); - Context context = MainApp.instance().getApplicationContext(); - Intent intent = new Intent(context, DanaRExecutionService.class); - context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - MainApp.bus().register(this); - pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.05d; @@ -78,6 +73,22 @@ public class DanaRPlugin extends AbstractDanaRPlugin { pumpDescription.storesCarbInfo = true; } + @Override + protected void onStart() { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, DanaRExecutionService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + MainApp.bus().register(this); + } + + @Override + protected void onStop() { + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(mConnection); + + MainApp.bus().unregister(this); + } + private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java index 94adcc6f82..44a805fadf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/DanaRKoreanPlugin.java @@ -26,6 +26,8 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaRKorean.services.DanaRKoreanExecutionService; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; +import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -47,11 +49,6 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { log = LoggerFactory.getLogger(DanaRKoreanPlugin.class); useExtendedBoluses = SP.getBoolean("danar_useextended", false); - Context context = MainApp.instance().getApplicationContext(); - Intent intent = new Intent(context, DanaRKoreanExecutionService.class); - context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - MainApp.bus().register(this); - pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.1d; @@ -79,6 +76,22 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin { pumpDescription.storesCarbInfo = true; } + @Override + protected void onStart() { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, DanaRKoreanExecutionService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + MainApp.bus().register(this); + } + + @Override + protected void onStop() { + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(mConnection); + + MainApp.bus().unregister(this); + } + private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java index 3f372de5db..74edcac728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/DanaRv2Plugin.java @@ -23,6 +23,8 @@ import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.PumpDescription; import info.nightscout.androidaps.plugins.ConfigBuilder.DetailedBolusInfoStorage; import info.nightscout.androidaps.plugins.PumpDanaR.AbstractDanaRPlugin; +import info.nightscout.androidaps.plugins.PumpDanaRS.events.EventDanaRSDeviceChange; +import info.nightscout.androidaps.plugins.PumpDanaRS.services.DanaRSService; import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService; import info.nightscout.utils.Round; import info.nightscout.utils.SP; @@ -44,11 +46,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { log = LoggerFactory.getLogger(DanaRv2Plugin.class); useExtendedBoluses = false; - Context context = MainApp.instance().getApplicationContext(); - Intent intent = new Intent(context, DanaRv2ExecutionService.class); - context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); - MainApp.bus().register(this); - pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.05d; @@ -78,6 +75,23 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { pumpDescription.storesCarbInfo = true; } + @Override + protected void onStart() { + Context context = MainApp.instance().getApplicationContext(); + Intent intent = new Intent(context, DanaRv2ExecutionService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + + MainApp.bus().register(this); + } + + @Override + protected void onStop() { + Context context = MainApp.instance().getApplicationContext(); + context.unbindService(mConnection); + + MainApp.bus().unregister(this); + } + private ServiceConnection mConnection = new ServiceConnection() { public void onServiceDisconnected(ComponentName name) { From 364364f2055e4d22f66a07ff3966e3e6f3d04483 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 31 Mar 2018 11:31:09 +0200 Subject: [PATCH 4/5] ConfigBuilderTest --- .../ConfigBuilder/ConfigBuilderPlugin.java | 4 +- .../IobCobCalculatorPlugin.java | 4 +- .../plugins/Overview/OverviewPlugin.java | 4 +- .../XDripStatusline/StatuslinePlugin.java | 4 +- app/src/test/java/info/AAPSMocker.java | 29 ++++++++++++++ .../androidaps/data/ProfileTest.java | 39 ++++++------------- .../ConfigBuilderPluginTest.java | 34 +++++++++++++++- 7 files changed, 82 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index 0ad9bedab0..dace12d1ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -106,13 +106,13 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa } @Override - public void onStart() { + protected void onStart() { super.onStart(); MainApp.bus().register(this); } @Override - public void onStop() { + protected void onStop() { super.onStop(); MainApp.bus().unregister(this); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 21dcefdb1b..fe2b834d6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -76,13 +76,13 @@ public class IobCobCalculatorPlugin extends PluginBase { } @Override - public void onStart() { + protected void onStart() { super.onStart(); MainApp.bus().register(this); } @Override - public void onStop() { + protected void onStop() { super.onStop(); MainApp.bus().unregister(this); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java index bc219d6f32..5e9ff75e10 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewPlugin.java @@ -61,12 +61,12 @@ public class OverviewPlugin extends PluginBase { } @Override - public void onStart() { + protected void onStart() { MainApp.bus().register(this); } @Override - public void onStop() { + protected void onStop() { MainApp.bus().unregister(this); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index b7cd680859..95b6b449d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -79,14 +79,14 @@ public class StatuslinePlugin extends PluginBase { } @Override - public void onStart() { + protected void onStart() { super.onStart(); MainApp.bus().register(this); sendStatus(); } @Override - public void onStop() { + protected void onStop() { super.onStop(); MainApp.bus().unregister(this); sendStatus(); diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index 9ec0019ae5..199a87a4c5 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -76,6 +76,8 @@ public class AAPSMocker { when(MainApp.gs(R.string.absolute)).thenReturn("Absolute"); when(MainApp.gs(R.string.waitingforpumpresult)).thenReturn("Waiting for result"); when(MainApp.gs(R.string.insulin_unit_shortname)).thenReturn("U"); + when(MainApp.gs(R.string.minimalbasalvaluereplaced)).thenReturn("Basal value replaced by minimal supported value"); + when(MainApp.gs(R.string.basalprofilenotaligned)).thenReturn("Basal values not aligned to hours: %s"); } public static MainApp mockMainApp() { @@ -125,4 +127,31 @@ public class AAPSMocker { } catch (JSONException ignored) {} return profile; } + + private static MockedBus bus = new MockedBus(); + + public static void prepareMockedBus() { + when(MainApp.bus()).thenReturn(bus); + } + + public static class MockedBus extends Bus { + public boolean registered = false; + public boolean notificationSent = false; + + @Override + public void register(Object event) { + registered = true; + } + + @Override + public void unregister(Object event) { + registered = false; + } + + @Override + public void post(Object event) { + notificationSent = true; + } + } + } diff --git a/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java b/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java index 664515d45d..78a5a338aa 100644 --- a/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java +++ b/app/src/test/java/info/nightscout/androidaps/data/ProfileTest.java @@ -5,6 +5,7 @@ import com.squareup.otto.Bus; import junit.framework.Assert; import org.json.JSONObject; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -16,6 +17,7 @@ import java.util.Calendar; import java.util.Locale; import java.util.TimeZone; +import info.AAPSMocker; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -44,12 +46,8 @@ public class ProfileTest { //String profileStore = "{\"defaultProfile\":\"Default\",\"store\":{\"Default\":" + validProfile + "}}"; - boolean notificationSent = false; - @Test public void doTests() throws Exception { - prepareMock(); - Profile p = new Profile(); // Test valid profile @@ -105,7 +103,7 @@ public class ProfileTest { //Test basal profile below limit p = new Profile(new JSONObject(belowLimitValidProfile), 100, 0); p.isValid("Test"); - Assert.assertEquals(true, notificationSent); + Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); // Test profile w/o units p = new Profile(new JSONObject(noUnitsValidProfile), 100, 0); @@ -140,37 +138,24 @@ public class ProfileTest { // Test hour alignment MainApp.getConfigBuilder().getActivePump().getPumpDescription().is30minBasalRatesCapable = false; - notificationSent = false; + ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent = false; p = new Profile(new JSONObject(notAllignedBasalValidProfile), 100, 0); p.isValid("Test"); - Assert.assertEquals(true, notificationSent); + Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent); } - private void prepareMock() throws Exception { - Locale.setDefault(new Locale("en", "US")); - ConfigBuilderPlugin configBuilderPlugin = mock(ConfigBuilderPlugin.class); - PowerMockito.mockStatic(ConfigBuilderPlugin.class); + @Before + public void prepareMock() throws Exception { + AAPSMocker.mockMainApp(); + AAPSMocker.mockConfigBuilder(); + AAPSMocker.mockStrings(); + AAPSMocker.prepareMockedBus(); - MainApp mainApp = mock(MainApp.class); - PowerMockito.mockStatic(MainApp.class); - when(MainApp.instance()).thenReturn(mainApp); - when(MainApp.getConfigBuilder()).thenReturn(configBuilderPlugin); when(MainApp.getConfigBuilder().getActivePump()).thenReturn(pump); - when(MainApp.gs(R.string.minimalbasalvaluereplaced)).thenReturn("AnyString"); - when(MainApp.gs(R.string.basalprofilenotaligned)).thenReturn("AnyString"); PowerMockito.mockStatic(FabricPrivacy.class); // PowerMockito.doNothing().when(FabricPrivacy.log("")); - MockedBus bus = new MockedBus(); - when(MainApp.bus()).thenReturn(bus); } - class MockedBus extends Bus { - @Override - public void post(Object event) { - notificationSent = true; - } - } - -} + } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java index 68193f7b94..59628a8dea 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPluginTest.java @@ -2,13 +2,21 @@ package info.nightscout.androidaps.plugins.ConfigBuilder; import junit.framework.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import static org.junit.Assert.*; +import info.AAPSMocker; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.interfaces.PluginType; + +import static org.powermock.api.mockito.PowerMockito.mock; @RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class}) public class ConfigBuilderPluginTest { @Test @@ -16,4 +24,28 @@ public class ConfigBuilderPluginTest { ConfigBuilderPlugin configBuilderPlugin = ConfigBuilderPlugin.getPlugin(); Assert.assertNotNull(configBuilderPlugin); } + + @Test + public void onStartTest() { + ConfigBuilderPlugin configBuilderPlugin = ConfigBuilderPlugin.getPlugin(); + configBuilderPlugin.setPluginEnabled(PluginType.GENERAL, true); + Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).registered); + } + + @Test + public void onStopTest() { + ConfigBuilderPlugin configBuilderPlugin = ConfigBuilderPlugin.getPlugin(); + configBuilderPlugin.setPluginEnabled(PluginType.GENERAL, true); + configBuilderPlugin.setPluginEnabled(PluginType.GENERAL, false); + Assert.assertEquals(false, ((AAPSMocker.MockedBus) MainApp.bus()).registered); + } + + @Before + public void prepareMock() throws Exception { + MainApp mainApp = mock(MainApp.class); + PowerMockito.mockStatic(MainApp.class); + AAPSMocker.prepareMockedBus(); + } + + } \ No newline at end of file From 66f6ddf0520544e4f69449d5f1ee8faaf38d3e11 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 31 Mar 2018 12:12:49 +0200 Subject: [PATCH 5/5] Subscribe fix --- .../androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java | 3 ++- .../plugins/SmsCommunicator/SmsCommunicatorPlugin.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index dace12d1ba..60f75718d9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -192,12 +192,14 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa } } + // Detect settings prior 1.60 private void upgradeSettings() { if (!SP.contains("ConfigBuilder_1_NSProfilePlugin_Enabled")) return; if (Config.logPrefsChange) log.debug("Upgrading stored settings"); for (PluginBase p : pluginList) { + log.debug("Processing " + p.getName()); for (int type = 1; type < 11; type++) { PluginType newType; switch (type) { @@ -250,7 +252,6 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa } } } - verifySelectionInCategories(); } public static CommandQueue getCommandQueue() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index 19550fc534..9162de1750 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -138,7 +138,7 @@ public class SmsCommunicatorPlugin extends PluginBase { } @Subscribe - private void processSettings(final EventPreferenceChange ev) { + public void processSettings(final EventPreferenceChange ev) { if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) { String settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "");