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
|
2021-03-03 16:39:35 +01:00
|
|
|
import android.content.Intent
|
|
|
|
import android.net.Uri
|
|
|
|
import android.provider.Settings
|
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.Constants
|
|
|
|
import info.nightscout.androidaps.R
|
2021-04-29 20:42:45 +02:00
|
|
|
import info.nightscout.androidaps.data.ProfileSealed
|
2019-12-30 00:53:44 +01:00
|
|
|
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
|
|
|
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
2021-04-13 23:27:55 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.*
|
2019-12-30 00:53:44 +01:00
|
|
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
2021-10-15 14:56:22 +02:00
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBus
|
2019-12-30 00:53:44 +01:00
|
|
|
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.profile.local.LocalProfileFragment
|
|
|
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
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
|
2021-09-13 19:06:32 +02:00
|
|
|
import info.nightscout.androidaps.utils.HardLimits
|
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,
|
2021-10-15 14:56:22 +02:00
|
|
|
private val rxBus: RxBus,
|
2020-03-30 13:14:24 +02:00
|
|
|
private val context: Context,
|
2021-11-04 10:56:12 +01:00
|
|
|
rh: ResourceHelper,
|
2019-12-30 00:53:44 +01:00
|
|
|
private val sp: SP,
|
|
|
|
private val profileFunction: ProfileFunction,
|
|
|
|
private val localProfilePlugin: LocalProfilePlugin,
|
2021-04-14 00:45:30 +02:00
|
|
|
private val activePlugin: ActivePlugin,
|
2021-11-07 17:19:06 +01:00
|
|
|
private val commandQueue: CommandQueue,
|
2019-12-30 11:35:49 +01:00
|
|
|
private val objectivesPlugin: ObjectivesPlugin,
|
2021-04-13 23:27:55 +02:00
|
|
|
private val configBuilder: ConfigBuilder,
|
2020-01-10 23:14:58 +01:00
|
|
|
private val loopPlugin: LoopPlugin,
|
|
|
|
private val nsClientPlugin: NSClientPlugin,
|
2021-04-14 19:15:10 +02:00
|
|
|
private val importExportPrefs: ImportExportPrefs,
|
2020-04-21 14:50:28 +02:00
|
|
|
private val androidPermission: AndroidPermission,
|
2020-05-07 09:54:36 +02:00
|
|
|
private val cryptoUtil: CryptoUtil,
|
2021-09-13 19:06:32 +02:00
|
|
|
private val config: Config,
|
|
|
|
private val hardLimits: HardLimits
|
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))
|
2021-03-03 16:39:35 +01:00
|
|
|
private val screenPermissionWindow = SWScreen(injector, R.string.permission)
|
|
|
|
.skippable(false)
|
|
|
|
.add(SWInfoText(injector)
|
2021-11-04 10:56:12 +01:00
|
|
|
.label(rh.gs(R.string.needsystemwindowpermission)))
|
2021-03-03 16:39:35 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
|
|
|
.text(R.string.askforpermission)
|
|
|
|
.visibility { !Settings.canDrawOverlays(activity) }
|
|
|
|
.action { activity.startActivity(Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity.packageName))) })
|
|
|
|
.visibility { !Settings.canDrawOverlays(activity) }
|
|
|
|
.validator { Settings.canDrawOverlays(activity) }
|
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)
|
2021-11-04 10:56:12 +01:00
|
|
|
.label(rh.gs(R.string.needwhitelisting, rh.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)
|
2021-11-04 10:56:12 +01:00
|
|
|
.label(rh.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)
|
2021-11-04 10:56:12 +01:00
|
|
|
.label(rh.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 {
|
2021-04-13 23:27:55 +02:00
|
|
|
configBuilder.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
|
|
|
}
|
2021-11-09 17:57:51 +01:00
|
|
|
.visibility { !nsClientPlugin.isEnabled() })
|
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
|
|
|
)
|
2021-05-03 14:15:19 +02:00
|
|
|
.validator { nsClientPlugin.nsClientService?.isConnected == true && nsClientPlugin.nsClientService?.hasWriteAuth == true }
|
|
|
|
.visibility { !(nsClientPlugin.nsClientService?.isConnected == true && nsClientPlugin.nsClientService?.hasWriteAuth == true) }
|
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))
|
2021-10-19 12:05:52 +02:00
|
|
|
.add(SWEditIntNumber(injector, 48, 1, 100)
|
2021-02-15 13:57:01 +01:00
|
|
|
.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
|
2021-10-19 12:05:52 +02:00
|
|
|
&& sp.getInt(R.string.key_treatmentssafety_maxcarbs, 0) > 0
|
2021-02-17 19:28:43 +01:00
|
|
|
}
|
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 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()))
|
2021-05-03 14:15:19 +02:00
|
|
|
.validator {
|
2021-11-04 10:56:12 +01:00
|
|
|
localProfilePlugin.profile?.getDefaultProfile()?.let { ProfileSealed.Pure(it).isValid("StartupWizard", activePlugin.activePump, config, rh, rxBus, hardLimits, false).isValid }
|
2021-05-03 14:15:19 +02:00
|
|
|
?: false
|
|
|
|
}
|
2021-04-14 00:45:30 +02:00
|
|
|
.visibility { localProfilePlugin.isEnabled() }
|
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)
|
2021-09-21 15:35:59 +02:00
|
|
|
.action { ProfileSwitchDialog().show(activity.supportFragmentManager, "ProfileSwitchDialog") })
|
2020-12-06 13:19:53 +01:00
|
|
|
.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)
|
2021-11-20 20:57:30 +01:00
|
|
|
.action { commandQueue.readStatus(rh.gs(R.string.clicked_connect_to_pump), null) }
|
2020-12-06 13:19:53 +01:00
|
|
|
.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 {
|
2021-04-13 23:27:55 +02:00
|
|
|
configBuilder.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
|
|
|
}
|
2021-11-09 17:57:51 +01:00
|
|
|
.visibility { !loopPlugin.isEnabled() })
|
|
|
|
.validator { loopPlugin.isEnabled() }
|
|
|
|
.visibility { !loopPlugin.isEnabled() && 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
|
2021-03-03 16:39:35 +01:00
|
|
|
.add(screenPermissionWindow)
|
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(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
|
2021-03-03 16:39:35 +01:00
|
|
|
.add(screenPermissionWindow)
|
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(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
|
2021-03-03 16:39:35 +01:00
|
|
|
.add(screenPermissionWindow)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|