Skip to content

Commit

Permalink
[1.199.*] Pre-release merge (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Jul 26, 2024
2 parents 1bcdcfa + ff4f218 commit 7893ef0
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,5 @@ val DeTwineStrings =
noPinnedSources = "No pinned feeds/groups",
databaseMaintainenceTitle = "Please wait...",
databaseMaintainenceSubtitle = "Performing database maintainence, don't close the app",
cdLoadFullArticle = "Load full article",
)
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ val EnTwineStrings =
noPinnedSources = "No pinned feeds/groups",
databaseMaintainenceTitle = "Please wait...",
databaseMaintainenceSubtitle = "Performing database maintainence, don't close the app",
cdLoadFullArticle = "Load full article",
)
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ val TrTwineStrings =
noPinnedSources = "Sabitlenmiş yayın/grup yok",
databaseMaintainenceTitle = "Lütfen bekleyin...",
databaseMaintainenceSubtitle = "Veritabanı bakımı gerçekleştiriliyor, uygulamayı kapatmayın",
cdLoadFullArticle = "Load full article",
)
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ data class TwineStrings(
val noPinnedSources: String,
val databaseMaintainenceTitle: String,
val databaseMaintainenceSubtitle: String,
val cdLoadFullArticle: String,
)

object Locales {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ val ZhTwineStrings =
noPinnedSources = "没有置顶的订阅/分组",
databaseMaintainenceTitle = "请稍候...",
databaseMaintainenceSubtitle = "正在进行数据库维护,请勿关闭应用",
cdLoadFullArticle = "Load full article",
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import dev.sasikanth.rss.reader.components.image.AsyncImage
import dev.sasikanth.rss.reader.core.model.local.PostWithMetadata
import dev.sasikanth.rss.reader.ui.AppTheme
import dev.sasikanth.rss.reader.util.relativeDurationString
import dev.sasikanth.rss.reader.utils.Constants
import dev.sasikanth.rss.reader.utils.LocalWindowSizeClass

private val featuredImageAspectRatio: Float
Expand All @@ -71,12 +72,14 @@ internal fun FeaturedPostItem(
onCommentsClick: () -> Unit,
onSourceClick: () -> Unit,
onTogglePostReadClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Column(
modifier =
Modifier.clip(MaterialTheme.shapes.extraLarge)
Modifier.then(modifier)
.clip(MaterialTheme.shapes.extraLarge)
.clickable(onClick = onClick)
.alpha(if (item.read) 0.65f else 1f)
.alpha(if (item.read) Constants.ITEM_READ_ALPHA else Constants.ITEM_READ_ALPHA)
) {
val density = LocalDensity.current
var descriptionBottomPadding by remember(item.link) { mutableStateOf(0.dp) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.PagerDefaults
Expand All @@ -50,7 +51,6 @@ import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEachIndexed
import coil3.size.Size
import dev.sasikanth.rss.reader.components.LocalDynamicColorState
import dev.sasikanth.rss.reader.components.image.AsyncImage
Expand Down Expand Up @@ -154,80 +154,79 @@ internal fun FeaturedSection(
}
}

FeaturedSectionBackground(
featuredPosts = featuredPosts,
pagerState = pagerState,
featuredItemBlurEnabled = featuredItemBlurEnabled
)

HorizontalPager(
state = pagerState,
contentPadding = pagerContentPadding,
pageSpacing = 16.dp,
verticalAlignment = Alignment.Top,
flingBehavior =
PagerDefaults.flingBehavior(
state = pagerState,
snapAnimationSpec = spring(stiffness = Spring.StiffnessVeryLow)
)
),
) { page ->
val featuredPost = featuredPosts.getOrNull(page)
if (featuredPost != null) {
FeaturedPostItem(
item = featuredPost,
page = page,
pagerState = pagerState,
onClick = { onItemClick(featuredPost) },
onBookmarkClick = { onPostBookmarkClick(featuredPost) },
onCommentsClick = { onPostCommentsClick(featuredPost.commentsLink!!) },
onSourceClick = { onPostSourceClick(featuredPost.sourceId) },
onTogglePostReadClick = { onTogglePostReadClick(featuredPost.id, featuredPost.read) }
)
Box {
FeaturedSectionBackground(
post = featuredPost,
featuredItemBlurEnabled = featuredItemBlurEnabled,
modifier =
Modifier.graphicsLayer {
val pageOffset = pagerState.getOffsetFractionForPage(page)

translationX = size.width * pageOffset
alpha = (1f - pageOffset.absoluteValue)
}
)

FeaturedPostItem(
modifier = Modifier.padding(pagerContentPadding),
item = featuredPost,
page = page,
pagerState = pagerState,
onClick = { onItemClick(featuredPost) },
onBookmarkClick = { onPostBookmarkClick(featuredPost) },
onCommentsClick = { onPostCommentsClick(featuredPost.commentsLink!!) },
onSourceClick = { onPostSourceClick(featuredPost.sourceId) },
onTogglePostReadClick = { onTogglePostReadClick(featuredPost.id, featuredPost.read) }
)
}
}
}
}
}
}

