Skip to content

Commit

Permalink
[1.206.*] Pre-release merge (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Jul 28, 2024
2 parents 727938f + 092f69c commit 543f902
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -51,7 +52,8 @@ internal data class HomeState(
activeSource = null,
featuredItemBlurEnabled = true,
hasFeeds = null,
postsType = PostsType.ALL
postsType = PostsType.ALL,
hasUnreadPosts = false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -77,6 +81,7 @@ internal fun HomeTopAppBar(
postsType: PostsType,
listState: LazyListState,
hasFeeds: Boolean?,
hasUnreadPosts: Boolean,
modifier: Modifier = Modifier,
onSearchClicked: () -> Unit,
onBookmarksClicked: () -> Unit,
Expand Down Expand Up @@ -138,7 +143,11 @@ internal fun HomeTopAppBar(
) {
PostsFilterButton(postsType = postsType, onPostTypeChanged = onPostTypeChanged)

MarkPostsAsReadButton(source = source, onMarkPostsAsRead = onMarkPostsAsRead)
MarkPostsAsReadButton(
source = source,
onMarkPostsAsRead = onMarkPostsAsRead,
enabled = hasUnreadPosts,
)
}
}
}
Expand Down Expand Up @@ -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),
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package dev.sasikanth.rss.reader.reader.ui

import androidx.compose.ui.unit.LayoutDirection
import twine.shared.generated.resources.Res

object ReaderHTML {
Expand All @@ -26,6 +27,7 @@ object ReaderHTML {
feedHomePageLink: String,
publishedAt: String,
locale: String,
direction: LayoutDirection
): String {
val readabilityJS = readFile("readability.js")
val readerJS = readFile("main.js")
Expand All @@ -41,7 +43,7 @@ object ReaderHTML {

// language=HTML
return """
<html lang="$locale">
<html lang="$locale" dir="${direction.name}">
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.unit.dp
import com.multiplatform.webview.jsbridge.rememberWebViewJsBridge
Expand Down Expand Up @@ -240,6 +241,7 @@ internal fun ReaderScreen(
this.supportZoom = false
}

val layoutDirection = LocalLayoutDirection.current
LaunchedEffect(state.content) {
withContext(dispatchersProvider.io) {
val htmlTemplate =
Expand All @@ -248,7 +250,8 @@ internal fun ReaderScreen(
feedName = state.feed!!.name,
feedHomePageLink = state.feed!!.homepageLink,
publishedAt = state.publishedAt!!,
locale = Locale.current.toLanguageTag()
locale = Locale.current.toLanguageTag(),
direction = layoutDirection
)

navigator.loadHtml(htmlTemplate, state.link)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,14 @@ class RssRepository(
}
}

fun hasUnreadPosts(sourceId: String?, postsAfter: Instant = Instant.DISTANT_PAST): Flow<Boolean> {
return postQueries
.unreadPostsCount(sourceId = sourceId, after = postsAfter)
.asFlow()
.mapToOne(ioDispatcher)
.map { it > 0 }
}

private fun sanitizeSearchQuery(searchQuery: String): String {
return searchQuery.replace(Regex.fromLiteral("\""), "\"\"").run { "\"$this\"" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ WHERE post.id = :id;

hasPost:
SELECT EXISTS(SELECT 1 FROM post WHERE id = :id);

unreadPostsCount:
SELECT COUNT(*) FROM post WHERE read != 1 AND date > :after AND (sourceId = :sourceId OR :sourceId IS NULL);

0 comments on commit 543f902

Please sign in to comment.