Temporary workaround for pod activation and deactivation wizard crashes on rotation
This commit is contained in:
parent
159c1f941d
commit
c56bc5ae61
9 changed files with 82 additions and 120 deletions
|
@ -5,7 +5,6 @@ import info.nightscout.androidaps.data.Profile;
|
|||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
|
||||
|
||||
public interface OmnipodCommunicationManagerInterface {
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dialogs
|
|||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter
|
||||
import com.atech.android.library.wizardpager.WizardPagerActivity
|
||||
import com.atech.android.library.wizardpager.WizardPagerContext
|
||||
import com.atech.android.library.wizardpager.data.WizardPagerSettings
|
||||
|
@ -97,6 +98,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
|
|||
pagerSettings.setBackStringResourceId(R.string.cancel)
|
||||
pagerSettings.cancelAction = refreshAction
|
||||
pagerSettings.finishAction = refreshAction
|
||||
pagerSettings.pagerAdapterBehavior = FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
||||
|
||||
val wizardPagerContext = WizardPagerContext.getInstance()
|
||||
|
||||
|
@ -124,6 +126,7 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
|
|||
pagerSettings.setBackStringResourceId(R.string.cancel)
|
||||
pagerSettings.cancelAction = refreshAction
|
||||
pagerSettings.finishAction = refreshAction
|
||||
pagerSettings.pagerAdapterBehavior = FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
||||
|
||||
val wizardPagerContext = WizardPagerContext.getInstance();
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -13,7 +15,7 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.atech.android.library.wizardpager.util.WizardPagesUtil;
|
||||
import com.tech.freak.wizardpager.model.Page;
|
||||
|
@ -30,7 +32,6 @@ import dagger.android.HasAndroidInjector;
|
|||
import dagger.android.support.DaggerFragment;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
|
||||
|
||||
|
@ -38,7 +39,10 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitReceiver;
|
|||
* Created by andy on 12/11/2019
|
||||
*/
|
||||
public class InitActionFragment extends DaggerFragment implements PodInitReceiver {
|
||||
private static final String ARG_KEY = "key";
|
||||
protected static final String ARG_KEY = "key";
|
||||
protected static final String ARG_POD_INIT_ACTION_TYPE = "podInitActionType";
|
||||
|
||||
private static boolean isFirstView;
|
||||
|
||||
protected PageFragmentCallbacks mCallbacks;
|
||||
protected String mKey;
|
||||
|
@ -51,39 +55,42 @@ public class InitActionFragment extends DaggerFragment implements PodInitReceive
|
|||
protected PodInitActionType podInitActionType;
|
||||
protected List<PodInitActionType> children;
|
||||
protected Map<PodInitActionType, CheckBox> mapCheckBoxes;
|
||||
protected InitActionFragment instance;
|
||||
|
||||
protected PumpEnactResult callResult;
|
||||
|
||||
@Inject HasAndroidInjector injector;
|
||||
|
||||
|
||||
public static InitActionFragment create(String key, PodInitActionType podInitActionType) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_KEY, key);
|
||||
args.putSerializable(ARG_POD_INIT_ACTION_TYPE, podInitActionType);
|
||||
|
||||
InitActionFragment fragment = new InitActionFragment();
|
||||
fragment.setArguments(args);
|
||||
fragment.setPodInitActionType(podInitActionType);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public InitActionFragment() {
|
||||
this.instance = this;
|
||||
}
|
||||
|
||||
@SuppressLint("SourceLockedOrientationActivity")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState == null) {
|
||||
isFirstView = true;
|
||||
}
|
||||
|
||||
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
|
||||
Bundle args = getArguments();
|
||||
mKey = args.getString(ARG_KEY);
|
||||
podInitActionType = (PodInitActionType) args.getSerializable(ARG_POD_INIT_ACTION_TYPE);
|
||||
mPage = (InitActionPage) mCallbacks.onGetPage(mKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
View rootView = inflater.inflate(R.layout.omnipod_initpod_init_action, container, false);
|
||||
WizardPagesUtil.setTitle(mPage, rootView);
|
||||
|
||||
|
@ -98,7 +105,6 @@ public class InitActionFragment extends DaggerFragment implements PodInitReceive
|
|||
mapCheckBoxes = new HashMap<>();
|
||||
|
||||
for (PodInitActionType child : children) {
|
||||
|
||||
CheckBox checkBox1 = new CheckBox(getContext());
|
||||
checkBox1.setText(child.getResourceId());
|
||||
checkBox1.setClickable(false);
|
||||
|
@ -129,15 +135,17 @@ public class InitActionFragment extends DaggerFragment implements PodInitReceive
|
|||
}
|
||||
});
|
||||
|
||||
new InitPodTask(injector, instance).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
new InitPodTask(injector, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
});
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
FragmentActivity activity = getActivity();
|
||||
|
||||
if (!(activity instanceof PageFragmentCallbacks)) {
|
||||
throw new ClassCastException("Activity must implement PageFragmentCallbacks");
|
||||
|
@ -152,46 +160,16 @@ public class InitActionFragment extends DaggerFragment implements PodInitReceive
|
|||
mCallbacks = null;
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (isFirstView) {
|
||||
isFirstView = false;
|
||||
new InitPodTask(injector, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
} else {
|
||||
System.out.println("ACTION: Not visible");
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -209,11 +187,10 @@ public class InitActionFragment extends DaggerFragment implements PodInitReceive
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void processOnFinishedActions(boolean isOk, String errorMessage) {
|
||||
|
||||
getActivity().runOnUiThread(() -> {
|
||||
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(() -> {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
if (!isOk) {
|
||||
|
@ -229,17 +206,18 @@ public class InitActionFragment extends DaggerFragment implements PodInitReceive
|
|||
mPage.notifyDataChanged();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setCheckBox(PodInitActionType podInitActionType, boolean isSuccess) {
|
||||
getActivity().runOnUiThread(() -> {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
activity.runOnUiThread(() -> {
|
||||
mapCheckBoxes.get(podInitActionType).setChecked(isSuccess);
|
||||
mapCheckBoxes.get(podInitActionType).setTextColor(isSuccess ? Color.rgb(34, 135, 91) :
|
||||
Color.rgb(168, 36, 15));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.SystemClock;
|
||||
import android.view.View;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
@ -24,7 +23,9 @@ public class InitPodTask extends AsyncTask<Void, Void, String> {
|
|||
this.initActionFragment = initActionFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
initActionFragment.progressBar.setVisibility(View.VISIBLE);
|
||||
initActionFragment.errorView.setVisibility(View.GONE);
|
||||
initActionFragment.retryButton.setVisibility(View.GONE);
|
||||
|
@ -32,21 +33,20 @@ public class InitPodTask extends AsyncTask<Void, Void, String> {
|
|||
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
|
||||
if (initActionFragment.podInitActionType == PodInitActionType.PairAndPrimeWizardStep) {
|
||||
initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod(
|
||||
initActionFragment.podInitActionType,
|
||||
initActionFragment.instance,
|
||||
initActionFragment,
|
||||
null
|
||||
);
|
||||
} else if (initActionFragment.podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) {
|
||||
initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod(
|
||||
initActionFragment.podInitActionType,
|
||||
initActionFragment.instance,
|
||||
initActionFragment,
|
||||
profileFunction.getProfile()
|
||||
);
|
||||
} else if (initActionFragment.podInitActionType == PodInitActionType.DeactivatePodWizardStep) {
|
||||
initActionFragment.callResult = AapsOmnipodManager.getInstance().deactivatePod(initActionFragment.instance);
|
||||
initActionFragment.callResult = AapsOmnipodManager.getInstance().deactivatePod(initActionFragment);
|
||||
}
|
||||
|
||||
return "OK";
|
||||
|
@ -59,5 +59,4 @@ public class InitPodTask extends AsyncTask<Void, Void, String> {
|
|||
initActionFragment.actionOnReceiveResponse(result);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ public abstract class InitPodWizardModel extends AbstractWizardModel {
|
|||
|
||||
@Override
|
||||
public Fragment getReviewFragment() {
|
||||
PodInfoFragment.isInitPod = true;
|
||||
return new PodInfoFragment();
|
||||
return PodInfoFragment.create("initPodInfoFragment", true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,9 +40,7 @@ public class RemovePodWizardModel extends AbstractWizardModel {
|
|||
|
||||
@Override
|
||||
protected PageList onNewRootPageList() {
|
||||
|
||||
return new PageList(
|
||||
|
||||
new DisplayTextPage(this,
|
||||
R.string.omnipod_remove_pod_wizard_step1_title,
|
||||
R.string.omnipod_remove_pod_wizard_step1_desc,
|
||||
|
@ -56,11 +54,8 @@ public class RemovePodWizardModel extends AbstractWizardModel {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
public Fragment getReviewFragment() {
|
||||
PodInfoFragment.isInitPod = false;
|
||||
return new PodInfoFragment();
|
||||
return PodInfoFragment.create("removePodInfoFragment", false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -10,6 +11,8 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.tech.freak.wizardpager.model.ReviewItem;
|
||||
import com.tech.freak.wizardpager.ui.PageFragmentCallbacks;
|
||||
|
||||
|
@ -28,32 +31,35 @@ import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
|
|||
*/
|
||||
public class PodInfoFragment extends DaggerFragment {
|
||||
private static final String ARG_KEY = "key";
|
||||
private static final String ARG_INIT_POD = "initPod";
|
||||
|
||||
@Inject OmnipodUtil omnipodUtil;
|
||||
@Inject PodStateManager podStateManager;
|
||||
|
||||
private PageFragmentCallbacks mCallbacks;
|
||||
private String mKey;
|
||||
private PodInfoPage mPage;
|
||||
public static boolean isInitPod = false;
|
||||
public boolean isInitPod;
|
||||
private ArrayList<ReviewItem> mCurrentReviewItems;
|
||||
|
||||
public static PodInfoFragment create(String key, boolean initPod) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_KEY, key);
|
||||
isInitPod = initPod;
|
||||
args.putBoolean(ARG_INIT_POD, initPod);
|
||||
|
||||
PodInfoFragment fragment = new PodInfoFragment();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public PodInfoFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("SourceLockedOrientationActivity") @Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
|
||||
Bundle args = getArguments();
|
||||
mKey = args.getString(ARG_KEY);
|
||||
isInitPod = args.getBoolean(ARG_INIT_POD);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,7 +67,7 @@ public class PodInfoFragment extends DaggerFragment {
|
|||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.omnipod_initpod_pod_info, container, false);
|
||||
|
||||
TextView titleView = (TextView) rootView.findViewById(R.id.podInfoTitle);
|
||||
TextView titleView = rootView.findViewById(R.id.podInfoTitle);
|
||||
titleView.setText(R.string.omnipod_init_pod_wizard_pod_info_title);
|
||||
titleView.setTextColor(getResources().getColor(com.tech.freak.wizardpager.R.color.review_green));
|
||||
|
||||
|
@ -70,7 +76,6 @@ public class PodInfoFragment extends DaggerFragment {
|
|||
R.string.omnipod_init_pod_wizard_pod_info_init_pod_description : //
|
||||
R.string.omnipod_init_pod_wizard_pod_info_remove_pod_description);
|
||||
|
||||
|
||||
if (isInitPod) {
|
||||
if (createDataOfPod()) {
|
||||
|
||||
|
@ -80,7 +85,6 @@ public class PodInfoFragment extends DaggerFragment {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
@ -108,8 +112,10 @@ public class PodInfoFragment extends DaggerFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
FragmentActivity activity = getActivity();
|
||||
|
||||
if (!(activity instanceof PageFragmentCallbacks)) {
|
||||
throw new ClassCastException("Activity must implement PageFragmentCallbacks");
|
||||
|
@ -124,12 +130,6 @@ public class PodInfoFragment extends DaggerFragment {
|
|||
mCallbacks = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
|
||||
private class PodInfoAdapter extends ArrayAdapter<ReviewItem> {
|
||||
|
||||
private ArrayList<ReviewItem> dataSet;
|
||||
|
|
|
@ -15,27 +15,17 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.In
|
|||
* Created by andy on 29/11/2019
|
||||
*/
|
||||
public class RemoveActionFragment extends InitActionFragment implements PodInitReceiver {
|
||||
private static final String ARG_KEY = "key";
|
||||
|
||||
public static RemoveActionFragment create(String key, PodInitActionType podInitActionType) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_KEY, key);
|
||||
args.putString(InitActionFragment.ARG_KEY, key);
|
||||
args.putSerializable(InitActionFragment.ARG_POD_INIT_ACTION_TYPE, podInitActionType);
|
||||
|
||||
RemoveActionFragment fragment = new RemoveActionFragment();
|
||||
fragment.setArguments(args);
|
||||
fragment.setPodInitActionType(podInitActionType);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public RemoveActionFragment() {
|
||||
this.instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
}
|
||||
|
||||
public void actionOnReceiveResponse(String result) {
|
||||
System.out.println("ACTION: actionOnReceiveResponse: " + result);
|
||||
|
||||
|
@ -67,6 +57,4 @@ public class RemoveActionFragment extends InitActionFragment implements PodInitR
|
|||
setCheckBox(podInitActionType, isSuccess);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManage
|
|||
/**
|
||||
* Created by andy on 4.8.2019
|
||||
*/
|
||||
// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
|
||||
// FIXME Rename this class to EventRileyLinkStatusChanged and use EventOmnipodPumpValuesChanged
|
||||
// for changes in Pod status
|
||||
class EventOmnipodDeviceStatusChange : Event {
|
||||
|
||||
var rileyLinkServiceState: RileyLinkServiceState? = null
|
||||
|
|
Loading…
Reference in a new issue