From 8283909e9f8d1bf8ba0e8749bed984ab7c279222 Mon Sep 17 00:00:00 2001 From: odaridavid Date: Mon, 11 Mar 2024 23:13:43 +0100 Subject: [PATCH] introduce empty data state incase user deselects all options --- .../odaridavid/weatherapp/core/model/ExcludedData.kt | 1 + .../weatherapp/ui/settings/SettingsViewModel.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/odaridavid/weatherapp/core/model/ExcludedData.kt b/app/src/main/java/com/github/odaridavid/weatherapp/core/model/ExcludedData.kt index 7be523f..10bd630 100644 --- a/app/src/main/java/com/github/odaridavid/weatherapp/core/model/ExcludedData.kt +++ b/app/src/main/java/com/github/odaridavid/weatherapp/core/model/ExcludedData.kt @@ -5,4 +5,5 @@ enum class ExcludedData(val value:String){ DAILY("daily"), MINUTELY("minutely"), ALERTS("alerts"), + NONE(""), } diff --git a/app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/SettingsViewModel.kt index 97b2320..b026a1f 100644 --- a/app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/com/github/odaridavid/weatherapp/ui/settings/SettingsViewModel.kt @@ -2,6 +2,7 @@ package com.github.odaridavid.weatherapp.ui.settings import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.github.odaridavid.weatherapp.core.api.Logger import com.github.odaridavid.weatherapp.core.api.SettingsRepository import com.github.odaridavid.weatherapp.core.model.ExcludedData import dagger.hilt.android.lifecycle.HiltViewModel @@ -14,7 +15,8 @@ import javax.inject.Inject @HiltViewModel class SettingsViewModel @Inject constructor( - private val settingsRepository: SettingsRepository + private val settingsRepository: SettingsRepository, + private val logger: Logger, ) : ViewModel() { private val _state = MutableStateFlow(SettingsScreenViewState()) @@ -104,7 +106,10 @@ class SettingsViewModel @Inject constructor( ExcludedData.DAILY.value -> ExcludedData.DAILY ExcludedData.MINUTELY.value -> ExcludedData.MINUTELY ExcludedData.ALERTS.value -> ExcludedData.ALERTS - else -> throw IllegalArgumentException("Invalid excluded data") + else ->{ + logger.logException(IllegalArgumentException("Invalid excluded data")) + ExcludedData.NONE + } } } }