From 8e6953cc92f8a1c93edeef8d3fc409eadb2f6a68 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 26 Mar 2018 09:25:57 +0200 Subject: [PATCH] activate button on NSProfile fragment --- .../plugins/Actions/ActionsFragment.java | 8 +++++++- .../plugins/ProfileNS/NSProfileFragment.java | 20 +++++++++++++++++++ .../java/info/nightscout/utils/OKDialog.java | 15 ++++++++++++++ .../main/res/layout/nsprofile_fragment.xml | 10 ++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java index 05313ffb90..9a14471318 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Actions/ActionsFragment.java @@ -116,9 +116,14 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL activity.runOnUiThread(new Runnable() { @Override public void run() { + if (MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() != null) { + profileSwitch.setVisibility(View.VISIBLE); + } else { + profileSwitch.setVisibility(View.GONE); + } + if (MainApp.getConfigBuilder().getProfile() == null) { tempTarget.setVisibility(View.GONE); - profileSwitch.setVisibility(View.GONE); extendedBolus.setVisibility(View.GONE); extendedBolusCancel.setVisibility(View.GONE); tempBasal.setVisibility(View.GONE); @@ -126,6 +131,7 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL fill.setVisibility(View.GONE); return; } + final PumpInterface pump = ConfigBuilderPlugin.getActivePump(); final boolean basalprofileEnabled = MainApp.isEngineeringModeOrRelease() && pump.getPumpDescription().isSetBasalProfileCapable; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java index 9d30021cd0..62fb71a0a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ProfileNS/NSProfileFragment.java @@ -7,6 +7,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.Spinner; import android.widget.TextView; @@ -16,16 +17,19 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; import butterknife.OnItemSelected; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.ProfileStore; +import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.ProfileNS.events.EventNSProfileUpdateGUI; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.FabricPrivacy; +import info.nightscout.utils.OKDialog; import static butterknife.OnItemSelected.Callback.NOTHING_SELECTED; @@ -53,6 +57,8 @@ public class NSProfileFragment extends SubscriberFragment { TextView target; @BindView(R.id.basal_graph) ProfileGraph basalGraph; + @BindView(R.id.nsprofile_profileswitch) + Button activateButton; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -132,4 +138,18 @@ public class NSProfileFragment extends SubscriberFragment { basal.setText(""); target.setText(""); } + + @OnClick(R.id.nsprofile_profileswitch) + public void onClickProfileSwitch() { + String name = profileSpinner.getSelectedItem().toString(); + ProfileStore store = NSProfilePlugin.getPlugin().getProfile(); + if (store != null) { + Profile profile = store.getSpecificProfile(name); + if (profile != null) { + OKDialog.showConfirmation(getActivity(), MainApp.gs(R.string.activate_profile) + ": " + name + " ?", () -> + NewNSTreatmentDialog.doProfileSwitch(store, name, 0, 100, 0) + ); + } + } + } } diff --git a/app/src/main/java/info/nightscout/utils/OKDialog.java b/app/src/main/java/info/nightscout/utils/OKDialog.java index 6bd84cbe71..3212e6b1fd 100644 --- a/app/src/main/java/info/nightscout/utils/OKDialog.java +++ b/app/src/main/java/info/nightscout/utils/OKDialog.java @@ -61,4 +61,19 @@ public class OKDialog { log.debug("show_dialog exception: " + e); } } + + public static void showConfirmation(final Activity activity, String message, final Runnable runnable) { + AlertDialog alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme)) + .setMessage(message) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + dialog.dismiss(); + if (runnable != null) { + SystemClock.sleep(100); + activity.runOnUiThread(runnable); + } + }) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } + } diff --git a/app/src/main/res/layout/nsprofile_fragment.xml b/app/src/main/res/layout/nsprofile_fragment.xml index e8a38195cb..0c1c40d1e4 100644 --- a/app/src/main/res/layout/nsprofile_fragment.xml +++ b/app/src/main/res/layout/nsprofile_fragment.xml @@ -14,4 +14,14 @@ layout="@layout/profileviewer_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" /> + +