Skip to content

Commit

Permalink
feat(ui): grey out read articles even if read
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Jan 28, 2024
1 parent a79945f commit bbdf5b9
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 75 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package me.ash.reader.infrastructure.preference

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.datastore.preferences.core.Preferences
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import me.ash.reader.R
import me.ash.reader.ui.ext.DataStoreKeys
import me.ash.reader.ui.ext.dataStore
import me.ash.reader.ui.ext.put

sealed class FlowArticleReadIndicatorPreference(val value: Boolean) : Preference() {
object ExcludingStarred : FlowArticleReadIndicatorPreference(true)
object AllRead : FlowArticleReadIndicatorPreference(false)

override fun put(context: Context, scope: CoroutineScope) {
scope.launch {
context.dataStore.put(
DataStoreKeys.FlowArticleListReadIndicator,
value
)
}
}

val description: String
@Composable get() {
return when (this) {
AllRead -> stringResource(id = R.string.all_read)
ExcludingStarred -> stringResource(id = R.string.read_excluding_starred)
}
}

companion object {

val default = ExcludingStarred
val values = listOf(ExcludingStarred, AllRead)

fun fromPreferences(preferences: Preferences) =
when (preferences[DataStoreKeys.FlowArticleListReadIndicator.key]) {
true -> ExcludingStarred
false -> AllRead
else -> default
}

}
}

