From af3ac727a4cfaf51f61bb17ebc687ec4662b8fe2 Mon Sep 17 00:00:00 2001 From: Aparna Vadlamani Date: Fri, 22 Nov 2024 19:20:30 +0530 Subject: [PATCH] NTP-11931 | Notify Me: NotificationSettings Error handling changes (#13766) --- .../viewmodel/NotificationSettingsVM.kt | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/android/app/src/main/java/com/naviapp/appsettings/viewmodel/NotificationSettingsVM.kt b/android/app/src/main/java/com/naviapp/appsettings/viewmodel/NotificationSettingsVM.kt index 8b8aadc698..c2cff39fe3 100644 --- a/android/app/src/main/java/com/naviapp/appsettings/viewmodel/NotificationSettingsVM.kt +++ b/android/app/src/main/java/com/naviapp/appsettings/viewmodel/NotificationSettingsVM.kt @@ -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(