see previous commit corrent

This commit is contained in:
Andy Rozman 2019-11-30 12:17:02 +00:00
parent a2ad20f616
commit e955331259
12 changed files with 54 additions and 252 deletions

View file

@ -16,6 +16,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod.
import info.nightscout.androidaps.utils.OKDialog
import kotlinx.android.synthetic.main.omnipod_pod_mgmt.*
/**
* Created by andy on 30/08/2019
*/
class PodManagementActivity : NoSplashActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -75,7 +78,7 @@ class PodManagementActivity : NoSplashActivity() {
pagerSettings.setFinishButtonBackground(R.drawable.finish_background)
pagerSettings.setNextButtonBackground(R.drawable.selectable_item_background)
pagerSettings.setBackStringResourceId(R.string.cancel)
pagerSettings.setCancelAction(InitPodCancelAction())
//pagerSettings.setCancelAction(InitPodCancelAction())
val wizardPagerContext = WizardPagerContext.getInstance();

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages;
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod;
import android.app.Activity;
import android.graphics.Color;

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages;
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;

View file

@ -4,6 +4,9 @@ import com.atech.android.library.wizardpager.defs.action.AbstractCancelAction;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
/**
* Created by andy on 12/11/2019
*/
public class InitPodCancelAction extends AbstractCancelAction {
@Override
public void execute(String cancelReason) {

View file

@ -2,6 +2,9 @@ package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod;
import com.atech.android.library.wizardpager.defs.action.AbstractFinishAction;
/**
* Created by andy on 12/11/2019
*/
public class InitPodFinishAction extends AbstractFinishAction {
@Override
public void execute() {

View file

@ -27,9 +27,11 @@ import com.tech.freak.wizardpager.model.PageList;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.InitActionPage;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodInfoFragment;
/**
* Created by andy on 12/11/2019
*/
public class InitPodWizardModel extends AbstractWizardModel {
public InitPodWizardModel(Context context) {
super(context);

View file

@ -35,6 +35,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionStat
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
/**
* Created by andy on 12/11/2019
*/
public class PodInfoFragment extends Fragment {
private static final String ARG_KEY = "key";

View file

@ -10,7 +10,7 @@ import java.util.ArrayList;
/**
* A page asking for a name and an email.
* Created by andy on 12/11/2019
*/
public class PodInfoPage extends Page {
public static final String NAME_DATA_KEY = "name";

View file

@ -1,52 +1,20 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages;
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod;
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;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.InitActionFragment;
/**
* Created by TechFreak on 04/09/2014.
* Created by andy on 29/11/2019
*/
public class RemoveActionFragment extends Fragment implements PodInitReceiver {
public class RemoveActionFragment extends InitActionFragment 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);
@ -61,158 +29,30 @@ public class RemoveActionFragment extends Fragment implements PodInitReceiver {
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");
}
}
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()) {
@ -225,15 +65,5 @@ public class RemoveActionFragment extends Fragment implements PodInitReceiver {
}
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

@ -1,74 +1,31 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages;
package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod;
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;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.InitActionPage;
/**
* 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 RemovePodActionPage extends InitActionPage {
private PodInitActionType podInitActionType;
private boolean actionCompleted = false;
private boolean actionSuccess = false;
public InitActionPage(ModelCallbacks callbacks, String title) {
public RemovePodActionPage(ModelCallbacks callbacks, String title) {
super(callbacks, title);
}
public InitActionPage(ModelCallbacks callbacks, @StringRes int titleId, PodInitActionType podInitActionType) {
super(callbacks, titleId);
this.podInitActionType = podInitActionType;
public RemovePodActionPage(ModelCallbacks callbacks, @StringRes int titleId, PodInitActionType podInitActionType) {
super(callbacks, titleId, 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;
return RemoveActionFragment.create(getKey(), this.podInitActionType);
}
}

View file

@ -21,16 +21,17 @@ import android.content.Context;
import androidx.fragment.app.Fragment;
import com.atech.android.library.wizardpager.model.DisplayTextPage;
import com.atech.android.library.wizardpager.ui.DisplayTextFragment;
import com.tech.freak.wizardpager.model.AbstractWizardModel;
import com.tech.freak.wizardpager.model.PageList;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.InitActionPage;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodInfoFragment;
/**
* Created by andy on 12/11/2019
*/
public class RemovePodWizardModel extends AbstractWizardModel {
public RemovePodWizardModel(Context context) {
@ -47,7 +48,7 @@ public class RemovePodWizardModel extends AbstractWizardModel {
R.string.omnipod_remove_pod_wizard_step1_desc,
R.style.WizardPagePodContent).setRequired(true).setCancelReason("None"),
new InitActionPage(this,
new RemovePodActionPage(this,
R.string.omnipod_remove_pod_wizard_step2_title,
PodInitActionType.DeactivatePodWizardStep
).setRequired(true).setCancelReason("Cancel")

View file

@ -1672,7 +1672,7 @@
<string name="omnipod_remove_pod_wizard_step1_title">Prepare for Pod Removal</string>
<string name="omnipod_remove_pod_wizard_step1_desc">\nPress <b>Next</b> to begin Pod removal process.\n\n\nThis will stop delivery of insulin and deactivate Pod.</string>
<string name="omnipod_remove_pod_wizard_step2_title">Remove the Pod</string>
<string name="omnipod_remove_pod_wizard_step2_action_header">We are trying to communicate with Pod.\n\nWhen all items are checked, you can press Next. If Pod removal fails and you click on Cancel, Pod will be forcefully removed from AAPS.</string>
<string name="omnipod_remove_pod_wizard_step2_action_header">We are trying to communicate with Pod.\n\nWhen all items are checked, you can press Next. If Pod removal fails you need to click on Cancel.</string>
<string name="omnipod_init_pod_wizard_pod_info_remove_pod_description">Pod deactivated.\n\nRemove and discard the Pod.\n\nWhen you are ready, prepare the next Pod and start <b>Init Pod</b> action.</string>