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);
@@ -91,7 +105,6 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
mapCheckBoxes = new HashMap<>();
for (PodInitActionType child : children) {
-
CheckBox checkBox1 = new CheckBox(getContext());
checkBox1.setText(child.getResourceId());
checkBox1.setClickable(false);
@@ -122,15 +135,17 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
}
});
- new InitPodTask(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");
@@ -145,46 +160,16 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
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");
- new InitPodTask(this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
-
- } else {
- System.out.println("ACTION: Not visible");
+ public void onResume() {
+ super.onResume();
+ if (isFirstView) {
+ isFirstView = false;
+ new InitPodTask(injector, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
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
@@ -202,37 +187,37 @@ public class InitActionFragment extends Fragment implements PodInitReceiver {
}
}
-
private void processOnFinishedActions(boolean isOk, String errorMessage) {
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ activity.runOnUiThread(() -> {
+ progressBar.setVisibility(View.GONE);
- getActivity().runOnUiThread(() -> {
+ if (!isOk) {
+ errorView.setVisibility(View.VISIBLE);
+ errorView.setText(errorMessage);
- progressBar.setVisibility(View.GONE);
+ retryButton.setVisibility(View.VISIBLE);
+ }
- if (!isOk) {
- errorView.setVisibility(View.VISIBLE);
- errorView.setText(errorMessage);
+ mPage.setActionCompleted(isOk);
- retryButton.setVisibility(View.VISIBLE);
- }
-
- mPage.setActionCompleted(isOk);
-
- mPage.getData().putString(Page.SIMPLE_DATA_KEY, UUID.randomUUID().toString());
- mPage.notifyDataChanged();
-
- });
+ mPage.getData().putString(Page.SIMPLE_DATA_KEY, UUID.randomUUID().toString());
+ mPage.notifyDataChanged();
+ });
+ }
}
-
public void setCheckBox(PodInitActionType podInitActionType, boolean isSuccess) {
- getActivity().runOnUiThread(() -> {
- mapCheckBoxes.get(podInitActionType).setChecked(isSuccess);
- mapCheckBoxes.get(podInitActionType).setTextColor(isSuccess ? Color.rgb(34, 135, 91) :
- Color.rgb(168, 36, 15));
- });
+ 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));
+ });
+ }
}
-
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java
index 8b34b99193..3ba9145749 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitActionPage.java
@@ -14,7 +14,7 @@ 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 {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodTask.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodTask.java
similarity index 74%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodTask.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodTask.java
index 1ab711871c..5496843cf9 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodTask.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodTask.java
@@ -5,6 +5,7 @@ import android.view.View;
import javax.inject.Inject;
+import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
@@ -15,14 +16,17 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodMa
public class InitPodTask extends AsyncTask {
@Inject ProfileFunction profileFunction;
+ @Inject AapsOmnipodManager aapsOmnipodManager;
private InitActionFragment initActionFragment;
- public InitPodTask(InitActionFragment initActionFragment) {
-
+ public InitPodTask(HasAndroidInjector injector, InitActionFragment initActionFragment) {
+ injector.androidInjector().inject(this);
this.initActionFragment = initActionFragment;
}
+ @Override
protected void onPreExecute() {
+ super.onPreExecute();
initActionFragment.progressBar.setVisibility(View.VISIBLE);
initActionFragment.errorView.setVisibility(View.GONE);
initActionFragment.retryButton.setVisibility(View.GONE);
@@ -30,21 +34,20 @@ public class InitPodTask extends AsyncTask {
@Override
protected String doInBackground(Void... params) {
-
if (initActionFragment.podInitActionType == PodInitActionType.PairAndPrimeWizardStep) {
- initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod(
+ initActionFragment.callResult = aapsOmnipodManager.initPod(
initActionFragment.podInitActionType,
- initActionFragment.instance,
+ initActionFragment,
null
);
} else if (initActionFragment.podInitActionType == PodInitActionType.FillCannulaSetBasalProfileWizardStep) {
- initActionFragment.callResult = AapsOmnipodManager.getInstance().initPod(
+ initActionFragment.callResult = aapsOmnipodManager.initPod(
initActionFragment.podInitActionType,
- initActionFragment.instance,
+ initActionFragment,
profileFunction.getProfile()
);
} else if (initActionFragment.podInitActionType == PodInitActionType.DeactivatePodWizardStep) {
- initActionFragment.callResult = AapsOmnipodManager.getInstance().deactivatePod(initActionFragment.instance);
+ initActionFragment.callResult = aapsOmnipodManager.deactivatePod(initActionFragment);
}
return "OK";
@@ -57,5 +60,4 @@ public class InitPodTask extends AsyncTask {
initActionFragment.actionOnReceiveResponse(result);
}
-
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/FullInitPodWizardModel.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/FullInitPodWizardModel.java
similarity index 97%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/FullInitPodWizardModel.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/FullInitPodWizardModel.java
index a2e7383091..7c70f64c2c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/FullInitPodWizardModel.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/FullInitPodWizardModel.java
@@ -5,7 +5,7 @@ import android.content.Context;
import com.atech.android.library.wizardpager.model.DisplayTextPage;
import com.tech.freak.wizardpager.model.PageList;
-import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.InitActionPage;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/InitPodWizardModel.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/InitPodWizardModel.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/InitPodWizardModel.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/InitPodWizardModel.java
index f5208a48d8..405b4dd063 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/InitPodWizardModel.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/InitPodWizardModel.java
@@ -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);
}
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/RemovePodWizardModel.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/RemovePodWizardModel.java
similarity index 94%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/RemovePodWizardModel.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/RemovePodWizardModel.java
index 57a7f81414..c0088984b4 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/RemovePodWizardModel.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/RemovePodWizardModel.java
@@ -24,7 +24,7 @@ import com.atech.android.library.wizardpager.model.DisplayTextPage;
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.R;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodInfoFragment;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod.RemovePodActionPage;
@@ -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);
}
-
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/ShortInitPodWizardModel.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/ShortInitPodWizardModel.java
similarity index 96%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/ShortInitPodWizardModel.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/ShortInitPodWizardModel.java
index 5499fdf8ec..51676a20a6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/ShortInitPodWizardModel.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/model/ShortInitPodWizardModel.java
@@ -5,7 +5,7 @@ import android.content.Context;
import com.atech.android.library.wizardpager.model.DisplayTextPage;
import com.tech.freak.wizardpager.model.PageList;
-import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInitActionType;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.InitActionPage;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java
similarity index 66%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java
index 70dac25789..80935bad7c 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/InitPodRefreshAction.java
@@ -9,17 +9,14 @@ import org.json.JSONObject;
import javax.inject.Inject;
import dagger.android.HasAndroidInjector;
-import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.Source;
+import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress;
-import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.PodManagementActivity;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.defs.PodActionType;
-import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodDriverState;
-import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@@ -29,17 +26,16 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
*/
public class InitPodRefreshAction extends AbstractCancelAction implements FinishActionInterface {
- private PodManagementActivity podManagementActivity;
private PodActionType actionType;
- @Inject OmnipodUtil omnipodUtil;
+ @Inject PodStateManager podStateManager;
@Inject AAPSLogger aapsLogger;
@Inject SP sp;
@Inject NSUpload nsUpload;
+ @Inject DatabaseHelperInterface databaseHelper;
- public InitPodRefreshAction(HasAndroidInjector injector, PodManagementActivity podManagementActivity, PodActionType actionType) {
+ public InitPodRefreshAction(HasAndroidInjector injector, PodActionType actionType) {
injector.androidInjector().inject(this);
- this.podManagementActivity = podManagementActivity;
this.actionType = actionType;
}
@@ -48,32 +44,19 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish
if (cancelReason != null && cancelReason.trim().length() > 0) {
this.cancelActionText = cancelReason;
}
-
- if (this.cancelActionText.equals("Cancel")) {
- //AapsOmnipodManager.getInstance().resetPodStatus();
- }
-
- podManagementActivity.refreshButtons();
}
@Override
public void execute() {
if (actionType == PodActionType.InitPod) {
- if (omnipodUtil.getPodSessionState().getSetupProgress().isBefore(SetupProgress.COMPLETED)) {
- omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodInitializing);
- } else {
- omnipodUtil.setDriverState(OmnipodDriverState.Initalized_PodAttached);
+ if (podStateManager.isPodRunning()) {
uploadCareportalEvent(System.currentTimeMillis(), CareportalEvent.SITECHANGE);
}
- } else {
- omnipodUtil.setDriverState(OmnipodDriverState.Initalized_NoPod);
}
-
- podManagementActivity.refreshButtons();
}
private void uploadCareportalEvent(long date, String event) {
- if (MainApp.getDbHelper().getCareportalEventFromTimestamp(date) != null)
+ if (databaseHelper.getCareportalEventFromTimestamp(date) != null)
return;
try {
JSONObject data = new JSONObject();
@@ -86,14 +69,13 @@ public class InitPodRefreshAction extends AbstractCancelAction implements Finish
careportalEvent.source = Source.USER;
careportalEvent.eventType = event;
careportalEvent.json = data.toString();
- MainApp.getDbHelper().createOrUpdate(careportalEvent);
+ databaseHelper.createOrUpdate(careportalEvent);
nsUpload.uploadCareportalEntryToNS(data);
} catch (JSONException e) {
aapsLogger.error(LTag.PUMPCOMM, "Unhandled exception when uploading SiteChange event.", e);
}
}
-
@Override
public String getFinishActionText() {
return "Finish_OK";
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java
similarity index 73%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java
index 65d032739d..0d4f3c52c6 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoFragment.java
@@ -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;
@@ -18,8 +21,8 @@ import java.util.ArrayList;
import javax.inject.Inject;
import dagger.android.support.DaggerFragment;
-import info.nightscout.androidaps.R;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@@ -28,31 +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 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
@@ -60,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));
@@ -69,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()) {
@@ -79,40 +85,37 @@ public class PodInfoFragment extends DaggerFragment {
}
}
-
return rootView;
}
private boolean createDataOfPod() {
-
- PodSessionState podSessionState = omnipodUtil.getPodSessionState();
-
-// PodSessionState podSessionState = new PodSessionState(DateTimeZone.UTC,
-// 483748738,
-// new DateTime(),
-// new FirmwareVersion(1,0,0),
-// new FirmwareVersion(1,0,0),
-// 574875,
-// 5487584,
-// 1,
-// 1
-// );
-
- if (podSessionState == null)
+ if (podStateManager == null)
return false;
mCurrentReviewItems = new ArrayList<>();
- mCurrentReviewItems.add(new ReviewItem("Pod Address", "" + podSessionState.getAddress(), "33"));
- mCurrentReviewItems.add(new ReviewItem("Activated At", podSessionState.getActivatedAt().toString("dd.MM.yyyy HH:mm:ss"), "34"));
- mCurrentReviewItems.add(new ReviewItem("Firmware Version", podSessionState.getPiVersion().toString(), "35"));
- mCurrentReviewItems.add(new ReviewItem("LOT", "" + podSessionState.getLot(), "36"));
+ mCurrentReviewItems.add(new ReviewItem("Pod Address", "" + podStateManager.getAddress(), "33"));
+ mCurrentReviewItems.add(new ReviewItem("Activated At", podStateManager.getActivatedAt() == null ? "Not activated yet" : podStateManager.getActivatedAt().toString("dd.MM.yyyy HH:mm:ss"), "34"));
+ if (podStateManager.getLot() != null) {
+ mCurrentReviewItems.add(new ReviewItem("LOT", "" + podStateManager.getLot(), "35"));
+ }
+ if (podStateManager.getTid() != null) {
+ mCurrentReviewItems.add(new ReviewItem("TID", "" + podStateManager.getLot(), "36"));
+ }
+ if (podStateManager.getPiVersion() != null) {
+ mCurrentReviewItems.add(new ReviewItem("Pi Version", podStateManager.getPiVersion().toString(), "37"));
+ }
+ if (podStateManager.getPmVersion() != null) {
+ mCurrentReviewItems.add(new ReviewItem("Pm Version", podStateManager.getPmVersion().toString(), "38"));
+ }
return true;
}
@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");
@@ -127,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 {
private ArrayList dataSet;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoPage.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoPage.java
similarity index 100%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoPage.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/pages/PodInfoPage.java
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java
similarity index 86%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java
index 2531185697..935ee65085 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemoveActionFragment.java
@@ -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.putSerializable(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);
}
}
-
-
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java
similarity index 99%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java
index 7f5b2b8503..444c8a4b11 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/removepod/RemovePodActionPage.java
@@ -11,7 +11,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.In
/**
* Created by andy on 12/11/2019
- *
*/
public class RemovePodActionPage extends InitActionPage {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java
similarity index 70%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java
index 67fae56e08..f1c0474829 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/OmnipodPumpStatus.java
@@ -10,113 +10,76 @@ import info.nightscout.androidaps.plugins.pump.common.data.PumpStatus;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
+import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem;
-import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError;
-import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
-import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
-import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* Created by andy on 4.8.2019
*/
@Singleton
+@Deprecated
public class OmnipodPumpStatus extends PumpStatus {
+ // TODO remove all fields that can also be obtained via PodStateManager
+ // We can probably get rid of this class altogether
- private final ResourceHelper resourceHelper;
private final SP sp;
private final RileyLinkUtil rileyLinkUtil;
private final RxBusWrapper rxBus;
- public String errorDescription = null;
+ public String rileyLinkErrorDescription = null;
public String rileyLinkAddress = null;
public boolean inPreInit = true;
// statuses
- public RileyLinkServiceState rileyLinkServiceState = RileyLinkServiceState.NotStarted;
- public RileyLinkError rileyLinkError;
public double currentBasal = 0;
public long tempBasalStart;
public long tempBasalEnd;
public Double tempBasalAmount = 0.0d;
public Integer tempBasalLength;
public long tempBasalPumpId;
- public PodSessionState podSessionState;
public PumpType pumpType;
public String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}";
- public String podNumber;
- public PodDeviceState podDeviceState = PodDeviceState.NeverContacted;
- public Boolean podAvailable = false;
- public boolean podAvailibityChecked = false;
- public boolean ackAlertsAvailable = false;
- public String ackAlertsText = null;
-
public boolean beepBolusEnabled = true;
public boolean beepBasalEnabled = true;
public boolean beepSMBEnabled = true;
public boolean beepTBREnabled = true;
public boolean podDebuggingOptionsEnabled = false;
- public String podLotNumber = "???";
public boolean timeChangeEventEnabled = true;
- public OmnipodDriverState driverState = OmnipodDriverState.NotInitalized;
private PumpDeviceState pumpDeviceState;
@Inject
- public OmnipodPumpStatus(ResourceHelper resourceHelper,
- info.nightscout.androidaps.utils.sharedPreferences.SP sp,
+ public OmnipodPumpStatus(SP sp,
RxBusWrapper rxBus,
RileyLinkUtil rileyLinkUtil) {
super(PumpType.Insulet_Omnipod);
- this.resourceHelper = resourceHelper;
this.sp = sp;
this.rxBus = rxBus;
this.rileyLinkUtil = rileyLinkUtil;
initSettings();
}
-
@Override
public void initSettings() {
this.activeProfileName = "";
this.reservoirRemainingUnits = 75d;
this.batteryRemaining = 75;
this.lastConnection = sp.getLong(OmnipodConst.Statistics.LastGoodPumpCommunicationTime, 0L);
- this.lastDataTime = this.lastConnection;
this.pumpType = PumpType.Insulet_Omnipod;
- this.podAvailable = false;
- }
-
-
- public String getErrorInfo() {
- //verifyConfiguration();
-
- return (this.errorDescription == null) ? "-" : this.errorDescription;
}
+ // For Omnipod, this method only returns a RileyLink error description
@Override
- public E getCustomData(String key, Class clazz) {
- switch(key) {
- case "POD_LOT_NUMBER":
- return (E)podLotNumber;
-
- case "POD_AVAILABLE":
- return (E)podAvailable;
-
- default:
- return null;
- }
-
+ public String getErrorInfo() {
+ return this.rileyLinkErrorDescription;
}
-
// public boolean setNotInPreInit() {
// this.inPreInit = false;
//
@@ -146,23 +109,14 @@ public class OmnipodPumpStatus extends PumpStatus {
@Override
public String toString() {
return "OmnipodPumpStatus{" +
- "errorDescription='" + errorDescription + '\'' +
+ "rileyLinkErrorDescription='" + rileyLinkErrorDescription + '\'' +
", rileyLinkAddress='" + rileyLinkAddress + '\'' +
", inPreInit=" + inPreInit +
- ", rileyLinkServiceState=" + rileyLinkServiceState +
- ", rileyLinkError=" + rileyLinkError +
- ", currentBasal=" + currentBasal +
", tempBasalStart=" + tempBasalStart +
", tempBasalEnd=" + tempBasalEnd +
", tempBasalAmount=" + tempBasalAmount +
", tempBasalLength=" + tempBasalLength +
- ", podSessionState=" + podSessionState +
", regexMac='" + regexMac + '\'' +
- ", podNumber='" + podNumber + '\'' +
- ", podDeviceState=" + podDeviceState +
- ", podAvailable=" + podAvailable +
- ", ackAlertsAvailable=" + ackAlertsAvailable +
- ", ackAlertsText='" + ackAlertsText + '\'' +
", lastDataTime=" + lastDataTime +
", lastConnection=" + lastConnection +
", previousConnection=" + previousConnection +
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java
similarity index 77%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java
index 575fe385ec..645802bd87 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java
@@ -2,41 +2,41 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.comm;
import android.content.Context;
import android.content.Intent;
-import android.text.TextUtils;
-import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
-import info.nightscout.androidaps.MainApp;
-import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.ErrorHelperActivity;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
+import info.nightscout.androidaps.db.OmnipodHistoryRecord;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.Event;
-import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
+import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
+import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
-import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.SetupActionResult;
@@ -50,7 +50,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalMes
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPacketTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalPodProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalResponseException;
-import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalSetupProgressException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.IllegalVersionResponseTypeException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.MessageDecodingException;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.NonceOutOfSyncException;
@@ -61,29 +60,28 @@ import info.nightscout.androidaps.plugins.pump.omnipod.comm.exception.PodReturne
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.StatusResponse;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoRecentPulseLog;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.message.response.podinfo.PodInfoResponse;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.FaultEventCode;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodInfoType;
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.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalScheduleEntry;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
-import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistory;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistoryEntryType;
-import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodAcknowledgeAlertsChanged;
-import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.exception.OmnipodException;
+import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import io.reactivex.disposables.Disposable;
+import io.reactivex.subjects.SingleSubject;
-public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface {
+@Singleton
+public class AapsOmnipodManager implements IOmnipodManager {
+ private final PodStateManager podStateManager;
private final OmnipodUtil omnipodUtil;
private final AAPSLogger aapsLogger;
private final RxBusWrapper rxBus;
@@ -92,21 +90,14 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
private final ActivePluginProvider activePlugin;
private final OmnipodPumpStatus pumpStatus;
private final Context context;
+ private final SP sp;
private final OmnipodManager delegate;
+ private DatabaseHelperInterface databaseHelper;
- //TODO: remove and use injection
- private static AapsOmnipodManager instance;
-
- private Date lastBolusTime;
- private Double lastBolusUnits;
-
- public static AapsOmnipodManager getInstance() {
- return instance;
- }
-
+ @Inject
public AapsOmnipodManager(OmnipodCommunicationManager communicationService,
- PodSessionState podState,
+ PodStateManager podStateManager,
OmnipodPumpStatus pumpStatus,
OmnipodUtil omnipodUtil,
AAPSLogger aapsLogger,
@@ -115,7 +106,12 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
ResourceHelper resourceHelper,
HasAndroidInjector injector,
ActivePluginProvider activePlugin,
- Context context) {
+ Context context,
+ DatabaseHelperInterface databaseHelper) {
+ if (podStateManager == null) {
+ throw new IllegalArgumentException("Pod state manager can not be null");
+ }
+ this.podStateManager = podStateManager;
this.omnipodUtil = omnipodUtil;
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
@@ -124,77 +120,14 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
this.activePlugin = activePlugin;
this.pumpStatus = pumpStatus;
this.context = context;
+ this.databaseHelper = databaseHelper;
+ this.sp = sp;
- delegate = new OmnipodManager(aapsLogger, sp, communicationService, podState, podSessionState -> {
- // Handle pod state changes
- omnipodUtil.setPodSessionState(podSessionState);
- updatePumpStatus(podSessionState);
- });
- instance = this;
+ delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager);
}
- private void updatePumpStatus(PodSessionState podSessionState) {
- if (pumpStatus != null) {
- if (podSessionState == null) {
- pumpStatus.ackAlertsText = null;
- pumpStatus.ackAlertsAvailable = false;
- pumpStatus.lastBolusTime = null;
- pumpStatus.lastBolusAmount = null;
- pumpStatus.reservoirRemainingUnits = 0.0;
- pumpStatus.pumpStatusType = PumpStatusType.Suspended;
- sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
- sendEvent(new EventOmnipodPumpValuesChanged());
- sendEvent(new EventRefreshOverview("Omnipod Pump", false));
- } else {
- // Update active alerts
- if (podSessionState.hasActiveAlerts()) {
- List alerts = translateActiveAlerts(podSessionState);
- String alertsText = TextUtils.join("\n", alerts);
-
- if (!pumpStatus.ackAlertsAvailable || !alertsText.equals(pumpStatus.ackAlertsText)) {
- pumpStatus.ackAlertsAvailable = true;
- pumpStatus.ackAlertsText = TextUtils.join("\n", alerts);
-
- sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
- }
- } else {
- if (pumpStatus.ackAlertsAvailable || StringUtils.isNotEmpty(pumpStatus.ackAlertsText)) {
- pumpStatus.ackAlertsText = null;
- pumpStatus.ackAlertsAvailable = false;
- sendEvent(new EventOmnipodAcknowledgeAlertsChanged());
- }
- }
-
- // Update other info: last bolus, units remaining, suspended
- if (!Objects.equals(lastBolusTime, pumpStatus.lastBolusTime) //
- || !Objects.equals(lastBolusUnits, pumpStatus.lastBolusAmount) //
- || !isReservoirStatusUpToDate(pumpStatus, podSessionState.getReservoirLevel())
- || podSessionState.isSuspended() != PumpStatusType.Suspended.equals(pumpStatus.pumpStatusType)) {
- pumpStatus.lastBolusTime = lastBolusTime;
- pumpStatus.lastBolusAmount = lastBolusUnits;
- pumpStatus.reservoirRemainingUnits = podSessionState.getReservoirLevel() == null ? 75.0 : podSessionState.getReservoirLevel();
- pumpStatus.pumpStatusType = podSessionState.isSuspended() ? PumpStatusType.Suspended : PumpStatusType.Running;
- sendEvent(new EventOmnipodPumpValuesChanged());
-
- if (podSessionState.isSuspended() != PumpStatusType.Suspended.equals(pumpStatus.pumpStatusType)) {
- sendEvent(new EventRefreshOverview("Omnipod Pump", false));
- }
- }
- }
- }
- }
-
- private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
- double expectedUnitsRemaining = unitsRemaining == null ? 75.0 : unitsRemaining;
- return Math.abs(expectedUnitsRemaining - pumpStatus.reservoirRemainingUnits) < 0.000001;
- }
-
- private List translateActiveAlerts(PodSessionState podSessionState) {
- List alerts = new ArrayList<>();
- for (AlertSlot alertSlot : podSessionState.getActiveAlerts().getAlertSlots()) {
- alerts.add(translateAlertType(podSessionState.getConfiguredAlertType(alertSlot)));
- }
- return alerts;
+ public PodStateManager getPodStateManager() {
+ return podStateManager;
}
@Override
@@ -202,13 +135,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
long time = System.currentTimeMillis();
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
try {
- int address = obtainNextPodAddress();
-
- Disposable disposable = delegate.pairAndPrime(address).subscribe(res -> //
+ Disposable disposable = delegate.pairAndPrime().subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
- removeNextPodAddress();
-
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
@@ -226,6 +155,9 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
}
Disposable disposable = delegate.insertCannula(basalSchedule).subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, profile));
+
+ rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED));
+
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
@@ -270,8 +202,6 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
podInitReceiver.returnInitTaskStatus(PodInitActionType.DeactivatePodWizardStep, true, null);
- this.omnipodUtil.setPodSessionState(null);
-
return new PumpEnactResult(injector).success(true).enacted(true);
}
@@ -301,19 +231,15 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
}
-
return new PumpEnactResult(injector).success(true).enacted(true);
}
@Override
public PumpEnactResult resetPodStatus() {
- delegate.resetPodState(true);
+ getPodStateManager().removeState();
reportImplicitlyCanceledTbr();
- this.omnipodUtil.setPodSessionState(null);
- this.omnipodUtil.removeNextPodAddress();
-
addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.ResetPodState, null);
return new PumpEnactResult(injector).success(true).enacted(true);
@@ -348,52 +274,82 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
showErrorDialog(getStringResource(R.string.omnipod_bolus_failed_uncertain), R.raw.boluserror);
}
+ detailedBolusInfo.date = bolusStarted.getTime();
+ detailedBolusInfo.source = Source.PUMP;
+
+ // Store the current bolus for in case the app crashes, gets killed, the phone dies or whatever before the bolus finishes
+ // If we have a stored value for the current bolus on startup, we'll create a Treatment for it
+ // However this can potentially be hours later if for example your phone died and you can't charge it
+ // FIXME !!!
+ // The proper solution here would be to create a treatment right after the bolus started,
+ // and update that treatment after the bolus has finished in case the actual units delivered don't match the requested bolus units
+ // That way, the bolus would immediately be sent to NS so in case the phone dies you could still see the bolus
+ // Unfortunately this doesn't work because
+ // a) when cancelling a bolus within a few seconds of starting it, after updating the Treatment,
+ // we get a new treatment event from NS containing the originally created treatment with the original insulin amount.
+ // This event is processed in TreatmentService.createTreatmentFromJsonIfNotExists().
+ // Opposed to what the name of this method suggests, it does createOrUpdate,
+ // overwriting the insulin delivered with the original value.
+ // So practically it seems impossible to update a Treatment when using NS
+ // b) we only send newly created treatments to NS, so the insulin amount in NS would never be updated
+ //
+ // I discussed this with the AAPS team but nobody seems to care so we're stuck with this ugly workaround for now
+ try {
+ sp.putString(OmnipodConst.Prefs.CurrentBolus, omnipodUtil.getGsonInstance().toJson(detailedBolusInfo));
+ } catch (Exception ex) {
+ aapsLogger.error(LTag.PUMP, "Failed to store current bolus to SP", ex);
+ }
+
// Wait for the bolus to finish
OmnipodManager.BolusDeliveryResult bolusDeliveryResult =
bolusCommandResult.getDeliveryResultSubject().blockingGet();
- double unitsDelivered = bolusDeliveryResult.getUnitsDelivered();
+ detailedBolusInfo.insulin = bolusDeliveryResult.getUnitsDelivered();
- if (pumpStatus != null && !detailedBolusInfo.isSMB) {
- lastBolusTime = pumpStatus.lastBolusTime = bolusStarted;
- lastBolusUnits = pumpStatus.lastBolusAmount = unitsDelivered;
- }
+ addBolusToHistory(detailedBolusInfo);
- long pumpId = addSuccessToHistory(bolusStarted.getTime(), PodHistoryEntryType.SetBolus, unitsDelivered + ";" + detailedBolusInfo.carbs);
+ sp.remove(OmnipodConst.Prefs.CurrentBolus);
- detailedBolusInfo.date = bolusStarted.getTime();
- detailedBolusInfo.insulin = unitsDelivered;
- detailedBolusInfo.pumpId = pumpId;
- detailedBolusInfo.source = Source.PUMP;
-
- activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
-
- if (delegate.getPodState().hasFaultEvent()) {
- showPodFaultErrorDialog(delegate.getPodState().getFaultEvent().getFaultEventCode(), R.raw.urgentalarm);
- }
-
- return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(unitsDelivered);
+ return new PumpEnactResult(injector).success(true).enacted(true).bolusDelivered(detailedBolusInfo.insulin);
}
@Override
public PumpEnactResult cancelBolus() {
- long time = System.currentTimeMillis();
+ SingleSubject bolusCommandExecutionSubject = delegate.getBolusCommandExecutionSubject();
+ if (bolusCommandExecutionSubject != null) {
+ // Wait until the bolus command has actually been executed before sending the cancel bolus command
+ aapsLogger.debug(LTag.PUMP, "Cancel bolus was requested, but the bolus command is still being executed. Awaiting bolus command execution");
+ boolean bolusCommandSuccessfullyExecuted = bolusCommandExecutionSubject.blockingGet();
+ if (bolusCommandSuccessfullyExecuted) {
+ aapsLogger.debug(LTag.PUMP, "Bolus command successfully executed. Proceeding bolus cancellation");
+ } else {
+ aapsLogger.debug(LTag.PUMP, "Not cancelling bolus: bolus command failed");
+ String comment = getStringResource(R.string.omnipod_bolus_did_not_succeed);
+ addFailureToHistory(System.currentTimeMillis(), PodHistoryEntryType.CancelBolus, comment);
+ return new PumpEnactResult(injector).success(true).enacted(false).comment(comment);
+ }
+ }
+
String comment = null;
- while (delegate.hasActiveBolus()) {
+ for (int i = 1; delegate.hasActiveBolus(); i++) {
+ aapsLogger.debug(LTag.PUMP, "Attempting to cancel bolus (#{})", i);
try {
delegate.cancelBolus(isBolusBeepsEnabled());
- addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
+ aapsLogger.debug(LTag.PUMP, "Successfully cancelled bolus", i);
+ addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (PodFaultException ex) {
+ aapsLogger.debug(LTag.PUMP, "Successfully cancelled bolus (implicitly because of a Pod Fault)");
showPodFaultErrorDialog(ex.getFaultEvent().getFaultEventCode(), null);
- addSuccessToHistory(time, PodHistoryEntryType.CancelBolus, null);
+ addSuccessToHistory(System.currentTimeMillis(), PodHistoryEntryType.CancelBolus, null);
return new PumpEnactResult(injector).success(true).enacted(true);
} catch (Exception ex) {
+ aapsLogger.debug(LTag.PUMP, "Failed to cancel bolus", ex);
comment = handleAndTranslateException(ex);
}
}
- addFailureToHistory(time, PodHistoryEntryType.CancelBolus, comment);
+ addFailureToHistory(System.currentTimeMillis(), PodHistoryEntryType.CancelBolus, comment);
return new PumpEnactResult(injector).success(false).enacted(false).comment(comment);
}
@@ -543,11 +499,13 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
}
public boolean isInitialized() {
- return delegate.isReadyForDelivery();
+ return delegate.isPodRunning();
}
- public String getPodStateAsString() {
- return delegate.getPodStateAsString();
+ public void addBolusToHistory(DetailedBolusInfo detailedBolusInfo) {
+ long pumpId = addSuccessToHistory(detailedBolusInfo.date, PodHistoryEntryType.SetBolus, detailedBolusInfo.insulin + ";" + detailedBolusInfo.carbs);
+ detailedBolusInfo.pumpId = pumpId;
+ activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
}
private void reportImplicitlyCanceledTbr() {
@@ -579,44 +537,30 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
}
private long addToHistory(long requestTime, PodHistoryEntryType entryType, Object data, boolean success) {
- PodHistory podHistory = new PodHistory(requestTime, entryType);
+ OmnipodHistoryRecord omnipodHistoryRecord = new OmnipodHistoryRecord(requestTime, entryType.getCode());
if (data != null) {
if (data instanceof String) {
- podHistory.setData((String) data);
+ omnipodHistoryRecord.setData((String) data);
} else {
- podHistory.setData(omnipodUtil.getGsonInstance().toJson(data));
+ omnipodHistoryRecord.setData(omnipodUtil.getGsonInstance().toJson(data));
}
}
- podHistory.setSuccess(success);
- podHistory.setPodSerial(pumpStatus.podNumber);
+ omnipodHistoryRecord.setSuccess(success);
+ omnipodHistoryRecord.setPodSerial(podStateManager.hasPodState() ? String.valueOf(podStateManager.getAddress()) : "None");
- MainApp.getDbHelper().createOrUpdate(podHistory);
+ databaseHelper.createOrUpdate(omnipodHistoryRecord);
- return podHistory.getPumpId();
- }
-
- private int obtainNextPodAddress() {
- Integer nextPodAddress = this.omnipodUtil.getNextPodAddress();
- if (nextPodAddress == null) {
- nextPodAddress = OmnipodManager.generateRandomAddress();
- this.omnipodUtil.setNextPodAddress(nextPodAddress);
- }
-
- return nextPodAddress;
- }
-
- private void removeNextPodAddress() {
- this.omnipodUtil.removeNextPodAddress();
+ return omnipodHistoryRecord.getPumpId();
}
private void handleSetupActionResult(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, SetupActionResult res, long time, Profile profile) {
String comment = null;
switch (res.getResultType()) {
case FAILURE: {
- aapsLogger.error(LTag.PUMP, "Setup action failed: illegal setup progress: {}", res.getSetupProgress());
- comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state, res.getSetupProgress());
+ aapsLogger.error(LTag.PUMP, "Setup action failed: illegal setup progress: {}", res.getPodProgressStatus());
+ comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state, res.getPodProgressStatus());
}
break;
case VERIFICATION_FAILURE: {
@@ -651,8 +595,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
comment = getStringResource(R.string.omnipod_driver_error_crc_mismatch);
} else if (ex instanceof IllegalPacketTypeException) {
comment = getStringResource(R.string.omnipod_driver_error_invalid_packet_type);
- } else if (ex instanceof IllegalPodProgressException || ex instanceof IllegalSetupProgressException
- || ex instanceof IllegalDeliveryStatusException) {
+ } else if (ex instanceof IllegalPodProgressException || ex instanceof IllegalDeliveryStatusException) {
comment = getStringResource(R.string.omnipod_driver_error_invalid_progress_state);
} else if (ex instanceof IllegalVersionResponseTypeException) {
comment = getStringResource(R.string.omnipod_driver_error_invalid_response);
@@ -672,7 +615,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
comment = getStringResource(R.string.omnipod_driver_error_not_enough_data);
} else if (ex instanceof PodFaultException) {
FaultEventCode faultEventCode = ((PodFaultException) ex).getFaultEvent().getFaultEventCode();
- showPodFaultErrorDialog(faultEventCode, R.raw.urgentalarm);
+ showPodFaultErrorDialog(faultEventCode);
comment = createPodFaultErrorMessage(faultEventCode);
} else if (ex instanceof PodReturnedErrorResponseException) {
comment = getStringResource(R.string.omnipod_driver_error_pod_returned_error_response);
@@ -700,15 +643,23 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
rxBus.send(event);
}
+ private void showPodFaultErrorDialog(FaultEventCode faultEventCode) {
+ showErrorDialog(createPodFaultErrorMessage(faultEventCode), null);
+ }
+
private void showPodFaultErrorDialog(FaultEventCode faultEventCode, Integer sound) {
showErrorDialog(createPodFaultErrorMessage(faultEventCode), sound);
}
+ private void showErrorDialog(String message) {
+ showErrorDialog(message, null);
+ }
+
private void showErrorDialog(String message, Integer sound) {
Intent intent = new Intent(context, ErrorHelperActivity.class);
- intent.putExtra("soundid", sound == null ? 0 : sound);
+ intent.putExtra("soundid", sound);
intent.putExtra("status", message);
- intent.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror));
+ intent.putExtra("title", resourceHelper.gs(R.string.error));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
@@ -724,28 +675,6 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
sendEvent(new EventNewNotification(notification));
}
- private String translateAlertType(AlertType alertType) {
- if (alertType == null) {
- return getStringResource(R.string.omnipod_alert_unknown_alert);
- }
- switch (alertType) {
- case FINISH_PAIRING_REMINDER:
- return getStringResource(R.string.omnipod_alert_finish_pairing_reminder);
- case FINISH_SETUP_REMINDER:
- return getStringResource(R.string.omnipod_alert_finish_setup_reminder_reminder);
- case EXPIRATION_ALERT:
- return getStringResource(R.string.omnipod_alert_expiration);
- case EXPIRATION_ADVISORY_ALERT:
- return getStringResource(R.string.omnipod_alert_expiration_advisory);
- case SHUTDOWN_IMMINENT_ALARM:
- return getStringResource(R.string.omnipod_alert_shutdown_imminent);
- case LOW_RESERVOIR_ALERT:
- return getStringResource(R.string.omnipod_alert_low_reservoir);
- default:
- return alertType.name();
- }
- }
-
private boolean isBolusBeepsEnabled() {
return this.pumpStatus.beepBolusEnabled;
}
diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsPodStateManager.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsPodStateManager.java
new file mode 100644
index 0000000000..14ee37ea95
--- /dev/null
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsPodStateManager.java
@@ -0,0 +1,108 @@
+package info.nightscout.androidaps.plugins.pump.omnipod.driver.comm;
+
+import java.util.Date;
+import java.util.Objects;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import info.nightscout.androidaps.events.Event;
+import info.nightscout.androidaps.events.EventRefreshOverview;
+import info.nightscout.androidaps.logging.AAPSLogger;
+import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
+import info.nightscout.androidaps.plugins.pump.common.defs.PumpStatusType;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
+import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
+import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
+import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
+import info.nightscout.androidaps.utils.DateUtil;
+import info.nightscout.androidaps.utils.resources.ResourceHelper;
+import info.nightscout.androidaps.utils.sharedPreferences.SP;
+
+@Singleton
+public class AapsPodStateManager extends PodStateManager {
+ private final AAPSLogger aapsLogger;
+ private final SP sp;
+ private final OmnipodPumpStatus omnipodPumpStatus;
+ private final RxBusWrapper rxBus;
+
+ @Inject
+ public AapsPodStateManager(AAPSLogger aapsLogger, SP sp, OmnipodPumpStatus omnipodPumpStatus,
+ RxBusWrapper rxBus) {
+ super(aapsLogger);
+
+ if (aapsLogger == null) {
+ throw new IllegalArgumentException("aapsLogger can not be null");
+ }
+ if (sp == null) {
+ throw new IllegalArgumentException("sp can not be null");
+ }
+ if (omnipodPumpStatus == null) {
+ throw new IllegalArgumentException("omnipodPumpStatus can not be null");
+ }
+ if (rxBus == null) {
+ throw new IllegalArgumentException("rxBus can not be null");
+ }
+
+ this.aapsLogger = aapsLogger;
+ this.sp = sp;
+ this.omnipodPumpStatus = omnipodPumpStatus;
+ this.rxBus = rxBus;
+ }
+
+ @Override
+ protected String readPodState() {
+ return sp.getString(OmnipodConst.Prefs.PodState, "");
+ }
+
+ @Override
+ protected void storePodState(String podState) {
+ sp.putString(OmnipodConst.Prefs.PodState, podState);
+ }
+
+ @Override
+ protected void notifyPodStateChanged() {
+ if (!hasPodState()) {
+ omnipodPumpStatus.lastBolusTime = null;
+ omnipodPumpStatus.lastBolusAmount = null;
+ omnipodPumpStatus.reservoirRemainingUnits = 0.0;
+ // TODO this does not seem to set the pump status to suspended anymore
+ // Also, verify that AAPS is aware that no insulin is delivered anymore at this point
+ omnipodPumpStatus.pumpStatusType = PumpStatusType.Suspended;
+ sendEvent(new EventRefreshOverview("Omnipod Pump", false));
+ } else {
+ Date lastBolusStartTime = getLastBolusStartTime() == null ? null : getLastBolusStartTime().toDate();
+ Double lastBolusAmount = getLastBolusAmount();
+
+ // Update other info: last bolus, units remaining, suspended
+ boolean suspended = isSuspended() || !isPodRunning();
+ if (Objects.equals(lastBolusStartTime, omnipodPumpStatus.lastBolusTime) //
+ || !Objects.equals(lastBolusAmount, omnipodPumpStatus.lastBolusAmount) //
+ || !isReservoirStatusUpToDate(omnipodPumpStatus, getReservoirLevel())
+ || suspended != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType)) {
+ omnipodPumpStatus.lastBolusTime = lastBolusStartTime;
+ omnipodPumpStatus.lastBolusAmount = lastBolusAmount;
+ omnipodPumpStatus.reservoirRemainingUnits = getReservoirLevel() == null ? 75.0 : getReservoirLevel();
+
+ boolean sendRefreshOverviewEvent = suspended != PumpStatusType.Suspended.equals(omnipodPumpStatus.pumpStatusType);
+ // TODO this does not seem to set the pump status to suspended anymore
+ // Also, verify that AAPS is aware that no insulin is delivered anymore at this point
+ omnipodPumpStatus.pumpStatusType = suspended ? PumpStatusType.Suspended : PumpStatusType.Running;
+
+ if (sendRefreshOverviewEvent) {
+ sendEvent(new EventRefreshOverview("Omnipod Pump", false));
+ }
+ }
+ }
+ sendEvent(new EventOmnipodPumpValuesChanged());
+ }
+
+ private static boolean isReservoirStatusUpToDate(OmnipodPumpStatus pumpStatus, Double unitsRemaining) {
+ double expectedUnitsRemaining = unitsRemaining == null ? 75.0 : unitsRemaining;
+ return Math.abs(expectedUnitsRemaining - pumpStatus.reservoirRemainingUnits) < 0.000001;
+ }
+
+ private void sendEvent(Event event) {
+ rxBus.send(event);
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java
similarity index 92%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java
index 981796b497..351a845e8d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/db/PodHistoryEntryType.java
@@ -5,8 +5,8 @@ import androidx.annotation.StringRes;
import java.util.HashMap;
import java.util.Map;
-import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
/**
* Created by andy on 24.11.2019
@@ -37,8 +37,7 @@ public enum PodHistoryEntryType {
SuspendDelivery(60, R.string.omnipod_cmd_suspend_delivery, PumpHistoryEntryGroup.Basal),
ResumeDelivery(61, R.string.omnipod_cmd_resume_delivery, PumpHistoryEntryGroup.Basal),
- UnknownEntryType(99, R.string.omnipod_cmd_unknown_entry)
- ;
+ UnknownEntryType(99, R.string.omnipod_cmd_unknown_entry);
private int code;
private static Map instanceMap;
@@ -48,7 +47,6 @@ public enum PodHistoryEntryType {
private PumpHistoryEntryGroup group;
-
static {
instanceMap = new HashMap<>();
@@ -57,7 +55,6 @@ public enum PodHistoryEntryType {
}
}
-
PodHistoryEntryType(int code, @StringRes int resourceId) {
this.code = code;
this.resourceId = resourceId;
@@ -77,6 +74,9 @@ public enum PodHistoryEntryType {
return this.group;
}
+ public static PodHistoryEntryType getByCode(long code) {
+ return getByCode((int) code);
+ }
public static PodHistoryEntryType getByCode(int code) {
if (instanceMap.containsKey(code)) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java
similarity index 54%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java
index 698762bb15..d39559e4b5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIComm.java
@@ -3,9 +3,10 @@ package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
+import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
+import info.nightscout.androidaps.plugins.pump.omnipod.data.RLHistoryItemOmnipod;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
-import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
/**
* Created by andy on 4.8.2019
@@ -14,23 +15,22 @@ public class OmnipodUIComm {
private final HasAndroidInjector injector;
private final AAPSLogger aapsLogger;
- private final OmnipodUtil omnipodUtil;
- private final OmnipodCommunicationManagerInterface omnipodCommunicationManager;
private final OmnipodUIPostprocessor omnipodUIPostprocessor;
-
+ private final IOmnipodManager omnipodCommunicationManager;
+ private RileyLinkUtil rileyLinkUtil;
public OmnipodUIComm(
HasAndroidInjector injector,
AAPSLogger aapsLogger,
- OmnipodUtil omnipodUtil,
OmnipodUIPostprocessor omnipodUIPostprocessor,
- OmnipodCommunicationManagerInterface omnipodCommunicationManager
+ IOmnipodManager omnipodCommunicationManager,
+ RileyLinkUtil rileyLinkUtil
) {
this.injector = injector;
this.aapsLogger = aapsLogger;
- this.omnipodUtil = omnipodUtil;
this.omnipodUIPostprocessor = omnipodUIPostprocessor;
this.omnipodCommunicationManager = omnipodCommunicationManager;
+ this.rileyLinkUtil = rileyLinkUtil;
}
@@ -40,36 +40,10 @@ public class OmnipodUIComm {
OmnipodUITask task = new OmnipodUITask(injector, commandType, parameters);
- omnipodUtil.setCurrentCommand(commandType);
-
- // new Thread(() -> {
- // LOG.warn("@@@ Start Thread");
- //
- // task.execute(getCommunicationManager());
- //
- // LOG.warn("@@@ End Thread");
- // });
+ rileyLinkUtil.getRileyLinkHistory().add(new RLHistoryItemOmnipod(commandType));
task.execute(this.omnipodCommunicationManager);
- // for (int i = 0; i < getMaxWaitTime(commandType); i++) {
- // synchronized (task) {
- // // try {
- // //
- // // //task.wait(1000);
- // // } catch (InterruptedException e) {
- // // LOG.error("executeCommand InterruptedException", e);
- // // }
- //
- //
- // SystemClock.sleep(1000);
- // }
- //
- // if (task.isReceived()) {
- // break;
- // }
- // }
-
if (!task.isReceived()) {
aapsLogger.warn(LTag.PUMP, "Reply not received for " + commandType);
}
diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java
new file mode 100644
index 0000000000..33d734bdde
--- /dev/null
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUIPostprocessor.java
@@ -0,0 +1,64 @@
+package info.nightscout.androidaps.plugins.pump.omnipod.driver.ui;
+
+import java.util.Date;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import info.nightscout.androidaps.data.DetailedBolusInfo;
+import info.nightscout.androidaps.data.PumpEnactResult;
+import info.nightscout.androidaps.logging.AAPSLogger;
+import info.nightscout.androidaps.logging.LTag;
+import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
+
+/**
+ * Created by andy on 4.8.2019
+ */
+// TODO remove once OmnipodPumpStatus has been removed
+@Singleton
+public class OmnipodUIPostprocessor {
+ private final AAPSLogger aapsLogger;
+ private final OmnipodPumpStatus pumpStatus;
+
+ @Inject
+ public OmnipodUIPostprocessor(AAPSLogger aapsLogger, OmnipodPumpStatus pumpStatus) {
+ this.aapsLogger = aapsLogger;
+ this.pumpStatus = pumpStatus;
+ }
+
+ // this is mostly intended for command that return certain statuses (Remaining Insulin, ...), and
+ // where responses won't be directly used
+ public void postProcessData(OmnipodUITask uiTask) {
+
+ switch (uiTask.commandType) {
+ case SetBolus:
+ if (uiTask.returnData != null) {
+
+ PumpEnactResult result = uiTask.returnData;
+
+ DetailedBolusInfo detailedBolusInfo = (DetailedBolusInfo) uiTask.getObjectFromParameters(0);
+
+ if (result.success) {
+ boolean isSmb = detailedBolusInfo.isSMB;
+
+ if (!isSmb) {
+ pumpStatus.lastBolusAmount = detailedBolusInfo.insulin;
+ pumpStatus.lastBolusTime = new Date();
+ }
+ }
+ }
+ break;
+
+ case CancelTemporaryBasal:
+ pumpStatus.tempBasalStart = 0;
+ pumpStatus.tempBasalEnd = 0;
+ pumpStatus.tempBasalAmount = null;
+ pumpStatus.tempBasalLength = null;
+ break;
+
+ default:
+ aapsLogger.debug(LTag.PUMP, "Post-processing not implemented for {}.", uiTask.commandType.name());
+
+ }
+ }
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java
similarity index 85%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java
index 3479a299eb..140f1de335 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/ui/OmnipodUITask.java
@@ -10,15 +10,12 @@ import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.IOmnipodManager;
import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommandType;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.OmnipodCommunicationManagerInterface;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodDeviceState;
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.PodResponseType;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
-import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodDeviceStatusChange;
-import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
/**
@@ -57,7 +54,7 @@ public class OmnipodUITask {
}
- public void execute(OmnipodCommunicationManagerInterface communicationManager) {
+ public void execute(IOmnipodManager communicationManager) {
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ In execute. {}", commandType);
@@ -191,10 +188,9 @@ public class OmnipodUITask {
}
+ // FIXME remove once OmnipodPumpStatus has been removed
public void postProcess(OmnipodUIPostprocessor postprocessor) {
- EventOmnipodDeviceStatusChange statusChange;
-
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. {}", commandType);
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType);
@@ -204,22 +200,9 @@ public class OmnipodUITask {
aapsLogger.debug(LTag.PUMP, "OmnipodUITask: @@@ postProcess. responseType={}", responseType);
- if (responseType == PodResponseType.Invalid) {
- statusChange = new EventOmnipodDeviceStatusChange(PodDeviceState.ErrorWhenCommunicating,
- "Unsupported command in OmnipodUITask");
- omnipodPumpStatus.setLastFailedCommunicationToNow();
- rxBus.send(statusChange);
- } else if (responseType == PodResponseType.Error) {
- statusChange = new EventOmnipodDeviceStatusChange(PodDeviceState.ErrorWhenCommunicating,
- errorDescription);
- omnipodPumpStatus.setLastFailedCommunicationToNow();
- rxBus.send(statusChange);
- } else {
+ if (!responseType.isError()) {
omnipodPumpStatus.setLastCommunicationToNow();
- rxBus.send(new EventOmnipodPumpValuesChanged());
}
-
- omnipodUtil.setPodDeviceState(PodDeviceState.Sleeping);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodAcknowledgeAlertsChanged.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodAcknowledgeAlertsChanged.kt
similarity index 73%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodAcknowledgeAlertsChanged.kt
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodAcknowledgeAlertsChanged.kt
index 9938319858..0bc2b5dc4b 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodAcknowledgeAlertsChanged.kt
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodAcknowledgeAlertsChanged.kt
@@ -5,4 +5,5 @@ import info.nightscout.androidaps.events.Event
/**
* Created by andy on 04.06.2018.
*/
+// FIXME can be removed, we should just use EventOmnipodPumpValuesChanged
class EventOmnipodAcknowledgeAlertsChanged : Event()
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodPumpValuesChanged.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodPumpValuesChanged.kt
similarity index 100%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodPumpValuesChanged.kt
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodPumpValuesChanged.kt
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodRefreshButtonState.kt b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodRefreshButtonState.kt
similarity index 61%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodRefreshButtonState.kt
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodRefreshButtonState.kt
index 8bbbfd33e6..9ad6f2129e 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodRefreshButtonState.kt
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/events/EventOmnipodRefreshButtonState.kt
@@ -2,4 +2,4 @@ package info.nightscout.androidaps.plugins.pump.omnipod.events
import info.nightscout.androidaps.events.Event
-class EventOmnipodRefreshButtonState (val newState : Boolean): Event()
\ No newline at end of file
+class EventOmnipodRefreshButtonState(val newState: Boolean) : Event()
\ No newline at end of file
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/exception/OmnipodException.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/exception/OmnipodException.java
similarity index 100%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/exception/OmnipodException.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/exception/OmnipodException.java
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java
similarity index 67%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java
index 61fd548f7b..90612bc815 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/service/RileyLinkOmnipodService.java
@@ -1,34 +1,32 @@
package info.nightscout.androidaps.plugins.pump.omnipod.service;
import android.content.Intent;
-import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Binder;
import android.os.IBinder;
-import com.google.gson.Gson;
-
import org.apache.commons.lang3.StringUtils;
import javax.inject.Inject;
-import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
-import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
-import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RileyLinkBLE;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkEncodingType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
-import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkService;
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin;
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
import info.nightscout.androidaps.plugins.pump.omnipod.comm.OmnipodCommunicationManager;
-import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodSessionState;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager;
+import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIComm;
+import info.nightscout.androidaps.plugins.pump.omnipod.driver.ui.OmnipodUIPostprocessor;
+import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodPumpValuesChanged;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
@@ -42,50 +40,42 @@ public class RileyLinkOmnipodService extends RileyLinkService {
@Inject OmnipodPumpPlugin omnipodPumpPlugin;
@Inject OmnipodPumpStatus omnipodPumpStatus;
@Inject OmnipodUtil omnipodUtil;
-
- private static RileyLinkOmnipodService instance;
-
- private OmnipodCommunicationManager omnipodCommunicationManager;
- private AapsOmnipodManager aapsOmnipodManager;
+ @Inject OmnipodUIPostprocessor omnipodUIPostprocessor;
+ @Inject PodStateManager podStateManager;
+ @Inject DatabaseHelperInterface databaseHelper;
+ @Inject AapsOmnipodManager aapsOmnipodManager;
+ @Inject OmnipodCommunicationManager omnipodCommunicationManager;
private IBinder mBinder = new LocalBinder();
private boolean rileyLinkAddressChanged = false;
private boolean inPreInit = true;
+ OmnipodUIComm omnipodUIComm;
public RileyLinkOmnipodService() {
super();
- instance = this;
}
-
- public static RileyLinkOmnipodService getInstance() {
- return instance;
- }
-
-
@Override
public void onConfigurationChanged(Configuration newConfig) {
aapsLogger.warn(LTag.PUMPCOMM, "onConfigurationChanged");
super.onConfigurationChanged(newConfig);
}
-
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
-
@Override
public RileyLinkEncodingType getEncoding() {
return RileyLinkEncodingType.Manchester;
}
-
/**
* If you have customized RileyLinkServiceData you need to override this
*/
+ @Override
public void initRileyLinkServiceData() {
rileyLinkServiceData.targetDevice = RileyLinkTargetDevice.Omnipod;
@@ -94,8 +84,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
// get most recently used RileyLink address
rileyLinkServiceData.rileylinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
- rileyLinkBLE = new RileyLinkBLE(injector, this); // or this
- rfspy = new RFSpy(injector, rileyLinkBLE);
rfspy.startReader();
initializeErosOmnipodManager();
@@ -105,37 +93,16 @@ public class RileyLinkOmnipodService extends RileyLinkService {
}
private void initializeErosOmnipodManager() {
- if (AapsOmnipodManager.getInstance() == null) {
- PodSessionState podState = null;
- if (sp.contains(OmnipodConst.Prefs.PodState) && omnipodUtil.getPodSessionState() == null) {
- try {
- Gson gson = omnipodUtil.getGsonInstance();
- String storedPodState = sp.getString(OmnipodConst.Prefs.PodState, "");
- aapsLogger.info(LTag.PUMPCOMM, "PodSessionState-SP: loaded from SharedPreferences: " + storedPodState);
- podState = gson.fromJson(storedPodState, PodSessionState.class);
- podState.injectDaggerClass(injector);
- omnipodUtil.setPodSessionState(podState);
- } catch (Exception ex) {
- aapsLogger.error(LTag.PUMPCOMM, "Could not deserialize Pod state", ex);
- }
- }
- OmnipodCommunicationManager omnipodCommunicationService = new OmnipodCommunicationManager(injector, rfspy);
- //omnipodCommunicationService.setPumpStatus(omnipodPumpStatus);
- this.omnipodCommunicationManager = omnipodCommunicationService;
-
- this.aapsOmnipodManager = new AapsOmnipodManager(omnipodCommunicationService, podState, omnipodPumpStatus,
- omnipodUtil, aapsLogger, rxBus, sp, resourceHelper, injector, activePlugin, this);
- } else {
- aapsOmnipodManager = AapsOmnipodManager.getInstance();
+ if (omnipodUIComm == null) {
+ omnipodUIComm = new OmnipodUIComm(injector, aapsLogger, omnipodUIPostprocessor, aapsOmnipodManager, rileyLinkUtil);
}
+ rxBus.send(new EventOmnipodPumpValuesChanged());
}
-
- public void resetRileyLinkConfiguration() {
- rfspy.resetRileyLinkConfiguration();
+ public OmnipodUIComm getDeviceCommandExecutor() {
+ return this.omnipodUIComm;
}
-
@Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() {
return omnipodCommunicationManager;
@@ -146,53 +113,34 @@ public class RileyLinkOmnipodService extends RileyLinkService {
this.omnipodPumpStatus.setPumpDeviceState(pumpDeviceState);
}
-
public class LocalBinder extends Binder {
-
public RileyLinkOmnipodService getServiceInstance() {
return RileyLinkOmnipodService.this;
}
}
-
/* private functions */
// PumpInterface - REMOVE
public boolean isInitialized() {
- return RileyLinkServiceState.isReady(rileyLinkServiceData.rileyLinkServiceState);
+ return rileyLinkServiceData.rileyLinkServiceState.isReady();
}
-
@Override
- public String getDeviceSpecificBroadcastsIdentifierPrefix() {
- return null;
- }
-
-
- public boolean handleDeviceSpecificBroadcasts(Intent intent) {
- return false;
- }
-
-
- @Override
- public void registerDeviceSpecificBroadcasts(IntentFilter intentFilter) {
- }
-
-
public boolean verifyConfiguration() {
try {
- omnipodPumpStatus.errorDescription = "-";
+ omnipodPumpStatus.rileyLinkErrorDescription = null;
String rileyLinkAddress = sp.getString(RileyLinkConst.Prefs.RileyLinkAddress, "");
if (StringUtils.isEmpty(rileyLinkAddress)) {
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: no address");
- omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
+ omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
return false;
} else {
if (!rileyLinkAddress.matches(omnipodPumpStatus.regexMac)) {
- omnipodPumpStatus.errorDescription = resourceHelper.gs(R.string.medtronic_error_rileylink_address_invalid);
+ omnipodPumpStatus.rileyLinkErrorDescription = resourceHelper.gs(R.string.omnipod_error_rileylink_address_invalid);
aapsLogger.debug(LTag.PUMPCOMM, "RileyLink address invalid: {}", rileyLinkAddress);
} else {
if (!rileyLinkAddress.equals(this.omnipodPumpStatus.rileyLinkAddress)) {
@@ -217,17 +165,14 @@ public class RileyLinkOmnipodService extends RileyLinkService {
return true;
} catch (Exception ex) {
- this.omnipodPumpStatus.errorDescription = ex.getMessage();
+ this.omnipodPumpStatus.rileyLinkErrorDescription = ex.getMessage();
aapsLogger.error(LTag.PUMPCOMM, "Error on Verification: " + ex.getMessage(), ex);
return false;
}
}
-
private boolean reconfigureService() {
-
if (!inPreInit) {
-
if (rileyLinkAddressChanged) {
rileyLinkUtil.sendBroadcastMessage(RileyLinkConst.Intents.RileyLinkNewAddressSet, this);
rileyLinkAddressChanged = false;
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmniCRC.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmniCRC.java
similarity index 98%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmniCRC.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmniCRC.java
index ba5c91c0b5..77d0cc1aad 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmniCRC.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmniCRC.java
@@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.util;
public class OmniCRC {
- public static final int[] crc16lookup = new int[] {
+ public static final int[] crc16lookup = new int[]{
0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java
similarity index 87%
rename from app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java
rename to omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java
index d12fbd31df..81bbf5d501 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodConst.java
@@ -2,7 +2,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.util;
import org.joda.time.Duration;
-import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
/**
* Created by andy on 4.8.2019
@@ -12,9 +12,9 @@ public class OmnipodConst {
static final String Prefix = "AAPS.Omnipod.";
- public class Prefs {
+ public static class Prefs {
public static final String PodState = Prefix + "pod_state";
- public static final String NextPodAddress = Prefix + "next_pod_address";
+ public static final String CurrentBolus = Prefix + "current_bolus";
public static final int BeepBasalEnabled = R.string.key_omnipod_beep_basal_enabled;
public static final int BeepBolusEnabled = R.string.key_omnipod_beep_bolus_enabled;
public static final int BeepSMBEnabled = R.string.key_omnipod_beep_smb_enabled;
@@ -23,15 +23,13 @@ public class OmnipodConst {
public static final int TimeChangeEventEnabled = R.string.key_omnipod_timechange_enabled;
}
- public class Statistics {
+ public static class Statistics {
public static final String StatsPrefix = "omnipod_";
public static final String FirstPumpStart = Prefix + "first_pump_use";
public static final String LastGoodPumpCommunicationTime = Prefix + "lastGoodPumpCommunicationTime";
- //public static final String LastGoodPumpFrequency = Prefix + "LastGoodPumpFrequency";
public static final String TBRsSet = StatsPrefix + "tbrs_set";
public static final String StandardBoluses = StatsPrefix + "std_boluses_delivered";
public static final String SMBBoluses = StatsPrefix + "smb_boluses_delivered";
- //public static final String LastPumpHistoryEntry = StatsPrefix + "pump_history_entry";
}
public static final double POD_PULSE_SIZE = 0.05;
@@ -45,6 +43,7 @@ public class OmnipodConst {
public static final int DEFAULT_ADDRESS = 0xffffffff;
public static final Duration AVERAGE_BOLUS_COMMAND_COMMUNICATION_DURATION = Duration.millis(1500);
+ public static final Duration AVERAGE_TEMP_BASAL_COMMAND_COMMUNICATION_DURATION = Duration.millis(1500);
public static final Duration SERVICE_DURATION = Duration.standardHours(80);
public static final Duration EXPIRATION_ADVISORY_WINDOW = Duration.standardHours(9);
diff --git a/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java
new file mode 100644
index 0000000000..ddc0022372
--- /dev/null
+++ b/omnipod/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/util/OmnipodUtil.java
@@ -0,0 +1,90 @@
+package info.nightscout.androidaps.plugins.pump.omnipod.util;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonDeserializer;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializer;
+
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeZone;
+import org.joda.time.format.ISODateTimeFormat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import info.nightscout.androidaps.plugins.pump.omnipod.R;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSet;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertSlot;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.AlertType;
+import info.nightscout.androidaps.plugins.pump.omnipod.defs.state.PodStateManager;
+import info.nightscout.androidaps.utils.resources.ResourceHelper;
+
+/**
+ * Created by andy on 4/8/19.
+ */
+@Singleton
+public class OmnipodUtil {
+
+ private final ResourceHelper resourceHelper;
+
+ private Gson gsonInstance = createGson();
+
+ @Inject
+ public OmnipodUtil(ResourceHelper resourceHelper) {
+ this.resourceHelper = resourceHelper;
+ }
+
+ private Gson createGson() {
+ GsonBuilder gsonBuilder = new GsonBuilder()
+ .registerTypeAdapter(DateTime.class, (JsonSerializer) (dateTime, typeOfSrc, context) ->
+ new JsonPrimitive(ISODateTimeFormat.dateTime().print(dateTime)))
+ .registerTypeAdapter(DateTime.class, (JsonDeserializer) (json, typeOfT, context) ->
+ ISODateTimeFormat.dateTime().parseDateTime(json.getAsString()))
+ .registerTypeAdapter(DateTimeZone.class, (JsonSerializer) (timeZone, typeOfSrc, context) ->
+ new JsonPrimitive(timeZone.getID()))
+ .registerTypeAdapter(DateTimeZone.class, (JsonDeserializer) (json, typeOfT, context) ->
+ DateTimeZone.forID(json.getAsString()));
+
+ return gsonBuilder.create();
+ }
+
+ public Gson getGsonInstance() {
+ return this.gsonInstance;
+ }
+
+ public List getTranslatedActiveAlerts(PodStateManager podStateManager) {
+ List translatedAlerts = new ArrayList<>();
+ AlertSet activeAlerts = podStateManager.getActiveAlerts();
+
+ for (AlertSlot alertSlot : activeAlerts.getAlertSlots()) {
+ translatedAlerts.add(translateAlertType(podStateManager.getConfiguredAlertType(alertSlot)));
+ }
+ return translatedAlerts;
+ }
+
+ private String translateAlertType(AlertType alertType) {
+ if (alertType == null) {
+ return resourceHelper.gs(R.string.omnipod_alert_unknown_alert);
+ }
+ switch (alertType) {
+ case FINISH_PAIRING_REMINDER:
+ return resourceHelper.gs(R.string.omnipod_alert_finish_pairing_reminder);
+ case FINISH_SETUP_REMINDER:
+ return resourceHelper.gs(R.string.omnipod_alert_finish_setup_reminder_reminder);
+ case EXPIRATION_ALERT:
+ return resourceHelper.gs(R.string.omnipod_alert_expiration);
+ case EXPIRATION_ADVISORY_ALERT:
+ return resourceHelper.gs(R.string.omnipod_alert_expiration_advisory);
+ case SHUTDOWN_IMMINENT_ALARM:
+ return resourceHelper.gs(R.string.omnipod_alert_shutdown_imminent);
+ case LOW_RESERVOIR_ALERT:
+ return resourceHelper.gs(R.string.omnipod_alert_low_reservoir);
+ default:
+ return alertType.name();
+ }
+ }
+}
diff --git a/omnipod/src/main/res/drawable/ic_actions_temptarget.xml b/omnipod/src/main/res/drawable/ic_actions_temptarget.xml
new file mode 100644
index 0000000000..5dbd5d8b0c
--- /dev/null
+++ b/omnipod/src/main/res/drawable/ic_actions_temptarget.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/omnipod/src/main/res/drawable/ic_cp_pump_canula.xml b/omnipod/src/main/res/drawable/ic_cp_pump_canula.xml
new file mode 100644
index 0000000000..b43de7ceaa
--- /dev/null
+++ b/omnipod/src/main/res/drawable/ic_cp_pump_canula.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/app/src/main/res/layout/omnipod_fragment.xml b/omnipod/src/main/res/layout/omnipod_fragment.xml
similarity index 84%
rename from app/src/main/res/layout/omnipod_fragment.xml
rename to omnipod/src/main/res/layout/omnipod_fragment.xml
index 912d975168..72c3910ad9 100644
--- a/app/src/main/res/layout/omnipod_fragment.xml
+++ b/omnipod/src/main/res/layout/omnipod_fragment.xml
@@ -26,8 +26,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
- android:paddingBottom="5dp"
android:paddingTop="2dp"
+ android:paddingBottom="5dp"
android:visibility="gone">
@@ -93,10 +93,10 @@
@@ -119,8 +119,8 @@
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
- android:paddingEnd="2dp"
android:paddingStart="2dp"
+ android:paddingEnd="2dp"
android:text=":"
android:textSize="14sp" />
@@ -133,12 +133,118 @@
android:paddingLeft="5dp"
android:textColor="@android:color/white"
android:textSize="14sp" />
+