diff --git a/app/build.gradle b/app/build.gradle index 38d1108967..4981d315ad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,8 +23,8 @@ android { applicationId "info.nightscout.androidaps" minSdkVersion 21 targetSdkVersion 23 - versionCode 1006 - versionName "1.0.06" + versionCode 1007 + versionName "1.0.07" } buildTypes { release { 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 d36c511542..dbf3d5e529 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -15,13 +15,14 @@ public interface PluginBase { int CONSTRAINTS = 7; int LOOP = 8; int BGSOURCE = 9; + int LAST = 10; // keep always highest number public int getType(); String getName(); - boolean isEnabled(); - boolean isVisibleInTabs(); - boolean canBeHidden(); - void setFragmentEnabled(boolean fragmentEnabled); - void setFragmentVisible(boolean fragmentVisible); + boolean isEnabled(int type); + boolean isVisibleInTabs(int type); + boolean canBeHidden(int type); + void setFragmentEnabled(int type, boolean fragmentEnabled); + void setFragmentVisible(int type, boolean fragmentVisible); } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java index f9124eedb0..a5897c2a79 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/CareportalFragment.java @@ -101,27 +101,27 @@ public class CareportalFragment extends Fragment implements PluginBase, View.OnC } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java index b3b89cb503..9c87e3828f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Careportal/Dialogs/NewNSTreatmentDialog.java @@ -327,6 +327,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick break; case R.id.careportal_announcement: data.put("eventType", "Announcement"); + data.put("isAnnouncement", true); break; case R.id.careportal_cgmsensorinsert: data.put("eventType", "Sensor Change"); 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 fd731bb14c..a82f961ff5 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 @@ -145,31 +145,31 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI void setViews() { // TODO: hide empty categories - bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.BGSOURCE)); + bgsourceDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.BGSOURCE), PluginBase.BGSOURCE); bgsourceListView.setAdapter(bgsourceDataAdapter); setListViewHeightBasedOnChildren(bgsourceListView); - pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PUMP)); + pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PUMP), PluginBase.PUMP); pumpListView.setAdapter(pumpDataAdapter); setListViewHeightBasedOnChildren(pumpListView); - loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.LOOP)); + loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.LOOP), PluginBase.LOOP); loopListView.setAdapter(loopDataAdapter); setListViewHeightBasedOnChildren(loopListView); - treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TREATMENT)); + treatmentsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TREATMENT), PluginBase.TREATMENT); treatmentsListView.setAdapter(treatmentsDataAdapter); setListViewHeightBasedOnChildren(treatmentsListView); - tempsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TEMPBASAL)); + tempsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.TEMPBASAL), PluginBase.TEMPBASAL); tempsListView.setAdapter(tempsDataAdapter); setListViewHeightBasedOnChildren(tempsListView); - profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.PROFILE)); + profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(ProfileInterface.class), PluginBase.PROFILE); profileListView.setAdapter(profileDataAdapter); setListViewHeightBasedOnChildren(profileListView); - apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.APS)); + apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.APS), PluginBase.APS); apsListView.setAdapter(apsDataAdapter); setListViewHeightBasedOnChildren(apsListView); - constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class)); + constraintsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class), PluginBase.CONSTRAINTS); constraintsListView.setAdapter(constraintsDataAdapter); setListViewHeightBasedOnChildren(constraintsListView); - generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.GENERAL)); + generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainActivity.getSpecificPluginsList(PluginBase.GENERAL), PluginBase.GENERAL); generalListView.setAdapter(generalDataAdapter); setListViewHeightBasedOnChildren(generalListView); @@ -189,27 +189,27 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return true; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return true; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return false; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { // Always enabled } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { // Always visible } @@ -414,12 +414,14 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI private class PluginCustomAdapter extends ArrayAdapter { private ArrayList pluginList; + final private int type; public PluginCustomAdapter(Context context, int textViewResourceId, - ArrayList pluginList) { + ArrayList pluginList, int type) { super(context, textViewResourceId, pluginList); this.pluginList = new ArrayList(); this.pluginList.addAll(pluginList); + this.type = type; } private class PluginViewHolder { @@ -446,9 +448,9 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI public void onClick(View v) { CheckBox cb = (CheckBox) v; PluginBase plugin = (PluginBase) cb.getTag(); - plugin.setFragmentEnabled(cb.isChecked()); - if (cb.isChecked()) plugin.setFragmentVisible(true); - onEnabledCategoryChanged(plugin); + plugin.setFragmentEnabled(type, cb.isChecked()); + if (cb.isChecked()) plugin.setFragmentVisible(type, true); + onEnabledCategoryChanged(plugin, type); storeSettings(); } }); @@ -457,7 +459,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI public void onClick(View v) { CheckBox cb = (CheckBox) v; PluginBase plugin = (PluginBase) cb.getTag(); - plugin.setFragmentVisible(cb.isChecked()); + plugin.setFragmentVisible(type, cb.isChecked()); storeSettings(); MainApp.bus().post(new EventRefreshGui()); } @@ -468,13 +470,13 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI PluginBase plugin = pluginList.get(position); holder.name.setText(plugin.getName()); - holder.checkboxEnabled.setChecked(plugin.isEnabled()); - holder.checkboxVisible.setChecked(plugin.isVisibleInTabs()); + holder.checkboxEnabled.setChecked(plugin.isEnabled(type)); + holder.checkboxVisible.setChecked(plugin.isVisibleInTabs(type)); holder.name.setTag(plugin); holder.checkboxEnabled.setTag(plugin); holder.checkboxVisible.setTag(plugin); - if (!plugin.canBeHidden()) { + if (!plugin.canBeHidden(type)) { holder.checkboxEnabled.setEnabled(false); holder.checkboxVisible.setEnabled(false); } @@ -491,7 +493,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI // Hide disabled profiles by default if (type == PluginBase.PROFILE) { - if (!plugin.isEnabled()) { + if (!plugin.isEnabled(type)) { holder.checkboxVisible.setEnabled(false); holder.checkboxVisible.setChecked(false); } else { @@ -530,9 +532,9 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI return activeLoop; } - void onEnabledCategoryChanged(PluginBase changedPlugin) { + void onEnabledCategoryChanged(PluginBase changedPlugin, int type) { int category = changedPlugin.getType(); - ArrayList pluginsInCategory = MainActivity.getSpecificPluginsList(category); + ArrayList pluginsInCategory = null; switch (category) { // Multiple selection allowed case PluginBase.APS: @@ -541,116 +543,115 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI break; // Single selection allowed case PluginBase.PROFILE: - case PluginBase.PUMP: + pluginsInCategory = MainActivity.getSpecificPluginsListByInterface(ProfileInterface.class); + break; case PluginBase.BGSOURCE: case PluginBase.LOOP: case PluginBase.TEMPBASAL: case PluginBase.TREATMENT: - boolean newSelection = changedPlugin.isEnabled(); - if (newSelection) { // new plugin selected -> disable others - for (PluginBase p : pluginsInCategory) { - if (p.getName().equals(changedPlugin.getName())) { - // this is new selected - } else { - p.setFragmentEnabled(false); - setViews(); - } - } - } else { // enable first plugin in list - pluginsInCategory.get(0).setFragmentEnabled(true); - } + case PluginBase.PUMP: + pluginsInCategory = MainActivity.getSpecificPluginsList(category); break; } + if (pluginsInCategory != null) { + boolean newSelection = changedPlugin.isEnabled(type); + if (newSelection) { // new plugin selected -> disable others + for (PluginBase p : pluginsInCategory) { + if (p.getName().equals(changedPlugin.getName())) { + // this is new selected + } else { + p.setFragmentEnabled(type, false); + setViews(); + } + } + } else { // enable first plugin in list + pluginsInCategory.get(0).setFragmentEnabled(type, true); + } + } } private void verifySelectionInCategories() { - for (int category : new int[]{PluginBase.GENERAL, PluginBase.APS, PluginBase.PROFILE, PluginBase.PUMP, PluginBase.LOOP, PluginBase.TEMPBASAL, PluginBase.TREATMENT, PluginBase.BGSOURCE}) { - ArrayList pluginsInCategory = MainActivity.getSpecificPluginsList(category); - switch (category) { - // Multiple selection allowed - case PluginBase.APS: - case PluginBase.GENERAL: - case PluginBase.CONSTRAINTS: - break; - // Single selection allowed - case PluginBase.BGSOURCE: - activeBgSource = (BgSourceInterface) getTheOneEnabledInArray(pluginsInCategory); - if (Config.logConfigBuilder) - log.debug("Selected bgSource interface: " + ((PluginBase) activeBgSource).getName()); - for (PluginBase p : pluginsInCategory) { - if (!p.getName().equals(((PluginBase) activeBgSource).getName())) { - p.setFragmentVisible(false); - } - } - break; - // Single selection allowed - case PluginBase.PROFILE: - activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory); - if (Config.logConfigBuilder) - log.debug("Selected profile interface: " + ((PluginBase) activeProfile).getName()); - for (PluginBase p : pluginsInCategory) { - if (!p.getName().equals(((PluginBase) activeProfile).getName())) { - p.setFragmentVisible(false); - } - } - break; - case PluginBase.PUMP: - activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory); - if (Config.logConfigBuilder) - log.debug("Selected pump interface: " + ((PluginBase) activePump).getName()); - for (PluginBase p : pluginsInCategory) { - if (!p.getName().equals(((PluginBase) activePump).getName())) { - p.setFragmentVisible(false); - } - } - break; - case PluginBase.LOOP: - activeLoop = (LoopFragment) getTheOneEnabledInArray(pluginsInCategory); - if (activeLoop != null) { - if (Config.logConfigBuilder) - log.debug("Selected loop interface: " + activeLoop.getName()); - for (PluginBase p : pluginsInCategory) { - if (!p.getName().equals(activeLoop.getName())) { - p.setFragmentVisible(false); - } - } - } - break; - case PluginBase.TEMPBASAL: - activeTempBasals = (TempBasalsInterface) getTheOneEnabledInArray(pluginsInCategory); - if (Config.logConfigBuilder) - log.debug("Selected tempbasal interface: " + ((PluginBase) activeTempBasals).getName()); - for (PluginBase p : pluginsInCategory) { - if (!p.getName().equals(((PluginBase) activeTempBasals).getName())) { - p.setFragmentVisible(false); - } - } - break; - case PluginBase.TREATMENT: - activeTreatments = (TreatmentsInterface) getTheOneEnabledInArray(pluginsInCategory); - if (Config.logConfigBuilder) - log.debug("Selected treatment interface: " + ((PluginBase) activeTreatments).getName()); - for (PluginBase p : pluginsInCategory) { - if (!p.getName().equals(((PluginBase) activeTreatments).getName())) { - p.setFragmentVisible(false); - } - } - break; - } + ArrayList pluginsInCategory; + // PluginBase.PROFILE + pluginsInCategory = MainActivity.getSpecificPluginsListByInterface(ProfileInterface.class); + activeProfile = (ProfileInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PROFILE); + if (Config.logConfigBuilder) + log.debug("Selected profile interface: " + ((PluginBase) activeProfile).getName()); + for (PluginBase p : pluginsInCategory) { + if (!p.getName().equals(((PluginBase) activeProfile).getName())) { + p.setFragmentVisible(PluginBase.PROFILE, false); + } + } + + // PluginBase.BGSOURCE + pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.BGSOURCE); + activeBgSource = (BgSourceInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.BGSOURCE); + if (Config.logConfigBuilder) + log.debug("Selected bgSource interface: " + ((PluginBase) activeBgSource).getName()); + for (PluginBase p : pluginsInCategory) { + if (!p.getName().equals(((PluginBase) activeBgSource).getName())) { + p.setFragmentVisible(PluginBase.BGSOURCE, false); + } + } + + // PluginBase.PUMP + pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.PUMP); + activePump = (PumpInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.PUMP); + if (Config.logConfigBuilder) + log.debug("Selected pump interface: " + ((PluginBase) activePump).getName()); + for (PluginBase p : pluginsInCategory) { + if (!p.getName().equals(((PluginBase) activePump).getName())) { + p.setFragmentVisible(PluginBase.PUMP, false); + } + } + + // PluginBase.LOOP + pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.LOOP); + activeLoop = (LoopFragment) getTheOneEnabledInArray(pluginsInCategory, PluginBase.LOOP); + if (activeLoop != null) { + if (Config.logConfigBuilder) + log.debug("Selected loop interface: " + activeLoop.getName()); + for (PluginBase p : pluginsInCategory) { + if (!p.getName().equals(activeLoop.getName())) { + p.setFragmentVisible(PluginBase.LOOP, false); + } + } + } + + // PluginBase.TEMPBASAL + pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.TEMPBASAL); + activeTempBasals = (TempBasalsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TEMPBASAL); + if (Config.logConfigBuilder) + log.debug("Selected tempbasal interface: " + ((PluginBase) activeTempBasals).getName()); + for (PluginBase p : pluginsInCategory) { + if (!p.getName().equals(((PluginBase) activeTempBasals).getName())) { + p.setFragmentVisible(PluginBase.TEMPBASAL, false); + } + } + + // PluginBase.TREATMENT + pluginsInCategory = MainActivity.getSpecificPluginsList(PluginBase.TREATMENT); + activeTreatments = (TreatmentsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TREATMENT); + if (Config.logConfigBuilder) + log.debug("Selected treatment interface: " + ((PluginBase) activeTreatments).getName()); + for (PluginBase p : pluginsInCategory) { + if (!p.getName().equals(((PluginBase) activeTreatments).getName())) { + p.setFragmentVisible(PluginBase.TREATMENT, false); + } } } @Nullable - private PluginBase getTheOneEnabledInArray(ArrayList pluginsInCategory) { + private PluginBase getTheOneEnabledInArray(ArrayList pluginsInCategory, int type) { PluginBase found = null; for (PluginBase p : pluginsInCategory) { - if (p.isEnabled() && found == null) { + if (p.isEnabled(type) && found == null) { found = p; continue; - } else if (p.isEnabled()) { + } else if (p.isEnabled(type)) { // set others disabled - p.setFragmentEnabled(false); + p.setFragmentEnabled(type, false); } } // If none enabled, enable first one @@ -666,9 +667,13 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences.Editor editor = settings.edit(); - for (PluginBase p : pluginList) { - editor.putBoolean("ConfigBuilder" + p.getName() + "Enabled", p.isEnabled()); - editor.putBoolean("ConfigBuilder" + p.getName() + "Visible", p.isVisibleInTabs()); + for (int type = 1; type < PluginBase.LAST; type++) { + for (PluginBase p : pluginList) { + String settingEnabled = "ConfigBuilder_" + type + "_" + p.getName() + "_Enabled"; + String settingVisible = "ConfigBuilder_" + p.getName() + "_Visible"; + editor.putBoolean(settingEnabled, p.isEnabled(type)); + editor.putBoolean(settingVisible, p.isVisibleInTabs(type)); + } } editor.commit(); verifySelectionInCategories(); @@ -678,12 +683,16 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI private void loadSettings() { if (Config.logPrefsChange) log.debug("Loading stored settings"); - SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); - for (PluginBase p : pluginList) { - if (settings.contains("ConfigBuilder" + p.getName() + "Enabled")) - p.setFragmentEnabled(settings.getBoolean("ConfigBuilder" + p.getName() + "Enabled", true)); - if (settings.contains("ConfigBuilder" + p.getName() + "Visible")) - p.setFragmentVisible(settings.getBoolean("ConfigBuilder" + p.getName() + "Visible", true)); + SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); + for (int type = 1; type < PluginBase.LAST; type++) { + for (PluginBase p : pluginList) { + String settingEnabled = "ConfigBuilder_" + type + "_" + p.getName() + "_Enabled"; + String settingVisible = "ConfigBuilder_" + p.getName() + "_Visible"; + if (SP.contains(settingEnabled)) + p.setFragmentEnabled(type, SP.getBoolean(settingEnabled, true)); + if (SP.contains("ConfigBuilder" + p.getName() + "Visible")) + p.setFragmentVisible(type, SP.getBoolean(settingVisible, true)); + } } verifySelectionInCategories(); } @@ -724,7 +733,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; result = result && constrain.isLoopEnabled(); } return result; @@ -737,7 +746,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; result = result && constrain.isClosedModeEnabled(); } return result; @@ -750,7 +759,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; result = result && constrain.isAutosensModeEnabled(); } return result; @@ -763,7 +772,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; result = result && constrain.isAMAModeEnabled(); } return result; @@ -775,7 +784,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; rateAfterConstrain = Math.min(constrain.applyBasalConstraints(absoluteRate), rateAfterConstrain); } return rateAfterConstrain; @@ -787,7 +796,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; rateAfterConstrain = Math.min(constrain.applyBasalConstraints(percentRate), rateAfterConstrain); } return rateAfterConstrain; @@ -799,7 +808,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; insulinAfterConstrain = Math.min(constrain.applyBolusConstraints(insulin), insulinAfterConstrain); } return insulinAfterConstrain; @@ -811,7 +820,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; carbsAfterConstrain = Math.min(constrain.applyCarbsConstraints(carbs), carbsAfterConstrain); } return carbsAfterConstrain; @@ -823,7 +832,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI ArrayList constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class); for (PluginBase p : constraintsPlugins) { ConstraintsInterface constrain = (ConstraintsInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue; maxIobAfterConstrain = Math.min(constrain.applyMaxIOBConstraints(maxIob), maxIobAfterConstrain); } return maxIobAfterConstrain; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java index fcb2ed8bff..b08e3f1db4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaConnection.java @@ -333,6 +333,7 @@ public class DanaConnection { mSerialEngine.sendMessage(new MsgSettingPumpTime()); mSerialEngine.sendMessage(new MsgSettingActiveProfile()); mSerialEngine.sendMessage(new MsgSettingProfileRatios()); + mSerialEngine.sendMessage(new MsgSettingProfileRatiosAll()); danaRPump.lastSettingsRead = now; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java index 580d56089c..c7a8f52e1a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRFragment.java @@ -7,10 +7,13 @@ import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.preference.PreferenceManager; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.TextView; import com.squareup.otto.Subscribe; @@ -35,18 +38,18 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.PluginBase; +import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; -import info.nightscout.androidaps.plugins.DanaR.comm.MsgSetTempBasalStop; +import info.nightscout.androidaps.plugins.DanaR.Dialogs.ProfileViewDialog; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRConnectionStatus; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRNewStatus; -import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DateUtil; import info.nightscout.utils.Round; import info.nightscout.utils.SetWarnColor; -public class DanaRFragment extends Fragment implements PluginBase, PumpInterface, ConstraintsInterface { +public class DanaRFragment extends Fragment implements PluginBase, PumpInterface, ConstraintsInterface, ProfileInterface { private static Logger log = LoggerFactory.getLogger(DanaRFragment.class); Handler mHandler; @@ -56,13 +59,16 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface private static DanaRPump sDanaRPump = new DanaRPump(); private static boolean useExtendedBoluses = false; - boolean fragmentEnabled = true; - boolean fragmentVisible = true; + boolean fragmentPumpEnabled = true; + boolean fragmentProfileEnabled = true; + boolean fragmentPumpVisible = true; boolean visibleNow = false; Handler loopHandler = new Handler(); Runnable refreshLoop = null; + NSProfile convertedProfile = null; + TextView lastConnectionView; TextView btConnectionView; TextView lastBolusView; @@ -73,6 +79,7 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface TextView batteryView; TextView reservoirView; TextView iobView; + Button viewProfileButton; public static DanaConnection getDanaConnection() { return sDanaConnection; @@ -148,6 +155,16 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface batteryView = (TextView) view.findViewById(R.id.danar_battery); reservoirView = (TextView) view.findViewById(R.id.danar_reservoir); iobView = (TextView) view.findViewById(R.id.danar_iob); + viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile); + + viewProfileButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + FragmentManager manager = getFragmentManager(); + ProfileViewDialog profileViewDialog = new ProfileViewDialog(); + profileViewDialog.show(manager, "ProfileViewDialog"); + } + }); btConnectionView.setOnClickListener(new View.OnClickListener() { @Override @@ -225,28 +242,35 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface } @Override - public boolean isEnabled() { - return fragmentEnabled; + public boolean isEnabled(int type) { + if (type == PluginBase.PROFILE) return fragmentProfileEnabled; + else if (type == PluginBase.PUMP) return fragmentPumpEnabled; + else if (type == PluginBase.CONSTRAINTS) return fragmentPumpEnabled; + return false; } @Override - public boolean isVisibleInTabs() { - return fragmentVisible; + 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() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { - this.fragmentEnabled = fragmentEnabled; - } + public void setFragmentEnabled(int type, boolean fragmentEnabled) { + if (type == PluginBase.PROFILE) this.fragmentProfileEnabled = fragmentEnabled; + else if (type == PluginBase.PUMP) this.fragmentPumpEnabled = fragmentEnabled; + } @Override - public void setFragmentVisible(boolean fragmentVisible) { - this.fragmentVisible = fragmentVisible; + public void setFragmentVisible(int type, boolean fragmentVisible) { + if (type == PluginBase.PUMP) + this.fragmentPumpVisible = fragmentVisible; } // Pump interface @@ -803,5 +827,14 @@ public class DanaRFragment extends Fragment implements PluginBase, PumpInterface return maxIob; } + @Nullable + @Override + public NSProfile getProfile() { + DanaRPump pump = getDanaRPump(); + if (pump.lastSettingsRead.getTime() == 0) + return null; // no info now + return pump.convertedProfile; + } + // TODO: daily total constraint } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java index c1ae06a240..64cef160b8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/DanaRPump.java @@ -1,7 +1,15 @@ package info.nightscout.androidaps.plugins.DanaR; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.text.DecimalFormat; import java.util.Date; +import info.nightscout.androidaps.Constants; +import info.nightscout.client.data.NSProfile; + /** * Created by mike on 04.07.2016. */ @@ -10,7 +18,7 @@ public class DanaRPump { public static final int UNITS_MMOL = 1; Date lastConnection = new Date(0); - Date lastSettingsRead = new Date(0); + public Date lastSettingsRead = new Date(0); // Info public String serialNumber = ""; @@ -56,19 +64,19 @@ public class DanaRPump { public int easyBasalMode; public boolean basal48Enable = false; public int currentCIR; - public int currentCF; - public int currentAI; - public int currentTarget; + public double currentCF; + public double currentAI; + public double currentTarget; public int currentAIDR; public int morningCIR; - public int morningCF; + public double morningCF; public int afternoonCIR; - public int afternoonCF; + public double afternoonCF; public int eveningCIR; - public int eveningCF; + public double eveningCF; public int nightCIR; - public int nightCF; + public double nightCF; public int activeProfile = 0; @@ -77,4 +85,65 @@ public class DanaRPump { //Limits public double maxBolus; public double maxBasal; + + NSProfile convertedProfile = null; + + public void createConvertedProfile() { + JSONObject json = new JSONObject(); + JSONObject store = new JSONObject(); + JSONObject profile = new JSONObject(); + +// Morning / 6:00–10:59 +// Afternoon / 11:00–16:59 +// Evening / 17:00–21:59 +// Night / 22:00–5:59 + + try { + json.put("defaultProfile", "" + (activeProfile + 1)); + json.put("store", store); + profile.put("dia", 3); // TODO: fixed DIA, maybe would be needed to have it configurable in settings + + JSONArray carbratios = new JSONArray(); + carbratios.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF)); + carbratios.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCF)); + carbratios.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCF)); + carbratios.put(new JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCF)); + carbratios.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF)); + profile.put("carbratio", carbratios); + + profile.put("carbs_hr", 20); // TODO: fixed CAR, maybe would be needed to have it configurable in settings + + JSONArray sens = new JSONArray(); + sens.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR)); + sens.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR)); + sens.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR)); + sens.put(new JSONObject().put("time", "17:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR)); + sens.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR)); + profile.put("sens", sens); + + JSONArray basals = new JSONArray(); + int basalValues = basal48Enable ? 48 : 24; + int basalIncrement = basal48Enable ? 30 * 60 : 60 * 60; + for (int h = 0; h < basalValues; h++) { + String time; + DecimalFormat df = new DecimalFormat("00"); + if (basal48Enable) { + time = df.format((long) h / 2) + ":" + df.format(30 * (h % 2)); + } else { + time = df.format(h) + ":00"; + } + basals.put(new JSONObject().put("time", time).put("timeAsSeconds", h * basalIncrement).put("value", pumpProfiles[activeProfile][h])); + } + profile.put("basal", basals); + + profile.put("target_low", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget))); + profile.put("target_high", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget))); + profile.put("units", units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL); + store.put("" + (activeProfile + 1), profile); + } catch (JSONException e) { + e.printStackTrace(); + } + convertedProfile = new NSProfile(json, "" + (activeProfile + 1)); + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Dialogs/ProfileViewDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Dialogs/ProfileViewDialog.java new file mode 100644 index 0000000000..0ccd633f5b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/Dialogs/ProfileViewDialog.java @@ -0,0 +1,108 @@ +package info.nightscout.androidaps.plugins.DanaR.Dialogs; + +import android.support.v4.app.DialogFragment; +import android.os.Bundle; +import android.os.Handler; +import android.os.HandlerThread; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.DecimalFormat; +import java.util.Date; + +import info.nightscout.androidaps.MainActivity; +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.plugins.DanaR.DanaRFragment; +import info.nightscout.client.data.NSProfile; + +/** + * Created by mike on 10.07.2016. + */ +public class ProfileViewDialog extends DialogFragment { + private static Logger log = LoggerFactory.getLogger(ProfileViewDialog.class); + + private static TextView noProfile; + private static TextView units; + private static TextView dia; + private static TextView activeProfile; + private static TextView ic; + private static TextView isf; + private static TextView basal; + private static TextView target; + + private static Button refreshButton; + + private static DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00"); + + Handler mHandler; + static HandlerThread mHandlerThread; + + NSProfile profile = null; + + public ProfileViewDialog() { + mHandlerThread = new HandlerThread(ProfileViewDialog.class.getSimpleName()); + mHandlerThread.start(); + + mHandler = new Handler(mHandlerThread.getLooper()); + profile = ((DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class)).getProfile(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View layout = inflater.inflate(R.layout.nsprofileviewer_fragment, container, false); + + noProfile = (TextView) layout.findViewById(R.id.profileview_noprofile); + units = (TextView) layout.findViewById(R.id.profileview_units); + dia = (TextView) layout.findViewById(R.id.profileview_dia); + activeProfile = (TextView) layout.findViewById(R.id.profileview_activeprofile); + ic = (TextView) layout.findViewById(R.id.profileview_ic); + isf = (TextView) layout.findViewById(R.id.profileview_isf); + basal = (TextView) layout.findViewById(R.id.profileview_basal); + target = (TextView) layout.findViewById(R.id.profileview_target); + refreshButton = (Button) layout.findViewById(R.id.profileview_reload); + refreshButton.setVisibility(View.VISIBLE); + refreshButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mHandler.post(new Runnable() { + @Override + public void run() { + DanaRFragment.getDanaRPump().lastSettingsRead = new Date(0); + DanaRFragment.getDanaConnection().connectIfNotConnected("ProfileViewDialog"); + //refreshButton.setVisibility(View.VISIBLE); + } + }); + //refreshButton.setVisibility(View.GONE); + dismiss(); + } + }); + + setContent(); + return layout; + } + + private void setContent() { + if (profile == null) { + noProfile.setVisibility(View.VISIBLE); + return; + } else { + noProfile.setVisibility(View.GONE); + } + units.setText(profile.getUnits()); + dia.setText(formatNumber2decimalplaces.format(profile.getDia()) + " h"); + activeProfile.setText(profile.getActiveProfile()); + ic.setText(profile.getIcList()); + isf.setText(profile.getIsfList()); + basal.setText(profile.getBasalList()); + target.setText(profile.getTargetList()); + } + + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatios.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatios.java index 7be7a7fada..221995dcd1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatios.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatios.java @@ -21,15 +21,15 @@ public class MsgSettingProfileRatios extends DanaRMessage { if (DanaRFragment.getDanaRPump().units == DanaRPump.UNITS_MGDL) { DanaRFragment.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2); DanaRFragment.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2); - DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100; + DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d; DanaRFragment.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2); - DanaRFragment.getDanaRPump().currentAIDR = intFromBuff(bytes, 6, 1); + DanaRFragment.getDanaRPump().currentAIDR = intFromBuff(bytes, 8, 1); } else { DanaRFragment.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2); - DanaRFragment.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2) / 100; - DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100; - DanaRFragment.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2) / 100; - DanaRFragment.getDanaRPump().currentAIDR = intFromBuff(bytes, 6, 1); + DanaRFragment.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2) / 100d; + DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d; + DanaRFragment.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2) / 100d; + DanaRFragment.getDanaRPump().currentAIDR = intFromBuff(bytes, 8, 1); } if (Config.logDanaMessageDetail) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatiosAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatiosAll.java index 141cc67243..f2e95a80cd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatiosAll.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgSettingProfileRatiosAll.java @@ -29,13 +29,13 @@ public class MsgSettingProfileRatiosAll extends DanaRMessage { DanaRFragment.getDanaRPump().nightCF = intFromBuff(bytes, 14, 2); } else { DanaRFragment.getDanaRPump().morningCIR = intFromBuff(bytes, 0, 2); - DanaRFragment.getDanaRPump().morningCF = intFromBuff(bytes, 2, 2) / 100; + DanaRFragment.getDanaRPump().morningCF = intFromBuff(bytes, 2, 2) / 100d; DanaRFragment.getDanaRPump().afternoonCIR = intFromBuff(bytes, 4, 2); - DanaRFragment.getDanaRPump().afternoonCF = intFromBuff(bytes, 6, 2) / 100; + DanaRFragment.getDanaRPump().afternoonCF = intFromBuff(bytes, 6, 2) / 100d; DanaRFragment.getDanaRPump().eveningCIR = intFromBuff(bytes, 8, 2); - DanaRFragment.getDanaRPump().eveningCF = intFromBuff(bytes, 10, 2) / 100; + DanaRFragment.getDanaRPump().eveningCF = intFromBuff(bytes, 10, 2) / 100d; DanaRFragment.getDanaRPump().nightCIR = intFromBuff(bytes, 12, 2); - DanaRFragment.getDanaRPump().nightCF = intFromBuff(bytes, 14, 2) / 100; + DanaRFragment.getDanaRPump().nightCF = intFromBuff(bytes, 14, 2) / 100d; } if (Config.logDanaMessageDetail) { @@ -49,6 +49,7 @@ public class MsgSettingProfileRatiosAll extends DanaRMessage { log.debug("Current pump night CIR: " + DanaRFragment.getDanaRPump().nightCIR); log.debug("Current pump night CF: " + DanaRFragment.getDanaRPump().nightCF); } - } + DanaRFragment.getDanaRPump().createConvertedProfile(); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgStatusProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgStatusProfile.java index 3fabf9bef4..22b953bc09 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgStatusProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/DanaR/comm/MsgStatusProfile.java @@ -21,13 +21,13 @@ public class MsgStatusProfile extends DanaRMessage { if (DanaRFragment.getDanaRPump().units == DanaRPump.UNITS_MGDL) { DanaRFragment.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2); DanaRFragment.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2); - DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100; + DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d; DanaRFragment.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2); } else { DanaRFragment.getDanaRPump().currentCIR = intFromBuff(bytes, 0, 2); - DanaRFragment.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2) / 100; - DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100; - DanaRFragment.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2) / 100; + DanaRFragment.getDanaRPump().currentCF = intFromBuff(bytes, 2, 2) / 100d; + DanaRFragment.getDanaRPump().currentAI = intFromBuff(bytes, 4, 2) / 100d; + DanaRFragment.getDanaRPump().currentTarget = intFromBuff(bytes, 6, 2) / 100d; } if (Config.logDanaMessageDetail) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java index 7fef247c89..e05dcf9136 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopFragment.java @@ -116,27 +116,27 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } @@ -229,14 +229,14 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug ConfigBuilderFragment configBuilder = MainApp.getConfigBuilder(); APSResult result = null; - if (constraintsInterface == null || configBuilder == null || !isEnabled()) + if (constraintsInterface == null || configBuilder == null || !isEnabled(PluginBase.GENERAL)) return; APSInterface usedAPS = null; ArrayList apsPlugins = MainActivity.getSpecificPluginsList(PluginBase.APS); for (PluginBase p : apsPlugins) { APSInterface aps = (APSInterface) p; - if (!p.isEnabled()) continue; + if (!p.isEnabled(PluginBase.APS)) continue; aps.invoke(); result = aps.getLastAPSResult(); if (result == null) continue; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java index a6c437ce69..b86b2659d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/LowSuspend/LowSuspendFragment.java @@ -118,27 +118,27 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } @@ -218,7 +218,7 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); - if (!isEnabled()) { + if (!isEnabled(PluginBase.APS)) { updateResultGUI(MainApp.instance().getString(R.string.openapsma_disabled)); if (Config.logAPSResult) log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java index e1633a8051..8e162e6c13 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSProfileViewer/NSProfileViewerFragment.java @@ -61,27 +61,27 @@ public class NSProfileViewerFragment extends Fragment implements PluginBase, Pro } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java index b77874194c..b331119ddf 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Objectives/ObjectivesFragment.java @@ -54,26 +54,26 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return true; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java index b06049a957..dcf62ae561 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterJS.java @@ -278,7 +278,7 @@ public class DetermineBasalAdapterJS implements Parcelable { mProfile.add("min_bg", minBg); mProfile.add("max_bg", maxBg); mProfile.add("carbratio", profile.getIc(profile.secondsFromMidnight())); - mProfile.add("sens", NSProfile.toMgdl(profile.getIsf(profile.secondsFromMidnight()).doubleValue(), units)); + mProfile.add("sens", NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()).doubleValue(), units)); mProfile.add("current_basal", pump.getBaseBasalRate()); mCurrentTemp.add("duration", pump.getTempBasalRemainingMinutes()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java index c5dd57f9c8..7b0ad5e6db 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/OpenAPSMAFragment.java @@ -107,27 +107,27 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @@ -214,7 +214,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); PumpInterface pump = MainApp.getConfigBuilder().getActivePump(); - if (!isEnabled()) { + if (!isEnabled(PluginBase.APS)) { updateResultGUI(MainApp.instance().getString(R.string.openapsma_disabled)); if (Config.logAPSResult) log.debug(MainApp.instance().getString(R.string.openapsma_disabled)); 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 608c49a455..05026e0f17 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 @@ -102,27 +102,27 @@ public class OverviewFragment extends Fragment implements PluginBase { } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return true; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return true; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return false; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { // Always enabled } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { // Always visible } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java index 98ade2a3bf..dde7b12a58 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SafetyFragment/SafetyFragment.java @@ -34,27 +34,27 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return true; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return false; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int tyep, boolean fragmentEnabled) { } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { } public static SafetyFragment newInstance() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java index 363c192f8b..8ddd9e6c27 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SimpleProfile/SimpleProfileFragment.java @@ -77,27 +77,27 @@ public class SimpleProfileFragment extends Fragment implements PluginBase, Profi } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java index c2e53dc016..fc541762d5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceNSClient/SourceNSClientFragment.java @@ -31,27 +31,27 @@ public class SourceNSClientFragment extends Fragment implements PluginBase, BgSo } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return false; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java index fc3bfa33c8..d667a05200 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SourceXdrip/SourceXdripFragment.java @@ -32,27 +32,27 @@ public class SourceXdripFragment extends Fragment implements PluginBase, BgSourc } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return false; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { } public static SourceXdripFragment newInstance() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java index b8a84b1914..6300c5d7f9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/TempBasals/TempBasalsFragment.java @@ -72,27 +72,27 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java index f96982f7a4..6fd8747820 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsFragment.java @@ -73,27 +73,27 @@ public class TreatmentsFragment extends Fragment implements View.OnClickListener } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } @Override - public void setFragmentEnabled(boolean fragmentEnabled) { + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java index 3a410527bc..14351e6892 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/VirtualPump/VirtualPumpFragment.java @@ -58,26 +58,27 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt } @Override - public boolean isEnabled() { + public boolean isEnabled(int type) { return fragmentEnabled; } @Override - public boolean isVisibleInTabs() { + public boolean isVisibleInTabs(int type) { return fragmentVisible; } @Override - public boolean canBeHidden() { + public boolean canBeHidden(int type) { return true; } - public void setFragmentEnabled(boolean fragmentEnabled) { + @Override + public void setFragmentEnabled(int type, boolean fragmentEnabled) { this.fragmentEnabled = fragmentEnabled; } @Override - public void setFragmentVisible(boolean fragmentVisible) { + public void setFragmentVisible(int type, boolean fragmentVisible) { this.fragmentVisible = fragmentVisible; } diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java index d712e5f455..3a144b5c34 100644 --- a/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java +++ b/app/src/main/java/info/nightscout/androidaps/receivers/KeepAliveReceiver.java @@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainActivity; +import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.plugins.DanaR.DanaRFragment; import info.nightscout.androidaps.plugins.DanaR.Services.DanaRService; @@ -31,7 +32,7 @@ public class KeepAliveReceiver extends BroadcastReceiver { log.debug("KeepAlive received"); DanaRFragment danaRFragment = (DanaRFragment) MainActivity.getSpecificPlugin(DanaRFragment.class); - if (Config.DANAR && danaRFragment != null && danaRFragment.isEnabled()) { + if (Config.DANAR && danaRFragment != null && danaRFragment.isEnabled(PluginBase.PUMP)) { Intent intent = new Intent(context, DanaRService.class); context.startService(intent); } 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 e952e1d66f..901ebabe80 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -45,7 +45,7 @@ public class TabPageAdapter extends FragmentStatePagerAdapter { public void registerNewFragment(Fragment fragment) { PluginBase plugin = (PluginBase) fragment; fragmentList.add(plugin); - if (plugin.isVisibleInTabs()) { + if (plugin.isVisibleInTabs(plugin.getType())) { visibleFragmentList.add(plugin); notifyDataSetChanged(); } diff --git a/app/src/main/java/info/nightscout/client/data/NSProfile.java b/app/src/main/java/info/nightscout/client/data/NSProfile.java index 74d22e2b15..f89ed3fe9f 100644 --- a/app/src/main/java/info/nightscout/client/data/NSProfile.java +++ b/app/src/main/java/info/nightscout/client/data/NSProfile.java @@ -213,7 +213,7 @@ public class NSProfile { JSONObject profile = getDefaultProfile(); if (profile != null) { try { - return getValuesList(profile.getJSONArray("carbratio"), null, new DecimalFormat("0"), "g"); + return getValuesList(profile.getJSONArray("carbratio"), null, new DecimalFormat("0.0"), "g"); } catch (JSONException e) { e.printStackTrace(); } diff --git a/app/src/main/res/layout/danar_fragment.xml b/app/src/main/res/layout/danar_fragment.xml index d4126df2ef..750dc36b7a 100644 --- a/app/src/main/res/layout/danar_fragment.xml +++ b/app/src/main/res/layout/danar_fragment.xml @@ -250,6 +250,18 @@ android:textAppearance="?android:attr/textAppearanceMedium" /> + + + +