hide buttons based on pump description

This commit is contained in:
Milos Kozak 2016-12-10 00:18:20 +01:00
parent cf4851250d
commit 617192dc3a

View file

@ -7,8 +7,13 @@ import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.R;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; 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 { public class ActionsFragment extends Fragment implements FragmentBase, View.OnClickListener {
static ActionsPlugin actionsPlugin = new ActionsPlugin(); static ActionsPlugin actionsPlugin = new ActionsPlugin();
static public ActionsPlugin getPlugin() { static public ActionsPlugin getPlugin() {
return actionsPlugin; return actionsPlugin;
} }
Button profileSwitch;
Button extendedBolus;
Button tempBasal;
Button fill;
public ActionsFragment() { public ActionsFragment() {
} }
@ -35,14 +46,57 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl
Bundle savedInstanceState) { Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.actions_fragment, container, false); View view = inflater.inflate(R.layout.actions_fragment, container, false);
view.findViewById(R.id.actions_profileswitch).setOnClickListener(this); profileSwitch = (Button) view.findViewById(R.id.actions_profileswitch);
view.findViewById(R.id.actions_extendedbolus).setOnClickListener(this); extendedBolus = (Button) view.findViewById(R.id.actions_extendedbolus);
view.findViewById(R.id.actions_settempbasal).setOnClickListener(this); tempBasal = (Button) view.findViewById(R.id.actions_settempbasal);
view.findViewById(R.id.actions_fill).setOnClickListener(this); fill = (Button) view.findViewById(R.id.actions_fill);
profileSwitch.setOnClickListener(this);
extendedBolus.setOnClickListener(this);
tempBasal.setOnClickListener(this);
fill.setOnClickListener(this);
updateGUIIfVisible();
return view; 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 @Override
public void onClick(View view) { public void onClick(View view) {
FragmentManager manager = getFragmentManager(); FragmentManager manager = getFragmentManager();
@ -57,11 +111,11 @@ public class ActionsFragment extends Fragment implements FragmentBase, View.OnCl
case R.id.actions_extendedbolus: case R.id.actions_extendedbolus:
NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog(); NewExtendedBolusDialog newExtendedDialog = new NewExtendedBolusDialog();
newExtendedDialog.show(manager, "NewExtendedDialog"); newExtendedDialog.show(manager, "NewExtendedDialog");
break; break;
case R.id.actions_settempbasal: case R.id.actions_settempbasal:
NewTempBasalDialog newTempDialog = new NewTempBasalDialog(); NewTempBasalDialog newTempDialog = new NewTempBasalDialog();
newTempDialog.show(manager, "NewTempDialog"); newTempDialog.show(manager, "NewTempDialog");
break; break;
case R.id.actions_fill: case R.id.actions_fill:
FillDialog fillDialog = new FillDialog(); FillDialog fillDialog = new FillDialog();
fillDialog.show(manager, "FillDialog"); fillDialog.show(manager, "FillDialog");