From 3d6d3768401ca01bd0c80cdc5ae463abc7b10126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=C2=A0Koby=C5=82ko?= Date: Sat, 21 Oct 2023 20:55:35 +0200 Subject: [PATCH] Fix null values in advanced settings --- .../src/main/java/com/twofasapp/common/domain/Service.kt | 4 ++++ .../advancedsettings/AdvancedSettingsScreen.kt | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/core/common/src/main/java/com/twofasapp/common/domain/Service.kt b/core/common/src/main/java/com/twofasapp/common/domain/Service.kt index 680a40c3..8a84b5f0 100644 --- a/core/common/src/main/java/com/twofasapp/common/domain/Service.kt +++ b/core/common/src/main/java/com/twofasapp/common/domain/Service.kt @@ -58,6 +58,10 @@ data class Service( } companion object { + val DefaultAlgorithm = Algorithm.SHA1 + const val DefaultPeriod = 30 + const val DefaultDigits = 6 + val Empty = Service( id = 0L, serviceTypeId = null, diff --git a/feature/home/src/main/java/com/twofasapp/feature/home/ui/editservice/advancedsettings/AdvancedSettingsScreen.kt b/feature/home/src/main/java/com/twofasapp/feature/home/ui/editservice/advancedsettings/AdvancedSettingsScreen.kt index bc1eda9c..01aa3c88 100644 --- a/feature/home/src/main/java/com/twofasapp/feature/home/ui/editservice/advancedsettings/AdvancedSettingsScreen.kt +++ b/feature/home/src/main/java/com/twofasapp/feature/home/ui/editservice/advancedsettings/AdvancedSettingsScreen.kt @@ -15,9 +15,8 @@ import com.twofasapp.designsystem.TwTheme import com.twofasapp.designsystem.common.TwTopAppBar import com.twofasapp.designsystem.settings.SettingsDivider import com.twofasapp.designsystem.settings.SettingsLink -import com.twofasapp.locale.TwLocale import com.twofasapp.locale.R -import com.twofasapp.feature.home.ui.editservice.EditServiceViewModel +import com.twofasapp.locale.TwLocale @Composable internal fun AdvancedSettingsScreen( @@ -74,7 +73,7 @@ internal fun AdvancedSettingsScreen( item { SettingsLink( title = TwLocale.strings.addManualAlgorithm, - subtitle = service.algorithm?.name.orEmpty(), + subtitle = service.algorithm?.name ?: Service.DefaultAlgorithm.name, enabled = false, ) } @@ -83,7 +82,7 @@ internal fun AdvancedSettingsScreen( item { SettingsLink( title = TwLocale.strings.addManualRefreshTime, - subtitle = service.period.toString(), + subtitle = (service.period ?: Service.DefaultPeriod).toString(), enabled = false, ) } @@ -102,7 +101,7 @@ internal fun AdvancedSettingsScreen( item { SettingsLink( title = TwLocale.strings.addManualDigits, - subtitle = service.digits.toString(), + subtitle = (service.digits ?: Service.DefaultDigits).toString(), enabled = false, ) }