From a2ad20f6163f1027e653b36d6f8b560298c91b3c Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Sat, 30 Nov 2019 12:15:25 +0000 Subject: [PATCH] - Fixed RemovePod to NOT forcebully remove the Pod if failed (Cancel) - CHanged InitPodFragment, to respond onli to that call, and NOT to PumpResultEvent --- .../pump/omnipod/dialogs/InitPodWizard.kt | 14 - .../InitActionFragment.java | 112 ++++---- .../{pages => initpod}/InitActionPage.java | 11 +- .../removepod/RemoveActionFragment.java | 239 ++++++++++++++++++ .../wizard/removepod/RemovePodActionPage.java | 74 ++++++ 5 files changed, 382 insertions(+), 68 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/InitPodWizard.kt rename app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/{pages => initpod}/InitActionFragment.java (75%) rename app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/{pages => initpod}/InitActionPage.java (86%) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/InitPodWizard.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/InitPodWizard.kt deleted file mode 100644 index 6089bcc389..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/InitPodWizard.kt +++ /dev/null @@ -1,14 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.omnipod.dialogs - -import info.nightscout.androidaps.activities.NoSplashAppCompatActivity - -class InitPodWizard : NoSplashAppCompatActivity() { - - - init { - - - } - - -} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionFragment.java similarity index 75% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionFragment.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionFragment.java index c7da0c44ab..bab02c1be4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionFragment.java @@ -31,22 +31,25 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; /** - * Created by TechFreak on 04/09/2014. + * Created by andy on 12/11/2019 */ public class InitActionFragment extends Fragment implements PodInitReceiver { private static final String ARG_KEY = "key"; - private PageFragmentCallbacks mCallbacks; - private String mKey; - private InitActionPage mPage; + protected PageFragmentCallbacks mCallbacks; + protected String mKey; + protected InitActionPage mPage; - private ProgressBar progressBar; - private TextView errorView; + protected ProgressBar progressBar; + protected TextView errorView; + + protected PodInitActionType podInitActionType; + protected List children; + protected Map mapCheckBoxes; + protected InitActionFragment instance; + + protected PumpEnactResult callResult; - private PodInitActionType podInitActionType; - //private List children; - private Map mapCheckBoxes; - private InitActionFragment instance; public static InitActionFragment create(String key, PodInitActionType podInitActionType) { Bundle args = new Bundle(); @@ -84,7 +87,7 @@ public class InitActionFragment extends Fragment implements PodInitReceiver { LinearLayout linearLayout = rootView.findViewById(R.id.initAction_ItemsHolder); - List children = podInitActionType.getChildren(); + children = podInitActionType.getChildren(); mapCheckBoxes = new HashMap<>(); for (PodInitActionType child : children) { @@ -126,20 +129,6 @@ public class InitActionFragment extends Fragment implements PodInitReceiver { mCallbacks = null; } -// @Override -// public void onViewCreated(View view, Bundle savedInstanceState) { -// super.onViewCreated(view, savedInstanceState); -// -// } - -// @Override -// public void setMenuVisibility(boolean menuVisible) { -// super.setMenuVisibility(menuVisible); -// -// // In a future update to the support library, this should override setUserVisibleHint -// // instead of setMenuVisibility. -// -// } public PodInitActionType getPodInitActionType() { return podInitActionType; @@ -154,14 +143,12 @@ public class InitActionFragment extends Fragment implements PodInitReceiver { @Override public void setUserVisibleHint(boolean isVisibleToUser) { super.setUserVisibleHint(isVisibleToUser); - System.out.println("ACTION: setUserVisibleHint="+ isVisibleToUser); + //System.out.println("ACTION: setUserVisibleHint="+ isVisibleToUser); if (isVisibleToUser) { - System.out.println("ACTION: Visible"); + //System.out.println("ACTION: Visible"); new AsyncTask() { - PumpEnactResult callResult; - protected void onPreExecute() { progressBar.setVisibility(View.VISIBLE); } @@ -169,19 +156,19 @@ public class InitActionFragment extends Fragment implements PodInitReceiver { @Override protected String doInBackground(Void... params) { if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { - this.callResult = AapsOmnipodManager.getInstance().initPod( + callResult = AapsOmnipodManager.getInstance().initPod( podInitActionType, instance, null ); } else if (podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) { - this.callResult = AapsOmnipodManager.getInstance().initPod( + callResult = AapsOmnipodManager.getInstance().initPod( podInitActionType, instance, ProfileFunctions.getInstance().getProfile() ); } else if (podInitActionType == PodInitActionType.DeactivatePodWizardStep) { - this.callResult = AapsOmnipodManager.getInstance().deactivatePod(instance); + callResult = AapsOmnipodManager.getInstance().deactivatePod(instance); } return "OK"; @@ -191,21 +178,7 @@ public class InitActionFragment extends Fragment implements PodInitReceiver { protected void onPostExecute(String result) { super.onPostExecute(result); - System.out.println("ACTION: onPostExecute: " + result); - - boolean isOk = callResult.success; - - progressBar.setVisibility(View.GONE); - - if (!isOk) { - errorView.setVisibility(View.VISIBLE); - errorView.setText(callResult.comment); - } - - mPage.setActionCompleted(isOk); - - mPage.getData().putString(Page.SIMPLE_DATA_KEY, "ddd"); - mPage.notifyDataChanged(); + actionOnReceiveResponse(result); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -214,18 +187,61 @@ public class InitActionFragment extends Fragment implements PodInitReceiver { } } + public void actionOnReceiveResponse(String result) { +// System.out.println("ACTION: actionOnReceiveResponse: " + result); +// +// boolean isOk = callResult.success; +// +// progressBar.setVisibility(View.GONE); +// +// if (!isOk) { +// errorView.setVisibility(View.VISIBLE); +// errorView.setText(callResult.comment); +// } +// +// mPage.setActionCompleted(isOk); +// +// mPage.getData().putString(Page.SIMPLE_DATA_KEY, "ddd"); +// mPage.notifyDataChanged(); + } + @Override public void returnInitTaskStatus(PodInitActionType podInitActionType, boolean isSuccess, String errorMessage) { if (podInitActionType.isParent()) { for (PodInitActionType actionType : mapCheckBoxes.keySet()) { setCheckBox(actionType, isSuccess); } + + // special handling for init + processOnFinishedActions(isSuccess, errorMessage); + } else { setCheckBox(podInitActionType, isSuccess); } } + private void processOnFinishedActions(boolean isOk, String errorMessage) { + + getActivity().runOnUiThread(() -> { + + progressBar.setVisibility(View.GONE); + + if (!isOk) { + errorView.setVisibility(View.VISIBLE); + errorView.setText(errorMessage); + } + + mPage.setActionCompleted(isOk); + + mPage.getData().putString(Page.SIMPLE_DATA_KEY, "ddd"); + mPage.notifyDataChanged(); + + }); + + } + + public void setCheckBox(PodInitActionType podInitActionType, boolean isSuccess) { getActivity().runOnUiThread(() -> { mapCheckBoxes.get(podInitActionType).setChecked(true); @@ -235,6 +251,4 @@ public class InitActionFragment extends Fragment implements PodInitReceiver { } - - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionPage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java similarity index 86% rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionPage.java rename to app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java index 385febed49..cc18ed11a8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitActionPage.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java @@ -13,14 +13,16 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; /** - * A page asking for a name and an email. + * Created by andy on 12/11/2019 + * + * This page is for InitPod and RemovePod, but Fragments called for this 2 actions are different */ public class InitActionPage extends Page { - private PodInitActionType podInitActionType; + protected PodInitActionType podInitActionType; - private boolean actionCompleted = false; - private boolean actionSuccess = false; + protected boolean actionCompleted = false; + protected boolean actionSuccess = false; public InitActionPage(ModelCallbacks callbacks, String title) { super(callbacks, title); @@ -42,7 +44,6 @@ public class InitActionPage extends Page { @Override public boolean isCompleted() { - System.out.println("ACTION: Page.isCompleted " + actionCompleted); return actionCompleted; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java new file mode 100644 index 0000000000..f40be9807f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java @@ -0,0 +1,239 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages; + +import android.app.Activity; +import android.graphics.Color; +import android.os.AsyncTask; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.CheckBox; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; + +import androidx.fragment.app.Fragment; + +import com.atech.android.library.wizardpager.util.WizardPagesUtil; +import com.tech.freak.wizardpager.model.Page; +import com.tech.freak.wizardpager.ui.PageFragmentCallbacks; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import info.nightscout.androidaps.R; +import info.nightscout.androidaps.data.PumpEnactResult; +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver; +import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager; + +/** + * Created by TechFreak on 04/09/2014. + */ +public class RemoveActionFragment extends Fragment implements PodInitReceiver { + private static final String ARG_KEY = "key"; + + private PageFragmentCallbacks mCallbacks; + private String mKey; + private InitActionPage mPage; + + private ProgressBar progressBar; + private TextView errorView; + + private PodInitActionType podInitActionType; + //private List children; + private Map mapCheckBoxes; + private RemoveActionFragment instance; + + public static RemoveActionFragment create(String key, PodInitActionType podInitActionType) { + Bundle args = new Bundle(); + args.putString(ARG_KEY, key); + + RemoveActionFragment fragment = new RemoveActionFragment(); + fragment.setArguments(args); + fragment.setPodInitActionType(podInitActionType); + return fragment; + } + + public RemoveActionFragment() { + this.instance = this; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Bundle args = getArguments(); + mKey = args.getString(ARG_KEY); + mPage = (InitActionPage) mCallbacks.onGetPage(mKey); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.omnipod_initpod_init_action, container, false); + WizardPagesUtil.setTitle(mPage, rootView); + + this.progressBar = rootView.findViewById(R.id.initAction_progressBar); + this.errorView = rootView.findViewById(R.id.initAction_textErrorMessage); + + TextView headerView = rootView.findViewById(R.id.initAction_header); + + LinearLayout linearLayout = rootView.findViewById(R.id.initAction_ItemsHolder); + + List children = podInitActionType.getChildren(); + mapCheckBoxes = new HashMap<>(); + + for (PodInitActionType child : children) { + + CheckBox checkBox1 = new CheckBox(getContext()); + checkBox1.setText(child.getResourceId()); + checkBox1.setClickable(false); + checkBox1.setTextAppearance(R.style.WizardPagePodListItem); + checkBox1.setHeight(140); + checkBox1.setTextSize(16); + checkBox1.setTextColor(headerView.getTextColors().getDefaultColor()); + + linearLayout.addView(checkBox1); + + mapCheckBoxes.put(child, checkBox1); + } + + if (podInitActionType==PodInitActionType.DeactivatePodWizardStep) { + headerView.setText(R.string.omnipod_remove_pod_wizard_step2_action_header); + } + + return rootView; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + if (!(activity instanceof PageFragmentCallbacks)) { + throw new ClassCastException("Activity must implement PageFragmentCallbacks"); + } + + mCallbacks = (PageFragmentCallbacks) activity; + } + + @Override + public void onDetach() { + super.onDetach(); + mCallbacks = null; + } + +// @Override +// public void onViewCreated(View view, Bundle savedInstanceState) { +// super.onViewCreated(view, savedInstanceState); +// +// } + +// @Override +// public void setMenuVisibility(boolean menuVisible) { +// super.setMenuVisibility(menuVisible); +// +// // In a future update to the support library, this should override setUserVisibleHint +// // instead of setMenuVisibility. +// +// } + + public PodInitActionType getPodInitActionType() { + return podInitActionType; + } + + + public void setPodInitActionType(PodInitActionType podInitActionType) { + this.podInitActionType = podInitActionType; + } + + + @Override + public void setUserVisibleHint(boolean isVisibleToUser) { + super.setUserVisibleHint(isVisibleToUser); + System.out.println("ACTION: setUserVisibleHint="+ isVisibleToUser); + if (isVisibleToUser) { + System.out.println("ACTION: Visible"); + + new AsyncTask() { + + PumpEnactResult callResult; + + protected void onPreExecute() { + progressBar.setVisibility(View.VISIBLE); + } + + @Override + protected String doInBackground(Void... params) { + if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { + this.callResult = AapsOmnipodManager.getInstance().initPod( + podInitActionType, + instance, + null + ); + } else if (podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) { + this.callResult = AapsOmnipodManager.getInstance().initPod( + podInitActionType, + instance, + ProfileFunctions.getInstance().getProfile() + ); + } else if (podInitActionType == PodInitActionType.DeactivatePodWizardStep) { + this.callResult = AapsOmnipodManager.getInstance().deactivatePod(instance); + } + + return "OK"; + } + + @Override + protected void onPostExecute(String result) { + super.onPostExecute(result); + + System.out.println("ACTION: onPostExecute: " + result); + + boolean isOk = callResult.success; + + progressBar.setVisibility(View.GONE); + + if (!isOk) { + errorView.setVisibility(View.VISIBLE); + errorView.setText(callResult.comment); + } + + mPage.setActionCompleted(isOk); + + mPage.getData().putString(Page.SIMPLE_DATA_KEY, "ddd"); + mPage.notifyDataChanged(); + } + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + } else { + System.out.println("ACTION: Not visible"); + } + } + + @Override + public void returnInitTaskStatus(PodInitActionType podInitActionType, boolean isSuccess, String errorMessage) { + if (podInitActionType.isParent()) { + for (PodInitActionType actionType : mapCheckBoxes.keySet()) { + setCheckBox(actionType, isSuccess); + } + } else { + setCheckBox(podInitActionType, isSuccess); + } + } + + + public void setCheckBox(PodInitActionType podInitActionType, boolean isSuccess) { + getActivity().runOnUiThread(() -> { + mapCheckBoxes.get(podInitActionType).setChecked(true); + mapCheckBoxes.get(podInitActionType).setTextColor(isSuccess ? Color.rgb(34, 135, 91) : + Color.rgb(168, 36, 15)); + }); + } + + + + +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java new file mode 100644 index 0000000000..1c2bcd5dfa --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java @@ -0,0 +1,74 @@ +package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages; + +import androidx.annotation.StringRes; +import androidx.fragment.app.Fragment; + +import com.tech.freak.wizardpager.model.ModelCallbacks; +import com.tech.freak.wizardpager.model.Page; +import com.tech.freak.wizardpager.model.ReviewItem; + +import java.util.ArrayList; + +import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType; + + +/** + * Created by andy on 12/11/2019 + * + * This page is for InitPod and RemovePod, but Fragments called for this 2 actions are different + */ +public class InitActionPage extends Page { + + private PodInitActionType podInitActionType; + + private boolean actionCompleted = false; + private boolean actionSuccess = false; + + public InitActionPage(ModelCallbacks callbacks, String title) { + super(callbacks, title); + } + + public InitActionPage(ModelCallbacks callbacks, @StringRes int titleId, PodInitActionType podInitActionType) { + super(callbacks, titleId); + this.podInitActionType = podInitActionType; + } + + @Override + public Fragment createFragment() { + return InitActionFragment.create(getKey(), this.podInitActionType); + } + + @Override + public void getReviewItems(ArrayList dest) { + } + + @Override + public boolean isCompleted() { + System.out.println("ACTION: Page.isCompleted " + actionCompleted); + return actionCompleted; + } + + public void setActionCompleted(boolean success) { + this.actionCompleted = true; + this.actionSuccess = success; + } + + /** + * This is used just if we want to override default behavior (for example when we enter Page we want prevent any action, until something happens. + * + * @return + */ + public boolean isBackActionPossible() { + return actionCompleted; + } + + /** + * This is used just if we want to override default behavior (for example when we enter Page we want prevent any action, until something happens. + * + * @return + */ + public boolean isNextActionPossible() { + return actionSuccess; + } + +}