- Fixed RemovePod to NOT forcebully remove the Pod if failed (Cancel)

- CHanged InitPodFragment, to respond onli to that call, and NOT to PumpResultEvent
This commit is contained in:
Andy Rozman 2019-11-30 12:15:25 +00:00
parent bea4bde8cb
commit a2ad20f616
5 changed files with 382 additions and 68 deletions

View file

@ -1,14 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
class InitPodWizard : NoSplashAppCompatActivity() {
init {
}
}

View file

@ -31,22 +31,25 @@ 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.defs.PodInitReceiver;
/** /**
* Created by TechFreak on 04/09/2014. * Created by andy on 12/11/2019
*/ */
public class InitActionFragment extends Fragment implements PodInitReceiver { public class InitActionFragment extends Fragment implements PodInitReceiver {
private static final String ARG_KEY = "key"; private static final String ARG_KEY = "key";
private PageFragmentCallbacks mCallbacks; protected PageFragmentCallbacks mCallbacks;
private String mKey; protected String mKey;
private InitActionPage mPage; protected InitActionPage mPage;
private ProgressBar progressBar; protected ProgressBar progressBar;
private TextView errorView; protected TextView errorView;
protected PodInitActionType podInitActionType;
protected List<PodInitActionType> children;
protected Map<PodInitActionType, CheckBox> mapCheckBoxes;
protected InitActionFragment instance;
protected PumpEnactResult callResult;
private PodInitActionType podInitActionType;
//private List<PodInitActionType> children;
private Map<PodInitActionType, CheckBox> mapCheckBoxes;
private InitActionFragment instance;
public static InitActionFragment create(String key, PodInitActionType podInitActionType) { public static InitActionFragment create(String key, PodInitActionType podInitActionType) {
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -84,7 +87,7 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
LinearLayout linearLayout = rootView.findViewById(R.id.initAction_ItemsHolder); LinearLayout linearLayout = rootView.findViewById(R.id.initAction_ItemsHolder);
List<PodInitActionType> children = podInitActionType.getChildren(); children = podInitActionType.getChildren();
mapCheckBoxes = new HashMap<>(); mapCheckBoxes = new HashMap<>();
for (PodInitActionType child : children) { for (PodInitActionType child : children) {
@ -126,20 +129,6 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
mCallbacks = null; 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() { public PodInitActionType getPodInitActionType() {
return podInitActionType; return podInitActionType;
@ -154,14 +143,12 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
@Override @Override
public void setUserVisibleHint(boolean isVisibleToUser) { public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser); super.setUserVisibleHint(isVisibleToUser);
System.out.println("ACTION: setUserVisibleHint="+ isVisibleToUser); //System.out.println("ACTION: setUserVisibleHint="+ isVisibleToUser);
if (isVisibleToUser) { if (isVisibleToUser) {
System.out.println("ACTION: Visible"); //System.out.println("ACTION: Visible");
new AsyncTask<Void, Void, String>() { new AsyncTask<Void, Void, String>() {
PumpEnactResult callResult;
protected void onPreExecute() { protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
} }
@ -169,19 +156,19 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
@Override @Override
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) {
this.callResult = AapsOmnipodManager.getInstance().initPod( callResult = AapsOmnipodManager.getInstance().initPod(
podInitActionType, podInitActionType,
instance, instance,
null null
); );
} else if (podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) { } else if (podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) {
this.callResult = AapsOmnipodManager.getInstance().initPod( callResult = AapsOmnipodManager.getInstance().initPod(
podInitActionType, podInitActionType,
instance, instance,
ProfileFunctions.getInstance().getProfile() ProfileFunctions.getInstance().getProfile()
); );
} else if (podInitActionType == PodInitActionType.DeactivatePodWizardStep) { } else if (podInitActionType == PodInitActionType.DeactivatePodWizardStep) {
this.callResult = AapsOmnipodManager.getInstance().deactivatePod(instance); callResult = AapsOmnipodManager.getInstance().deactivatePod(instance);
} }
return "OK"; return "OK";
@ -191,21 +178,7 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
protected void onPostExecute(String result) { protected void onPostExecute(String result) {
super.onPostExecute(result); super.onPostExecute(result);
System.out.println("ACTION: onPostExecute: " + result); 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();
} }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.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 @Override
public void returnInitTaskStatus(PodInitActionType podInitActionType, boolean isSuccess, String errorMessage) { public void returnInitTaskStatus(PodInitActionType podInitActionType, boolean isSuccess, String errorMessage) {
if (podInitActionType.isParent()) { if (podInitActionType.isParent()) {
for (PodInitActionType actionType : mapCheckBoxes.keySet()) { for (PodInitActionType actionType : mapCheckBoxes.keySet()) {
setCheckBox(actionType, isSuccess); setCheckBox(actionType, isSuccess);
} }
// special handling for init
processOnFinishedActions(isSuccess, errorMessage);
} else { } else {
setCheckBox(podInitActionType, isSuccess); 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) { public void setCheckBox(PodInitActionType podInitActionType, boolean isSuccess) {
getActivity().runOnUiThread(() -> { getActivity().runOnUiThread(() -> {
mapCheckBoxes.get(podInitActionType).setChecked(true); mapCheckBoxes.get(podInitActionType).setChecked(true);
@ -235,6 +251,4 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
} }
} }

View file

@ -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 { public class InitActionPage extends Page {
private PodInitActionType podInitActionType; protected PodInitActionType podInitActionType;
private boolean actionCompleted = false; protected boolean actionCompleted = false;
private boolean actionSuccess = false; protected boolean actionSuccess = false;
public InitActionPage(ModelCallbacks callbacks, String title) { public InitActionPage(ModelCallbacks callbacks, String title) {
super(callbacks, title); super(callbacks, title);
@ -42,7 +44,6 @@ public class InitActionPage extends Page {
@Override @Override
public boolean isCompleted() { public boolean isCompleted() {
System.out.println("ACTION: Page.isCompleted " + actionCompleted);
return actionCompleted; return actionCompleted;
} }

View file

@ -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<PodInitActionType> children;
private Map<PodInitActionType, CheckBox> 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<PodInitActionType> 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<Void, Void, String>() {
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));
});
}
}

View file

@ -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<ReviewItem> 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;
}
}