NTP-11931 | Notify Me: NotificationSettings Error handling changes (#13766)

This commit is contained in:
Aparna Vadlamani
2024-11-22 19:20:30 +05:30
committed by GitHub
parent afef1ccbd6
commit af3ac727a4

View File

@@ -8,10 +8,10 @@
package com.naviapp.appsettings.viewmodel
import androidx.lifecycle.viewModelScope
import com.navi.base.utils.EMPTY
import com.navi.common.basemvi.BaseMviViewModel
import com.navi.common.basemvi.UiEffect
import com.navi.common.network.models.isSuccess
import com.navi.common.network.models.isSuccessWithData
import com.naviapp.appsettings.model.notificationSettings.BottomSheetContent
import com.naviapp.appsettings.model.notificationSettings.NotificationSettingsBottomSheetType
import com.naviapp.appsettings.model.notificationSettings.NotificationSettingsUiEvents
@@ -24,7 +24,6 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withTimeout
@HiltViewModel
class NotificationSettingsVM
@@ -40,35 +39,25 @@ constructor(private val repository: NotificationSettingsRepository) :
notificationPermission: Boolean
) {
viewModelScope.launch(Dispatchers.IO) {
try {
withTimeout(5000) {
val response =
repository.fetchNotificationData(
naeScreenName = naeScreenName,
type = type,
notificationPermission = notificationPermission
)
val response =
repository.fetchNotificationData(
naeScreenName = naeScreenName,
type = type,
notificationPermission = notificationPermission
)
if (response.error == null && response.isSuccess()) {
sendEvent(
NotificationSettingsUiEvents.UpdateNotificationSettingsState(
SettingsState.Success(
response.data?.globalNotificationSettings ?: emptyList()
)
)
)
} else {
sendEvent(
NotificationSettingsUiEvents.UpdateNotificationSettingsState(
SettingsState.Error(response.error?.message.orEmpty())
)
)
}
}
} catch (e: Exception) {
if (response.isSuccessWithData()) {
sendEvent(
NotificationSettingsUiEvents.UpdateNotificationSettingsState(
SettingsState.Error(EMPTY)
SettingsState.Success(
response.data?.globalNotificationSettings ?: emptyList()
)
)
)
} else {
sendEvent(
NotificationSettingsUiEvents.UpdateNotificationSettingsState(
SettingsState.Error(response.error?.message.orEmpty())
)
)
}
@@ -87,7 +76,7 @@ constructor(private val repository: NotificationSettingsRepository) :
val updatedList = currentList.map { modifiedMap[it.medium] ?: it }
val response =
repository.updateCommunicationMediums(type = type, updatedList, naeScreenName)
if (response.error == null && response.errors.isNullOrEmpty()) {
if (response.isSuccess()) {
sendEvent(NotificationSettingsUiEvents.UpdateNotificationSettings(updatedList))
} else {
sendEvent(