activate button on NSProfile fragment
This commit is contained in:
parent
545debde92
commit
8e6953cc92
4 changed files with 52 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,4 +14,14 @@
|
|||
layout="@layout/profileviewer_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/nsprofile_profileswitch"
|
||||
style="?android:attr/buttonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="@string/activate_profile"
|
||||
android:textColor="@color/colorProfileSwitchButton" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in a new issue