From 617192dc3a9b335726e948051a44cc3a1857dd1a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 10 Dec 2016 00:18:20 +0100 Subject: [PATCH] hide buttons based on pump description --- .../plugins/Actions/ActionsFragment.java | 66 +++++++++++++++++-- 1 file changed, 60 insertions(+), 6 deletions(-) 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 f263adcc99..ee3de3267e 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 @@ -7,8 +7,13 @@ import android.support.v4.app.FragmentManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import com.squareup.otto.Subscribe; + +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; @@ -22,10 +27,16 @@ import info.nightscout.androidaps.plugins.Actions.dialogs.NewTempBasalDialog; public class ActionsFragment extends Fragment implements FragmentBase, View.OnClickListener { static ActionsPlugin actionsPlugin = new ActionsPlugin(); + static public ActionsPlugin getPlugin() { return actionsPlugin; } + Button profileSwitch; + Button extendedBolus; + Button tempBasal; + Button fill; + public ActionsFragment() { } @@ -35,14 +46,57 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl Bundle savedInstanceState) { View view = inflater.inflate(R.layout.actions_fragment, container, false); - view.findViewById(R.id.actions_profileswitch).setOnClickListener(this); - view.findViewById(R.id.actions_extendedbolus).setOnClickListener(this); - view.findViewById(R.id.actions_settempbasal).setOnClickListener(this); - view.findViewById(R.id.actions_fill).setOnClickListener(this); + profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch); + extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus); + tempBasal = (Button) view.findViewById(R.id.actions_settempbasal); + fill = (Button) view.findViewById(R.id.actions_fill); + profileSwitch.setOnClickListener(this); + extendedBolus.setOnClickListener(this); + tempBasal.setOnClickListener(this); + fill.setOnClickListener(this); + + updateGUIIfVisible(); return view; } + @Override + public void onPause() { + super.onPause(); + MainApp.bus().unregister(this); + } + + @Override + public void onResume() { + super.onResume(); + MainApp.bus().register(this); + } + + @Subscribe + public void onStatusEvent(final EventRefreshGui ev) { + updateGUIIfVisible(); + } + + void updateGUIIfVisible() { + if (!MainApp.getConfigBuilder().getPumpDescription().isSetBasalProfileCapable) + profileSwitch.setVisibility(View.GONE); + else + profileSwitch.setVisibility(View.VISIBLE); + if (!MainApp.getConfigBuilder().getPumpDescription().isExtendedBolusCapable) + extendedBolus.setVisibility(View.GONE); + else + extendedBolus.setVisibility(View.VISIBLE); + if (!MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable) + tempBasal.setVisibility(View.GONE); + else + tempBasal.setVisibility(View.VISIBLE); + if (!MainApp.getConfigBuilder().getPumpDescription().isRefillingCapable) + fill.setVisibility(View.GONE); + else + fill.setVisibility(View.VISIBLE); + } + + @Override public void onClick(View view) { FragmentManager manager = getFragmentManager(); @@ -57,11 +111,11 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl case R.id.actions_extendedbolus: NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog(); newExtendedDialog.show(manager, "NewExtendedDialog"); - break; + break; case R.id.actions_settempbasal: NewTempBasalDialog newTempDialog = new NewTempBasalDialog(); newTempDialog.show(manager, "NewTempDialog"); - break; + break; case R.id.actions_fill: FillDialog fillDialog = new FillDialog(); fillDialog.show(manager, "FillDialog");