operator fun FlowArticleReadIndicatorPreference.not(): FlowArticleReadIndicatorPreference =
when (value) {
true -> FlowArticleReadIndicatorPreference.AllRead
false -> FlowArticleReadIndicatorPreference.ExcludingStarred
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun Preferences.toSettings(): Settings {
flowArticleListDateStickyHeader = FlowArticleListDateStickyHeaderPreference.fromPreferences(
this
),
flowArticleListAlwaysHighlightStarred = FlowArticleListAlwaysHighlightStarredPreference.fromPreferences(this),
flowArticleListReadIndicator = FlowArticleReadIndicatorPreference.fromPreferences(this),
flowArticleListTonalElevation = FlowArticleListTonalElevationPreference.fromPreferences(this),

// Reading page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ data class Settings(
val flowArticleListTime: FlowArticleListTimePreference = FlowArticleListTimePreference.default,
val flowArticleListDateStickyHeader: FlowArticleListDateStickyHeaderPreference = FlowArticleListDateStickyHeaderPreference.default,
val flowArticleListTonalElevation: FlowArticleListTonalElevationPreference = FlowArticleListTonalElevationPreference.default,
val flowArticleListAlwaysHighlightStarred: FlowArticleListAlwaysHighlightStarredPreference = FlowArticleListAlwaysHighlightStarredPreference.default,
val flowArticleListReadIndicator: FlowArticleReadIndicatorPreference = FlowArticleReadIndicatorPreference.default,

// Reading page
val readingTheme: ReadingThemePreference = ReadingThemePreference.default,
Expand Down Expand Up @@ -142,8 +142,8 @@ val LocalFlowArticleListDateStickyHeader =
compositionLocalOf<FlowArticleListDateStickyHeaderPreference> { FlowArticleListDateStickyHeaderPreference.default }
val LocalFlowArticleListTonalElevation =
compositionLocalOf<FlowArticleListTonalElevationPreference> { FlowArticleListTonalElevationPreference.default }
val LocalFlowArticleListAlwaysHighlightStarred =
compositionLocalOf<FlowArticleListAlwaysHighlightStarredPreference> { FlowArticleListAlwaysHighlightStarredPreference.default }
val LocalFlowArticleListReadIndicator =
compositionLocalOf<FlowArticleReadIndicatorPreference> { FlowArticleReadIndicatorPreference.default }

// Reading page
val LocalReadingTheme = compositionLocalOf<ReadingThemePreference> { ReadingThemePreference.default }
Expand Down Expand Up @@ -237,7 +237,7 @@ fun SettingsProvider(
LocalFlowFilterBarFilled provides settings.flowFilterBarFilled,
LocalFlowFilterBarPadding provides settings.flowFilterBarPadding,
LocalFlowFilterBarTonalElevation provides settings.flowFilterBarTonalElevation,
LocalFlowArticleListAlwaysHighlightStarred provides settings.flowArticleListAlwaysHighlightStarred,
LocalFlowArticleListReadIndicator provides settings.flowArticleListReadIndicator,

// Reading page
LocalReadingTheme provides settings.readingTheme,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/me/ash/reader/ui/ext/DataStoreExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ sealed class DataStoreKeys<T> {
get() = intPreferencesKey("flowArticleListTonalElevation")
}

object FlowArticleListAlwaysHighlightStarred : DataStoreKeys<Boolean>() {
object FlowArticleListReadIndicator : DataStoreKeys<Boolean>() {

override val key: Preferences.Key<Boolean>
get() = booleanPreferencesKey("flowArticleListAlwaysHighlightStarred")
get() = booleanPreferencesKey("flowArticleListReadIndicator")
}

// Reading page
Expand Down
50 changes: 33 additions & 17 deletions app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,27 @@ fun ArticleItem(
val articleListImage = LocalFlowArticleListImage.current
val articleListDesc = LocalFlowArticleListDesc.current
val articleListDate = LocalFlowArticleListTime.current
val articleListAlwaysHighlightStarred = LocalFlowArticleListAlwaysHighlightStarred.current
val articleListReadIndicator = LocalFlowArticleListReadIndicator.current

Column(
modifier = Modifier
.padding(horizontal = 12.dp)
.clip(Shape20)
.clickable { onClick(articleWithFeed) }
.padding(horizontal = 12.dp, vertical = 12.dp)
.alpha(if (articleWithFeed.article.isUnread ||
(articleWithFeed.article.isStarred && articleListAlwaysHighlightStarred.value)) 1f else 0.5f),
.alpha(
articleWithFeed.article.run {
when (articleListReadIndicator) {
FlowArticleReadIndicatorPreference.AllRead -> {
if (isUnread) 1f else 0.5f
}

FlowArticleReadIndicatorPreference.ExcludingStarred -> {
if (isUnread || isStarred) 1f else 0.5f
}
}
}
),
) {
// Top
Row(
Expand Down Expand Up @@ -159,23 +170,25 @@ fun ArticleItem(
}
}
}

@ExperimentalMaterialApi
@Composable
fun SwipeableArticleItem(
articleWithFeed: ArticleWithFeed,
isFilterUnread: Boolean,
articleListTonalElevation: Int,
onClick: (ArticleWithFeed) -> Unit = {},
onSwipeOut: (ArticleWithFeed) -> Unit = {},
articleWithFeed: ArticleWithFeed,
isFilterUnread: Boolean,
articleListTonalElevation: Int,
onClick: (ArticleWithFeed) -> Unit = {},
onSwipeOut: (ArticleWithFeed) -> Unit = {},
) {
var isArticleVisible by remember { mutableStateOf(true) }
val dismissState = rememberDismissState(initialValue = DismissValue.Default, confirmStateChange = {
if (it == DismissValue.DismissedToEnd) {
isArticleVisible = !isFilterUnread
onSwipeOut(articleWithFeed)
}
isFilterUnread
})
val dismissState =
rememberDismissState(initialValue = DismissValue.Default, confirmStateChange = {
if (it == DismissValue.DismissedToEnd) {
isArticleVisible = !isFilterUnread
onSwipeOut(articleWithFeed)
}
isFilterUnread
})
if (isArticleVisible) {
SwipeToDismiss(
state = dismissState,
Expand Down Expand Up @@ -211,8 +224,11 @@ fun SwipeableArticleItem(
Box(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.surfaceColorAtElevation(articleListTonalElevation.dp
) onDark MaterialTheme.colorScheme.surface)
.background(
MaterialTheme.colorScheme.surfaceColorAtElevation(
articleListTonalElevation.dp
) onDark MaterialTheme.colorScheme.surface
)
) {
ArticleItem(articleWithFeed, onClick)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fun FlowPageStylePage(
val articleListTime = LocalFlowArticleListTime.current
val articleListStickyDate = LocalFlowArticleListDateStickyHeader.current
val articleListTonalElevation = LocalFlowArticleListTonalElevation.current
val articleListAlwaysHighlightStarred = LocalFlowArticleListAlwaysHighlightStarred.current
val articleListReadIndicator = LocalFlowArticleListReadIndicator.current

val scope = rememberCoroutineScope()

Expand All @@ -48,6 +48,7 @@ fun FlowPageStylePage(
var filterBarTonalElevationDialogVisible by remember { mutableStateOf(false) }
var topBarTonalElevationDialogVisible by remember { mutableStateOf(false) }
var articleListTonalElevationDialogVisible by remember { mutableStateOf(false) }
var articleListReadIndicatorDialogVisible by remember { mutableStateOf(false) }

var filterBarPaddingValue: Int? by remember { mutableStateOf(filterBarPadding) }

Expand Down Expand Up @@ -185,15 +186,12 @@ fun FlowPageStylePage(
}
}
SettingItem(
title = stringResource(R.string.article_list_always_highlight_starred),
title = stringResource(R.string.grey_out_articles),
desc = articleListReadIndicator.description,
onClick = {
(!articleListAlwaysHighlightStarred).put(context, scope)
},
) {
RYSwitch(activated = articleListAlwaysHighlightStarred.value) {
(!articleListAlwaysHighlightStarred).put(context, scope)
articleListReadIndicatorDialogVisible = true
}
}
)
SettingItem(
title = stringResource(R.string.tonal_elevation),
desc = "${articleListTonalElevation.value}dp",
Expand Down Expand Up @@ -328,4 +326,19 @@ fun FlowPageStylePage(
) {
articleListTonalElevationDialogVisible = false
}

RadioDialog(
visible = articleListReadIndicatorDialogVisible,
title = stringResource(id = R.string.grey_out_articles),
options = FlowArticleReadIndicatorPreference.values.map {
RadioDialogOption(
text = it.description,
selected = it == articleListReadIndicator
) {
it.put(context, scope)
}
}
) {
articleListReadIndicatorDialogVisible = false
}
}
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@
<string name="tips_top_bar_tonal_elevation">Tonal elevation for the top bar list is only available when scrolling</string>
<string name="tips_article_list_tonal_elevation">Tonal elevation for the article list is only available in the light theme</string>
<string name="tips_group_list_tonal_elevation">Tonal elevation for the group list is only available in the light theme</string>
<string name="article_list_always_highlight_starred">Always highlight starred articles</string>
<string name="share">Share</string>
<string name="touch_to_play_video">Tap to play a video</string>
<string name="text">Text</string>
Expand Down Expand Up @@ -407,4 +406,7 @@
<string name="include_additional_info">Include additional info</string>
<string name="exclude">Exclude</string>
<string name="additional_info_desc">Additional information includes configuration options for each feed, such as whether to allow notification, parse full content, etc. When you intend to use the exported OPML file with other readers, please select \"Exclude\".</string>
<string name="grey_out_articles">Grey out articles</string>
<string name="all_read">All read</string>
<string name="read_excluding_starred">Read, excluding starred</string>
</resources>

0 comments on commit bbdf5b9

Please sign in to comment.