Move uploading Care Portal events from some UI class to AapsOmnipodManager
This commit is contained in:
parent
50c3ec702c
commit
fc90d3eb43
4 changed files with 43 additions and 108 deletions
|
@ -11,7 +11,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.ui.PodHistoryActivity
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.PodManagementActivity
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.PodManagementActivity
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.initpod.InitActionFragment
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.initpod.InitActionFragment
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.initpod.InitPodTask
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.initpod.InitPodTask
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.pages.InitPodRefreshAction
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.pages.PodInfoFragment
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.pages.PodInfoFragment
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.removepod.RemoveActionFragment
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.removepod.RemoveActionFragment
|
||||||
|
|
||||||
|
@ -34,7 +33,6 @@ abstract class OmnipodModule {
|
||||||
abstract fun omnipodCommunicationManagerProvider(): OmnipodRileyLinkCommunicationManager
|
abstract fun omnipodCommunicationManagerProvider(): OmnipodRileyLinkCommunicationManager
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
@ContributesAndroidInjector abstract fun initPodRefreshAction(): InitPodRefreshAction
|
|
||||||
@ContributesAndroidInjector abstract fun initPodTask(): InitPodTask
|
@ContributesAndroidInjector abstract fun initPodTask(): InitPodTask
|
||||||
@ContributesAndroidInjector abstract fun rlHistoryItemOmnipod(): RLHistoryItemOmnipod
|
@ContributesAndroidInjector abstract fun rlHistoryItemOmnipod(): RLHistoryItemOmnipod
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@ package info.nightscout.androidaps.plugins.pump.omnipod.manager;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -15,15 +17,18 @@ import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.OmnipodHistoryRecord;
|
import info.nightscout.androidaps.db.OmnipodHistoryRecord;
|
||||||
import info.nightscout.androidaps.db.Source;
|
import info.nightscout.androidaps.db.Source;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.events.Event;
|
import info.nightscout.androidaps.events.Event;
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
import info.nightscout.androidaps.logging.LTag;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
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.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
|
||||||
|
@ -75,6 +80,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpVal
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.manager.OmnipodRileyLinkCommunicationManager;
|
import info.nightscout.androidaps.plugins.pump.omnipod.rileylink.manager.OmnipodRileyLinkCommunicationManager;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.AapsOmnipodUtil;
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodAlertUtil;
|
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodAlertUtil;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||||
import io.reactivex.subjects.SingleSubject;
|
import io.reactivex.subjects.SingleSubject;
|
||||||
|
@ -93,6 +99,8 @@ public class AapsOmnipodManager {
|
||||||
private final OmnipodManager delegate;
|
private final OmnipodManager delegate;
|
||||||
private final DatabaseHelperInterface databaseHelper;
|
private final DatabaseHelperInterface databaseHelper;
|
||||||
private final OmnipodAlertUtil omnipodAlertUtil;
|
private final OmnipodAlertUtil omnipodAlertUtil;
|
||||||
|
private final NSUpload nsUpload;
|
||||||
|
private final ProfileFunction profileFunction;
|
||||||
|
|
||||||
private boolean basalBeepsEnabled;
|
private boolean basalBeepsEnabled;
|
||||||
private boolean bolusBeepsEnabled;
|
private boolean bolusBeepsEnabled;
|
||||||
|
@ -113,10 +121,10 @@ public class AapsOmnipodManager {
|
||||||
HasAndroidInjector injector,
|
HasAndroidInjector injector,
|
||||||
ActivePluginProvider activePlugin,
|
ActivePluginProvider activePlugin,
|
||||||
DatabaseHelperInterface databaseHelper,
|
DatabaseHelperInterface databaseHelper,
|
||||||
OmnipodAlertUtil omnipodAlertUtil) {
|
OmnipodAlertUtil omnipodAlertUtil,
|
||||||
if (podStateManager == null) {
|
NSUpload nsUpload,
|
||||||
throw new IllegalArgumentException("Pod state manager can not be null");
|
ProfileFunction profileFunction
|
||||||
}
|
) {
|
||||||
this.podStateManager = podStateManager;
|
this.podStateManager = podStateManager;
|
||||||
this.aapsOmnipodUtil = aapsOmnipodUtil;
|
this.aapsOmnipodUtil = aapsOmnipodUtil;
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
|
@ -127,6 +135,8 @@ public class AapsOmnipodManager {
|
||||||
this.activePlugin = activePlugin;
|
this.activePlugin = activePlugin;
|
||||||
this.databaseHelper = databaseHelper;
|
this.databaseHelper = databaseHelper;
|
||||||
this.omnipodAlertUtil = omnipodAlertUtil;
|
this.omnipodAlertUtil = omnipodAlertUtil;
|
||||||
|
this.nsUpload = nsUpload;
|
||||||
|
this.profileFunction = profileFunction;
|
||||||
|
|
||||||
delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager);
|
delegate = new OmnipodManager(aapsLogger, sp, communicationService, podStateManager);
|
||||||
|
|
||||||
|
@ -185,6 +195,10 @@ public class AapsOmnipodManager {
|
||||||
return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage);
|
return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uploadCareportalEvent(System.currentTimeMillis() - 2000, CareportalEvent.PUMPBATTERYCHANGE);
|
||||||
|
uploadCareportalEvent(System.currentTimeMillis() - 1000, CareportalEvent.INSULINCHANGE);
|
||||||
|
uploadCareportalEvent(System.currentTimeMillis(), CareportalEvent.SITECHANGE);
|
||||||
|
|
||||||
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED));
|
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED));
|
||||||
|
|
||||||
cancelSuspendedFakeTbrIfExists();
|
cancelSuspendedFakeTbrIfExists();
|
||||||
|
@ -866,4 +880,29 @@ public class AapsOmnipodManager {
|
||||||
|
|
||||||
return new BasalSchedule(entries);
|
return new BasalSchedule(entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void uploadCareportalEvent(long date, String event) {
|
||||||
|
if (databaseHelper.getCareportalEventFromTimestamp(date) != null)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
String enteredBy = sp.getString("careportal_enteredby", "");
|
||||||
|
if (enteredBy.isEmpty()) {
|
||||||
|
data.put("enteredBy", enteredBy);
|
||||||
|
}
|
||||||
|
data.put("created_at", DateUtil.toISOString(date));
|
||||||
|
data.put("mills", date);
|
||||||
|
data.put("eventType", event);
|
||||||
|
data.put("units", profileFunction.getUnits());
|
||||||
|
CareportalEvent careportalEvent = new CareportalEvent(injector);
|
||||||
|
careportalEvent.date = date;
|
||||||
|
careportalEvent.source = Source.USER;
|
||||||
|
careportalEvent.eventType = event;
|
||||||
|
careportalEvent.json = data.toString();
|
||||||
|
databaseHelper.createOrUpdate(careportalEvent);
|
||||||
|
nsUpload.uploadCareportalEntryToNS(data);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
aapsLogger.error(LTag.PUMPCOMM, "Unhandled exception when uploading SiteChange event.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.driver.definition.PodProg
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged
|
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodPumpValuesChanged
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
|
import info.nightscout.androidaps.plugins.pump.omnipod.manager.AapsOmnipodManager
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.defs.PodActionType
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.FullInitPodWizardModel
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.FullInitPodWizardModel
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.RemovePodWizardModel
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.RemovePodWizardModel
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.ShortInitPodWizardModel
|
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.model.ShortInitPodWizardModel
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.pages.InitPodRefreshAction
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||||
import info.nightscout.androidaps.utils.extensions.plusAssign
|
import info.nightscout.androidaps.utils.extensions.plusAssign
|
||||||
|
@ -93,15 +91,11 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
|
||||||
private fun initPodAction() {
|
private fun initPodAction() {
|
||||||
|
|
||||||
val pagerSettings = WizardPagerSettings()
|
val pagerSettings = WizardPagerSettings()
|
||||||
var refreshAction = InitPodRefreshAction(injector, PodActionType.INIT_POD)
|
|
||||||
|
|
||||||
pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext)
|
pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext)
|
||||||
pagerSettings.setFinishStringResourceId(R.string.close)
|
pagerSettings.setFinishStringResourceId(R.string.close)
|
||||||
pagerSettings.setFinishButtonBackground(R.drawable.finish_background)
|
pagerSettings.setFinishButtonBackground(R.drawable.finish_background)
|
||||||
pagerSettings.setNextButtonBackground(R.drawable.selectable_item_background)
|
pagerSettings.setNextButtonBackground(R.drawable.selectable_item_background)
|
||||||
pagerSettings.setBackStringResourceId(R.string.cancel)
|
pagerSettings.setBackStringResourceId(R.string.cancel)
|
||||||
pagerSettings.cancelAction = refreshAction
|
|
||||||
pagerSettings.finishAction = refreshAction
|
|
||||||
pagerSettings.pagerAdapterBehavior = FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
pagerSettings.pagerAdapterBehavior = FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
||||||
|
|
||||||
val wizardPagerContext = WizardPagerContext.getInstance()
|
val wizardPagerContext = WizardPagerContext.getInstance()
|
||||||
|
@ -121,15 +115,12 @@ class PodManagementActivity : NoSplashAppCompatActivity() {
|
||||||
|
|
||||||
private fun deactivatePodAction() {
|
private fun deactivatePodAction() {
|
||||||
val pagerSettings = WizardPagerSettings()
|
val pagerSettings = WizardPagerSettings()
|
||||||
var refreshAction = InitPodRefreshAction(injector, PodActionType.DEACTIVATE_POD)
|
|
||||||
|
|
||||||
pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext)
|
pagerSettings.setWizardStepsWayType(WizardStepsWayType.CancelNext)
|
||||||
pagerSettings.setFinishStringResourceId(R.string.close)
|
pagerSettings.setFinishStringResourceId(R.string.close)
|
||||||
pagerSettings.setFinishButtonBackground(R.drawable.finish_background)
|
pagerSettings.setFinishButtonBackground(R.drawable.finish_background)
|
||||||
pagerSettings.setNextButtonBackground(R.drawable.selectable_item_background)
|
pagerSettings.setNextButtonBackground(R.drawable.selectable_item_background)
|
||||||
pagerSettings.setBackStringResourceId(R.string.cancel)
|
pagerSettings.setBackStringResourceId(R.string.cancel)
|
||||||
pagerSettings.cancelAction = refreshAction
|
|
||||||
pagerSettings.finishAction = refreshAction
|
|
||||||
pagerSettings.pagerAdapterBehavior = FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
pagerSettings.pagerAdapterBehavior = FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
||||||
|
|
||||||
val wizardPagerContext = WizardPagerContext.getInstance();
|
val wizardPagerContext = WizardPagerContext.getInstance();
|
||||||
|
|
|
@ -1,93 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.pages;
|
|
||||||
|
|
||||||
import com.atech.android.library.wizardpager.defs.action.AbstractCancelAction;
|
|
||||||
import com.atech.android.library.wizardpager.defs.action.FinishActionInterface;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
|
||||||
import info.nightscout.androidaps.db.Source;
|
|
||||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
|
||||||
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.driver.manager.PodStateManager;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.omnipod.ui.wizard.defs.PodActionType;
|
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by andy on 12/11/2019
|
|
||||||
*/
|
|
||||||
public class InitPodRefreshAction extends AbstractCancelAction implements FinishActionInterface {
|
|
||||||
|
|
||||||
private final PodActionType actionType;
|
|
||||||
private final HasAndroidInjector injector;
|
|
||||||
|
|
||||||
@Inject PodStateManager podStateManager;
|
|
||||||
@Inject AAPSLogger aapsLogger;
|
|
||||||
@Inject SP sp;
|
|
||||||
@Inject NSUpload nsUpload;
|
|
||||||
@Inject DatabaseHelperInterface databaseHelper;
|
|
||||||
@Inject ProfileFunction profileFunction;
|
|
||||||
|
|
||||||
public InitPodRefreshAction(HasAndroidInjector injector, PodActionType actionType) {
|
|
||||||
this.injector = injector;
|
|
||||||
injector.androidInjector().inject(this);
|
|
||||||
this.actionType = actionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(String cancelReason) {
|
|
||||||
if (cancelReason != null && cancelReason.trim().length() > 0) {
|
|
||||||
this.cancelActionText = cancelReason;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute() {
|
|
||||||
if (actionType == PodActionType.INIT_POD) {
|
|
||||||
if (podStateManager.isPodRunning()) {
|
|
||||||
uploadCareportalEvent(System.currentTimeMillis() - 2000, CareportalEvent.PUMPBATTERYCHANGE);
|
|
||||||
uploadCareportalEvent(System.currentTimeMillis() - 1000, CareportalEvent.INSULINCHANGE);
|
|
||||||
uploadCareportalEvent(System.currentTimeMillis(), CareportalEvent.SITECHANGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void uploadCareportalEvent(long date, String event) {
|
|
||||||
if (databaseHelper.getCareportalEventFromTimestamp(date) != null)
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
JSONObject data = new JSONObject();
|
|
||||||
String enteredBy = sp.getString("careportal_enteredby", "");
|
|
||||||
if (enteredBy.isEmpty()) {
|
|
||||||
data.put("enteredBy", enteredBy);
|
|
||||||
}
|
|
||||||
data.put("created_at", DateUtil.toISOString(date));
|
|
||||||
data.put("mills", date);
|
|
||||||
data.put("eventType", event);
|
|
||||||
data.put("units", profileFunction.getUnits());
|
|
||||||
CareportalEvent careportalEvent = new CareportalEvent(injector);
|
|
||||||
careportalEvent.date = date;
|
|
||||||
careportalEvent.source = Source.USER;
|
|
||||||
careportalEvent.eventType = event;
|
|
||||||
careportalEvent.json = data.toString();
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue