diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt index c3420ca77..936d7d634 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/app/AppPresenter.kt @@ -174,9 +174,8 @@ class AppPresenter( navigation.push(Config.Reader(postLink)) } else { linkHandler.openLink(postLink) + rssRepository.updatePostReadStatus(read = true, link = postLink) } - - rssRepository.updatePostReadStatus(read = true, link = postLink) } } diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderEvent.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderEvent.kt index 3801b2d52..43b96fe65 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderEvent.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderEvent.kt @@ -25,4 +25,6 @@ sealed interface ReaderEvent { data object TogglePostBookmark : ReaderEvent data object ArticleShortcutClicked : ReaderEvent + + data object MarkPostAsRead : ReaderEvent } diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderPresenter.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderPresenter.kt index d916b2606..c7969590d 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderPresenter.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/reader/ReaderPresenter.kt @@ -20,6 +20,7 @@ import com.arkivanov.decompose.ComponentContext import com.arkivanov.essenty.instancekeeper.InstanceKeeper import com.arkivanov.essenty.instancekeeper.getOrCreate import com.arkivanov.essenty.lifecycle.doOnCreate +import com.arkivanov.essenty.lifecycle.doOnDestroy import dev.sasikanth.readability.Readability import dev.sasikanth.rss.reader.core.network.post.PostSourceFetcher import dev.sasikanth.rss.reader.reader.ReaderState.PostMode.Idle @@ -70,6 +71,7 @@ class ReaderPresenter( init { lifecycle.doOnCreate { presenterInstance.dispatch(ReaderEvent.Init(postLink)) } + lifecycle.doOnDestroy { presenterInstance.dispatch(ReaderEvent.MarkPostAsRead) } } internal val state = presenterInstance.state @@ -110,9 +112,14 @@ class ReaderPresenter( } ReaderEvent.TogglePostBookmark -> togglePostBookmark(postLink) ReaderEvent.ArticleShortcutClicked -> articleShortcutClicked() + ReaderEvent.MarkPostAsRead -> markPostAsRead(postLink) } } + private fun markPostAsRead(postLink: String) { + coroutineScope.launch { rssRepository.updatePostReadStatus(read = true, link = postLink) } + } + private fun togglePostBookmark(postLink: String) { coroutineScope.launch { val isBookmarked = state.value.isBookmarked ?: false