From 403551406ba11cbc69f3cb92c87f6c96775b26f7 Mon Sep 17 00:00:00 2001 From: Bart Sopers Date: Sun, 15 Dec 2019 22:51:41 +0100 Subject: [PATCH] Add workaround for anti pattern in wizard pager model --- .../omnipod/dialogs/PodManagementActivity.kt | 9 ++- .../initpod/FullInitPodWizardModel.java | 67 ++++++++++++++++ .../wizard/initpod/InitPodWizardModel.java | 79 +------------------ .../initpod/ShortInitPodWizardModel.java | 58 ++++++++++++++ 4 files changed, 134 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/FullInitPodWizardModel.java create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/ShortInitPodWizardModel.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt index c42a288b72..3b1ca5642a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodManagementActivity.kt @@ -12,7 +12,8 @@ import info.nightscout.androidaps.activities.NoSplashActivity import info.nightscout.androidaps.events.EventRefreshOverview import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.pump.omnipod.defs.SetupProgress -import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.InitPodWizardModel +import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.FullInitPodWizardModel +import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod.ShortInitPodWizardModel import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.InitPodRefreshAction import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.removepod.RemovePodWizardModel import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsOmnipodManager @@ -86,7 +87,11 @@ class PodManagementActivity : NoSplashActivity() { wizardPagerContext.pagerSettings = pagerSettings val podSessionState = OmnipodUtil.getPodSessionState() val isFullInit = podSessionState == null || podSessionState.setupProgress.isBefore(SetupProgress.PRIMING_FINISHED) - wizardPagerContext.wizardModel = InitPodWizardModel(applicationContext, isFullInit) + if(isFullInit) { + wizardPagerContext.wizardModel = FullInitPodWizardModel(applicationContext) + } else { + wizardPagerContext.wizardModel = ShortInitPodWizardModel(applicationContext) + } val myIntent = Intent(this@PodManagementActivity, WizardPagerActivity::class.java) this@PodManagementActivity.startActivity(myIntent) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/FullInitPodWizardModel.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/FullInitPodWizardModel.java new file mode 100644 index 0000000000..db9953a29b --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/FullInitPodWizardModel.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012 Roman Nurik + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod; + +import android.content.Context; + +import androidx.fragment.app.Fragment; + +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.defs.PodInitActionType; +import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodInfoFragment; + +/** + * Created by andy on 12/11/2019 + */ +// Full init pod wizard model +// Cannot be merged with ShortInitPodWizardModel, because we can't set any instance variables +// before the onNewRootPageList method is called (which happens in the super constructor) +public class FullInitPodWizardModel extends InitPodWizardModel { + + public FullInitPodWizardModel(Context context) { + super(context); + } + + @Override + protected PageList onNewRootPageList() { + return new PageList( + new DisplayTextPage(this, + R.string.omnipod_init_pod_wizard_step1_title, + R.string.omnipod_init_pod_wizard_step1_desc, + R.style.WizardPagePodContent).setRequired(true).setCancelReason("None"), + + new InitActionPage(this, + R.string.omnipod_init_pod_wizard_step2_title, + PodInitActionType.PairAndPrimeWizardStep + ).setRequired(true).setCancelReason("Cancel"), + + new DisplayTextPage(this, + R.string.omnipod_init_pod_wizard_step3_title, + R.string.omnipod_init_pod_wizard_step3_desc, + R.style.WizardPagePodContent).setRequired(true).setCancelReason("Cancel"), + + new InitActionPage(this, + R.string.omnipod_init_pod_wizard_step4_title, + PodInitActionType.FillCannulaSetBasalProfileWizardStep + ).setRequired(true).setCancelReason("Cancel") + ); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodWizardModel.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodWizardModel.java index 68a7b82066..83f7e4010e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodWizardModel.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/InitPodWizardModel.java @@ -1,96 +1,21 @@ -/* - * Copyright 2012 Roman Nurik - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod; import android.content.Context; import androidx.fragment.app.Fragment; -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.defs.PodInitActionType; import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodInfoFragment; -/** - * Created by andy on 12/11/2019 - */ -public class InitPodWizardModel extends AbstractWizardModel { - - boolean isFullInit; - - public InitPodWizardModel(Context context, boolean isFullInit) { +public abstract class InitPodWizardModel extends AbstractWizardModel { + public InitPodWizardModel(Context context) { super(context); - this.isFullInit = isFullInit; } @Override - protected PageList onNewRootPageList() { - - if (isFullInit) { - - return new PageList( - - new DisplayTextPage(this, - R.string.omnipod_init_pod_wizard_step1_title, - R.string.omnipod_init_pod_wizard_step1_desc, - R.style.WizardPagePodContent).setRequired(true).setCancelReason("None"), - - new InitActionPage(this, - R.string.omnipod_init_pod_wizard_step2_title, - PodInitActionType.PairAndPrimeWizardStep - ).setRequired(true).setCancelReason("Cancel"), - - new DisplayTextPage(this, - R.string.omnipod_init_pod_wizard_step3_title, - R.string.omnipod_init_pod_wizard_step3_desc, - R.style.WizardPagePodContent).setRequired(true).setCancelReason("Cancel"), - - new InitActionPage(this, - R.string.omnipod_init_pod_wizard_step4_title, - PodInitActionType.FillCannulaSetBasalProfileWizardStep - ).setRequired(true).setCancelReason("Cancel") - ); - } else { - - return new PageList( - - new DisplayTextPage(this, - R.string.omnipod_init_pod_wizard_step3_title, - R.string.omnipod_init_pod_wizard_step3_desc, - R.style.WizardPagePodContent).setRequired(true).setCancelReason("Cancel"), - - new InitActionPage(this, - R.string.omnipod_init_pod_wizard_step4_title, - PodInitActionType.FillCannulaSetBasalProfileWizardStep - ).setRequired(true).setCancelReason("Cancel") - ); - - } - } - - public Fragment getReviewFragment() { PodInfoFragment.isInitPod = true; return new PodInfoFragment(); } - - } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/ShortInitPodWizardModel.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/ShortInitPodWizardModel.java new file mode 100644 index 0000000000..7d67213a10 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/wizard/initpod/ShortInitPodWizardModel.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012 Roman Nurik + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.initpod; + +import android.content.Context; + +import androidx.fragment.app.Fragment; + +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.defs.PodInitActionType; +import info.nightscout.androidaps.plugins.pump.omnipod.dialogs.wizard.pages.PodInfoFragment; + +/** + * Created by andy on 12/11/2019 + */ +// Init pod wizard model without the pair and prime step +// Cannot be merged with FullInitPodWizardModel, because we can't set any instance variables +// before the onNewRootPageList method is called (which happens in the super constructor) +public class ShortInitPodWizardModel extends InitPodWizardModel { + + public ShortInitPodWizardModel(Context context) { + super(context); + } + + @Override + protected PageList onNewRootPageList() { + return new PageList( + new DisplayTextPage(this, + R.string.omnipod_init_pod_wizard_step3_title, + R.string.omnipod_init_pod_wizard_step3_desc, + R.style.WizardPagePodContent).setRequired(true).setCancelReason("Cancel"), + + new InitActionPage(this, + R.string.omnipod_init_pod_wizard_step4_title, + PodInitActionType.FillCannulaSetBasalProfileWizardStep + ).setRequired(true).setCancelReason("Cancel") + ); + + } +}