fix: inbox reload when changing type from default and navigating (#406)

This commit is contained in:
Diego Beraldin 2023-12-31 14:46:59 +01:00 committed by GitHub
parent d349aa5dbe
commit f0623ca9a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 4 deletions

View File

@ -3,4 +3,5 @@ package com.github.diegoberaldin.raccoonforlemmy.core.notifications
interface ContentResetCoordinator {
var resetHome: Boolean
var resetExplore: Boolean
var resetInbox: Boolean
}

View File

@ -4,4 +4,5 @@ class DefaultContentResetCoordinator : ContentResetCoordinator {
override var resetHome = false
override var resetExplore = false
override var resetInbox = false
}

View File

@ -22,6 +22,7 @@ val inboxTabModule = module {
coordinator = get(),
settingsRepository = get(),
notificationCenter = get(),
contentResetCoordinator = get(),
)
}
}

View File

@ -2,6 +2,7 @@ package com.github.diegoberaldin.raccoonforlemmy.feature.inbox.main
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.DefaultMviModel
import com.github.diegoberaldin.raccoonforlemmy.core.architecture.MviModel
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.ContentResetCoordinator
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenter
import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationCenterEvent
import com.github.diegoberaldin.raccoonforlemmy.core.persistence.repository.SettingsRepository
@ -22,9 +23,12 @@ class InboxViewModel(
private val coordinator: InboxCoordinator,
private val settingsRepository: SettingsRepository,
private val notificationCenter: NotificationCenter,
private val contentResetCoordinator: ContentResetCoordinator,
) : InboxMviModel,
MviModel<InboxMviModel.Intent, InboxMviModel.UiState, InboxMviModel.Effect> by mvi {
private var firstLoad = true
override fun onStarted() {
mvi.onStarted()
mvi.scope?.launch {
@ -47,10 +51,18 @@ class InboxViewModel(
changeUnreadOnly(evt.unreadOnly)
}.launchIn(this)
val settingsUnreadOnly =
settingsRepository.currentSettings.value.defaultInboxType.toInboxUnreadOnly()
if (uiState.value.unreadOnly != settingsUnreadOnly) {
changeUnreadOnly(settingsUnreadOnly)
if (contentResetCoordinator.resetInbox) {
contentResetCoordinator.resetInbox = false
// apply new inbox type
firstLoad = true
}
if (firstLoad) {
firstLoad = false
val settingsUnreadOnly =
settingsRepository.currentSettings.value.defaultInboxType.toInboxUnreadOnly()
if (uiState.value.unreadOnly != settingsUnreadOnly) {
changeUnreadOnly(settingsUnreadOnly)
}
}
}
}

View File

@ -669,6 +669,7 @@ class SettingsViewModel(
defaultInboxType = value.toInboxDefaultType(),
)
saveSettings(settings)
contentResetCoordinator.resetInbox = true
}
}