@Composable
@OptIn(ExperimentalFoundationApi::class)
private fun FeaturedSectionBackground(
pagerState: PagerState,
featuredPosts: ImmutableList<PostWithMetadata>,
post: PostWithMetadata,
featuredItemBlurEnabled: Boolean,
modifier: Modifier = Modifier,
) {
// We want the gradient overlay to be displayed above the blur and gradient background, and
// also when overscrolling happens. For that reason we are applying the gradient modifier,
// directly to the individual composables rather than the parent Box.
val gradientOverlayModifier =
Modifier.drawWithCache {
val radialGradient =
Brush.radialGradient(
colors =
listOf(Color.Black, Color.Black.copy(alpha = 0.0f), Color.Black.copy(alpha = 0.0f)),
center = Offset(x = this.size.width, y = 40f)
)
val radialGradient =
Brush.radialGradient(
colors =
listOf(Color.Black, Color.Black.copy(alpha = 0.0f), Color.Black.copy(alpha = 0.0f)),
center = Offset(x = this.size.width, y = 40f)
)

val linearGradient =
Brush.verticalGradient(
colors = listOf(Color.Black, Color.Black.copy(alpha = 0.0f)),
)
val linearGradient =
Brush.verticalGradient(
colors = listOf(Color.Black, Color.Black.copy(alpha = 0.0f)),
)

onDrawWithContent {
drawContent()
drawRect(radialGradient)
drawRect(linearGradient)
onDrawWithContent {
drawContent()
drawRect(radialGradient)
drawRect(linearGradient)
}
}
}
.then(modifier)

Box(modifier = modifier) {
Box {
if (canBlurImage && featuredItemBlurEnabled) {
FeaturedSectionBlurredBackground(
featuredPosts = featuredPosts,
pagerState = pagerState,
modifier = gradientOverlayModifier
)
FeaturedSectionBlurredBackground(post = post, modifier = gradientOverlayModifier)
} else {
FeaturedSectionGradientBackground(modifier = gradientOverlayModifier)
}
Expand Down Expand Up @@ -257,47 +256,24 @@ private fun FeaturedSectionGradientBackground(modifier: Modifier = Modifier) {
}

@Composable
@OptIn(ExperimentalFoundationApi::class)
private fun FeaturedSectionBlurredBackground(
featuredPosts: ImmutableList<PostWithMetadata>,
pagerState: PagerState,
post: PostWithMetadata,
modifier: Modifier = Modifier
) {
// We are loading all featured posts images at once to avoid blinking issues that can occur
// due to state changes when we try to do this lazily. Since the alpha is set to 0 for images that
// don't need to be rendered, they are not drawn. If need more featured posts, we can convert this
// to a proper lazy layout. But for 6 items, this is the simplest approach to take.
featuredPosts.fastForEachIndexed { index, post ->
AsyncImage(
url = post.imageUrl!!,
modifier =
Modifier.aspectRatio(featuredImageBackgroundAspectRatio)
.graphicsLayer {
val offsetFraction =
if (index in 0..pagerState.pageCount) {
pagerState.getOffsetFractionForPage(index).absoluteValue.coerceIn(0f, 1f)
} else {
0f
}
alpha = ((1f - offsetFraction) / 1f)

val blurRadiusInPx = 100.dp.toPx()
// Since blur can be expensive memory wise, there is no point blurring images when not
// needed.
renderEffect =
if (index in pagerState.settledPage - 2..pagerState.settledPage + 2) {
BlurEffect(blurRadiusInPx, blurRadiusInPx, TileMode.Decal)
} else {
null
}
shape = RectangleShape
clip = false
}
.then(modifier),
contentDescription = null,
contentScale = ContentScale.Crop,
size = Size(128, 128),
backgroundColor = AppTheme.colorScheme.surfaceContainerLowest
)
}
AsyncImage(
url = post.imageUrl!!,
modifier =
Modifier.aspectRatio(featuredImageBackgroundAspectRatio)
.graphicsLayer {
val blurRadiusInPx = 100.dp.toPx()
renderEffect = BlurEffect(blurRadiusInPx, blurRadiusInPx, TileMode.Decal)
shape = RectangleShape
clip = false
}
.then(modifier),
contentDescription = null,
contentScale = ContentScale.Crop,
size = Size(128, 128),
backgroundColor = AppTheme.colorScheme.surfaceContainerLowest
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import dev.sasikanth.rss.reader.components.image.AsyncImage
import dev.sasikanth.rss.reader.core.model.local.PostWithMetadata
import dev.sasikanth.rss.reader.ui.AppTheme
import dev.sasikanth.rss.reader.util.relativeDurationString
import dev.sasikanth.rss.reader.utils.Constants
import dev.sasikanth.rss.reader.utils.LocalWindowSizeClass
import kotlinx.collections.immutable.ImmutableList

Expand Down Expand Up @@ -147,7 +148,10 @@ fun PostListItem(
Modifier.clickable(onClick = onClick)
.windowInsetsPadding(WindowInsets.systemBars.only(WindowInsetsSides.Horizontal))
.padding(postListPadding)
.alpha(if (item.read && reduceReadItemAlpha) 0.65f else 1f)
.alpha(
if (item.read && reduceReadItemAlpha) Constants.ITEM_READ_ALPHA
else Constants.ITEM_UNREAD_ALPHA
)
) {
Row(
modifier = Modifier.padding(start = 24.dp, top = 20.dp, end = 24.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import dev.sasikanth.rss.reader.resources.icons.Bookmarked
import dev.sasikanth.rss.reader.resources.icons.Share
import dev.sasikanth.rss.reader.resources.icons.TwineIcons
import dev.sasikanth.rss.reader.resources.icons.Website
import dev.sasikanth.rss.reader.resources.strings.LocalStrings
import dev.sasikanth.rss.reader.share.LocalShareHandler
import dev.sasikanth.rss.reader.ui.AppTheme
import dev.sasikanth.rss.reader.util.DispatchersProvider
Expand All @@ -92,7 +93,7 @@ internal fun ReaderScreen(
title = {},
navigationIcon = {
IconButton(onClick = { presenter.dispatch(ReaderEvent.BackClicked) }) {
Icon(TwineIcons.ArrowBack, contentDescription = null)
Icon(TwineIcons.ArrowBack, contentDescription = LocalStrings.current.buttonGoBack)
}
},
colors =
Expand Down Expand Up @@ -130,7 +131,7 @@ internal fun ReaderScreen(
TwineIcons.Bookmark
}
IconButton(onClick = { presenter.dispatch(ReaderEvent.TogglePostBookmark) }) {
Icon(bookmarkIcon, contentDescription = null)
Icon(bookmarkIcon, contentDescription = LocalStrings.current.bookmark)
}
}

Expand Down Expand Up @@ -159,7 +160,11 @@ internal fun ReaderScreen(
coroutineScope.launch { presenter.dispatch(ReaderEvent.ArticleShortcutClicked) }
}
) {
Icon(TwineIcons.ArticleShortcut, contentDescription = null, tint = iconTint)
Icon(
TwineIcons.ArticleShortcut,
contentDescription = LocalStrings.current.cdLoadFullArticle,
tint = iconTint
)
}
}
InProgress -> {
Expand All @@ -176,14 +181,14 @@ internal fun ReaderScreen(
Icon(
modifier = Modifier.requiredSize(24.dp),
imageVector = TwineIcons.Website,
contentDescription = null
contentDescription = LocalStrings.current.openWebsite
)
}
}

Box(Modifier.weight(1f), contentAlignment = Alignment.Center) {
IconButton(onClick = { coroutineScope.launch { sharedHandler.share(state.link!!) } }) {
Icon(TwineIcons.Share, contentDescription = null)
Icon(TwineIcons.Share, contentDescription = LocalStrings.current.share)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ internal object Constants {
const val MINIMUM_REQUIRED_SEARCH_CHARACTERS = 3

const val BADGE_COUNT_TRIM_LIMIT = 99

const val ITEM_READ_ALPHA = 0.65f
const val ITEM_UNREAD_ALPHA = 1f
}

0 comments on commit 7893ef0

Please sign in to comment.