From 86fb53ce3425f536e5bd2dfcf069f47e66cd55e2 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 15 Feb 2021 13:57:01 +0100 Subject: [PATCH] SetupWizard update --- .../dependencyInjection/WizardModule.kt | 3 +- .../androidaps/setupwizard/SWDefinition.kt | 55 ++++++++++------- .../setupwizard/elements/SWBreak.kt | 2 +- .../setupwizard/elements/SWEditNumber.kt | 60 +++++++++++++++++++ .../elements/SWEditNumberWithUnits.kt | 6 +- .../setupwizard/elements/SWEditUrl.kt | 2 +- .../setupwizard/elements/SWHtmlLink.kt | 2 +- .../elements/{SWInfotext.kt => SWInfoText.kt} | 8 +-- .../androidaps/setupwizard/elements/SWItem.kt | 12 +--- .../setupwizard/elements/SWPlugin.kt | 2 +- .../setupwizard/elements/SWRadioButton.kt | 20 +++---- app/src/main/res/values/strings.xml | 1 + 12 files changed, 121 insertions(+), 52 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumber.kt rename app/src/main/java/info/nightscout/androidaps/setupwizard/elements/{SWInfotext.kt => SWInfoText.kt} (82%) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt index 66c99d5e17..2c105e9ce7 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/WizardModule.kt @@ -13,12 +13,13 @@ abstract class WizardModule { @ContributesAndroidInjector abstract fun swBreakInjector(): SWBreak @ContributesAndroidInjector abstract fun swButtonInjector(): SWButton @ContributesAndroidInjector abstract fun swEditNumberWithUnitsInjector(): SWEditNumberWithUnits + @ContributesAndroidInjector abstract fun swEditNumberInjector(): SWEditNumber @ContributesAndroidInjector abstract fun swEditStringInjector(): SWEditString @ContributesAndroidInjector abstract fun swEditEncryptedPasswordInjector(): SWEditEncryptedPassword @ContributesAndroidInjector abstract fun swEditUrlInjector(): SWEditUrl @ContributesAndroidInjector abstract fun swFragmentInjector(): SWFragment @ContributesAndroidInjector abstract fun swHtmlLinkInjector(): SWHtmlLink - @ContributesAndroidInjector abstract fun swInfotextInjector(): SWInfotext + @ContributesAndroidInjector abstract fun swInfotextInjector(): SWInfoText @ContributesAndroidInjector abstract fun swItemInjector(): SWItem @ContributesAndroidInjector abstract fun swPluginInjector(): SWPlugin @ContributesAndroidInjector abstract fun swRadioButtonInjector(): SWRadioButton diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 0cc0a8c9e6..baf7bad0ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -74,11 +74,11 @@ class SWDefinition @Inject constructor( } private val screenSetupWizard = SWScreen(injector, R.string.nav_setupwizard) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.welcometosetupwizard)) private val screenEula = SWScreen(injector, R.string.end_user_license_agreement) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.end_user_license_agreement_text)) .add(SWBreak(injector)) .add(SWButton(injector) @@ -112,7 +112,7 @@ class SWDefinition @Inject constructor( .comment(R.string.high_mark_comment)) private val screenPermissionBattery = SWScreen(injector, R.string.permission) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(resourceHelper.gs(R.string.needwhitelisting, resourceHelper.gs(R.string.app_name)))) .add(SWBreak(injector)) .add(SWButton(injector) @@ -123,7 +123,7 @@ class SWDefinition @Inject constructor( .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) } private val screenPermissionBt = SWScreen(injector, R.string.permission) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(resourceHelper.gs(R.string.needlocationpermission))) .add(SWBreak(injector)) .add(SWButton(injector) @@ -134,7 +134,7 @@ class SWDefinition @Inject constructor( .validator { !androidPermission.permissionNotGranted(activity, Manifest.permission.ACCESS_FINE_LOCATION) } private val screenPermissionStore = SWScreen(injector, R.string.permission) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(resourceHelper.gs(R.string.needstoragepermission))) .add(SWBreak(injector)) .add(SWButton(injector) @@ -144,7 +144,7 @@ class SWDefinition @Inject constructor( .visibility { 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) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.storedsettingsfound)) .add(SWBreak(injector)) .add(SWButton(injector) @@ -153,7 +153,7 @@ class SWDefinition @Inject constructor( .visibility { importExportPrefs.prefsFileExists() && !androidPermission.permissionNotGranted(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) } private val screenNsClient = SWScreen(injector, R.string.nsclientinternal_title) .skippable(true) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.nsclientinfotext)) .add(SWBreak(injector)) .add(SWButton(injector) @@ -183,19 +183,19 @@ class SWDefinition @Inject constructor( .visibility { !(nsClientPlugin.nsClientService != null && NSClientService.isConnected && NSClientService.hasWriteAuth) } private val screenPatientName = SWScreen(injector, R.string.patient_name) .skippable(true) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.patient_name_summary)) .add(SWEditString(injector) .validator(SWTextValidator(String::isNotEmpty)) .preferenceId(R.string.key_patient_name)) private val screenMasterPassword = SWScreen(injector, R.string.master_password) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.master_password)) .add(SWEditEncryptedPassword(injector, cryptoUtil) .preferenceId(R.string.key_master_password)) .add(SWBreak(injector)) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.master_password_summary)) .validator { !cryptoUtil.checkPassword("", sp.getString(R.string.key_master_password, "")) } private val screenAge = SWScreen(injector, R.string.patientage) @@ -206,7 +206,20 @@ class SWDefinition @Inject constructor( .preferenceId(R.string.key_age) .label(R.string.patientage) .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) .skippable(false) .add(SWPlugin(injector, this) @@ -214,7 +227,7 @@ class SWDefinition @Inject constructor( .makeVisible(false) .label(R.string.configbuilder_insulin)) .add(SWBreak(injector)) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.diawarning)) private val screenBgSource = SWScreen(injector, R.string.configbuilder_bgsource) .skippable(false) @@ -224,7 +237,7 @@ class SWDefinition @Inject constructor( .add(SWBreak(injector)) private val screenProfile = SWScreen(injector, R.string.configbuilder_profile) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.setupwizard_profile_description)) .add(SWBreak(injector)) .add(SWPlugin(injector, this) @@ -232,7 +245,7 @@ class SWDefinition @Inject constructor( .label(R.string.configbuilder_profile)) private val screenNsProfile = SWScreen(injector, R.string.nsprofile) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.adjustprofileinns)) .add(SWFragment(injector, this) .add(NSProfileFragment())) @@ -246,7 +259,7 @@ class SWDefinition @Inject constructor( .visibility { localProfilePlugin.isEnabled(PluginType.PROFILE) } private val screenProfileSwitch = SWScreen(injector, R.string.careportal_profileswitch) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.profileswitch_ismissing)) .add(SWButton(injector) .text(R.string.doprofileswitch) @@ -259,11 +272,11 @@ class SWDefinition @Inject constructor( .option(PluginType.PUMP, R.string.configbuilder_pump_description) .label(R.string.configbuilder_pump)) .add(SWBreak(injector)) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.setupwizard_pump_pump_not_initialized) .visibility { !isPumpInitialized() }) .add( // Omnipod only - SWInfotext(injector) + SWInfoText(injector) .label(R.string.setupwizard_pump_waiting_for_riley_link_connection) .visibility { val activePump = activePlugin.activePump @@ -295,7 +308,7 @@ class SWDefinition @Inject constructor( private val screenAps = SWScreen(injector, R.string.configbuilder_aps) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.setupwizard_aps_description)) .add(SWBreak(injector)) .add(SWPlugin(injector, this) @@ -314,7 +327,7 @@ class SWDefinition @Inject constructor( .validator { sp.contains(R.string.key_aps_mode) } private val screenLoop = SWScreen(injector, R.string.configbuilder_loop) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.setupwizard_loop_description)) .add(SWBreak(injector)) .add(SWButton(injector) @@ -328,7 +341,7 @@ class SWDefinition @Inject constructor( .visibility { !loopPlugin.isEnabled(PluginType.LOOP) && config.APS } private val screenSensitivity = SWScreen(injector, R.string.configbuilder_sensitivity) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.setupwizard_sensitivity_description)) .add(SWHtmlLink(injector) .label(R.string.setupwizard_sensitivity_url)) @@ -338,7 +351,7 @@ class SWDefinition @Inject constructor( .label(R.string.configbuilder_sensitivity)) private val getScreenObjectives = SWScreen(injector, R.string.objectives) .skippable(false) - .add(SWInfotext(injector) + .add(SWInfoText(injector) .label(R.string.startobjective)) .add(SWBreak(injector)) .add(SWFragment(injector, this) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWBreak.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWBreak.kt index 775d5b72d0..2d6f4926a3 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWBreak.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWBreak.kt @@ -6,7 +6,7 @@ import android.widget.TextView import dagger.android.HasAndroidInjector 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 visibilityValidator: SWValidator? = null diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumber.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumber.kt new file mode 100644 index 0000000000..f29f7a1328 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumber.kt @@ -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 + } + +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumberWithUnits.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumberWithUnits.kt index 2d49eb3a97..7f9934f2c8 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumberWithUnits.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditNumberWithUnits.kt @@ -16,11 +16,11 @@ import info.nightscout.androidaps.utils.SafeParse import java.text.DecimalFormat 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 - private val validator: SWNumberValidator? = SWNumberValidator { value -> value >= min && value <= max } + private val validator: SWNumberValidator = SWNumberValidator { value -> value in min..max } private var updateDelay = 0 override fun generateDialog(layout: LinearLayout) { @@ -28,7 +28,7 @@ class SWEditNumberWithUnits(injector: HasAndroidInjector, private val init: Doub 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 != null && validator.isValid(SafeParse.stringToDouble(s.toString()))) + if (validator.isValid(SafeParse.stringToDouble(s.toString()))) save(s.toString(), updateDelay.toLong()) } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.kt index cc9f38ff43..90647b51cf 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWEditUrl.kt @@ -38,7 +38,7 @@ class SWEditUrl(injector: HasAndroidInjector) : SWItem(injector, Type.URL) { editText.addTextChangedListener(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 (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) {} diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWHtmlLink.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWHtmlLink.kt index fe5b34241e..73bb625537 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWHtmlLink.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWHtmlLink.kt @@ -8,7 +8,7 @@ import androidx.annotation.StringRes import dagger.android.HasAndroidInjector 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 l: TextView? = null diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWInfotext.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWInfoText.kt similarity index 82% rename from app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWInfotext.kt rename to app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWInfoText.kt index ca9b3b829f..9a8e0f00cd 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWInfotext.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWInfoText.kt @@ -6,22 +6,22 @@ import android.widget.TextView import dagger.android.HasAndroidInjector 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 l: TextView? = null private var visibilityValidator: SWValidator? = null - override fun label(label: Int): SWInfotext { + override fun label(label: Int): SWInfoText { this.label = label return this } - fun label(newLabel: String): SWInfotext { + fun label(newLabel: String): SWInfoText { textLabel = newLabel return this } - fun visibility(visibilityValidator: SWValidator): SWInfotext { + fun visibility(visibilityValidator: SWValidator): SWInfoText { this.visibilityValidator = visibilityValidator return this } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt index 48e40868c3..c6cc3f9620 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWItem.kt @@ -27,25 +27,18 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) { private var scheduledEventPost: ScheduledFuture<*>? = null init { + @Suppress("LeakingThis") injector.androidInjector().inject(this) } 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 comment: Int? = null 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 { this.label = label return this @@ -72,6 +65,7 @@ open class SWItem(val injector: HasAndroidInjector, var type: Type) { fun scheduleChange(updateDelay: Long) { class PostRunnable : Runnable { + override fun run() { aapsLogger.debug(LTag.CORE, "Firing EventPreferenceChange") rxBus.send(EventPreferenceChange(resourceHelper, preferenceId)) diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt index 60702978e9..76c140d708 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWPlugin.kt @@ -89,7 +89,7 @@ class SWPlugin(injector: HasAndroidInjector, val definition: SWDefinition) : SWI super.generateDialog(layout) } - fun addConfiguration(layout: LinearLayout, plugin: PluginBase) { + private fun addConfiguration(layout: LinearLayout, plugin: PluginBase) { if (plugin.preferencesId != -1) { fragment = MyPreferenceFragment() fragment?.arguments = Bundle().also { it.putInt("id", plugin.preferencesId) } diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.kt index 7201c47342..979bfe52fc 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.kt @@ -29,12 +29,12 @@ class SWRadioButton(injector: HasAndroidInjector) : SWItem(injector, Type.RADIOB override fun generateDialog(layout: LinearLayout) { val context = layout.context - val pdesc = TextView(context) - pdesc.text = getComment() + val desc = TextView(context) + comment?.let { desc.setText(it) } val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) params.setMargins(0, 0, 0, 40) - pdesc.layoutParams = params - layout.addView(pdesc) + desc.layoutParams = params + layout.addView(desc) // Get if there is already value in SP val previousValue = sp.getString(preferenceId, "none") @@ -43,12 +43,12 @@ class SWRadioButton(injector: HasAndroidInjector) : SWItem(injector, Type.RADIOB radioGroup?.orientation = LinearLayout.VERTICAL radioGroup?.visibility = View.VISIBLE for (i in labels().indices) { - val rdbtn = RadioButton(context) - rdbtn.id = View.generateViewId() - rdbtn.text = labels()[i] - if (previousValue == values()[i]) rdbtn.isChecked = true - rdbtn.tag = i - radioGroup!!.addView(rdbtn) + val rdBtn = RadioButton(context) + rdBtn.id = View.generateViewId() + rdBtn.text = labels()[i] + if (previousValue == values()[i]) rdBtn.isChecked = true + rdBtn.tag = i + radioGroup!!.addView(rdBtn) } radioGroup!!.setOnCheckedChangeListener { group: RadioGroup, checkedId: Int -> val i = group.findViewById(checkedId).tag as Int diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2982994458..0d7e5910da 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1381,5 +1381,6 @@ Trend arrow Cannula User entry + Use values of your largest food you usually eat\n