Skip to content

Commit

Permalink
Add option to mark individual posts as read/unread (#261)
Browse files Browse the repository at this point in the history
* Add event to home presenter to toggle post read status

* Add event to bookmarks presenter to toggle post read status

* Add event to search presenter to toggle post read status

* Add option to mark post as read/unread

* Add divider between post menu items

* Use customised DropdownMenu instead of Material one
  • Loading branch information
msasikanth authored Jan 30, 2024
1 parent 46f4ff6 commit 964d67d
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@ val EnTwineStrings =
postsToday = "Today",
openSource = "Open Source",
openSourceDesc =
"Twine is built on open source technologies and is completely free to use, you can find the source code of Twine and some of my other popular projects on GitHub. Click here to head over there."
"Twine is built on open source technologies and is completely free to use, you can find the source code of Twine and some of my other popular projects on GitHub. Click here to head over there.",
markAsRead = "Mark as Read",
markAsUnRead = "Mark as Unread"
)
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ data class TwineStrings(
val postsToday: String,
val openSource: String,
val openSourceDesc: String,
val markAsRead: String,
val markAsUnRead: String
)

object Locales {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ sealed interface BookmarksEvent {
data class OnPostBookmarkClick(val post: PostWithMetadata) : BookmarksEvent

data class OnPostClicked(val post: PostWithMetadata) : BookmarksEvent

data class TogglePostReadStatus(val postLink: String, val postRead: Boolean) : BookmarksEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ class BookmarksPresenter(
is BookmarksEvent.OnPostClicked -> {
// no-op
}
is BookmarksEvent.TogglePostReadStatus ->
togglePostReadStatus(event.postLink, event.postRead)
}
}

private fun togglePostReadStatus(postLink: String, postRead: Boolean) {
coroutineScope.launch {
rssRepository.updatePostReadStatus(read = !postRead, link = postLink)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ internal fun BookmarksScreen(
},
onPostSourceClick = {
// no-op
},
togglePostReadClick = {
bookmarksPresenter.dispatch(
BookmarksEvent.TogglePostReadStatus(post.link, post.read)
)
}
)
if (index != bookmarks.itemCount - 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ sealed interface HomeEvent {
data object EditFeedsClicked : HomeEvent

data object ExitFeedsEdit : HomeEvent

data class TogglePostReadStatus(val postLink: String, val postRead: Boolean) : HomeEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ class HomePresenter(
HomeEvent.ExitFeedsEdit -> exitFeedsEdit()
is HomeEvent.OnPostSourceClicked -> postSourceClicked(event.feedLink)
is HomeEvent.OnPostsTypeChanged -> onPostsTypeChanged(event.postsType)
is HomeEvent.TogglePostReadStatus -> togglePostReadStatus(event.postLink, event.postRead)
}
}

private fun togglePostReadStatus(postLink: String, postRead: Boolean) {
coroutineScope.launch {
rssRepository.updatePostReadStatus(read = !postRead, link = postLink)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ internal fun FeaturedPostItem(
onClick: () -> Unit,
onBookmarkClick: () -> Unit,
onCommentsClick: () -> Unit,
onSourceClick: () -> Unit
onSourceClick: () -> Unit,
onTogglePostReadClick: () -> Unit,
) {
val isLargeScreenLayout =
LocalWindowSizeClass.current.widthSizeClass == WindowWidthSizeClass.Expanded
Expand All @@ -85,7 +86,8 @@ internal fun FeaturedPostItem(
pagerState = pagerState,
onBookmarkClick = onBookmarkClick,
onCommentsClick = onCommentsClick,
onSourceClick = onSourceClick
onSourceClick = onSourceClick,
onTogglePostReadClick = onTogglePostReadClick
)
} else {
DefaultFeaturedPostItem(
Expand All @@ -94,7 +96,8 @@ internal fun FeaturedPostItem(
pagerState = pagerState,
onBookmarkClick = onBookmarkClick,
onCommentsClick = onCommentsClick,
onSourceClick = onSourceClick
onSourceClick = onSourceClick,
onTogglePostReadClick = onTogglePostReadClick
)
}
}
Expand All @@ -107,7 +110,8 @@ private fun DefaultFeaturedPostItem(
pagerState: PagerState,
onBookmarkClick: () -> Unit,
onCommentsClick: () -> Unit,
onSourceClick: () -> Unit
onSourceClick: () -> Unit,
onTogglePostReadClick: () -> Unit,
) {
Column {
AsyncImage(
Expand Down Expand Up @@ -167,6 +171,7 @@ private fun DefaultFeaturedPostItem(
onBookmarkClick = onBookmarkClick,
onCommentsClick = onCommentsClick,
onSourceClick = onSourceClick,
onTogglePostReadClick = onTogglePostReadClick,
modifier = Modifier.padding(start = 16.dp, end = 0.dp)
)

Expand All @@ -181,7 +186,8 @@ private fun LargeScreenFeaturedPostItem(
pagerState: PagerState,
onBookmarkClick: () -> Unit,
onCommentsClick: () -> Unit,
onSourceClick: () -> Unit
onSourceClick: () -> Unit,
onTogglePostReadClick: () -> Unit,
) {
Row(verticalAlignment = Alignment.CenterVertically) {
AsyncImage(
Expand Down Expand Up @@ -241,7 +247,8 @@ private fun LargeScreenFeaturedPostItem(
enablePostSource = true,
onBookmarkClick = onBookmarkClick,
onCommentsClick = onCommentsClick,
onSourceClick = onSourceClick
onSourceClick = onSourceClick,
onTogglePostReadClick = onTogglePostReadClick
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ internal fun FeaturedSection(
onPostBookmarkClick: (PostWithMetadata) -> Unit,
onPostCommentsClick: (String) -> Unit,
onPostSourceClick: (String) -> Unit,
onTogglePostReadClick: (String, Boolean) -> Unit,
) {
Box(modifier = modifier) {
if (featuredPosts.isNotEmpty()) {
Expand Down Expand Up @@ -179,7 +180,8 @@ internal fun FeaturedSection(
onClick = { onItemClick(featuredPost) },
onBookmarkClick = { onPostBookmarkClick(featuredPost) },
onCommentsClick = { onPostCommentsClick(featuredPost.commentsLink!!) },
onSourceClick = { onPostSourceClick(featuredPost.feedLink) }
onSourceClick = { onPostSourceClick(featuredPost.feedLink) },
onTogglePostReadClick = { onTogglePostReadClick(featuredPost.link, featuredPost.read) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif
homePresenter.dispatch(HomeEvent.OnPostSourceClicked(feedLink))
},
onNoFeedsSwipeUp = { coroutineScope.launch { bottomSheetState.expand() } },
onTogglePostReadStatus = { postLink, postRead ->
homePresenter.dispatch(HomeEvent.TogglePostReadStatus(postLink, postRead))
}
)
},
sheetContent = {
Expand Down Expand Up @@ -278,6 +281,7 @@ private fun HomeScreenContent(
onPostCommentsClick: (String) -> Unit,
onPostSourceClick: (String) -> Unit,
onNoFeedsSwipeUp: () -> Unit,
onTogglePostReadStatus: (String, Boolean) -> Unit,
) {
val featuredPosts = state.featuredPosts
val posts = state.posts?.collectAsLazyPagingItems()
Expand Down Expand Up @@ -312,6 +316,7 @@ private fun HomeScreenContent(
onPostBookmarkClick = onPostBookmarkClick,
onPostCommentsClick = onPostCommentsClick,
onPostSourceClick = onPostSourceClick,
onTogglePostReadClick = onTogglePostReadStatus
)
}
!hasFeeds -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ internal fun PostsList(
onPostClicked: (post: PostWithMetadata) -> Unit,
onPostBookmarkClick: (PostWithMetadata) -> Unit,
onPostCommentsClick: (String) -> Unit,
onPostSourceClick: (String) -> Unit
onPostSourceClick: (String) -> Unit,
onTogglePostReadClick: (String, Boolean) -> Unit,
) {
val topContentPadding =
if (featuredPosts.isEmpty()) {
Expand All @@ -97,7 +98,8 @@ internal fun PostsList(
onItemClick = onPostClicked,
onPostBookmarkClick = onPostBookmarkClick,
onPostCommentsClick = onPostCommentsClick,
onPostSourceClick = onPostSourceClick
onPostSourceClick = onPostSourceClick,
onTogglePostReadClick = onTogglePostReadClick
)
}

Expand All @@ -111,7 +113,8 @@ internal fun PostsList(
onClick = { onPostClicked(post) },
onPostBookmarkClick = { onPostBookmarkClick(post) },
onPostCommentsClick = { onPostCommentsClick(post.commentsLink!!) },
onPostSourceClick = { onPostSourceClick(post.feedLink) }
onPostSourceClick = { onPostSourceClick(post.feedLink) },
togglePostReadClick = { onTogglePostReadClick(post.link, post.read) }
)

if (index != posts.itemCount - 1) {
Expand All @@ -133,6 +136,7 @@ fun PostListItem(
onPostBookmarkClick: () -> Unit,
onPostCommentsClick: () -> Unit,
onPostSourceClick: () -> Unit,
togglePostReadClick: () -> Unit,
reduceReadItemAlpha: Boolean = false
) {
Column(
Expand Down Expand Up @@ -179,6 +183,7 @@ fun PostListItem(
onBookmarkClick = onPostBookmarkClick,
onCommentsClick = onPostCommentsClick,
onSourceClick = onPostSourceClick,
onTogglePostReadClick = togglePostReadClick,
modifier = Modifier.padding(start = 24.dp, end = 12.dp)
)
}
Expand Down
Loading

0 comments on commit 964d67d

Please sign in to comment.