diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt index 0a57aa02d..2fa60603e 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt @@ -349,6 +349,32 @@ class HomePresenter( .onEach { hasFeeds -> _state.update { it.copy(hasFeeds = hasFeeds) } } .launchIn(coroutineScope) + combine(observableActiveSource.activeSource, settingsRepository.postsType) { + activeSource, + postsType -> + Pair(activeSource, postsType) + } + .flatMapLatest { (activeSource, postsType) -> + val postsAfter = + when (postsType) { + PostsType.ALL, + PostsType.UNREAD -> Instant.DISTANT_PAST + PostsType.TODAY -> { + getTodayStartInstant() + } + PostsType.LAST_24_HOURS -> { + getLast24HourStart() + } + } + + rssRepository.hasUnreadPosts( + sourceId = activeSource?.id, + postsAfter = postsAfter, + ) + } + .onEach { hasUnreadPosts -> _state.update { it.copy(hasUnreadPosts = hasUnreadPosts) } } + .launchIn(coroutineScope) + settingsRepository.enableFeaturedItemBlur .onEach { value -> _state.update { it.copy(featuredItemBlurEnabled = value) } } .launchIn(coroutineScope) diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomeState.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomeState.kt index 034010c69..ccc045ec3 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomeState.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomeState.kt @@ -37,7 +37,8 @@ internal data class HomeState( val activeSource: Source?, val featuredItemBlurEnabled: Boolean, val hasFeeds: Boolean?, - val postsType: PostsType + val postsType: PostsType, + val hasUnreadPosts: Boolean ) { companion object { @@ -51,7 +52,8 @@ internal data class HomeState( activeSource = null, featuredItemBlurEnabled = true, hasFeeds = null, - postsType = PostsType.ALL + postsType = PostsType.ALL, + hasUnreadPosts = false, ) } diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt index 0f564aec7..b16ef9252 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt @@ -156,6 +156,7 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif postsType = state.postsType, listState = listState, hasFeeds = hasFeeds, + hasUnreadPosts = state.hasUnreadPosts, onSearchClicked = { homePresenter.dispatch(HomeEvent.SearchClicked) }, onBookmarksClicked = { homePresenter.dispatch(HomeEvent.BookmarksClicked) }, onSettingsClicked = { homePresenter.dispatch(HomeEvent.SettingsClicked) }, diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeTopAppBar.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeTopAppBar.kt index d73f578f1..f44079f44 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeTopAppBar.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeTopAppBar.kt @@ -16,6 +16,8 @@ package dev.sasikanth.rss.reader.home.ui +import androidx.compose.animation.animateColor +import androidx.compose.animation.core.updateTransition import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -41,9 +43,11 @@ import androidx.compose.material.icons.rounded.MoreVert import androidx.compose.material.icons.rounded.Search import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue @@ -77,6 +81,7 @@ internal fun HomeTopAppBar( postsType: PostsType, listState: LazyListState, hasFeeds: Boolean?, + hasUnreadPosts: Boolean, modifier: Modifier = Modifier, onSearchClicked: () -> Unit, onBookmarksClicked: () -> Unit, @@ -138,7 +143,11 @@ internal fun HomeTopAppBar( ) { PostsFilterButton(postsType = postsType, onPostTypeChanged = onPostTypeChanged) - MarkPostsAsReadButton(source = source, onMarkPostsAsRead = onMarkPostsAsRead) + MarkPostsAsReadButton( + source = source, + onMarkPostsAsRead = onMarkPostsAsRead, + enabled = hasUnreadPosts, + ) } } } @@ -223,29 +232,41 @@ private fun MarkPostsAsReadButton( source: Source?, onMarkPostsAsRead: (Source?) -> Unit, modifier: Modifier = Modifier, + enabled: Boolean = true, ) { + val transition = updateTransition(enabled, "button_enable_state") + val backgroundColor by + transition.animateColor { + if (it) Color.White.copy(alpha = 0.12f) else Color.White.copy(alpha = 0f) + } + val contentColor by + transition.animateColor { + if (it) AppTheme.colorScheme.textEmphasisHigh + else AppTheme.colorScheme.onSurface.copy(alpha = 0.38f) + } + Row( modifier = modifier .clip(RoundedCornerShape(8.dp)) - .clickable(onClick = { onMarkPostsAsRead(source) }) - .background(color = Color.White.copy(alpha = 0.12f)) + .clickable(enabled = enabled, onClick = { onMarkPostsAsRead(source) }) + .background(color = backgroundColor) .padding(vertical = 4.dp) .padding(start = 8.dp, end = 12.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), ) { - Text( - text = LocalStrings.current.markAsRead, - style = MaterialTheme.typography.bodyMedium, - color = AppTheme.colorScheme.textEmphasisHigh, - ) + CompositionLocalProvider(LocalContentColor provides contentColor) { + Text( + text = LocalStrings.current.markAsRead, + style = MaterialTheme.typography.bodyMedium, + ) - Icon( - imageVector = Icons.Filled.DoneAll, - contentDescription = null, - modifier = Modifier.requiredSize(20.dp), - tint = AppTheme.colorScheme.textEmphasisHigh, - ) + Icon( + imageVector = Icons.Filled.DoneAll, + contentDescription = null, + modifier = Modifier.requiredSize(20.dp), + ) + } } }