From 75a91997b791cda03f5c98c5f93cb11974cb096d Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 3 Apr 2018 14:34:15 +0200 Subject: [PATCH] lp reset --- .../ProfileLocal/LocalProfileFragment.java | 81 +++++++++++-------- .../ProfileLocal/LocalProfilePlugin.java | 1 + .../info/nightscout/utils/TimeListEdit.java | 1 + .../main/res/layout/localprofile_fragment.xml | 16 ++++ 4 files changed, 66 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java index fb8e2166e0..d4a8b87309 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileLocal/LocalProfileFragment.java @@ -4,6 +4,7 @@ package info.nightscout.androidaps.plugins.ProfileLocal; import android.app.Activity; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.v4.app.FragmentTransaction; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; @@ -48,45 +49,43 @@ public class LocalProfileFragment extends SubscriberFragment { TimeListEdit basalView; TimeListEdit targetView; Button profileswitchButton; + Button resetButton; TextView invalidProfile; + Runnable save = () -> { + doEdit(); + if (basalView != null) { + basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel()); + } + updateGUI(); + }; + + TextWatcher textWatch = new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) { + } + + @Override + public void beforeTextChanged(CharSequence s, int start, + int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, + int before, int count) { + LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString()); + doEdit(); + updateGUI(); + } + }; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { try { - Runnable save = new Runnable() { - @Override - public void run() { - LocalProfilePlugin.getPlugin().storeSettings(); - if (basalView != null) { - basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel()); - } - updateGUI(); - } - }; - - TextWatcher textWatch = new TextWatcher() { - - @Override - public void afterTextChanged(Editable s) { - } - - @Override - public void beforeTextChanged(CharSequence s, int start, - int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, - int before, int count) { - LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString()); - LocalProfilePlugin.getPlugin().storeSettings(); - updateGUI(); - } - }; PumpDescription pumpDescription = ConfigBuilderPlugin.getActivePump().getPumpDescription(); - View layout = inflater.inflate(R.layout.localprofile_fragment, container, false); diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia); diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch); @@ -97,6 +96,8 @@ public class LocalProfileFragment extends SubscriberFragment { basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save); targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save); profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch); + resetButton = (Button) layout.findViewById(R.id.localprofile_reset); + invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile); if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) { @@ -112,7 +113,7 @@ public class LocalProfileFragment extends SubscriberFragment { LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked(); LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl; mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); - LocalProfilePlugin.getPlugin().storeSettings(); + doEdit(); } }); mmolView.setOnClickListener(new View.OnClickListener() { @@ -121,7 +122,7 @@ public class LocalProfileFragment extends SubscriberFragment { LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked(); LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol; mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); - LocalProfilePlugin.getPlugin().storeSettings(); + doEdit(); } }); @@ -136,6 +137,16 @@ public class LocalProfileFragment extends SubscriberFragment { } }); + resetButton.setOnClickListener(view -> { + LocalProfilePlugin.getPlugin().loadSettings(); + mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl); + mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol); + diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch); + icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save); + isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save); + basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save); + targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save); + }); return layout; } catch (Exception e) { @@ -146,6 +157,10 @@ public class LocalProfileFragment extends SubscriberFragment { return null; } + public void doEdit() { + LocalProfilePlugin.getPlugin().storeSettings(); + } + @NonNull public String getSumLabel() { ProfileStore profile = LocalProfilePlugin.getPlugin().getProfile(); 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 512d452289..6ebf39b3b5 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 @@ -60,6 +60,7 @@ public class LocalProfilePlugin extends PluginBase implements ProfileInterface { } public void storeSettings() { + if (1==1) return; SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(LOCAL_PROFILE + "mmol", mmol); diff --git a/app/src/main/java/info/nightscout/utils/TimeListEdit.java b/app/src/main/java/info/nightscout/utils/TimeListEdit.java index bc41ece59d..ec03734b18 100644 --- a/app/src/main/java/info/nightscout/utils/TimeListEdit.java +++ b/app/src/main/java/info/nightscout/utils/TimeListEdit.java @@ -78,6 +78,7 @@ public class TimeListEdit { private void buildView() { layout = (LinearLayout) view.findViewById(resLayoutId); + layout.removeAllViews(); textlabel = new TextView(context); textlabel.setText(label); diff --git a/app/src/main/res/layout/localprofile_fragment.xml b/app/src/main/res/layout/localprofile_fragment.xml index 4b61e0235d..68d1bf81b5 100644 --- a/app/src/main/res/layout/localprofile_fragment.xml +++ b/app/src/main/res/layout/localprofile_fragment.xml @@ -153,6 +153,22 @@ android:text="@string/activate_profile" android:textColor="@color/colorProfileSwitchButton" /> +