2019-12-30 00:53:44 +01:00
|
|
|
package info.nightscout.androidaps.setupwizard
|
|
|
|
|
|
|
|
import android.Manifest
|
2020-03-30 13:14:24 +02:00
|
|
|
import android.content.Context
|
2019-12-30 00:53:44 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2020-03-21 13:11:17 +01:00
|
|
|
import dagger.android.HasAndroidInjector
|
2019-12-30 00:53:44 +01:00
|
|
|
import info.nightscout.androidaps.Config
|
|
|
|
import info.nightscout.androidaps.Constants
|
|
|
|
import info.nightscout.androidaps.R
|
|
|
|
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
|
|
|
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
2020-09-29 20:53:12 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
|
|
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
2021-01-18 17:36:18 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.ImportExportPrefsInterface
|
2020-09-29 20:53:12 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginType
|
|
|
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
2019-12-30 00:53:44 +01:00
|
|
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment
|
|
|
|
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientStatus
|
|
|
|
import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService
|
|
|
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfileFragment
|
|
|
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
|
|
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment
|
|
|
|
import info.nightscout.androidaps.plugins.profile.ns.NSProfilePlugin
|
2020-10-17 19:47:39 +02:00
|
|
|
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
|
2021-02-21 22:01:59 +01:00
|
|
|
import info.nightscout.androidaps.plugins.pump.omnipod.dash.OmnipodDashPumpPlugin
|
2021-02-09 21:05:40 +01:00
|
|
|
import info.nightscout.androidaps.plugins.pump.omnipod.eros.OmnipodErosPumpPlugin
|
2019-12-30 00:53:44 +01:00
|
|
|
import info.nightscout.androidaps.setupwizard.elements.*
|
|
|
|
import info.nightscout.androidaps.setupwizard.events.EventSWUpdate
|
|
|
|
import info.nightscout.androidaps.utils.AndroidPermission
|
2020-04-21 14:50:28 +02:00
|
|
|
import info.nightscout.androidaps.utils.CryptoUtil
|
2019-12-31 11:57:58 +01:00
|
|
|
import info.nightscout.androidaps.utils.extensions.isRunningTest
|
2019-12-30 00:53:44 +01:00
|
|
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
|
|
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|
|
|
import java.util.*
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Singleton
|
|
|
|
|
|
|
|
@Singleton
|
|
|
|
class SWDefinition @Inject constructor(
|
2020-03-21 13:11:17 +01:00
|
|
|
injector: HasAndroidInjector,
|
2019-12-30 00:53:44 +01:00
|
|
|
private val rxBus: RxBusWrapper,
|
2020-03-30 13:14:24 +02:00
|
|
|
private val context: Context,
|
2020-01-10 23:14:58 +01:00
|
|
|
resourceHelper: ResourceHelper,
|
2019-12-30 00:53:44 +01:00
|
|
|
private val sp: SP,
|
|
|
|
private val profileFunction: ProfileFunction,
|
|
|
|
private val localProfilePlugin: LocalProfilePlugin,
|
2020-01-10 23:14:58 +01:00
|
|
|
private val activePlugin: ActivePluginProvider,
|
|
|
|
private val commandQueue: CommandQueueProvider,
|
2019-12-30 11:35:49 +01:00
|
|
|
private val objectivesPlugin: ObjectivesPlugin,
|
2020-01-10 23:14:58 +01:00
|
|
|
private val configBuilderPlugin: ConfigBuilderPlugin,
|
|
|
|
private val loopPlugin: LoopPlugin,
|
|
|
|
private val nsClientPlugin: NSClientPlugin,
|
2020-03-22 20:49:36 +01:00
|
|
|
private val nsProfilePlugin: NSProfilePlugin,
|
2021-01-18 17:36:18 +01:00
|
|
|
private val importExportPrefs: ImportExportPrefsInterface,
|
2020-04-21 14:50:28 +02:00
|
|
|
private val androidPermission: AndroidPermission,
|
2020-05-07 09:54:36 +02:00
|
|
|
private val cryptoUtil: CryptoUtil,
|
|
|
|
private val config: Config
|
2019-12-30 00:53:44 +01:00
|
|
|
) {
|
|
|
|
|
2020-03-30 13:14:24 +02:00
|
|
|
lateinit var activity: AppCompatActivity
|
2019-12-30 00:53:44 +01:00
|
|
|
private val screens: MutableList<SWScreen> = ArrayList()
|
|
|
|
|
|
|
|
fun getScreens(): List<SWScreen> {
|
|
|
|
return screens
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun add(newScreen: SWScreen?): SWDefinition {
|
|
|
|
if (newScreen != null) screens.add(newScreen)
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenSetupWizard = SWScreen(injector, R.string.nav_setupwizard)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.welcometosetupwizard))
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenEula = SWScreen(injector, R.string.end_user_license_agreement)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.end_user_license_agreement_text))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.end_user_license_agreement_i_understand)
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { !sp.getBoolean(R.string.key_i_understand, false) }
|
|
|
|
.action {
|
2019-12-30 00:53:44 +01:00
|
|
|
sp.putBoolean(R.string.key_i_understand, true)
|
|
|
|
rxBus.send(EventSWUpdate(false))
|
2020-12-06 13:19:53 +01:00
|
|
|
})
|
|
|
|
.visibility { !sp.getBoolean(R.string.key_i_understand, false) }
|
|
|
|
.validator { sp.getBoolean(R.string.key_i_understand, false) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenUnits = SWScreen(injector, R.string.units)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWRadioButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(R.array.unitsArray, R.array.unitsValues)
|
|
|
|
.preferenceId(R.string.key_units).label(R.string.units)
|
|
|
|
.comment(R.string.setupwizard_units_prompt))
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { sp.contains(R.string.key_units) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val displaySettings = SWScreen(injector, R.string.wear_display_settings)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWEditNumberWithUnits(injector, Constants.LOWMARK * Constants.MGDL_TO_MMOLL, 3.0, 8.0)
|
2019-12-30 00:53:44 +01:00
|
|
|
.preferenceId(R.string.key_low_mark)
|
|
|
|
.updateDelay(5)
|
|
|
|
.label(R.string.low_mark)
|
|
|
|
.comment(R.string.low_mark_comment))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWEditNumberWithUnits(injector, Constants.HIGHMARK * Constants.MGDL_TO_MMOLL, 5.0, 20.0)
|
2019-12-30 00:53:44 +01:00
|
|
|
.preferenceId(R.string.key_high_mark)
|
|
|
|
.updateDelay(5)
|
|
|
|
.label(R.string.high_mark)
|
|
|
|
.comment(R.string.high_mark_comment))
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenPermissionBattery = SWScreen(injector, R.string.permission)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(resourceHelper.gs(R.string.needwhitelisting, resourceHelper.gs(R.string.app_name))))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.askforpermission)
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { androidPermission.permissionNotGranted(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }
|
2021-01-18 22:47:55 +01:00
|
|
|
.action { androidPermission.askForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }
|
|
|
|
.validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenPermissionBt = SWScreen(injector, R.string.permission)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(resourceHelper.gs(R.string.needlocationpermission)))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.askforpermission)
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }
|
2021-01-18 22:47:55 +01:00
|
|
|
.action { androidPermission.askForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }
|
|
|
|
.validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenPermissionStore = SWScreen(injector, R.string.permission)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(resourceHelper.gs(R.string.needstoragepermission)))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.askforpermission)
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
|
2021-01-18 22:47:55 +01:00
|
|
|
.action { androidPermission.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
|
|
|
|
.validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenImport = SWScreen(injector, R.string.nav_import)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.storedsettingsfound))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.nav_import)
|
2020-12-06 13:19:53 +01:00
|
|
|
.action { importExportPrefs.importSharedPreferences(activity) })
|
|
|
|
.visibility { importExportPrefs.prefsFileExists() && !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(true)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.nsclientinfotext))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.enable_nsclient)
|
2020-12-06 13:19:53 +01:00
|
|
|
.action {
|
|
|
|
configBuilderPlugin.performPluginSwitch(nsClientPlugin, true, PluginType.GENERAL)
|
2019-12-30 00:53:44 +01:00
|
|
|
rxBus.send(EventSWUpdate(true))
|
2020-12-06 13:19:53 +01:00
|
|
|
}
|
|
|
|
.visibility { !nsClientPlugin.isEnabled(PluginType.GENERAL) })
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWEditUrl(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.preferenceId(R.string.key_nsclientinternal_url)
|
|
|
|
.updateDelay(5)
|
|
|
|
.label(R.string.nsclientinternal_url_title)
|
|
|
|
.comment(R.string.nsclientinternal_url_dialogmessage))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWEditString(injector)
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { text: String -> text.length >= 12 }
|
2019-12-30 00:53:44 +01:00
|
|
|
.preferenceId(R.string.key_nsclientinternal_api_secret)
|
|
|
|
.updateDelay(5)
|
|
|
|
.label(R.string.nsclientinternal_secret_dialogtitle)
|
|
|
|
.comment(R.string.nsclientinternal_secret_dialogmessage))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWEventListener(injector, EventNSClientStatus::class.java)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.status)
|
2020-01-10 23:14:58 +01:00
|
|
|
.initialStatus(nsClientPlugin.status)
|
2019-12-30 00:53:44 +01:00
|
|
|
)
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth }
|
|
|
|
.visibility { !(nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) }
|
2020-04-03 00:45:37 +02:00
|
|
|
private val screenPatientName = SWScreen(injector, R.string.patient_name)
|
|
|
|
.skippable(true)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2020-04-03 00:45:37 +02:00
|
|
|
.label(R.string.patient_name_summary))
|
|
|
|
.add(SWEditString(injector)
|
2020-04-21 14:50:28 +02:00
|
|
|
.validator(SWTextValidator(String::isNotEmpty))
|
|
|
|
.preferenceId(R.string.key_patient_name))
|
2021-02-21 12:30:45 +01:00
|
|
|
private val privacy = SWScreen(injector, R.string.privacy_settings)
|
|
|
|
.skippable(true)
|
|
|
|
.add(SWInfoText(injector)
|
|
|
|
.label(R.string.privacy_summary))
|
|
|
|
.add(SWPreference(injector, this)
|
|
|
|
.option(R.xml.pref_datachoices)
|
|
|
|
)
|
2020-04-21 14:50:28 +02:00
|
|
|
private val screenMasterPassword = SWScreen(injector, R.string.master_password)
|
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2020-04-21 14:50:28 +02:00
|
|
|
.label(R.string.master_password))
|
|
|
|
.add(SWEditEncryptedPassword(injector, cryptoUtil)
|
|
|
|
.preferenceId(R.string.key_master_password))
|
|
|
|
.add(SWBreak(injector))
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2020-04-21 14:50:28 +02:00
|
|
|
.label(R.string.master_password_summary))
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { !cryptoUtil.checkPassword("", sp.getString(R.string.key_master_password, "")) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenAge = SWScreen(injector, R.string.patientage)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWRadioButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(R.array.ageArray, R.array.ageValues)
|
|
|
|
.preferenceId(R.string.key_age)
|
|
|
|
.label(R.string.patientage)
|
|
|
|
.comment(R.string.patientage_summary))
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWEditNumber(injector, 3.0, 0.1, 25.0)
|
|
|
|
.preferenceId(R.string.key_treatmentssafety_maxbolus)
|
|
|
|
.updateDelay(5)
|
|
|
|
.label(R.string.treatmentssafety_maxbolus_title)
|
|
|
|
.comment(R.string.common_values))
|
|
|
|
.add(SWEditNumber(injector, 48.0, 1.0, 100.0)
|
|
|
|
.preferenceId(R.string.key_treatmentssafety_maxcarbs)
|
|
|
|
.updateDelay(5)
|
|
|
|
.label(R.string.treatmentssafety_maxcarbs_title)
|
|
|
|
.comment(R.string.common_values))
|
2021-02-17 19:28:43 +01:00
|
|
|
.validator {
|
|
|
|
sp.contains(R.string.key_age)
|
|
|
|
&& sp.getDouble(R.string.key_treatmentssafety_maxbolus, 0.0) > 0
|
|
|
|
&& sp.getDouble(R.string.key_treatmentssafety_maxcarbs, 0.0) > 0
|
|
|
|
}
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-12-06 13:19:53 +01:00
|
|
|
.add(SWPlugin(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(PluginType.INSULIN, R.string.configbuilder_insulin_description)
|
|
|
|
.makeVisible(false)
|
|
|
|
.label(R.string.configbuilder_insulin))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.diawarning))
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-12-06 13:19:53 +01:00
|
|
|
.add(SWPlugin(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(PluginType.BGSOURCE, R.string.configbuilder_bgsource_description)
|
|
|
|
.label(R.string.configbuilder_bgsource))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
private val screenProfile = SWScreen(injector, R.string.configbuilder_profile)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.setupwizard_profile_description))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
2020-12-06 13:19:53 +01:00
|
|
|
.add(SWPlugin(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(PluginType.PROFILE, R.string.configbuilder_profile_description)
|
|
|
|
.label(R.string.configbuilder_profile))
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenNsProfile = SWScreen(injector, R.string.nsprofile)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.adjustprofileinns))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWFragment(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(NSProfileFragment()))
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { nsProfilePlugin.profile != null && nsProfilePlugin.profile!!.getDefaultProfile() != null && nsProfilePlugin.profile!!.getDefaultProfile()!!.isValid("StartupWizard") }
|
|
|
|
.visibility { nsProfilePlugin.isEnabled(PluginType.PROFILE) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenLocalProfile = SWScreen(injector, R.string.localprofile)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWFragment(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(LocalProfileFragment()))
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { localProfilePlugin.profile?.getDefaultProfile()?.isValid("StartupWizard") == true }
|
|
|
|
.visibility { localProfilePlugin.isEnabled(PluginType.PROFILE) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenProfileSwitch = SWScreen(injector, R.string.careportal_profileswitch)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.profileswitch_ismissing))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.doprofileswitch)
|
2020-12-06 13:19:53 +01:00
|
|
|
.action { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") })
|
|
|
|
.validator { profileFunction.getProfile() != null }
|
|
|
|
.visibility { profileFunction.getProfile() == null }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenPump = SWScreen(injector, R.string.configbuilder_pump)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-12-06 13:19:53 +01:00
|
|
|
.add(SWPlugin(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(PluginType.PUMP, R.string.configbuilder_pump_description)
|
|
|
|
.label(R.string.configbuilder_pump))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2020-09-05 04:26:22 +02:00
|
|
|
.label(R.string.setupwizard_pump_pump_not_initialized)
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility { !isPumpInitialized() })
|
2021-02-21 22:01:59 +01:00
|
|
|
.add( // Omnipod Eros only
|
2021-02-15 13:57:01 +01:00
|
|
|
SWInfoText(injector)
|
2020-10-01 19:32:56 +02:00
|
|
|
.label(R.string.setupwizard_pump_waiting_for_riley_link_connection)
|
2020-12-06 13:19:53 +01:00
|
|
|
.visibility {
|
2020-10-01 19:32:56 +02:00
|
|
|
val activePump = activePlugin.activePump
|
2021-02-09 21:05:40 +01:00
|
|
|
activePump is OmnipodErosPumpPlugin && !activePump.isRileyLinkReady
|
2020-12-06 13:19:53 +01:00
|
|
|
})
|
2021-02-21 22:01:59 +01:00
|
|
|
.add( // Omnipod Eros only
|
2020-10-17 19:47:39 +02:00
|
|
|
SWEventListener(injector, EventRileyLinkDeviceStatusChange::class.java)
|
|
|
|
.label(R.string.setupwizard_pump_riley_link_status)
|
2021-02-09 21:05:40 +01:00
|
|
|
.visibility { activePlugin.activePump is OmnipodErosPumpPlugin })
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.readstatus)
|
2020-12-06 13:19:53 +01:00
|
|
|
.action { commandQueue.readStatus("Clicked connect to pump", null) }
|
|
|
|
.visibility {
|
2020-10-01 19:32:56 +02:00
|
|
|
// Hide for Omnipod, because as we don't require a Pod to be paired in the setup wizard,
|
|
|
|
// Getting the status might not be possible
|
2021-02-21 22:01:59 +01:00
|
|
|
activePlugin.activePump !is OmnipodErosPumpPlugin && activePlugin.activePump !is OmnipodDashPumpPlugin
|
2020-12-06 13:19:53 +01:00
|
|
|
})
|
2020-10-17 19:47:39 +02:00
|
|
|
.add(SWEventListener(injector, EventPumpStatusChanged::class.java)
|
2021-02-21 22:01:59 +01:00
|
|
|
.visibility { activePlugin.activePump !is OmnipodErosPumpPlugin && activePlugin.activePump !is OmnipodDashPumpPlugin })
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { isPumpInitialized() }
|
2020-09-05 04:26:22 +02:00
|
|
|
|
2020-10-01 19:32:56 +02:00
|
|
|
private fun isPumpInitialized(): Boolean {
|
|
|
|
val activePump = activePlugin.activePump
|
|
|
|
|
2021-02-21 22:01:59 +01:00
|
|
|
// For Omnipod, activating a Pod can be done after setup through the Omnipod fragment
|
|
|
|
// For the Eros model, consider the pump initialized when a RL has been configured successfully
|
|
|
|
// For Dash model, consider the pump setup without any extra conditions
|
|
|
|
return activePump.isInitialized()
|
|
|
|
|| (activePump is OmnipodErosPumpPlugin && activePump.isRileyLinkReady)
|
|
|
|
|| activePump is OmnipodDashPumpPlugin
|
2020-10-01 19:32:56 +02:00
|
|
|
}
|
|
|
|
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenAps = SWScreen(injector, R.string.configbuilder_aps)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.setupwizard_aps_description))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
2020-12-06 13:19:53 +01:00
|
|
|
.add(SWPlugin(injector, this)
|
|
|
|
.option(PluginType.APS, R.string.configbuilder_aps_description)
|
|
|
|
.label(R.string.configbuilder_aps))
|
|
|
|
.add(SWBreak(injector))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWHtmlLink(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label("https://openaps.readthedocs.io/en/latest/"))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
private val screenApsMode = SWScreen(injector, R.string.apsmode_title)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWRadioButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(R.array.aps_modeArray, R.array.aps_modeValues)
|
|
|
|
.preferenceId(R.string.key_aps_mode).label(R.string.apsmode_title)
|
|
|
|
.comment(R.string.setupwizard_preferred_aps_mode))
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { sp.contains(R.string.key_aps_mode) }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenLoop = SWScreen(injector, R.string.configbuilder_loop)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.setupwizard_loop_description))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.enableloop)
|
2020-12-06 13:19:53 +01:00
|
|
|
.action {
|
|
|
|
configBuilderPlugin.performPluginSwitch(loopPlugin, true, PluginType.LOOP)
|
2019-12-30 00:53:44 +01:00
|
|
|
rxBus.send(EventSWUpdate(true))
|
2020-12-06 13:19:53 +01:00
|
|
|
}
|
|
|
|
.visibility { !loopPlugin.isEnabled(PluginType.LOOP) })
|
|
|
|
.validator { loopPlugin.isEnabled(PluginType.LOOP) }
|
|
|
|
.visibility { !loopPlugin.isEnabled(PluginType.LOOP) && config.APS }
|
2020-03-21 13:11:17 +01:00
|
|
|
private val screenSensitivity = SWScreen(injector, R.string.configbuilder_sensitivity)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.setupwizard_sensitivity_description))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWHtmlLink(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.setupwizard_sensitivity_url))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
2020-12-06 13:19:53 +01:00
|
|
|
.add(SWPlugin(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(PluginType.SENSITIVITY, R.string.configbuilder_sensitivity_description)
|
|
|
|
.label(R.string.configbuilder_sensitivity))
|
2020-03-21 13:11:17 +01:00
|
|
|
private val getScreenObjectives = SWScreen(injector, R.string.objectives)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2021-02-15 13:57:01 +01:00
|
|
|
.add(SWInfoText(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.startobjective))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWFragment(injector, this)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(ObjectivesFragment()))
|
2020-12-06 13:19:53 +01:00
|
|
|
.validator { objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted }
|
|
|
|
.visibility { !objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted && config.APS }
|
2019-12-30 00:53:44 +01:00
|
|
|
|
2020-03-16 21:40:29 +01:00
|
|
|
private fun swDefinitionFull() { // List all the screens here
|
2019-12-30 00:53:44 +01:00
|
|
|
add(screenSetupWizard)
|
2020-09-01 10:02:35 +02:00
|
|
|
//.add(screenLanguage)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenEula)
|
2020-03-16 21:40:29 +01:00
|
|
|
.add(if (isRunningTest()) null else screenPermissionBattery) // cannot mock ask battery optimization
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenPermissionBt)
|
|
|
|
.add(screenPermissionStore)
|
2020-04-21 14:50:28 +02:00
|
|
|
.add(screenMasterPassword)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenImport)
|
2021-02-21 12:30:45 +01:00
|
|
|
.add(privacy)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenUnits)
|
|
|
|
.add(displaySettings)
|
|
|
|
.add(screenNsClient)
|
2020-04-03 00:45:37 +02:00
|
|
|
.add(screenPatientName)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenAge)
|
|
|
|
.add(screenInsulin)
|
|
|
|
.add(screenBgSource)
|
|
|
|
.add(screenProfile)
|
|
|
|
.add(screenNsProfile)
|
|
|
|
.add(screenLocalProfile)
|
|
|
|
.add(screenProfileSwitch)
|
|
|
|
.add(screenPump)
|
|
|
|
.add(screenAps)
|
|
|
|
.add(screenApsMode)
|
|
|
|
.add(screenLoop)
|
|
|
|
.add(screenSensitivity)
|
|
|
|
.add(getScreenObjectives)
|
|
|
|
}
|
|
|
|
|
2020-03-16 21:40:29 +01:00
|
|
|
private fun swDefinitionPumpControl() { // List all the screens here
|
2019-12-30 00:53:44 +01:00
|
|
|
add(screenSetupWizard)
|
2020-09-01 10:02:35 +02:00
|
|
|
//.add(screenLanguage)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenEula)
|
2020-03-16 21:40:29 +01:00
|
|
|
.add(if (isRunningTest()) null else screenPermissionBattery) // cannot mock ask battery optimization
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenPermissionBt)
|
|
|
|
.add(screenPermissionStore)
|
2020-04-21 14:50:28 +02:00
|
|
|
.add(screenMasterPassword)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenImport)
|
|
|
|
.add(screenUnits)
|
|
|
|
.add(displaySettings)
|
|
|
|
.add(screenNsClient)
|
2020-04-03 00:45:37 +02:00
|
|
|
.add(screenPatientName)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenAge)
|
|
|
|
.add(screenInsulin)
|
|
|
|
.add(screenBgSource)
|
|
|
|
.add(screenProfile)
|
|
|
|
.add(screenNsProfile)
|
|
|
|
.add(screenLocalProfile)
|
|
|
|
.add(screenProfileSwitch)
|
|
|
|
.add(screenPump)
|
|
|
|
.add(screenSensitivity)
|
|
|
|
}
|
|
|
|
|
2020-03-16 21:40:29 +01:00
|
|
|
private fun swDefinitionNSClient() { // List all the screens here
|
2019-12-30 00:53:44 +01:00
|
|
|
add(screenSetupWizard)
|
2020-09-01 10:02:35 +02:00
|
|
|
//.add(screenLanguage)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenEula)
|
2020-03-16 21:40:29 +01:00
|
|
|
.add(if (isRunningTest()) null else screenPermissionBattery) // cannot mock ask battery optimization
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenPermissionStore)
|
2020-04-21 14:50:28 +02:00
|
|
|
.add(screenMasterPassword)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenImport)
|
|
|
|
.add(screenUnits)
|
|
|
|
.add(displaySettings)
|
|
|
|
.add(screenNsClient)
|
2020-07-02 20:28:42 +02:00
|
|
|
//.add(screenBgSource)
|
2020-04-03 00:45:37 +02:00
|
|
|
.add(screenPatientName)
|
2019-12-30 00:53:44 +01:00
|
|
|
.add(screenAge)
|
|
|
|
.add(screenInsulin)
|
|
|
|
.add(screenSensitivity)
|
|
|
|
}
|
|
|
|
|
|
|
|
init {
|
2020-05-07 09:54:36 +02:00
|
|
|
if (config.APS) swDefinitionFull() else if (config.PUMPCONTROL) swDefinitionPumpControl() else if (config.NSCLIENT) swDefinitionNSClient()
|
2019-12-30 00:53:44 +01:00
|
|
|
}
|
|
|
|
}
|