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 android.content.Intent
|
|
|
|
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.activities.PreferencesActivity
|
|
|
|
import info.nightscout.androidaps.dialogs.ProfileSwitchDialog
|
|
|
|
import info.nightscout.androidaps.events.EventConfigBuilderChange
|
|
|
|
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
2020-01-10 23:14:58 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
|
|
|
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
2019-12-30 00:53:44 +01:00
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase
|
|
|
|
import info.nightscout.androidaps.interfaces.PluginType
|
|
|
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
2020-05-07 09:54:36 +02:00
|
|
|
import info.nightscout.androidaps.interfaces.ProfileFunction
|
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.maintenance.ImportExportPrefs
|
|
|
|
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
|
|
|
|
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
|
2020-05-23 15:39:05 +02:00
|
|
|
import info.nightscout.androidaps.utils.locale.LocaleHelper.update
|
2019-12-31 11:57:58 +01:00
|
|
|
import info.nightscout.androidaps.utils.extensions.isRunningTest
|
2020-03-22 19:59:35 +01:00
|
|
|
import info.nightscout.androidaps.utils.protection.ProtectionCheck
|
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,
|
2020-03-30 13:14:24 +02:00
|
|
|
private val protectionCheck: ProtectionCheck,
|
2020-02-21 08:26:58 +01: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,
|
|
|
|
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)
|
|
|
|
.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 screenLanguage = SWScreen(injector, R.string.language)
|
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.languagesArray, R.array.languagesValues)
|
|
|
|
.preferenceId(R.string.key_language).label(R.string.language)
|
|
|
|
.comment(R.string.setupwizard_language_prompt))
|
2020-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator {
|
2020-03-30 13:14:24 +02:00
|
|
|
update(context)
|
2019-12-30 00:53:44 +01:00
|
|
|
sp.contains(R.string.key_language)
|
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)
|
2020-03-21 13:11:17 +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-03-21 13:11:17 +01:00
|
|
|
.visibility(SWValidator { !sp.getBoolean(R.string.key_i_understand, false) })
|
|
|
|
.action(Runnable {
|
2019-12-30 00:53:44 +01:00
|
|
|
sp.putBoolean(R.string.key_i_understand, true)
|
|
|
|
rxBus.send(EventSWUpdate(false))
|
2020-03-21 13:11:17 +01:00
|
|
|
}))
|
|
|
|
.visibility(SWValidator { !sp.getBoolean(R.string.key_i_understand, false) })
|
|
|
|
.validator(SWValidator { sp.getBoolean(R.string.key_i_understand, false) })
|
|
|
|
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-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator { sp.contains(R.string.key_units) })
|
|
|
|
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)
|
2020-03-21 13:11:17 +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-03-30 13:14:24 +02:00
|
|
|
.visibility(SWValidator { androidPermission.permissionNotGranted(context, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
|
|
|
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, AndroidPermission.CASE_BATTERY) }))
|
|
|
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) })
|
|
|
|
.validator(SWValidator { !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)
|
2020-03-21 13:11:17 +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-03-30 13:14:24 +02:00
|
|
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
|
|
|
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION, AndroidPermission.CASE_LOCATION) }))
|
|
|
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) })
|
|
|
|
.validator(SWValidator { !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)
|
2020-03-21 13:11:17 +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-03-30 13:14:24 +02:00
|
|
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
|
|
|
.action(Runnable { androidPermission.askForPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE, AndroidPermission.CASE_STORAGE) }))
|
|
|
|
.visibility(SWValidator { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) })
|
|
|
|
.validator(SWValidator { !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)
|
|
|
|
.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-02-21 08:26:58 +01:00
|
|
|
.action(Runnable { importExportPrefs.importSharedPreferences(activity) }))
|
|
|
|
.visibility(SWValidator { 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)
|
2020-03-21 13:11:17 +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-03-21 13:11:17 +01:00
|
|
|
.action(Runnable {
|
2020-01-10 23:14:58 +01:00
|
|
|
nsClientPlugin.setPluginEnabled(PluginType.GENERAL, true)
|
|
|
|
nsClientPlugin.setFragmentVisible(PluginType.GENERAL, true)
|
|
|
|
configBuilderPlugin.processOnEnabledCategoryChanged(nsClientPlugin, PluginType.GENERAL)
|
2019-12-30 00:53:44 +01:00
|
|
|
configBuilderPlugin.storeSettings("SetupWizard")
|
|
|
|
rxBus.send(EventConfigBuilderChange())
|
|
|
|
rxBus.send(EventSWUpdate(true))
|
2020-03-21 13:11:17 +01:00
|
|
|
})
|
|
|
|
.visibility(SWValidator { !nsClientPlugin.isEnabled(PluginType.GENERAL) }))
|
|
|
|
.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)
|
|
|
|
.validator(SWTextValidator { 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-03-21 13:11:17 +01:00
|
|
|
.add(SWBreak(injector))
|
|
|
|
.validator(SWValidator { nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth })
|
|
|
|
.visibility(SWValidator { !(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)
|
|
|
|
.add(SWInfotext(injector)
|
|
|
|
.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))
|
|
|
|
private val screenMasterPassword = SWScreen(injector, R.string.master_password)
|
|
|
|
.skippable(false)
|
|
|
|
.add(SWInfotext(injector)
|
|
|
|
.label(R.string.master_password))
|
|
|
|
.add(SWEditEncryptedPassword(injector, cryptoUtil)
|
|
|
|
.preferenceId(R.string.key_master_password))
|
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWInfotext(injector)
|
|
|
|
.label(R.string.master_password_summary))
|
|
|
|
.validator(SWValidator { !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))
|
2020-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator { sp.contains(R.string.key_age) })
|
|
|
|
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWPlugin(injector)
|
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))
|
|
|
|
.add(SWInfotext(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.label(R.string.diawarning))
|
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.insulinsourcesetup)
|
2020-03-21 13:11:17 +01:00
|
|
|
.action(Runnable {
|
2020-03-22 19:59:35 +01:00
|
|
|
val plugin = activePlugin.activeInsulin as PluginBase
|
2020-03-30 13:14:24 +02:00
|
|
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
|
|
|
val i = Intent(activity, PreferencesActivity::class.java)
|
|
|
|
i.putExtra("id", plugin.preferencesId)
|
|
|
|
activity.startActivity(i)
|
|
|
|
}, null)
|
2020-03-21 13:11:17 +01:00
|
|
|
})
|
|
|
|
.visibility(SWValidator { (activePlugin.activeInsulin as PluginBase).preferencesId > 0 }))
|
|
|
|
private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWPlugin(injector)
|
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))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.bgsourcesetup)
|
2020-03-21 13:11:17 +01:00
|
|
|
.action(Runnable {
|
2020-03-22 19:59:35 +01:00
|
|
|
val plugin = activePlugin.activeBgSource as PluginBase
|
2020-03-30 13:14:24 +02:00
|
|
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
|
|
|
val i = Intent(activity, PreferencesActivity::class.java)
|
|
|
|
i.putExtra("id", plugin.preferencesId)
|
|
|
|
activity.startActivity(i)
|
|
|
|
}, null)
|
2020-03-21 13:11:17 +01:00
|
|
|
})
|
|
|
|
.visibility(SWValidator { (activePlugin.activeBgSource as PluginBase).preferencesId > 0 }))
|
|
|
|
private val screenProfile = SWScreen(injector, R.string.configbuilder_profile)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +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))
|
|
|
|
.add(SWPlugin(injector)
|
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)
|
2020-03-21 13:11:17 +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-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator { nsProfilePlugin.profile != null && nsProfilePlugin.profile!!.getDefaultProfile() != null && nsProfilePlugin.profile!!.getDefaultProfile()!!.isValid("StartupWizard") })
|
|
|
|
.visibility(SWValidator { nsProfilePlugin.isEnabled(PluginType.PROFILE) })
|
|
|
|
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-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator { localProfilePlugin.profile?.getDefaultProfile()?.isValid("StartupWizard") == true })
|
|
|
|
.visibility(SWValidator { localProfilePlugin.isEnabled(PluginType.PROFILE) })
|
|
|
|
private val screenProfileSwitch = SWScreen(injector, R.string.careportal_profileswitch)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +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-03-30 13:14:24 +02:00
|
|
|
.action(Runnable { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") }))
|
2020-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator { profileFunction.getProfile() != null })
|
|
|
|
.visibility(SWValidator { profileFunction.getProfile() == null })
|
|
|
|
private val screenPump = SWScreen(injector, R.string.configbuilder_pump)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWPlugin(injector)
|
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))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.pumpsetup)
|
2020-03-21 13:11:17 +01:00
|
|
|
.action(Runnable {
|
2020-03-16 21:40:29 +01:00
|
|
|
val plugin = activePlugin.activePump as PluginBase
|
2020-03-30 13:14:24 +02:00
|
|
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
|
|
|
val i = Intent(activity, PreferencesActivity::class.java)
|
|
|
|
i.putExtra("id", plugin.preferencesId)
|
|
|
|
activity.startActivity(i)
|
|
|
|
}, null)
|
2020-03-21 13:11:17 +01:00
|
|
|
})
|
|
|
|
.visibility(SWValidator { (activePlugin.activePump as PluginBase).preferencesId > 0 }))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.readstatus)
|
2020-03-21 13:11:17 +01:00
|
|
|
.action(Runnable { commandQueue.readStatus("Clicked connect to pump", null) }))
|
|
|
|
.add(SWEventListener(injector, EventPumpStatusChanged::class.java))
|
|
|
|
.validator(SWValidator { activePlugin.activePump.isInitialized })
|
|
|
|
private val screenAps = SWScreen(injector, R.string.configbuilder_aps)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +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))
|
|
|
|
.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))
|
|
|
|
.add(SWPlugin(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.option(PluginType.APS, R.string.configbuilder_aps_description)
|
|
|
|
.label(R.string.configbuilder_aps))
|
2020-03-21 13:11:17 +01:00
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.apssetup)
|
2020-03-21 13:11:17 +01:00
|
|
|
.action(Runnable {
|
2020-03-22 19:59:35 +01:00
|
|
|
val plugin = activePlugin.activeAPS as PluginBase
|
2020-03-30 13:14:24 +02:00
|
|
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
|
|
|
val i = Intent(activity, PreferencesActivity::class.java)
|
|
|
|
i.putExtra("id", plugin.preferencesId)
|
|
|
|
activity.startActivity(i)
|
|
|
|
}, null)
|
2020-03-21 13:11:17 +01:00
|
|
|
})
|
|
|
|
.visibility(SWValidator { (activePlugin.activeAPS as PluginBase).preferencesId > 0 }))
|
2020-05-07 09:54:36 +02:00
|
|
|
.visibility(SWValidator { config.APS })
|
2020-03-21 13:11:17 +01:00
|
|
|
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-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator { sp.contains(R.string.key_aps_mode) })
|
|
|
|
private val screenLoop = SWScreen(injector, R.string.configbuilder_loop)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +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-03-21 13:11:17 +01:00
|
|
|
.action(Runnable {
|
2019-12-30 11:35:49 +01:00
|
|
|
loopPlugin.setPluginEnabled(PluginType.LOOP, true)
|
|
|
|
loopPlugin.setFragmentVisible(PluginType.LOOP, true)
|
|
|
|
configBuilderPlugin.processOnEnabledCategoryChanged(loopPlugin, PluginType.LOOP)
|
2019-12-30 00:53:44 +01:00
|
|
|
configBuilderPlugin.storeSettings("SetupWizard")
|
|
|
|
rxBus.send(EventConfigBuilderChange())
|
|
|
|
rxBus.send(EventSWUpdate(true))
|
2020-03-21 13:11:17 +01:00
|
|
|
})
|
|
|
|
.visibility(SWValidator { !loopPlugin.isEnabled(PluginType.LOOP) }))
|
|
|
|
.validator(SWValidator { loopPlugin.isEnabled(PluginType.LOOP) })
|
2020-05-07 09:54:36 +02:00
|
|
|
.visibility(SWValidator { !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)
|
2020-03-21 13:11:17 +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))
|
|
|
|
.add(SWPlugin(injector)
|
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
|
|
|
.add(SWBreak(injector))
|
|
|
|
.add(SWButton(injector)
|
2019-12-30 00:53:44 +01:00
|
|
|
.text(R.string.sensitivitysetup)
|
2020-03-21 13:11:17 +01:00
|
|
|
.action(Runnable {
|
2020-03-22 19:59:35 +01:00
|
|
|
val plugin = activePlugin.activeSensitivity as PluginBase
|
2020-03-30 13:14:24 +02:00
|
|
|
protectionCheck.queryProtection(activity, ProtectionCheck.Protection.PREFERENCES, Runnable {
|
|
|
|
val i = Intent(activity, PreferencesActivity::class.java)
|
|
|
|
i.putExtra("id", plugin.preferencesId)
|
|
|
|
activity.startActivity(i)
|
|
|
|
}, null)
|
2020-03-21 13:11:17 +01:00
|
|
|
})
|
|
|
|
.visibility(SWValidator { (activePlugin.activeSensitivity as PluginBase).preferencesId > 0 }))
|
|
|
|
private val getScreenObjectives = SWScreen(injector, R.string.objectives)
|
2019-12-30 00:53:44 +01:00
|
|
|
.skippable(false)
|
2020-03-21 13:11:17 +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-03-21 13:11:17 +01:00
|
|
|
.validator(SWValidator { objectivesPlugin.objectives[ObjectivesPlugin.FIRST_OBJECTIVE].isStarted })
|
2020-05-07 09:54:36 +02:00
|
|
|
.visibility(SWValidator { !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)
|
|
|
|
.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
|
|
|
}
|
|
|
|
}
|