diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt index 030f84bd..d13e00fb 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/main/notifications/list/NotificationsListViewModel.kt @@ -9,42 +9,33 @@ import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.* import javax.inject.Inject -typealias NotificationsListViewModel = BaseViewModel +abstract class NotificationsListViewModel : + BaseViewModel() { + + override fun createInitialState(): NotificationsListUiState = NotificationsListUiState() + + override fun dispatchEvent(partialChange: NotificationsListPartialChange): UiEvent? = + when (partialChange) { + is NotificationsListPartialChange.Refresh.Failure -> CommonUiEvent.Toast(partialChange.error.getErrorMessage()) + is NotificationsListPartialChange.LoadMore.Failure -> CommonUiEvent.Toast(partialChange.error.getErrorMessage()) + else -> null + } +} @HiltViewModel class ReplyMeListViewModel @Inject constructor() : NotificationsListViewModel() { - override fun createInitialState(): NotificationsListUiState = NotificationsListUiState() - override fun createPartialChangeProducer(): PartialChangeProducer { return NotificationsListPartialChangeProducer(NotificationsType.ReplyMe) } - - override fun dispatchEvent(partialChange: NotificationsListPartialChange): UiEvent? = - when (partialChange) { - is NotificationsListPartialChange.Refresh.Failure -> CommonUiEvent.Toast(partialChange.error.getErrorMessage()) - is NotificationsListPartialChange.LoadMore.Failure -> CommonUiEvent.Toast(partialChange.error.getErrorMessage()) - else -> null - } - } @HiltViewModel class AtMeListViewModel @Inject constructor() : NotificationsListViewModel() { - override fun createInitialState(): NotificationsListUiState = NotificationsListUiState() - override fun createPartialChangeProducer(): PartialChangeProducer { return NotificationsListPartialChangeProducer(NotificationsType.AtMe) } - - override fun dispatchEvent(partialChange: NotificationsListPartialChange): UiEvent? = - when (partialChange) { - is NotificationsListPartialChange.Refresh.Failure -> CommonUiEvent.Toast(partialChange.error.getErrorMessage()) - is NotificationsListPartialChange.LoadMore.Failure -> CommonUiEvent.Toast(partialChange.error.getErrorMessage()) - else -> null - } - } private class NotificationsListPartialChangeProducer(private val type: NotificationsType) : PartialChangeProducer {