diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 798c858a10..b66cba183f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -83,6 +83,8 @@ + + @@ -170,7 +172,7 @@ { Intent intent = new Intent(this, SingleFragmentActivity.class); intent.putExtra("plugin", MainApp.getPluginsList().indexOf(p)); startActivity(intent); + ((DrawerLayout) findViewById(R.id.drawer_layout)).closeDrawers(); return true; }); } diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 45aff91654..a677b65d6a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -69,6 +69,7 @@ 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.SourcePoctechPlugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin; @@ -178,6 +179,8 @@ public class MainApp extends Application { pluginsList.add(SourceGlimpPlugin.getPlugin()); if (!Config.NSCLIENT) pluginsList.add(SourceDexcomG5Plugin.getPlugin()); + if (!Config.NSCLIENT) + pluginsList.add(SourcePoctechPlugin.getPlugin()); if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin()); pluginsList.add(FoodPlugin.getPlugin()); 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 f8437d8d36..f8a9ed5d5e 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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.ProfileStore; @@ -38,6 +39,7 @@ 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.SourcePoctechPlugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.utils.BundleLogger; @@ -54,6 +56,7 @@ public class DataService extends IntentService { boolean mm640gEnabled = false; boolean glimpEnabled = false; boolean dexcomG5Enabled = false; + boolean poctechEnabled = false; public DataService() { super("DataService"); @@ -70,36 +73,49 @@ public class DataService extends IntentService { mm640gEnabled = false; glimpEnabled = false; dexcomG5Enabled = false; + poctechEnabled = false; } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceXdripPlugin.class)) { xDripEnabled = true; nsClientEnabled = false; mm640gEnabled = false; glimpEnabled = false; dexcomG5Enabled = false; + poctechEnabled = false; } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceNSClientPlugin.class)) { xDripEnabled = false; nsClientEnabled = true; mm640gEnabled = false; glimpEnabled = false; dexcomG5Enabled = false; + poctechEnabled = false; } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceMM640gPlugin.class)) { xDripEnabled = false; nsClientEnabled = false; mm640gEnabled = true; glimpEnabled = false; dexcomG5Enabled = false; + poctechEnabled = false; } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceGlimpPlugin.class)) { xDripEnabled = false; nsClientEnabled = false; mm640gEnabled = false; glimpEnabled = true; dexcomG5Enabled = false; + poctechEnabled = false; } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourceDexcomG5Plugin.class)) { xDripEnabled = false; nsClientEnabled = false; mm640gEnabled = false; glimpEnabled = false; dexcomG5Enabled = true; + poctechEnabled = false; + } else if (ConfigBuilderPlugin.getPlugin().getActiveBgSource().getClass().equals(SourcePoctechPlugin.class)) { + xDripEnabled = false; + nsClientEnabled = false; + mm640gEnabled = false; + glimpEnabled = false; + dexcomG5Enabled = false; + poctechEnabled = true; } boolean isNSProfile = MainApp.getConfigBuilder().getActiveProfileInterface() != null && MainApp.getConfigBuilder().getActiveProfileInterface().getClass().equals(NSProfilePlugin.class); @@ -129,6 +145,10 @@ public class DataService extends IntentService { if (dexcomG5Enabled) { handleNewDataFromDexcomG5(intent); } + } else if (Intents.POCTECH_BG.equals(action)) { + if (poctechEnabled) { + handleNewDataFromPoctech(intent); + } } else if (Intents.ACTION_NEW_SGV.equals(action)) { if (nsClientEnabled || SP.getBoolean(R.string.key_ns_autobackfill, true)) handleNewDataFromNSClient(intent); @@ -250,6 +270,41 @@ public class DataService extends IntentService { } } + private void handleNewDataFromPoctech(Intent intent) { + + Bundle bundle = intent.getExtras(); + if (bundle == null) return; + + BgReading bgReading = new BgReading(); + + String data = bundle.getString("data"); + log.debug("Received Poctech Data", data); + + try { + JSONArray jsonArray = new JSONArray(data); + log.debug("Received Poctech Data size:" + jsonArray.length()); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject json = jsonArray.getJSONObject(i); + bgReading.value = json.getDouble("current"); + bgReading.direction = json.getString("direction"); + bgReading.date = json.getLong("date"); + bgReading.raw = json.getDouble("raw"); + if (JsonHelper.safeGetString(json, "utils", Constants.MGDL).equals("mmol/L")) + bgReading.value = bgReading.value * Constants.MMOLL_TO_MGDL; + boolean isNew = MainApp.getDbHelper().createIfNotExists(bgReading, "Poctech"); + if (isNew && SP.getBoolean(R.string.key_dexcomg5_nsupload, false)) { + NSUpload.uploadBg(bgReading); + } + if (isNew && SP.getBoolean(R.string.key_dexcomg5_xdripupload, false)) { + NSUpload.sendToXdrip(bgReading); + } + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } + private void handleNewDataFromMM640g(Intent intent) { Bundle bundle = intent.getExtras(); if (bundle == null) return; diff --git a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java index 744530c8f2..25485fb34d 100644 --- a/app/src/main/java/info/nightscout/androidaps/Services/Intents.java +++ b/app/src/main/java/info/nightscout/androidaps/Services/Intents.java @@ -49,4 +49,6 @@ public interface Intents { String GLIMP_BG = "it.ct.glicemia.ACTION_GLUCOSE_MEASURED"; String DEXCOMG5_BG = "com.dexcom.cgm.DATA"; + + String POCTECH_BG = "com.china.poctech.data"; } 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 1173936430..ed9b5672a2 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginBase.java @@ -57,6 +57,11 @@ public abstract class PluginBase { return getName(); } + public String getDescription() { + if (pluginDescription.description == -1) return null; + else return MainApp.gs(pluginDescription.description); + } + public PluginType getType() { return pluginDescription.mainType; } diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java index c86ae639fa..1634fc672d 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/PluginDescription.java @@ -9,6 +9,7 @@ public class PluginDescription { boolean showInList = true; int pluginName = -1; int shortName = -1; + int description = -1; int preferencesId = -1; int advancedPreferencesId = -1; public boolean enableByDefault = false; @@ -74,6 +75,11 @@ public class PluginDescription { return this; } + public PluginDescription description(int description) { + this.description = description; + return this; + } + public String getFragmentClass() { return fragmentClass; } 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 2397410693..ff6275c9c9 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 @@ -17,6 +17,7 @@ public class ActionsPlugin extends PluginBase { .fragmentClass(ActionsFragment.class.getName()) .pluginName(R.string.actions) .shortName(R.string.actions_shortname) + .description(R.string.description_actions) ); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java index 7b9b8570d6..558a7c381c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/dialogs/FillDialog.java @@ -61,6 +61,10 @@ public class FillDialog extends DialogFragment implements OnClickListener { private EditText notesEdit; + //one shot guards + private boolean accepted; + private boolean okClicked; + final private TextWatcher textWatcher = new TextWatcher() { @Override public void afterTextChanged(Editable s) { @@ -163,7 +167,14 @@ public class FillDialog extends DialogFragment implements OnClickListener { } - private void confirmAndDeliver() { + private synchronized void confirmAndDeliver() { + if (okClicked) { + log.debug("guarding: ok already clicked"); + dismiss(); + return; + } + okClicked = true; + try { Double insulin = SafeParse.stringToDouble(editInsulin.getText()); @@ -198,32 +209,40 @@ public class FillDialog extends DialogFragment implements OnClickListener { if (insulinAfterConstraints > 0 || pumpSiteChangeCheckbox.isChecked() || insulinCartridgeChangeCheckbox.isChecked()) { builder.setMessage(Html.fromHtml(Joiner.on("
").join(confirmMessage))); builder.setPositiveButton(MainApp.gs(R.string.primefill), (dialog, id) -> { - if (finalInsulinAfterConstraints > 0) { - DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); - detailedBolusInfo.insulin = finalInsulinAfterConstraints; - detailedBolusInfo.context = context; - detailedBolusInfo.source = Source.USER; - detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) - detailedBolusInfo.notes = notes; - ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { - @Override - public void run() { - if (!result.success) { - Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); - i.putExtra("soundid", R.raw.boluserror); - i.putExtra("status", result.comment); - i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)); - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - MainApp.instance().startActivity(i); + synchronized (builder) { + if (accepted) { + log.debug("guarding: already accepted"); + return; + } + accepted = true; + + if (finalInsulinAfterConstraints > 0) { + DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); + detailedBolusInfo.insulin = finalInsulinAfterConstraints; + detailedBolusInfo.context = context; + detailedBolusInfo.source = Source.USER; + detailedBolusInfo.isValid = false; // do not count it in IOB (for pump history) + detailedBolusInfo.notes = notes; + ConfigBuilderPlugin.getCommandQueue().bolus(detailedBolusInfo, new Callback() { + @Override + public void run() { + if (!result.success) { + Intent i = new Intent(MainApp.instance(), ErrorHelperActivity.class); + i.putExtra("soundid", R.raw.boluserror); + i.putExtra("status", result.comment); + i.putExtra("title", MainApp.gs(R.string.treatmentdeliveryerror)); + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + MainApp.instance().startActivity(i); + } } - } - }); - FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill")); + }); + FabricPrivacy.getInstance().logCustom(new CustomEvent("Fill")); + } + if (pumpSiteChangeCheckbox.isChecked()) + NSUpload.uploadEvent(CareportalEvent.SITECHANGE, now(), notes); + if (insulinCartridgeChangeCheckbox.isChecked()) + NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, now() + 1000, notes); } - if (pumpSiteChangeCheckbox.isChecked()) - NSUpload.uploadEvent(CareportalEvent.SITECHANGE, now(), notes); - if (insulinCartridgeChangeCheckbox.isChecked()) - NSUpload.uploadEvent(CareportalEvent.INSULINCHANGE, now() + 1000, notes); }); } else { builder.setMessage(MainApp.gs(R.string.no_action_selected)); 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 1428880a81..22aa4686b2 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 @@ -23,6 +23,9 @@ public class CareportalPlugin extends PluginBase { .fragmentClass(CareportalFragment.class.getName()) .pluginName(R.string.careportal) .shortName(R.string.careportal_shortname) + .visibleByDefault(true) + .enableByDefault(true) + .description(R.string.description_careportal) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java index 5ca9232646..fabd83f0ea 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Common/SubscriberFragment.java @@ -21,7 +21,7 @@ abstract public class SubscriberFragment extends Fragment { updateGUI(); } - @Override public void onDestroyView() { + @Override public synchronized void onDestroyView() { super.onDestroyView(); if (unbinder != null) unbinder.unbind(); 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 e92ca52cd9..e91ad8079f 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 @@ -1,30 +1,31 @@ package info.nightscout.androidaps.plugins.ConfigBuilder; -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; -import android.widget.ImageView; +import android.widget.ImageButton; import android.widget.LinearLayout; -import android.widget.ListAdapter; -import android.widget.ListView; +import android.widget.RadioButton; +import android.widget.ScrollView; import android.widget.TextView; import com.crashlytics.android.answers.CustomEvent; import java.util.ArrayList; +import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnCheckedChanged; import butterknife.OnClick; -import info.nightscout.androidaps.Config; +import butterknife.Optional; +import butterknife.Unbinder; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.PreferencesActivity; import info.nightscout.androidaps.R; @@ -50,69 +51,47 @@ import info.nightscout.utils.PasswordProtection; public class ConfigBuilderFragment extends SubscriberFragment { - @BindView(R.id.configbuilder_insulinlistview) - ListView insulinListView; - @BindView(R.id.configbuilder_sensitivitylistview) - ListView sensitivityListView; - @BindView(R.id.configbuilder_bgsourcelistview) - ListView bgsourceListView; - @BindView(R.id.configbuilder_bgsourcelabel) - TextView bgsourceLabel; - @BindView(R.id.configbuilder_pumplistview) - ListView pumpListView; - @BindView(R.id.configbuilder_pumplabel) - TextView pumpLabel; - @BindView(R.id.configbuilder_looplistview) - ListView loopListView; - @BindView(R.id.configbuilder_looplabel) - TextView loopLabel; - @BindView(R.id.configbuilder_treatmentslistview) - ListView treatmentsListView; - @BindView(R.id.configbuilder_treatmentslabel) - TextView treatmentsLabel; - @BindView(R.id.configbuilder_profilelistview) - ListView profileListView; - @BindView(R.id.configbuilder_profilelabel) - TextView profileLabel; - @BindView(R.id.configbuilder_apslistview) - ListView apsListView; - @BindView(R.id.configbuilder_apslabel) - TextView apsLabel; - @BindView(R.id.configbuilder_constraintslistview) - ListView constraintsListView; - @BindView(R.id.configbuilder_constraintslabel) - TextView constraintsLabel; - @BindView(R.id.configbuilder_generallistview) - ListView generalListView; + private List pluginViews = new ArrayList<>(); - @BindView(R.id.configbuilder_mainlayout) - LinearLayout mainLayout; - @BindView(R.id.configbuilder_unlock) + @BindView(R.id.profile_plugins) + LinearLayout profilePlugins; + @BindView(R.id.insulin_plugins) + LinearLayout insulinPlugins; + @BindView(R.id.bgsource_plugins) + LinearLayout bgSourcePlugins; + @BindView(R.id.pump_plugins) + LinearLayout pumpPlugins; + @BindView(R.id.sensitivity_plugins) + LinearLayout sensitivityPlugins; + @BindView(R.id.aps_plugins) + LinearLayout apsPlugins; + @BindView(R.id.loop_plugins) + LinearLayout loopPlugins; + @BindView(R.id.constraints_plugins) + LinearLayout constraintsPlugins; + @BindView(R.id.treatments_plugins) + LinearLayout treatmentsPlugins; + @BindView(R.id.general_plugins) + LinearLayout generalPlugins; + + @BindView(R.id.main_layout) + ScrollView mainLayout; + @BindView(R.id.unlock) Button unlock; - PluginCustomAdapter insulinDataAdapter = null; - PluginCustomAdapter sensivityDataAdapter = null; - PluginCustomAdapter bgsourceDataAdapter = null; - PluginCustomAdapter pumpDataAdapter = null; - PluginCustomAdapter loopDataAdapter = null; - PluginCustomAdapter treatmentDataAdapter = null; - PluginCustomAdapter profileDataAdapter = null; - PluginCustomAdapter apsDataAdapter = null; - PluginCustomAdapter constraintsDataAdapter = null; - PluginCustomAdapter generalDataAdapter = null; - @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try { View view = inflater.inflate(R.layout.configbuilder_fragment, container, false); - unbinder = ButterKnife.bind(this, view); if (PasswordProtection.isLocked("settings_password")) mainLayout.setVisibility(View.GONE); - else - unlock.setVisibility(View.GONE); + else unlock.setVisibility(View.GONE); + + createViews(); + return view; } catch (Exception e) { FabricPrivacy.logException(e); @@ -121,222 +100,49 @@ public class ConfigBuilderFragment extends SubscriberFragment { return null; } - @OnClick(R.id.configbuilder_unlock) - public void onClickUnlock() { + @OnClick(R.id.unlock) + void onClickUnlock() { PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", () -> { mainLayout.setVisibility(View.VISIBLE); unlock.setVisibility(View.GONE); }, null); } + @Override + public void onDestroyView() { + super.onDestroyView(); + for (PluginView pluginView : pluginViews) pluginView.unbind(); + pluginViews.clear(); + } @Override protected void updateGUI() { - - 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, PluginType.BGSOURCE), PluginType.BGSOURCE); - bgsourceListView.setAdapter(bgsourceDataAdapter); - if (MainApp.getSpecificPluginsVisibleInList(PluginType.BGSOURCE).size() == 0) - bgsourceLabel.setVisibility(View.GONE); - setListViewHeightBasedOnChildren(bgsourceListView); - pumpDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP), PluginType.PUMP); - pumpListView.setAdapter(pumpDataAdapter); - if (MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size() == 0 || Config.NSCLIENT || Config.G5UPLOADER) { - pumpLabel.setVisibility(View.GONE); - pumpListView.setVisibility(View.GONE); - } - setListViewHeightBasedOnChildren(pumpListView); - loopDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP), PluginType.LOOP); - loopListView.setAdapter(loopDataAdapter); - setListViewHeightBasedOnChildren(loopListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP).size() == 0) - loopLabel.setVisibility(View.GONE); - treatmentDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT), PluginType.TREATMENT); - treatmentsListView.setAdapter(treatmentDataAdapter); - setListViewHeightBasedOnChildren(treatmentsListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT).size() == 0) - treatmentsLabel.setVisibility(View.GONE); - profileDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginType.PROFILE), PluginType.PROFILE); - profileListView.setAdapter(profileDataAdapter); - if (MainApp.getSpecificPluginsVisibleInList(PluginType.PROFILE).size() == 0) - profileLabel.setVisibility(View.GONE); - setListViewHeightBasedOnChildren(profileListView); - apsDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.APS), PluginType.APS); - apsListView.setAdapter(apsDataAdapter); - setListViewHeightBasedOnChildren(apsListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginType.APS).size() == 0) - apsLabel.setVisibility(View.GONE); - 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, PluginType.CONSTRAINTS), PluginType.CONSTRAINTS); - constraintsListView.setAdapter(constraintsDataAdapter); - setListViewHeightBasedOnChildren(constraintsListView); - if (MainApp.getSpecificPluginsVisibleInList(PluginType.CONSTRAINTS).size() == 0) - constraintsLabel.setVisibility(View.GONE); - generalDataAdapter = new PluginCustomAdapter(getContext(), R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginType.GENERAL), PluginType.GENERAL); - generalListView.setAdapter(generalDataAdapter); - setListViewHeightBasedOnChildren(generalListView); + for (PluginView pluginView : pluginViews) pluginView.update(); } - /* - * ConfigBuilderFragment code - */ - - private class PluginCustomAdapter extends ArrayAdapter { - - private ArrayList pluginList; - final private PluginType type; - - PluginCustomAdapter(Context context, int textViewResourceId, - ArrayList pluginList, PluginType type) { - super(context, textViewResourceId, pluginList); - this.pluginList = new ArrayList<>(); - this.pluginList.addAll(pluginList); - this.type = type; - } - - private class PluginViewHolder { - TextView name; - CheckBox checkboxEnabled; - CheckBox checkboxVisible; - ImageView settings; - } - - @NonNull - @Override - public View getView(int position, View view, @NonNull ViewGroup parent) { - - PluginViewHolder holder; - PluginBase plugin = pluginList.get(position); - - if (view == null) { - view = LayoutInflater.from(parent.getContext()).inflate(R.layout.configbuilder_simpleitem, null); - - holder = new PluginViewHolder(); - holder.name = (TextView) view.findViewById(R.id.configbuilder_simpleitem_name); - holder.checkboxEnabled = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxenabled); - holder.checkboxVisible = (CheckBox) view.findViewById(R.id.configbuilder_simpleitem_checkboxvisible); - holder.settings = (ImageView) view.findViewById(R.id.configbuilder_simpleitem_settings); - - if (plugin.isEnabled(type) && plugin.getPreferencesId() != -1) - holder.settings.setVisibility(View.VISIBLE); - else - holder.settings.setVisibility(View.INVISIBLE); - - view.setTag(holder); - - holder.checkboxEnabled.setOnClickListener(v -> { - CheckBox cb = (CheckBox) v; - PluginBase plugin1 = (PluginBase) cb.getTag(); - plugin1.setPluginEnabled(type, cb.isChecked()); - plugin1.setFragmentVisible(type, cb.isChecked()); - onEnabledCategoryChanged(plugin1, type); - ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled"); - MainApp.bus().post(new EventRefreshGui()); - MainApp.bus().post(new EventConfigBuilderChange()); - ConfigBuilderPlugin.getPlugin().logPluginStatus(); - FabricPrivacy.getInstance().logCustom(new CustomEvent("ConfigurationChange")); - }); - - holder.checkboxVisible.setOnClickListener(v -> { - CheckBox cb = (CheckBox) v; - PluginBase plugin12 = (PluginBase) cb.getTag(); - plugin12.setFragmentVisible(type, cb.isChecked()); - ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible"); - MainApp.bus().post(new EventRefreshGui()); - ConfigBuilderPlugin.getPlugin().logPluginStatus(); - }); - - holder.settings.setOnClickListener(v -> { - final PluginBase plugin13 = (PluginBase) v.getTag(); - PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(getContext(), PreferencesActivity.class); - i.putExtra("id", plugin13.getPreferencesId()); - startActivity(i); - }, null); - }); - - holder.name.setOnLongClickListener(v -> { - final PluginBase plugin14 = (PluginBase) v.getTag(); - PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", () -> { - Intent i = new Intent(getContext(), PreferencesActivity.class); - i.putExtra("id", plugin14.getPreferencesId()); - startActivity(i); - }, null); - return false; - }); - - } else { - holder = (PluginViewHolder) view.getTag(); - } - - holder.name.setText(plugin.getName()); - holder.checkboxEnabled.setChecked(plugin.isEnabled(type)); - holder.checkboxVisible.setChecked(plugin.isFragmentVisible()); - holder.name.setTag(plugin); - holder.checkboxEnabled.setTag(plugin); - holder.checkboxVisible.setTag(plugin); - holder.settings.setTag(plugin); - - if (plugin.pluginDescription.alwaysEnabled) { - holder.checkboxEnabled.setEnabled(false); - } - - if (plugin.pluginDescription.alwayVisible) { - holder.checkboxEnabled.setEnabled(false); - } - - if (!plugin.isEnabled(type)) { - holder.checkboxVisible.setEnabled(false); - } - - if (!plugin.hasFragment()) { - holder.checkboxVisible.setVisibility(View.INVISIBLE); - } - - // Hide enabled control and force enabled plugin if there is only one plugin available - 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("ForceEnable"); - } - - // Constraints cannot be disabled - if (type == PluginType.CONSTRAINTS) - holder.checkboxEnabled.setEnabled(false); - - // Hide disabled profiles by default - if (type == PluginType.PROFILE) { - if (!plugin.isEnabled(type)) { - holder.checkboxVisible.setEnabled(false); - holder.checkboxVisible.setChecked(false); - } else { - holder.checkboxVisible.setEnabled(true); - } - } - - // Disable profile control for pump profiles if pump is not enabled - if (type == PluginType.PROFILE) { - if (PumpInterface.class.isAssignableFrom(plugin.getClass())) { - if (!plugin.isEnabled(PluginType.PUMP)) { - holder.checkboxEnabled.setEnabled(false); - holder.checkboxEnabled.setChecked(false); - } - } - } - - if (plugin.isEnabled(type)) { - view.setBackgroundColor(MainApp.gc(R.color.configBuilderSelectedBackground)); - } - - return view; + private void createViews() { + createViewsForPlugins(profilePlugins, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginType.PROFILE)); + createViewsForPlugins(insulinPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(InsulinInterface.class, PluginType.INSULIN)); + createViewsForPlugins(bgSourcePlugins, MainApp.getSpecificPluginsVisibleInListByInterface(BgSourceInterface.class, PluginType.BGSOURCE)); + createViewsForPlugins(pumpPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.PUMP)); + createViewsForPlugins(sensitivityPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(SensitivityInterface.class, PluginType.SENSITIVITY)); + createViewsForPlugins(apsPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.APS)); + createViewsForPlugins(loopPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.LOOP)); + createViewsForPlugins(constraintsPlugins, MainApp.getSpecificPluginsVisibleInListByInterface(ConstraintsInterface.class, PluginType.CONSTRAINTS)); + createViewsForPlugins(treatmentsPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.TREATMENT)); + createViewsForPlugins(generalPlugins, MainApp.getSpecificPluginsVisibleInList(PluginType.GENERAL)); + } + private void createViewsForPlugins(LinearLayout parent, List plugins) { + for (PluginBase plugin: plugins) { + PluginView pluginView = new PluginView(plugin); + parent.addView(pluginView.getBaseView()); + pluginViews.add(pluginView); } + } + private boolean areMultipleSelectionsAllowed(PluginType type) { + return type == PluginType.GENERAL || type == PluginType.CONSTRAINTS ||type == PluginType.LOOP; } public static void processOnEnabledCategoryChanged(PluginBase changedPlugin, PluginType type) { @@ -394,35 +200,90 @@ public class ConfigBuilderFragment extends SubscriberFragment { } } - void onEnabledCategoryChanged(PluginBase changedPlugin, PluginType type) { - processOnEnabledCategoryChanged(changedPlugin, type); - updateGUI(); - } + class PluginView { - /**** - * Method for Setting the Height of the ListView dynamically. - * *** Hack to fix the issue of not showing all the items of the ListView - * *** when placed inside a ScrollView - ****/ - public static void setListViewHeightBasedOnChildren(ListView listView) { - ListAdapter listAdapter = listView.getAdapter(); - if (listAdapter == null) - return; + private Unbinder unbinder; + private PluginBase plugin; - int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED); - int totalHeight = 0; - View view = null; - for (int i = 0; i < listAdapter.getCount(); i++) { - view = listAdapter.getView(i, view, listView); - if (i == 0) - view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT)); + LinearLayout baseView; + @BindView(R.id.plugin_enabled_exclusive) + RadioButton enabledExclusive; + @BindView(R.id.plugin_enabled_inclusive) + CheckBox enabledInclusive; + @BindView(R.id.plugin_name) + TextView pluginName; + @BindView(R.id.plugin_description) + TextView pluginDescription; + @BindView(R.id.plugin_preferences) + ImageButton pluginPreferences; + @BindView(R.id.plugin_visibility) + CheckBox pluginVisibility; - view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED); - totalHeight += view.getMeasuredHeight(); + public PluginView(PluginBase plugin) { + this.plugin = plugin; + baseView = (LinearLayout) getLayoutInflater().inflate(R.layout.configbuilder_single_plugin, null); + unbinder = ButterKnife.bind(this, baseView); + update(); } - ViewGroup.LayoutParams params = listView.getLayoutParams(); - params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); - listView.setLayoutParams(params); + + public LinearLayout getBaseView() { + return baseView; + } + + public void update() { + enabledExclusive.setVisibility(areMultipleSelectionsAllowed(plugin.getType()) ? View.GONE : View.VISIBLE); + enabledInclusive.setVisibility(areMultipleSelectionsAllowed(plugin.getType()) ? View.VISIBLE : View.GONE); + enabledExclusive.setChecked(plugin.isEnabled(plugin.getType())); + enabledInclusive.setChecked(plugin.isEnabled(plugin.getType())); + enabledInclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled); + enabledExclusive.setEnabled(!plugin.pluginDescription.alwaysEnabled); + pluginName.setText(plugin.getName()); + if (plugin.getDescription() == null) pluginDescription.setVisibility(View.GONE); + else { + pluginDescription.setVisibility(View.VISIBLE); + pluginDescription.setText(plugin.getDescription()); + } + pluginPreferences.setVisibility(plugin.getPreferencesId() == -1 || !plugin.isEnabled(plugin.getType()) ? View.INVISIBLE : View.VISIBLE); + pluginVisibility.setVisibility(plugin.hasFragment() ? View.VISIBLE : View.INVISIBLE); + pluginVisibility.setEnabled(!(plugin.pluginDescription.neverVisible || plugin.pluginDescription.alwayVisible) && plugin.isEnabled(plugin.getType())); + pluginVisibility.setChecked(plugin.isFragmentVisible()); + } + + @OnClick(R.id.plugin_visibility) + void onVisibilityChanged() { + plugin.setFragmentVisible(plugin.getType(), pluginVisibility.isChecked()); + ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxVisible"); + MainApp.bus().post(new EventRefreshGui()); + ConfigBuilderPlugin.getPlugin().logPluginStatus(); + } + + @OnClick({R.id.plugin_enabled_exclusive, R.id.plugin_enabled_inclusive}) + void onEnabledChanged() { + boolean enabled = enabledExclusive.getVisibility() == View.VISIBLE ? enabledExclusive.isChecked() : enabledInclusive.isChecked(); + plugin.setPluginEnabled(plugin.getType(), enabled); + plugin.setFragmentVisible(plugin.getType(), enabled); + processOnEnabledCategoryChanged(plugin, plugin.getType()); + updateGUI(); + ConfigBuilderPlugin.getPlugin().storeSettings("CheckedCheckboxEnabled"); + MainApp.bus().post(new EventRefreshGui()); + MainApp.bus().post(new EventConfigBuilderChange()); + ConfigBuilderPlugin.getPlugin().logPluginStatus(); + FabricPrivacy.getInstance().logCustom(new CustomEvent("ConfigurationChange")); + } + + @OnClick(R.id.plugin_preferences) + void onPluginPreferencesClicked() { + PasswordProtection.QueryPassword(getContext(), R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(getContext(), PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + startActivity(i); + }, null); + } + + public void unbind() { + unbinder.unbind(); + } + } } 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 04e7dcdbfd..1911f588b1 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 @@ -92,6 +92,7 @@ public class ConfigBuilderPlugin extends PluginBase { .alwayVisible(false) .pluginName(R.string.configbuilder) .shortName(R.string.configbuilder_shortname) + .description(R.string.description_config_builder) ); } 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 293029b80f..010bb1277a 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 @@ -56,6 +56,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface .showInList(!Config.NSCLIENT && !Config.G5UPLOADER) .pluginName(R.string.objectives) .shortName(R.string.objectives_shortname) + .description(R.string.description_objectives) ); initializeData(); loadProgress(); 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 14eb318af4..84996f1a37 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 @@ -26,6 +26,7 @@ public class FoodPlugin extends PluginBase { .fragmentClass(FoodFragment.class.getName()) .pluginName(R.string.food) .shortName(R.string.food_short) + .description(R.string.description_food) ); this.service = new FoodService(); } 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 2c46cd7bb6..5d4d1187ac 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 @@ -29,6 +29,7 @@ public abstract class InsulinOrefBasePlugin extends PluginBase implements Insuli .fragmentClass(InsulinFragment.class.getName()) .pluginName(R.string.fastactinginsulin) .shortName(R.string.insulin_shortname) + .visibleByDefault(false) ); } 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 a710f742a7..c1fc44438f 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 @@ -24,7 +24,8 @@ public class InsulinOrefFreePeakPlugin extends InsulinOrefBasePlugin { super(); pluginDescription .pluginName(R.string.free_peak_oref) - .preferencesId(R.xml.pref_insulinoreffreepeak); + .preferencesId(R.xml.pref_insulinoreffreepeak) + .description(R.string.description_insulin_free_peak); } @Override 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 a8f9761771..c275aef3fd 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 @@ -22,7 +22,8 @@ public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin { private InsulinOrefRapidActingPlugin() { super(); pluginDescription - .pluginName(R.string.rapid_acting_oref); + .pluginName(R.string.rapid_acting_oref) + .description(R.string.description_insulin_rapid); } @Override 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 ba5fc99011..94e5910470 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 @@ -22,7 +22,8 @@ public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin { private InsulinOrefUltraRapidActingPlugin() { super(); pluginDescription - .pluginName(R.string.ultrarapid_oref); + .pluginName(R.string.ultrarapid_oref) + .description(R.string.description_insulin_ultra_rapid); } @Override 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 f6ec0ff7ab..c01cf0a641 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 @@ -94,6 +94,7 @@ public class LoopPlugin extends PluginBase { .pluginName(R.string.loop) .shortName(R.string.loop_shortname) .preferencesId(R.xml.pref_closedmode) + .description(R.string.description_loop) ); loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L); isSuperBolus = SP.getBoolean("isSuperBolus", false); 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 c43297ccf6..6949cdc8b1 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 @@ -69,6 +69,7 @@ public class NSClientPlugin extends PluginBase { .pluginName(R.string.nsclientinternal) .shortName(R.string.nsclientinternal_shortname) .preferencesId(R.xml.pref_nsclientinternal) + .description(R.string.description_ns_client) ); if (Config.NSCLIENT || Config.G5UPLOADER) { 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 143456f6fc..b6e07bb004 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 @@ -62,6 +62,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { .pluginName(R.string.openapsama) .shortName(R.string.oaps_shortname) .preferencesId(R.xml.pref_openapsama) + .description(R.string.description_ama) ); } 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 14dac65625..39d05f8ffb 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 @@ -62,6 +62,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface { .pluginName(R.string.openapsma) .shortName(R.string.oaps_shortname) .preferencesId(R.xml.pref_openapsma) + .description(R.string.description_ma) ); } 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 49a81ea612..f28a6eff8e 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 @@ -65,6 +65,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface { .pluginName(R.string.openapssmb) .shortName(R.string.smb_shortname) .preferencesId(R.xml.pref_openapssmb) + .description(R.string.description_smb) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java index c38f41b825..303ca10949 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/WizardDialog.java @@ -315,6 +315,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com confirmMessage += "
" + MainApp.gs(R.string.carbs) + ": " + "" + carbsAfterConstraints + "g" + ""; if (insulinAfterConstraints - calculatedTotalInsulin != 0 || !carbsAfterConstraints.equals(calculatedCarbs)) { + okClicked = false; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.gs(R.string.treatmentdeliveryerror)); builder.setMessage(MainApp.gs(R.string.constraints_violation) + "\n" + MainApp.gs(R.string.changeyourinput)); @@ -408,9 +409,9 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com private void initDialog() { Profile profile = MainApp.getConfigBuilder().getProfile(); - ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile(); + ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface() != null ? MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() : null; - if (profile == null) { + if (profile == null || profileStore == null) { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.noprofile)); dismiss(); return; 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 31aa098579..fadb30420c 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 @@ -672,12 +672,15 @@ public class OverviewFragment extends Fragment implements View.OnClickListener, private void onClickAcceptTemp() { Profile profile = MainApp.getConfigBuilder().getProfile(); + Context context = getContext(); + + if (context == null) return; if (LoopPlugin.getPlugin().isEnabled(PluginType.LOOP) && profile != null) { LoopPlugin.getPlugin().invoke("Accept temp button", false); final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun; if (finalLastRun != null && finalLastRun.lastAPSRun != null && finalLastRun.constraintsProcessed.isChangeRequested()) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(MainApp.gs(R.string.confirmation)); builder.setMessage(MainApp.gs(R.string.setbasalquestion) + "\n" + finalLastRun.constraintsProcessed); builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> { 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 67e494a76d..3b787fd768 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 @@ -50,6 +50,7 @@ public class OverviewPlugin extends PluginBase { .pluginName(R.string.overview) .shortName(R.string.overview_shortname) .preferencesId(R.xml.pref_overview) + .description(R.string.description_overview) ); String storedData = SP.getString("QuickWizard", "[]"); try { 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 ed57652d1f..5f6d50273a 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 @@ -57,6 +57,7 @@ public class PersistentNotificationPlugin extends PluginBase { .neverVisible(true) .pluginName(R.string.ongoingnotificaction) .enableByDefault(true) + .description(R.string.description_persistent_notification) ); this.ctx = ctx; } 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 95cfd60c99..8d4e2d6a36 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 @@ -64,6 +64,7 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface { .fragmentClass(LocalProfileFragment.class.getName()) .pluginName(R.string.localprofile) .shortName(R.string.localprofile_shortname) + .description(R.string.description_profile_local) ); loadSettings(); } 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 3a66d57dad..404aff0608 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 @@ -49,6 +49,7 @@ public class NSProfilePlugin extends PluginBase implements ProfileInterface { .alwaysEnabled(Config.NSCLIENT) .alwayVisible(Config.NSCLIENT) .showInList(!Config.NSCLIENT) + .description(R.string.description_profile_nightscout) ); loadNSProfile(); } 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 b321faca50..bb669289ee 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 @@ -52,6 +52,7 @@ public class SimpleProfilePlugin extends PluginBase implements ProfileInterface .fragmentClass(SimpleProfileFragment.class.getName()) .pluginName(R.string.simpleprofile) .shortName(R.string.simpleprofile_shortname) + .description(R.string.description_profile_simple) ); loadSettings(); } 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 eb06d4055d..b1f2b076ae 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 @@ -167,6 +167,7 @@ public class ComboPlugin extends PluginBase implements PumpInterface, Constraint .fragmentClass(ComboFragment.class.getName()) .pluginName(R.string.combopump) .shortName(R.string.combopump_shortname) + .description(R.string.description_pump_combo) ); ruffyScripter = new RuffyScripter(MainApp.instance().getApplicationContext()); } 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 903be558b9..1f51979126 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 @@ -59,6 +59,7 @@ public abstract class AbstractDanaRPlugin extends PluginBase implements PumpInte .pluginName(R.string.danarspump) .shortName(R.string.danarpump_shortname) .preferencesId(R.xml.pref_danars) + .description(R.string.description_pump_dana_r) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java index b37d0e945f..8d18ca4f04 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/DanaRFragment.java @@ -162,19 +162,24 @@ public class DanaRFragment extends SubscriberFragment { activity.runOnUiThread( new Runnable() { @Override - public void run() { - if (c.sStatus == EventPumpStatusChanged.CONNECTING) - btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s"); - else if (c.sStatus == EventPumpStatusChanged.CONNECTED) - btConnectionView.setText("{fa-bluetooth}"); - else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED) - btConnectionView.setText("{fa-bluetooth-b}"); + public void run() { + synchronized(DanaRFragment.this){ - if (!status.equals("")) { - pumpStatusView.setText(status); - pumpStatusLayout.setVisibility(View.VISIBLE); - } else { - pumpStatusLayout.setVisibility(View.GONE); + if(btConnectionView == null || pumpStatusView == null || pumpStatusLayout == null ) return; + + if (c.sStatus == EventPumpStatusChanged.CONNECTING) + btConnectionView.setText("{fa-bluetooth-b spin} " + c.sSecondsElapsed + "s"); + else if (c.sStatus == EventPumpStatusChanged.CONNECTED) + btConnectionView.setText("{fa-bluetooth}"); + else if (c.sStatus == EventPumpStatusChanged.DISCONNECTED) + btConnectionView.setText("{fa-bluetooth-b}"); + + if (!status.equals("")) { + pumpStatusView.setText(status); + pumpStatusLayout.setVisibility(View.VISIBLE); + } else { + pumpStatusLayout.setVisibility(View.GONE); + } } } } 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 69c07ce706..b1b0f3d9ce 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 @@ -382,6 +382,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin { @Override public PumpEnactResult setUserOptions() { - return null; + return sExecutionService.setUserOptions(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java index b7b7a793f4..4a670a7e81 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/activities/DanaRUserOptionsActivity.java @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.PumpDanaR.activities; import android.app.Activity; -import android.content.Intent; import android.os.Bundle; import android.widget.Button; import android.widget.RadioButton; @@ -20,13 +19,10 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventInitializationChanged; import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.Overview.Dialogs.ErrorHelperActivity; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; -import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; -import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.NumberPicker; /** @@ -83,9 +79,6 @@ public class DanaRUserOptionsActivity extends Activity { saveToPumpButton.setOnClickListener(v -> onSaveClick()); - boolean isv2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class) != null && MainApp.getSpecificPlugin(DanaRv2Plugin.class).isEnabled(PluginType.PUMP); - - DanaRPump pump = DanaRPump.getInstance(); //used for debugging log.debug("UserOptionsLoaded:" + (System.currentTimeMillis() - pump.lastConnection) / 1000 + " s ago" @@ -96,20 +89,6 @@ public class DanaRUserOptionsActivity extends Activity { + "\nbacklight:" + pump.backlightOnTimeSec + "\npumpUnits:" + pump.units + "\nlowReservoir:" + pump.lowReservoirRate); - log.debug("isV2:"+isv2); - if(isv2 && pump.lowReservoirRate < 10){ - log.debug("No user settings loaded forcing reload!"); - DanaRv2Plugin.getPlugin().getUserOptions(); - log.debug("UserOptionsLoaded:" + (System.currentTimeMillis() - pump.lastConnection) / 1000 + " s ago" - + "\ntimeDisplayType:" + pump.timeDisplayType - + "\nbuttonScroll:" + pump.buttonScrollOnOff - + "\ntimeDisplayType:" + pump.timeDisplayType - + "\nlcdOnTimeSec:" + pump.lcdOnTimeSec - + "\nbacklight:" + pump.backlightOnTimeSec - + "\npumpUnits:" + pump.units - + "\nlowReservoir:" + pump.lowReservoirRate); - - } screenTimeout.setParams((double) pump.lcdOnTimeSec, 5d, 240d, 5d, new DecimalFormat("1"), false); backlightTimeout.setParams((double) pump.backlightOnTimeSec, 1d, 60d, 1d, new DecimalFormat("1"), false); @@ -164,9 +143,6 @@ public class DanaRUserOptionsActivity extends Activity { //exit if pump is not DanaRS, Dana!, or DanaR with upgraded firmware return; } - if (isDanaRv2) { - DanaRv2Plugin.getPlugin().getUserOptions(); - } DanaRPump pump = DanaRPump.getInstance(); if (timeFormat.isChecked()) @@ -205,11 +181,7 @@ public class DanaRUserOptionsActivity extends Activity { } else pump.lowReservoirRate = 10; - if (isDanaRv2) { - DanaRv2Plugin.getPlugin().setUserOptions(); - } - - MainApp.getConfigBuilder().getCommandQueue().setUserSettings(null); + MainApp.getConfigBuilder().getCommandQueue().setUserOptions(null); finish(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java index 2d15d8236f..4b90b8f02d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTable.java @@ -56,11 +56,11 @@ public class MessageHashTable { put(new MsgSettingGlucose()); // 0x3209 CMD_SETTING_V_GLUCOSEandEASY put(new MsgSettingPumpTime()); // 0x320A CMD_SETTING_V_TIME_I put(new MsgSettingUserOptions()); // 0x320B CMD_SETTING_V_USER_OPTIONS - put(new MsgGetUserOptions()); // 0x320B CMD_SETTING_V_USER_OPTIONS - trying to get uptions put(new MsgSettingActiveProfile()); // 0x320C CMD_SETTING_V_PROFILE_NUMBER put(new MsgSettingProfileRatiosAll()); // 0x320D CMD_SETTING_V_CIR_CF_VALUE put(new MsgSetSingleBasalProfile()); // 0x3302 CMD_SETTING_BASAL_INS_S put(new MsgSetBasalProfile()); // 0x3306 CMD_SETTING_BASAL_PROFILE_S + put(new MsgSetUserOptions()); // 0x330B CMD_SETTING_USER_OPTIONS_S put(new MsgSetActivateBasalProfile()); // 0x330C CMD_SETTING_PROFILE_NUMBER_S put(new MsgHistoryAllDone()); // 0x41F1 CMD_HISTORY_ALL_DONE put(new MsgHistoryAll()); // 0x41F2 CMD_HISTORY_ALL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java new file mode 100644 index 0000000000..5cdf2d75fa --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptions.java @@ -0,0 +1,58 @@ +package info.nightscout.androidaps.plugins.PumpDanaR.comm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; + +/** + * Created by mike on 05.07.2016. + */ +public class MsgSetUserOptions extends MessageBase { + + public boolean done; + + public MsgSetUserOptions() { + SetCommand(0x330B); + + DanaRPump pump = DanaRPump.getInstance(); + + log.debug(" initializing MsgSetUserOptions"); + log.debug("timeDisplayType: " + (byte) pump.timeDisplayType); + log.debug("Button scroll: " + (byte) pump.buttonScrollOnOff); + log.debug("BeepAndAlarm: " + (byte) pump.beepAndAlarm); + log.debug("screen timeout: " + (byte) pump.lcdOnTimeSec); + log.debug("Backlight: " + (byte) pump.backlightOnTimeSec); + log.debug("Selected language: " + (byte) pump.selectedLanguage); + log.debug("Units: " + (byte) pump.units); + log.debug("Shutdown: " + (byte) pump.shutdownHour); + log.debug("Low reservoir: " + (byte) pump.lowReservoirRate); + // need to organize here + // glucoseunit is at pos 8 and lowReservoirRate is at pos 27 + AddParamByte((byte) pump.timeDisplayType); + AddParamByte((byte) pump.buttonScrollOnOff); + AddParamByte((byte) pump.beepAndAlarm); + AddParamByte((byte) pump.lcdOnTimeSec); + AddParamByte((byte) pump.backlightOnTimeSec); + AddParamByte((byte) pump.selectedLanguage); + AddParamByte((byte) pump.units); + AddParamByte((byte) pump.shutdownHour); + AddParamByte((byte) pump.lowReservoirRate); + } + + private static Logger log = LoggerFactory.getLogger(MsgSetUserOptions.class); + + public void handleMessage(byte[] bytes) { + log.debug("Entering handleMessage "); + int result = intFromBuff(bytes, 0, 1); + if (result != 1) { + failed = true; + log.debug("Setting user options: " + result + " FAILED!!!"); + } else { + if (Config.logDanaMessageDetail) + log.debug("Setting user options: " + result); + } + } + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java index f7fa834879..51c37b1217 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptions.java @@ -4,11 +4,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import android.support.v4.internal.view.SupportMenu; -import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; /** - * Created by mike on 05.07.2016. + * Created by Rumen Georgiev on 6/11/2018. */ +<<<<<<< HEAD public class MsgSettingUserOptions extends MessageBase { private int backlightOnTimeSec; @@ -63,6 +64,10 @@ public class MsgSettingUserOptions extends MessageBase { // 6 extended bolus on/off // 10 missed bolus } +======= + +public class MsgSettingUserOptions extends MessageBase { +>>>>>>> upstream/rsoption private static Logger log = LoggerFactory.getLogger(MsgSettingUserOptions.class); @@ -70,6 +75,7 @@ public class MsgSettingUserOptions extends MessageBase { SetCommand(0x320B); } +<<<<<<< HEAD public void handleMessage(byte[] bytes) { log.debug("Entering handleMessage "); newOptions = new byte[]{bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8], bytes[9], bytes[15], bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21], bytes[22], bytes[23], bytes[24], bytes[25], bytes[26], bytes[27], bytes[28], bytes[29], bytes[30], bytes[31], bytes[32]}; @@ -80,8 +86,52 @@ public class MsgSettingUserOptions extends MessageBase { } else { if (Config.logDanaMessageDetail) log.debug("Setting user options: " + result); +======= + public void handleMessage(byte[] packet) { + DanaRPump pump = DanaRPump.getInstance(); + byte[] bytes = getDataBytes(packet, 0, packet.length - 10); + for(int pos=0; pos < bytes.length; pos++) { + log.debug("[" + pos + "]" + bytes[pos]); +>>>>>>> upstream/rsoption } + pump.timeDisplayType = bytes[0] == (byte) 1 ? 0 : 1; // 1 -> 24h 0 -> 12h + pump.buttonScrollOnOff = bytes[1] == (byte) 1 ? 1 : 0; // 1 -> ON, 0-> OFF + pump.beepAndAlarm = bytes[2]; // 1 -> Sound on alarm 2-> Vibrate on alarm 3-> Both on alarm 5-> Sound + beep 6-> vibrate + beep 7-> both + beep Beep adds 4 + pump.lcdOnTimeSec = bytes[3] & 255; + pump.backlightOnTimeSec = bytes[4] & 255; + pump.selectedLanguage = bytes[5]; // on DanaRv2 is that needed ? + pump.units = bytes[8]; + pump.shutdownHour = bytes[9]; + pump.lowReservoirRate = bytes[32] & 255; + /* int selectableLanguage1 = bytes[10]; + int selectableLanguage2 = bytes[11]; + int selectableLanguage3 = bytes[12]; + int selectableLanguage4 = bytes[13]; + int selectableLanguage5 = bytes[14]; + */ + +// if (Config.logDanaMessageDetail) { + + log.debug("timeDisplayType: " + pump.timeDisplayType); + log.debug("Button scroll: " + pump.buttonScrollOnOff); + log.debug("BeepAndAlarm: " + pump.beepAndAlarm); + log.debug("screen timeout: " + pump.lcdOnTimeSec); + log.debug("Backlight: " + pump.backlightOnTimeSec); + log.debug("Selected language: " + pump.selectedLanguage); + log.debug("Units: " + pump.getUnits()); + log.debug("Shutdown: " + pump.shutdownHour); + log.debug("Low reservoir: " + pump.lowReservoirRate); +// } } + public static byte[] getDataBytes(byte[] bytes, int start, int len) { + if (bytes == null) { + return null; + } + byte[] ret = new byte[len]; + System.arraycopy(bytes, start + 6, ret, 0, len); + return ret; + } +<<<<<<< HEAD public byte[] getCommByte(int cmd, byte[] data) { int len = (data == null ? 0 : data.length) + 3; @@ -128,4 +178,6 @@ public class MsgSettingUserOptions extends MessageBase { return (li_crc ^ (((li_crc & 255) << 4) << 1)) & SupportMenu.USER_MASK; } +======= +>>>>>>> upstream/rsoption } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java index 17db916dae..e4c2933d43 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/AbstractDanaRExecutionService.java @@ -92,6 +92,7 @@ public abstract class AbstractDanaRExecutionService extends Service { public abstract boolean extendedBolusStop(); + public abstract PumpEnactResult setUserOptions(); protected BroadcastReceiver receiver = new BroadcastReceiver() { @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index de7eeb1591..7976430b77 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -18,8 +18,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgGetUserOptions; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventInitializationChanged; @@ -64,7 +64,6 @@ import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.queue.Callback; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; -import info.nightscout.utils.ToastUtils; public class DanaRExecutionService extends AbstractDanaRExecutionService{ @@ -179,6 +178,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{ mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll()); + mSerialIOThread.sendMessage(new MsgSettingUserOptions()); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); long timeDiff = (mDanaRPump.pumpTime.getTime() - System.currentTimeMillis()) / 1000L; @@ -384,30 +384,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{ return true; } - public PumpEnactResult getUserOptions() { - if (!isConnected()) - return new PumpEnactResult().success(false); - DanaRPump pump = DanaRPump.getInstance(); - MsgGetUserOptions msg = new MsgGetUserOptions(); - mDanaRPump.lastConnection = System.currentTimeMillis(); - return new PumpEnactResult().success(true); - } - - public PumpEnactResult updateUserOptions() { - if (!isConnected()) - return new PumpEnactResult().success(false); - DanaRPump pump = DanaRPump.getInstance(); - MsgSettingUserOptions msg = new MsgSettingUserOptions(pump.timeDisplayType, pump.buttonScrollOnOff, pump.beepAndAlarm, pump.lcdOnTimeSec, pump.backlightOnTimeSec, pump.selectedLanguage, pump.units, pump.shutdownHour, pump.lowReservoirRate, 0, 0); - - mSerialIOThread.sendMessage(msg); - while (!msg.done && mRfcommSocket.isConnected()) { - SystemClock.sleep(100); - } - SystemClock.sleep(200); - mDanaRPump.lastConnection = System.currentTimeMillis(); - return new PumpEnactResult().success(true); - } - @Subscribe public void onStatusEvent(EventAppExit event) { if (Config.logFunctionCalls) @@ -423,4 +399,13 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService{ log.debug("EventAppExit finished"); } + public PumpEnactResult setUserOptions() { + if (!isConnected()) + return new PumpEnactResult().success(false); + SystemClock.sleep(300); + MsgSetUserOptions msg = new MsgSetUserOptions(); + mSerialIOThread.sendMessage(msg); + SystemClock.sleep(200); + return new PumpEnactResult().success(!msg.failed); + } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index e46e3d6caf..7854426b5d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -327,4 +327,9 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService { return true; } + @Override + public PumpEnactResult setUserOptions() { + return null; + } + } 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 3457564cfb..b6d9d1721e 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 @@ -83,6 +83,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte .pluginName(R.string.danarspump) .shortName(R.string.danarspump_shortname) .preferencesId(R.xml.pref_danars) + .description(R.string.description_pump_dana_rs) ); pumpDescription.isBolusCapable = true; 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 87b02c60ae..517fb914c7 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 @@ -391,14 +391,11 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin { @Override public PumpEnactResult setUserOptions() { +<<<<<<< HEAD DanaRv2ExecutionService service = new DanaRv2ExecutionService(); return service.setUserOptions(); +======= + return sExecutionService.setUserOptions(); +>>>>>>> upstream/rsoption } - - public PumpEnactResult getUserOptions() { - DanaRv2ExecutionService service = new DanaRv2ExecutionService(); - log.debug("MsgGetUserOptions executed!"); - return service.getUserOptions(); - } - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java index cafba32239..8d1cd12be1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/comm/MessageHashTable_v2.java @@ -66,6 +66,7 @@ public class MessageHashTable_v2 { put(new MsgSettingProfileRatiosAll()); // 0x320D CMD_SETTING_V_CIR_CF_VALUE put(new MsgSetSingleBasalProfile()); // 0x3302 CMD_SETTING_BASAL_INS_S put(new MsgSetBasalProfile()); // 0x3306 CMD_SETTING_BASAL_PROFILE_S + put(new MsgSetUserOptions()); // 0x330B CMD_SETTING_USER_OPTIONS_S put(new MsgSetActivateBasalProfile()); // 0x330C CMD_SETTING_PROFILE_NUMBER_S put(new MsgHistoryAllDone()); // 0x41F1 CMD_HISTORY_ALL_DONE put(new MsgHistoryAll()); // 0x41F2 CMD_HISTORY_ALL diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java index 0927baa49b..a76856996b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRv2/services/DanaRv2ExecutionService.java @@ -18,8 +18,8 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.PumpEnactResult; -import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgGetUserOptions; import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSettingUserOptions; +import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgSetUserOptions; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventInitializationChanged; @@ -70,7 +70,6 @@ import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; import info.nightscout.utils.T; -import info.nightscout.utils.ToastUtils; public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { @@ -201,8 +200,12 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { mSerialIOThread.sendMessage(new MsgSettingGlucose()); mSerialIOThread.sendMessage(new MsgSettingActiveProfile()); mSerialIOThread.sendMessage(new MsgSettingProfileRatios()); +<<<<<<< HEAD //added by Roumen for testing and mSerialIOThread.sendMessage(new MsgGetUserOptions()); +======= + mSerialIOThread.sendMessage(new MsgSettingUserOptions()); +>>>>>>> upstream/rsoption mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll()); MainApp.bus().post(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime))); mSerialIOThread.sendMessage(new MsgSettingPumpTime()); @@ -477,26 +480,22 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { } public PumpEnactResult setUserOptions() { +<<<<<<< HEAD if (!isConnected()) { return new PumpEnactResult().success(false); } +======= + if (!isConnected()) + return new PumpEnactResult().success(false); +>>>>>>> upstream/rsoption SystemClock.sleep(300); - DanaRPump pump = DanaRPump.getInstance(); - MsgSettingUserOptions msg = new MsgSettingUserOptions(pump.timeDisplayType, pump.buttonScrollOnOff, pump.beepAndAlarm, pump.lcdOnTimeSec, pump.backlightOnTimeSec, pump.selectedLanguage, pump.units, pump.shutdownHour, pump.lowReservoirRate, 0, 0); - if (mSerialIOThread != null) { - mSerialIOThread.disconnect("MsgSetUserOptions - Recreate SerialIOThread"); - } - mSerialIOThread = new SerialIOThread(mRfcommSocket); - MainApp.bus().post(new EventPumpStatusChanged(EventPumpStatusChanged.CONNECTED, 0)); + MsgSetUserOptions msg = new MsgSetUserOptions(); mSerialIOThread.sendMessage(msg); - while (!msg.done && mRfcommSocket.isConnected()) { - SystemClock.sleep(100); - } SystemClock.sleep(200); - mDanaRPump.lastConnection = System.currentTimeMillis(); - return new PumpEnactResult().success(true); + return new PumpEnactResult().success(!msg.failed); } +<<<<<<< HEAD public PumpEnactResult getUserOptions() { if (!isConnected()) { return new PumpEnactResult().success(false); @@ -506,4 +505,6 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService { mDanaRPump.lastConnection = System.currentTimeMillis(); return new PumpEnactResult().success(true); } +======= +>>>>>>> upstream/rsoption } 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 b99b8ec908..9fb98d3175 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 @@ -112,6 +112,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai .pluginName(R.string.insightpump) .shortName(R.string.insightpump_shortname) .preferencesId(R.xml.pref_insightpump) + .description(R.string.description_pump_insight) ); log("InsightPlugin instantiated"); pumpDescription.isBolusCapable = true; 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 fed0c01c64..09cff7d97e 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 @@ -42,6 +42,7 @@ public class MDIPlugin extends PluginBase implements PumpInterface { super(new PluginDescription() .mainType(PluginType.PUMP) .pluginName(R.string.mdi) + .description(R.string.description_pump_mdi) ); pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.5d; 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 34d3fee80b..653ab66c21 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 @@ -77,6 +77,8 @@ public class VirtualPumpPlugin extends PluginBase implements PumpInterface { .pluginName(R.string.virtualpump) .shortName(R.string.virtualpump_shortname) .preferencesId(R.xml.pref_virtualpump) + .neverVisible(BuildConfig.NSCLIENTOLNY || BuildConfig.G5UPLOADER) + .description(R.string.description_pump_virtual) ); pumpDescription.isBolusCapable = true; pumpDescription.bolusStep = 0.1d; 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 75b1ea9675..d7421a3aa2 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 @@ -47,6 +47,7 @@ public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInte .pluginName(R.string.sensitivityaaps) .shortName(R.string.sensitivity_shortname) .preferencesId(R.xml.pref_absorption_aaps) + .description(R.string.description_sensitivity_aaps) ); } 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 15be72880d..e4bf00be99 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 @@ -46,6 +46,7 @@ public class SensitivityOref0Plugin extends PluginBase implements SensitivityInt .pluginName(R.string.sensitivityoref0) .shortName(R.string.sensitivity_shortname) .preferencesId(R.xml.pref_absorption_oref0) + .description(R.string.description_sensitivity_oref0) ); } 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 58f59701d9..3d33b5ae14 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 @@ -43,6 +43,7 @@ public class SensitivityWeightedAveragePlugin extends PluginBase implements Sens .pluginName(R.string.sensitivityweightedaverage) .shortName(R.string.sensitivity_shortname) .preferencesId(R.xml.pref_absorption_aaps) + .description(R.string.description_sensitivity_weighted_average) ); } 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 9de6cc6ad6..8e1dd06d2f 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 @@ -124,6 +124,7 @@ public class SmsCommunicatorPlugin extends PluginBase { .pluginName(R.string.smscommunicator) .shortName(R.string.smscommunicator_shortname) .preferencesId(R.xml.pref_smscommunicator) + .description(R.string.description_sms_communicator) ); processSettings(null); } 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 index d526a12971..af040c8c90 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceDexcomG5Plugin.java @@ -29,6 +29,7 @@ public class SourceDexcomG5Plugin extends PluginBase implements BgSourceInterfac .shortName(R.string.dexcomG5_shortname) .showInList(!Config.NSCLIENT) .preferencesId(R.xml.pref_dexcomg5) + .description(R.string.description_source_dexcom_g5) ); } 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 index 0846885df7..38b891ff65 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceGlimpPlugin.java @@ -24,6 +24,7 @@ public class SourceGlimpPlugin extends PluginBase implements BgSourceInterface { .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment.class.getName()) .pluginName(R.string.Glimp) + .description(R.string.description_source_glimp) ); } 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 index 8df63df1e6..041b084efd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceMM640gPlugin.java @@ -23,6 +23,7 @@ public class SourceMM640gPlugin extends PluginBase implements BgSourceInterface .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment.class.getName()) .pluginName(R.string.MM640g) + .description(R.string.description_source_mm640g) ); } 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 index 3bf5c66cca..e3c4181c05 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java @@ -27,6 +27,7 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac .pluginName(R.string.nsclientbg) .showInList(!Config.NSCLIENT) .alwaysEnabled(Config.NSCLIENT) + .description(R.string.description_source_ns_client) ); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java new file mode 100644 index 0000000000..13cb99d392 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourcePoctechPlugin.java @@ -0,0 +1,39 @@ +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 05.08.2016. + */ +public class SourcePoctechPlugin extends PluginBase implements BgSourceInterface { + + private static SourcePoctechPlugin plugin = null; + + public static SourcePoctechPlugin getPlugin() { + if (plugin == null) + plugin = new SourcePoctechPlugin(); + return plugin; + } + + private SourcePoctechPlugin() { + super(new PluginDescription() + .mainType(PluginType.BGSOURCE) + .fragmentClass(BGSourceFragment.class.getName()) + .pluginName(R.string.poctech) + .showInList(!Config.NSCLIENT) + .preferencesId(R.xml.pref_poctech) + .description(R.string.description_source_poctech) + ); + } + + @Override + public boolean advancedFilteringSupported() { + return false; + } + +} 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 index bd3d96162e..fa61c9ea61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java @@ -26,6 +26,7 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { .mainType(PluginType.BGSOURCE) .fragmentClass(BGSourceFragment.class.getName()) .pluginName(R.string.xdrip) + .description(R.string.description_source_xdrip) ); } 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 8ae2e6d7b1..a754b7dcfa 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 @@ -80,6 +80,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface .shortName(R.string.treatments_shortname) .preferencesId(R.xml.pref_absorption_oref0) .alwaysEnabled(true) + .description(R.string.description_treatments) ); this.service = new TreatmentService(); } 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 7282ac0763..6cb47e1a3a 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 @@ -56,6 +56,7 @@ public class WearPlugin extends PluginBase { .pluginName(R.string.wear) .shortName(R.string.wear_shortname) .preferencesId(R.xml.pref_wear) + .description(R.string.description_wear) ); this.ctx = ctx; } 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 03c6c48a1a..d5ac60a626 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 @@ -70,6 +70,7 @@ public class StatuslinePlugin extends PluginBase { .shortName(R.string.xdripstatus_shortname) .neverVisible(true) .preferencesId(R.xml.pref_xdripstatus) + .description(R.string.description_xdrip_status_line) ); this.ctx = ctx; this.mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index f76e6044aa..9f2fdf7eee 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -405,7 +405,7 @@ public class CommandQueue { } // returns true if command is queued - public boolean setUserSettings(Callback callback) { + public boolean setUserOptions(Callback callback) { if (isRunning(Command.CommandType.SETUSERSETTINGS)) { if (callback != null) callback.result(executingNowError()).run(); diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index dbdb22782a..0e7ba0e623 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; +import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.PreferencesActivity; import info.nightscout.androidaps.R; @@ -85,8 +86,14 @@ public class SWDefinition { return this; } - SWDefinition() { + if (BuildConfig.FLAVOR.equals("full")) + SWDefinitionFull(); + else if (BuildConfig.FLAVOR.equals("nsclient")) + SWDefinitionNSClient(); + } + + private void SWDefinitionFull() { // List all the screens here add(new SWScreen(R.string.nav_setupwizard) .add(new SWInfotext() @@ -228,6 +235,7 @@ public class SWDefinition { .add(new SWBreak()) .add(new SWPlugin() .option(PluginType.INSULIN) + .makeVisible(false) .label(R.string.configbuilder_insulin)) .add(new SWBreak()) .add(new SWButton() @@ -441,4 +449,177 @@ public class SWDefinition { ; } + private void SWDefinitionNSClient() { + // List all the screens here + add(new SWScreen(R.string.nav_setupwizard) + .add(new SWInfotext() + .label(R.string.welcometosetupwizard)) + .add(new SWButton() + .text(R.string.nav_import) + .action(() -> ImportExportPrefs.importSharedPreferences(getActivity())) + .visibility(ImportExportPrefs.file::exists)) + .add(new SWInfotext() + .label(R.string.backupismissing) + .visibility(() -> !ImportExportPrefs.file.exists())) + ) + .add(new SWScreen(R.string.language) + .skippable(false) + .add(new SWRadioButton() + .option(R.array.languagesArray, R.array.languagesValues) + .preferenceId(R.string.key_language).label(R.string.language) + .comment(R.string.setupwizard_language_prompt)) + .validator(() -> { + String lang = SP.getString("language", "en"); + LocaleHelper.setLocale(MainApp.instance().getApplicationContext(), lang); + return SP.contains(R.string.key_language); + }) + ) + .add(new SWScreen(R.string.end_user_license_agreement) + .skippable(false) + .add(new SWInfotext() + .label(R.string.end_user_license_agreement_text)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.end_user_license_agreement_i_understand) + .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) + .action(() -> { + SP.putBoolean(R.string.key_i_understand, true); + MainApp.bus().post(new EventSWUpdate(false)); + })) + .visibility(() -> !SP.getBoolean(R.string.key_i_understand, false)) + .validator(() -> SP.getBoolean(R.string.key_i_understand, false)) + ) + .add(new SWScreen(R.string.permission) + .skippable(false) + .add(new SWInfotext() + .label(String.format(MainApp.gs(R.string.needwhitelisting), MainApp.gs(R.string.app_name)))) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.askforpermission) + .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY))) + .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)) + .validator(() -> !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS))) + ) + .add(new SWScreen(R.string.permission) + .skippable(false) + .add(new SWInfotext() + .label(MainApp.gs(R.string.needstoragepermission))) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.askforpermission) + .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .action(() -> AndroidPermission.askForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE))) + .visibility(() -> Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) + .validator(() -> !(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !AndroidPermission.checkForPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE))) + ) + .add(new SWScreen(R.string.nsclientinternal_title) + .skippable(true) + .add(new SWInfotext() + .label(R.string.nsclientinfotext)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.enable_nsclient) + .action(() -> { + NSClientPlugin.getPlugin().setPluginEnabled(PluginType.GENERAL, true); + NSClientPlugin.getPlugin().setFragmentVisible(PluginType.GENERAL, true); + ConfigBuilderFragment.processOnEnabledCategoryChanged(NSClientPlugin.getPlugin(), PluginType.GENERAL); + ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); + MainApp.bus().post(new EventConfigBuilderChange()); + MainApp.bus().post(new EventSWUpdate(true)); + }) + .visibility(() -> !NSClientPlugin.getPlugin().isEnabled(PluginType.GENERAL))) + .add(new SWEditUrl() + .preferenceId(R.string.key_nsclientinternal_url) + .label(R.string.nsclientinternal_url_title) + .comment(R.string.nsclientinternal_url_dialogmessage)) + .add(new SWEditString() + .validator(text -> text.length() >= 12) + .preferenceId(R.string.key_nsclientinternal_api_secret) + .label(R.string.nsclientinternal_secret_dialogtitle) + .comment(R.string.nsclientinternal_secret_dialogmessage)) + .add(new SWBreak()) + .add(new SWEventListener(this) + .label(R.string.status) + .initialStatus(NSClientPlugin.getPlugin().status) + .listener(new Object() { + @Subscribe + public void onEventNSClientStatus(EventNSClientStatus event) { + MainApp.bus().post(new EventSWLabel(event.status)); + } + }) + ) + .add(new SWBreak()) + .validator(() -> NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth) + .visibility(() -> !(NSClientPlugin.getPlugin().nsClientService != null && NSClientPlugin.getPlugin().nsClientService.isConnected && NSClientPlugin.getPlugin().nsClientService.hasWriteAuth)) + ) + .add(new SWScreen(R.string.patientage) + .skippable(false) + .add(new SWInfotext() + .label(R.string.patientage_summary)) + .add(new SWBreak()) + .add(new SWRadioButton() + .option(R.array.ageArray, R.array.ageValues) + .preferenceId(R.string.key_age) + .label(R.string.patientage) + .comment(R.string.patientage_summary)) + .validator(() -> SP.contains(R.string.key_age)) + ) + .add(new SWScreen(R.string.configbuilder_insulin) + .skippable(false) + .add(new SWInfotext() + .label(MainApp.gs(R.string.rapid_acting_oref) + ": " + MainApp.gs(R.string.fastactinginsulincomment))) + .add(new SWInfotext() + .label(MainApp.gs(R.string.ultrarapid_oref) + ": " + MainApp.gs(R.string.ultrafastactinginsulincomment))) + .add(new SWInfotext() + .label(MainApp.gs(R.string.free_peak_oref) + ": " + MainApp.gs(R.string.free_peak_oref_description))) + .add(new SWBreak()) + .add(new SWInfotext() + .label(R.string.diawarning)) + .add(new SWBreak()) + .add(new SWPlugin() + .option(PluginType.INSULIN) + .makeVisible(false) + .label(R.string.configbuilder_insulin)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.insulinsourcesetup) + .action(() -> { + final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActiveInsulin(); + PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(activity, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + activity.startActivity(i); + }, null); + }) + .visibility(() -> MainApp.getConfigBuilder().getActiveInsulin()!= null && ((PluginBase) MainApp.getConfigBuilder().getActiveInsulin()).getPreferencesId() > 0)) + .validator(() -> MainApp.getConfigBuilder().getActiveInsulin() != null) + ) + .add(new SWScreen(R.string.configbuilder_sensitivity) + .skippable(false) + .add(new SWInfotext() + .label(R.string.setupwizard_sensitivity_description)) + .add(new SWHtmlLink() + .label(R.string.setupwizard_sensitivity_url)) + .add(new SWBreak()) + .add(new SWPlugin() + .option(PluginType.SENSITIVITY) + .label(R.string.configbuilder_sensitivity)) + .add(new SWBreak()) + .add(new SWButton() + .text(R.string.sensitivitysetup) + .action(() -> { + final PluginBase plugin = (PluginBase) MainApp.getConfigBuilder().getActiveSensitivity(); + PasswordProtection.QueryPassword(activity, R.string.settings_password, "settings_password", () -> { + Intent i = new Intent(activity, PreferencesActivity.class); + i.putExtra("id", plugin.getPreferencesId()); + activity.startActivity(i); + }, null); + }) + .visibility(() -> MainApp.getConfigBuilder().getActiveSensitivity() != null && ((PluginBase) MainApp.getConfigBuilder().getActiveSensitivity()).getPreferencesId() > 0)) + .validator(() -> MainApp.getConfigBuilder().getActiveSensitivity() != null) + ) + ; + } + } \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java index b9519bc9b5..06735ee72e 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.java @@ -25,6 +25,8 @@ public class SWPlugin extends SWItem { private PluginType pType; private RadioGroup radioGroup; + private boolean makeVisible = true; + public SWPlugin() { super(Type.PLUGIN); } @@ -34,6 +36,11 @@ public class SWPlugin extends SWItem { return this; } + public SWPlugin makeVisible(boolean makeVisible) { + this.makeVisible = makeVisible; + return this; + } + @Override public void generateDialog(View view, LinearLayout layout) { Context context = view.getContext(); @@ -58,10 +65,10 @@ public class SWPlugin extends SWItem { radioGroup.setOnCheckedChangeListener((group, checkedId) -> { RadioButton rb = group.findViewById(checkedId); - PluginBase plugin1 = (PluginBase) rb.getTag(); - plugin1.setPluginEnabled(pType, rb.isChecked()); - plugin1.setFragmentVisible(pType, rb.isChecked()); - ConfigBuilderFragment.processOnEnabledCategoryChanged(plugin1, pType); + PluginBase plugin = (PluginBase) rb.getTag(); + plugin.setPluginEnabled(pType, rb.isChecked()); + plugin.setFragmentVisible(pType, rb.isChecked() && makeVisible); + ConfigBuilderFragment.processOnEnabledCategoryChanged(plugin, pType); ConfigBuilderPlugin.getPlugin().storeSettings("SetupWizard"); MainApp.bus().post(new EventConfigBuilderChange()); MainApp.bus().post(new EventSWUpdate()); 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 c17646e901..79037ebcd8 100644 --- a/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/tabs/TabPageAdapter.java @@ -3,9 +3,11 @@ package info.nightscout.androidaps.tabs; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter; import android.view.ViewGroup; @@ -19,7 +21,7 @@ import info.nightscout.androidaps.interfaces.PluginBase; /** * Created by mike on 30.05.2016. */ -public class TabPageAdapter extends FragmentStatePagerAdapter { +public class TabPageAdapter extends FragmentPagerAdapter { ArrayList visibleFragmentList = new ArrayList<>(); @@ -76,5 +78,8 @@ public class TabPageAdapter extends FragmentStatePagerAdapter { } } - + @Override + public long getItemId(int position) { + return System.identityHashCode(visibleFragmentList.get(position)); + } } diff --git a/app/src/main/res/drawable-hdpi/ic_visibility.png b/app/src/main/res/drawable-hdpi/ic_visibility.png new file mode 100644 index 0000000000..a014628e30 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_visibility.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_visibility.png b/app/src/main/res/drawable-mdpi/ic_visibility.png new file mode 100644 index 0000000000..d5a9dc9ca4 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_visibility.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_visibility.png b/app/src/main/res/drawable-xhdpi/ic_visibility.png new file mode 100644 index 0000000000..1e16fb934f Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_visibility.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_visibility.png b/app/src/main/res/drawable-xxhdpi/ic_visibility.png new file mode 100644 index 0000000000..dbc192368f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_visibility.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_visibility.png b/app/src/main/res/drawable-xxxhdpi/ic_visibility.png new file mode 100644 index 0000000000..882eacdee5 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_visibility.png differ diff --git a/app/src/main/res/drawable/visibility_black_16x16.png b/app/src/main/res/drawable/visibility_black_16x16.png deleted file mode 100644 index d24867dcdf..0000000000 Binary files a/app/src/main/res/drawable/visibility_black_16x16.png and /dev/null differ diff --git a/app/src/main/res/layout/bgsource_fragment.xml b/app/src/main/res/layout/bgsource_fragment.xml index 316bc8e049..6ff108a4a6 100644 --- a/app/src/main/res/layout/bgsource_fragment.xml +++ b/app/src/main/res/layout/bgsource_fragment.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingTop="2dp" tools:context="info.nightscout.androidaps.plugins.Source.BGSourceFragment"> diff --git a/app/src/main/res/layout/combopump_fragment.xml b/app/src/main/res/layout/combopump_fragment.xml index 5bb90090be..45e6993b99 100644 --- a/app/src/main/res/layout/combopump_fragment.xml +++ b/app/src/main/res/layout/combopump_fragment.xml @@ -2,6 +2,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:paddingTop="5dp" tools:context=".plugins.PumpCombo.ComboFragment"> + android:gravity="center" + android:orientation="vertical"> + +