Skip to content

Commit

Permalink
Mark post as read when reader screen is being destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Apr 10, 2024
1 parent 13b8624 commit 3600f79
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ sealed interface ReaderEvent {
data object TogglePostBookmark : ReaderEvent

data object ArticleShortcutClicked : ReaderEvent

data object MarkPostAsRead : ReaderEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3600f79

Please sign in to comment.