SetupWizard update

This commit is contained in:
Milos Kozak 2021-02-15 13:57:01 +01:00
parent 1ef8629f57
commit 86fb53ce34
12 changed files with 121 additions and 52 deletions

View file

@ -13,12 +13,13 @@ abstract class WizardModule {
@ContributesAndroidInjector abstract fun swBreakInjector(): SWBreak @ContributesAndroidInjector abstract fun swBreakInjector(): SWBreak
@ContributesAndroidInjector abstract fun swButtonInjector(): SWButton @ContributesAndroidInjector abstract fun swButtonInjector(): SWButton
@ContributesAndroidInjector abstract fun swEditNumberWithUnitsInjector(): SWEditNumberWithUnits @ContributesAndroidInjector abstract fun swEditNumberWithUnitsInjector(): SWEditNumberWithUnits
@ContributesAndroidInjector abstract fun swEditNumberInjector(): SWEditNumber
@ContributesAndroidInjector abstract fun swEditStringInjector(): SWEditString @ContributesAndroidInjector abstract fun swEditStringInjector(): SWEditString
@ContributesAndroidInjector abstract fun swEditEncryptedPasswordInjector(): SWEditEncryptedPassword @ContributesAndroidInjector abstract fun swEditEncryptedPasswordInjector(): SWEditEncryptedPassword
@ContributesAndroidInjector abstract fun swEditUrlInjector(): SWEditUrl @ContributesAndroidInjector abstract fun swEditUrlInjector(): SWEditUrl
@ContributesAndroidInjector abstract fun swFragmentInjector(): SWFragment @ContributesAndroidInjector abstract fun swFragmentInjector(): SWFragment
@ContributesAndroidInjector abstract fun swHtmlLinkInjector(): SWHtmlLink @ContributesAndroidInjector abstract fun swHtmlLinkInjector(): SWHtmlLink
@ContributesAndroidInjector abstract fun swInfotextInjector(): SWInfotext @ContributesAndroidInjector abstract fun swInfotextInjector(): SWInfoText
@ContributesAndroidInjector abstract fun swItemInjector(): SWItem @ContributesAndroidInjector abstract fun swItemInjector(): SWItem
@ContributesAndroidInjector abstract fun swPluginInjector(): SWPlugin @ContributesAndroidInjector abstract fun swPluginInjector(): SWPlugin
@ContributesAndroidInjector abstract fun swRadioButtonInjector(): SWRadioButton @ContributesAndroidInjector abstract fun swRadioButtonInjector(): SWRadioButton

View file

@ -74,11 +74,11 @@ class SWDefinition @Inject constructor(
} }
private val screenSetupWizard = SWScreen(injector, R.string.nav_setupwizard) private val screenSetupWizard = SWScreen(injector, R.string.nav_setupwizard)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.welcometosetupwizard)) .label(R.string.welcometosetupwizard))
private val screenEula = SWScreen(injector, R.string.end_user_license_agreement) private val screenEula = SWScreen(injector, R.string.end_user_license_agreement)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.end_user_license_agreement_text)) .label(R.string.end_user_license_agreement_text))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
@ -112,7 +112,7 @@ class SWDefinition @Inject constructor(
.comment(R.string.high_mark_comment)) .comment(R.string.high_mark_comment))
private val screenPermissionBattery = SWScreen(injector, R.string.permission) private val screenPermissionBattery = SWScreen(injector, R.string.permission)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(resourceHelper.gs(R.string.needwhitelisting, resourceHelper.gs(R.string.app_name)))) .label(resourceHelper.gs(R.string.needwhitelisting, resourceHelper.gs(R.string.app_name))))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
@ -123,7 +123,7 @@ class SWDefinition @Inject constructor(
.validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) } .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) }
private val screenPermissionBt = SWScreen(injector, R.string.permission) private val screenPermissionBt = SWScreen(injector, R.string.permission)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(resourceHelper.gs(R.string.needlocationpermission))) .label(resourceHelper.gs(R.string.needlocationpermission)))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
@ -134,7 +134,7 @@ class SWDefinition @Inject constructor(
.validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) } .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) }
private val screenPermissionStore = SWScreen(injector, R.string.permission) private val screenPermissionStore = SWScreen(injector, R.string.permission)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(resourceHelper.gs(R.string.needstoragepermission))) .label(resourceHelper.gs(R.string.needstoragepermission)))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
@ -144,7 +144,7 @@ class SWDefinition @Inject constructor(
.visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) } .visibility { androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
.validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) } .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
private val screenImport = SWScreen(injector, R.string.nav_import) private val screenImport = SWScreen(injector, R.string.nav_import)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.storedsettingsfound)) .label(R.string.storedsettingsfound))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
@ -153,7 +153,7 @@ class SWDefinition @Inject constructor(
.visibility { importExportPrefs.prefsFileExists() && !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) } .visibility { importExportPrefs.prefsFileExists() && !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) }
private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title) private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title)
.skippable(true) .skippable(true)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.nsclientinfotext)) .label(R.string.nsclientinfotext))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
@ -183,19 +183,19 @@ class SWDefinition @Inject constructor(
.visibility { !(nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) } .visibility { !(nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) }
private val screenPatientName = SWScreen(injector, R.string.patient_name) private val screenPatientName = SWScreen(injector, R.string.patient_name)
.skippable(true) .skippable(true)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.patient_name_summary)) .label(R.string.patient_name_summary))
.add(SWEditString(injector) .add(SWEditString(injector)
.validator(SWTextValidator(String::isNotEmpty)) .validator(SWTextValidator(String::isNotEmpty))
.preferenceId(R.string.key_patient_name)) .preferenceId(R.string.key_patient_name))
private val screenMasterPassword = SWScreen(injector, R.string.master_password) private val screenMasterPassword = SWScreen(injector, R.string.master_password)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.master_password)) .label(R.string.master_password))
.add(SWEditEncryptedPassword(injector, cryptoUtil) .add(SWEditEncryptedPassword(injector, cryptoUtil)
.preferenceId(R.string.key_master_password)) .preferenceId(R.string.key_master_password))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.master_password_summary)) .label(R.string.master_password_summary))
.validator { !cryptoUtil.checkPassword("", sp.getString(R.string.key_master_password, "")) } .validator { !cryptoUtil.checkPassword("", sp.getString(R.string.key_master_password, "")) }
private val screenAge = SWScreen(injector, R.string.patientage) private val screenAge = SWScreen(injector, R.string.patientage)
@ -206,7 +206,20 @@ class SWDefinition @Inject constructor(
.preferenceId(R.string.key_age) .preferenceId(R.string.key_age)
.label(R.string.patientage) .label(R.string.patientage)
.comment(R.string.patientage_summary)) .comment(R.string.patientage_summary))
.validator { sp.contains(R.string.key_age) } .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))
.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 }
private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin) private val screenInsulin = SWScreen(injector, R.string.configbuilder_insulin)
.skippable(false) .skippable(false)
.add(SWPlugin(injector, this) .add(SWPlugin(injector, this)
@ -214,7 +227,7 @@ class SWDefinition @Inject constructor(
.makeVisible(false) .makeVisible(false)
.label(R.string.configbuilder_insulin)) .label(R.string.configbuilder_insulin))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.diawarning)) .label(R.string.diawarning))
private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource) private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource)
.skippable(false) .skippable(false)
@ -224,7 +237,7 @@ class SWDefinition @Inject constructor(
.add(SWBreak(injector)) .add(SWBreak(injector))
private val screenProfile = SWScreen(injector, R.string.configbuilder_profile) private val screenProfile = SWScreen(injector, R.string.configbuilder_profile)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.setupwizard_profile_description)) .label(R.string.setupwizard_profile_description))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWPlugin(injector, this) .add(SWPlugin(injector, this)
@ -232,7 +245,7 @@ class SWDefinition @Inject constructor(
.label(R.string.configbuilder_profile)) .label(R.string.configbuilder_profile))
private val screenNsProfile = SWScreen(injector, R.string.nsprofile) private val screenNsProfile = SWScreen(injector, R.string.nsprofile)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.adjustprofileinns)) .label(R.string.adjustprofileinns))
.add(SWFragment(injector, this) .add(SWFragment(injector, this)
.add(NSProfileFragment())) .add(NSProfileFragment()))
@ -246,7 +259,7 @@ class SWDefinition @Inject constructor(
.visibility { localProfilePlugin.isEnabled(PluginType.PROFILE) } .visibility { localProfilePlugin.isEnabled(PluginType.PROFILE) }
private val screenProfileSwitch = SWScreen(injector, R.string.careportal_profileswitch) private val screenProfileSwitch = SWScreen(injector, R.string.careportal_profileswitch)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.profileswitch_ismissing)) .label(R.string.profileswitch_ismissing))
.add(SWButton(injector) .add(SWButton(injector)
.text(R.string.doprofileswitch) .text(R.string.doprofileswitch)
@ -259,11 +272,11 @@ class SWDefinition @Inject constructor(
.option(PluginType.PUMP, R.string.configbuilder_pump_description) .option(PluginType.PUMP, R.string.configbuilder_pump_description)
.label(R.string.configbuilder_pump)) .label(R.string.configbuilder_pump))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.setupwizard_pump_pump_not_initialized) .label(R.string.setupwizard_pump_pump_not_initialized)
.visibility { !isPumpInitialized() }) .visibility { !isPumpInitialized() })
.add( // Omnipod only .add( // Omnipod only
SWInfotext(injector) SWInfoText(injector)
.label(R.string.setupwizard_pump_waiting_for_riley_link_connection) .label(R.string.setupwizard_pump_waiting_for_riley_link_connection)
.visibility { .visibility {
val activePump = activePlugin.activePump val activePump = activePlugin.activePump
@ -295,7 +308,7 @@ class SWDefinition @Inject constructor(
private val screenAps = SWScreen(injector, R.string.configbuilder_aps) private val screenAps = SWScreen(injector, R.string.configbuilder_aps)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.setupwizard_aps_description)) .label(R.string.setupwizard_aps_description))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWPlugin(injector, this) .add(SWPlugin(injector, this)
@ -314,7 +327,7 @@ class SWDefinition @Inject constructor(
.validator { sp.contains(R.string.key_aps_mode) } .validator { sp.contains(R.string.key_aps_mode) }
private val screenLoop = SWScreen(injector, R.string.configbuilder_loop) private val screenLoop = SWScreen(injector, R.string.configbuilder_loop)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.setupwizard_loop_description)) .label(R.string.setupwizard_loop_description))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWButton(injector) .add(SWButton(injector)
@ -328,7 +341,7 @@ class SWDefinition @Inject constructor(
.visibility { !loopPlugin.isEnabled(PluginType.LOOP) && config.APS } .visibility { !loopPlugin.isEnabled(PluginType.LOOP) && config.APS }
private val screenSensitivity = SWScreen(injector, R.string.configbuilder_sensitivity) private val screenSensitivity = SWScreen(injector, R.string.configbuilder_sensitivity)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.setupwizard_sensitivity_description)) .label(R.string.setupwizard_sensitivity_description))
.add(SWHtmlLink(injector) .add(SWHtmlLink(injector)
.label(R.string.setupwizard_sensitivity_url)) .label(R.string.setupwizard_sensitivity_url))
@ -338,7 +351,7 @@ class SWDefinition @Inject constructor(
.label(R.string.configbuilder_sensitivity)) .label(R.string.configbuilder_sensitivity))
private val getScreenObjectives = SWScreen(injector, R.string.objectives) private val getScreenObjectives = SWScreen(injector, R.string.objectives)
.skippable(false) .skippable(false)
.add(SWInfotext(injector) .add(SWInfoText(injector)
.label(R.string.startobjective)) .label(R.string.startobjective))
.add(SWBreak(injector)) .add(SWBreak(injector))
.add(SWFragment(injector, this) .add(SWFragment(injector, this)

View file

@ -6,7 +6,7 @@ import android.widget.TextView
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.setupwizard.SWValidator import info.nightscout.androidaps.setupwizard.SWValidator
class SWBreak(injector: HasAndroidInjector) : SWItem(injector, Type.TEXT) { class SWBreak(injector: HasAndroidInjector) : SWItem(injector, Type.BREAK) {
private var l: TextView? = null private var l: TextView? = null
private var visibilityValidator: SWValidator? = null private var visibilityValidator: SWValidator? = null

View file

@ -0,0 +1,60 @@
package info.nightscout.androidaps.setupwizard.elements
import android.graphics.Typeface
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.setupwizard.SWNumberValidator
import info.nightscout.androidaps.utils.SafeParse
import info.nightscout.androidaps.utils.ui.NumberPicker
import java.text.DecimalFormat
class SWEditNumber(injector: HasAndroidInjector, private val init: Double, private val min: Double, private val max: Double) : SWItem(injector, Type.DECIMAL_NUMBER) {
private val validator: SWNumberValidator = SWNumberValidator { value -> value in min..max }
private var updateDelay = 0
override fun generateDialog(layout: LinearLayout) {
val context = layout.context
val watcher: TextWatcher = object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (validator.isValid(SafeParse.stringToDouble(s.toString())))
save(s.toString(), updateDelay.toLong())
}
override fun afterTextChanged(s: Editable) {}
}
val l = TextView(context)
l.id = View.generateViewId()
label?.let { l.setText(it) }
l.setTypeface(l.typeface, Typeface.BOLD)
layout.addView(l)
val initValue = sp.getDouble(preferenceId, init)
val numberPicker = NumberPicker(context)
numberPicker.setParams(initValue, min, max, 0.1, DecimalFormat("0.0"), false, null, watcher)
layout.addView(numberPicker)
val c = TextView(context)
c.id = View.generateViewId()
comment?.let { c.setText(it) }
c.setTypeface(c.typeface, Typeface.ITALIC)
layout.addView(c)
super.generateDialog(layout)
}
fun preferenceId(preferenceId: Int): SWEditNumber {
this.preferenceId = preferenceId
return this
}
fun updateDelay(updateDelay: Int): SWEditNumber {
this.updateDelay = updateDelay
return this
}
}

View file

@ -16,11 +16,11 @@ import info.nightscout.androidaps.utils.SafeParse
import java.text.DecimalFormat import java.text.DecimalFormat
import javax.inject.Inject import javax.inject.Inject
class SWEditNumberWithUnits(injector: HasAndroidInjector, private val init: Double, private val min: Double, private val max: Double) : SWItem(injector, Type.UNITNUMBER) { class SWEditNumberWithUnits(injector: HasAndroidInjector, private val init: Double, private val min: Double, private val max: Double) : SWItem(injector, Type.UNIT_NUMBER) {
@Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var profileFunction: ProfileFunction
private val validator: SWNumberValidator? = SWNumberValidator { value -> value >= min && value <= max } private val validator: SWNumberValidator = SWNumberValidator { value -> value in min..max }
private var updateDelay = 0 private var updateDelay = 0
override fun generateDialog(layout: LinearLayout) { override fun generateDialog(layout: LinearLayout) {
@ -28,7 +28,7 @@ class SWEditNumberWithUnits(injector: HasAndroidInjector, private val init: Doub
val watcher: TextWatcher = object : TextWatcher { val watcher: TextWatcher = object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (validator != null && validator.isValid(SafeParse.stringToDouble(s.toString()))) if (validator.isValid(SafeParse.stringToDouble(s.toString())))
save(s.toString(), updateDelay.toLong()) save(s.toString(), updateDelay.toLong())
} }

View file

@ -38,7 +38,7 @@ class SWEditUrl(injector: HasAndroidInjector) : SWItem(injector, Type.URL) {
editText.addTextChangedListener(object : TextWatcher { editText.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (Patterns.WEB_URL.matcher(s).matches()) save(s.toString(), updateDelay.toLong()) else rxBus.send(EventSWLabel(resourceHelper.gs(R.string.error_url_not_valid))) if (Patterns.WEB_URL.matcher(s).matches()) save(s.toString(), updateDelay) else rxBus.send(EventSWLabel(resourceHelper.gs(R.string.error_url_not_valid)))
} }
override fun afterTextChanged(s: Editable) {} override fun afterTextChanged(s: Editable) {}

View file

@ -8,7 +8,7 @@ import androidx.annotation.StringRes
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.setupwizard.SWValidator import info.nightscout.androidaps.setupwizard.SWValidator
class SWHtmlLink(injector: HasAndroidInjector) : SWItem(injector, Type.HTMLLINK) { class SWHtmlLink(injector: HasAndroidInjector) : SWItem(injector, Type.HTML_LINK) {
private var textLabel: String? = null private var textLabel: String? = null
private var l: TextView? = null private var l: TextView? = null

View file

@ -6,22 +6,22 @@ import android.widget.TextView
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.setupwizard.SWValidator import info.nightscout.androidaps.setupwizard.SWValidator
class SWInfotext(injector: HasAndroidInjector) : SWItem(injector, Type.TEXT) { class SWInfoText(injector: HasAndroidInjector) : SWItem(injector, Type.TEXT) {
private var textLabel: String? = null private var textLabel: String? = null
private var l: TextView? = null private var l: TextView? = null
private var visibilityValidator: SWValidator? = null private var visibilityValidator: SWValidator? = null
override fun label(label: Int): SWInfotext { override fun label(label: Int): SWInfoText {
this.label = label this.label = label
return this return this
} }
fun label(newLabel: String): SWInfotext { fun label(newLabel: String): SWInfoText {
textLabel = newLabel textLabel = newLabel
return this return this
} }
fun visibility(visibilityValidator: SWValidator): SWInfotext { fun visibility(visibilityValidator: SWValidator): SWInfoText {
this.visibilityValidator = visibilityValidator this.visibilityValidator = visibilityValidator
return this return this
} }

View file

@ -27,25 +27,18 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) {
private var scheduledEventPost: ScheduledFuture<*>? = null private var scheduledEventPost: ScheduledFuture<*>? = null
init { init {
@Suppress("LeakingThis")
injector.androidInjector().inject(this) injector.androidInjector().inject(this)
} }
enum class Type { enum class Type {
NONE, TEXT, HTMLLINK, BREAK, LISTENER, URL, STRING, NUMBER, DECIMALNUMBER, CHECKBOX, RADIOBUTTON, PLUGIN, BUTTON, FRAGMENT, UNITNUMBER NONE, TEXT, HTML_LINK, BREAK, LISTENER, URL, STRING, NUMBER, DECIMAL_NUMBER, RADIOBUTTON, PLUGIN, BUTTON, FRAGMENT, UNIT_NUMBER
} }
var label: Int? = null var label: Int? = null
var comment: Int? = null var comment: Int? = null
var preferenceId = 0 var preferenceId = 0
fun getLabel(): String {
return label?.let { resourceHelper.gs(it) } ?: ""
}
fun getComment(): String {
return comment?.let { resourceHelper.gs(it) } ?: ""
}
open fun label(@StringRes label: Int): SWItem { open fun label(@StringRes label: Int): SWItem {
this.label = label this.label = label
return this return this
@ -72,6 +65,7 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) {
fun scheduleChange(updateDelay: Long) { fun scheduleChange(updateDelay: Long) {
class PostRunnable : Runnable { class PostRunnable : Runnable {
override fun run() { override fun run() {
aapsLogger.debug(LTag.CORE, "Firing EventPreferenceChange") aapsLogger.debug(LTag.CORE, "Firing EventPreferenceChange")
rxBus.send(EventPreferenceChange(resourceHelper, preferenceId)) rxBus.send(EventPreferenceChange(resourceHelper, preferenceId))

View file

@ -89,7 +89,7 @@ class SWPlugin(injector: HasAndroidInjector, val definition: SWDefinition) : SWI
super.generateDialog(layout) super.generateDialog(layout)
} }
fun addConfiguration(layout: LinearLayout, plugin: PluginBase) { private fun addConfiguration(layout: LinearLayout, plugin: PluginBase) {
if (plugin.preferencesId != -1) { if (plugin.preferencesId != -1) {
fragment = MyPreferenceFragment() fragment = MyPreferenceFragment()
fragment?.arguments = Bundle().also { it.putInt("id", plugin.preferencesId) } fragment?.arguments = Bundle().also { it.putInt("id", plugin.preferencesId) }

View file

@ -29,12 +29,12 @@ class SWRadioButton(injector: HasAndroidInjector) : SWItem(injector, Type.RADIOB
override fun generateDialog(layout: LinearLayout) { override fun generateDialog(layout: LinearLayout) {
val context = layout.context val context = layout.context
val pdesc = TextView(context) val desc = TextView(context)
pdesc.text = getComment() comment?.let { desc.setText(it) }
val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
params.setMargins(0, 0, 0, 40) params.setMargins(0, 0, 0, 40)
pdesc.layoutParams = params desc.layoutParams = params
layout.addView(pdesc) layout.addView(desc)
// Get if there is already value in SP // Get if there is already value in SP
val previousValue = sp.getString(preferenceId, "none") val previousValue = sp.getString(preferenceId, "none")
@ -43,12 +43,12 @@ class SWRadioButton(injector: HasAndroidInjector) : SWItem(injector, Type.RADIOB
radioGroup?.orientation = LinearLayout.VERTICAL radioGroup?.orientation = LinearLayout.VERTICAL
radioGroup?.visibility = View.VISIBLE radioGroup?.visibility = View.VISIBLE
for (i in labels().indices) { for (i in labels().indices) {
val rdbtn = RadioButton(context) val rdBtn = RadioButton(context)
rdbtn.id = View.generateViewId() rdBtn.id = View.generateViewId()
rdbtn.text = labels()[i] rdBtn.text = labels()[i]
if (previousValue == values()[i]) rdbtn.isChecked = true if (previousValue == values()[i]) rdBtn.isChecked = true
rdbtn.tag = i rdBtn.tag = i
radioGroup!!.addView(rdbtn) radioGroup!!.addView(rdBtn)
} }
radioGroup!!.setOnCheckedChangeListener { group: RadioGroup, checkedId: Int -> radioGroup!!.setOnCheckedChangeListener { group: RadioGroup, checkedId: Int ->
val i = group.findViewById<View>(checkedId).tag as Int val i = group.findViewById<View>(checkedId).tag as Int

View file

@ -1381,5 +1381,6 @@
<string name="trend_arrow">Trend arrow</string> <string name="trend_arrow">Trend arrow</string>
<string name="cannula">Cannula</string> <string name="cannula">Cannula</string>
<string name="userentry">User entry</string> <string name="userentry">User entry</string>
<string name="common_values">Use values of your largest food you usually eat\n</string>
</resources> </resources>