diff --git a/app/src/main/java/me/ash/reader/infrastructure/preference/FlowArticleListAlwaysHighlightStarredPreference.kt b/app/src/main/java/me/ash/reader/infrastructure/preference/FlowArticleListAlwaysHighlightStarredPreference.kt deleted file mode 100644 index e03e98afb..000000000 --- a/app/src/main/java/me/ash/reader/infrastructure/preference/FlowArticleListAlwaysHighlightStarredPreference.kt +++ /dev/null @@ -1,42 +0,0 @@ -package me.ash.reader.infrastructure.preference - -import android.content.Context -import androidx.datastore.preferences.core.Preferences -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch -import me.ash.reader.ui.ext.DataStoreKeys -import me.ash.reader.ui.ext.dataStore -import me.ash.reader.ui.ext.put - -sealed class FlowArticleListAlwaysHighlightStarredPreference(val value: Boolean) : Preference() { - object ON : FlowArticleListAlwaysHighlightStarredPreference(true) - object OFF : FlowArticleListAlwaysHighlightStarredPreference(false) - - override fun put(context: Context, scope: CoroutineScope) { - scope.launch { - context.dataStore.put( - DataStoreKeys.FlowArticleListAlwaysHighlightStarred, - value - ) - } - } - - companion object { - - val default = ON - val values = listOf(ON, OFF) - - fun fromPreferences(preferences: Preferences) = - when (preferences[DataStoreKeys.FlowArticleListAlwaysHighlightStarred.key]) { - true -> ON - false -> OFF - else -> default - } - } -} - -operator fun FlowArticleListAlwaysHighlightStarredPreference.not(): FlowArticleListAlwaysHighlightStarredPreference = - when (value) { - true -> FlowArticleListAlwaysHighlightStarredPreference.OFF - false -> FlowArticleListAlwaysHighlightStarredPreference.ON - } \ No newline at end of file diff --git a/app/src/main/java/me/ash/reader/infrastructure/preference/FlowArticleReadIndicatorPreference.kt b/app/src/main/java/me/ash/reader/infrastructure/preference/FlowArticleReadIndicatorPreference.kt new file mode 100644 index 000000000..5c010bb47 --- /dev/null +++ b/app/src/main/java/me/ash/reader/infrastructure/preference/FlowArticleReadIndicatorPreference.kt @@ -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 + } \ No newline at end of file diff --git a/app/src/main/java/me/ash/reader/infrastructure/preference/Preference.kt b/app/src/main/java/me/ash/reader/infrastructure/preference/Preference.kt index 5a457c3b3..371062920 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/preference/Preference.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/preference/Preference.kt @@ -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 diff --git a/app/src/main/java/me/ash/reader/infrastructure/preference/Settings.kt b/app/src/main/java/me/ash/reader/infrastructure/preference/Settings.kt index 357e67835..6dfeb5058 100644 --- a/app/src/main/java/me/ash/reader/infrastructure/preference/Settings.kt +++ b/app/src/main/java/me/ash/reader/infrastructure/preference/Settings.kt @@ -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, @@ -142,8 +142,8 @@ val LocalFlowArticleListDateStickyHeader = compositionLocalOf { FlowArticleListDateStickyHeaderPreference.default } val LocalFlowArticleListTonalElevation = compositionLocalOf { FlowArticleListTonalElevationPreference.default } -val LocalFlowArticleListAlwaysHighlightStarred = - compositionLocalOf { FlowArticleListAlwaysHighlightStarredPreference.default } +val LocalFlowArticleListReadIndicator = + compositionLocalOf { FlowArticleReadIndicatorPreference.default } // Reading page val LocalReadingTheme = compositionLocalOf { ReadingThemePreference.default } @@ -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, diff --git a/app/src/main/java/me/ash/reader/ui/ext/DataStoreExt.kt b/app/src/main/java/me/ash/reader/ui/ext/DataStoreExt.kt index 5fa5bf85b..1b69ee433 100644 --- a/app/src/main/java/me/ash/reader/ui/ext/DataStoreExt.kt +++ b/app/src/main/java/me/ash/reader/ui/ext/DataStoreExt.kt @@ -270,10 +270,10 @@ sealed class DataStoreKeys { get() = intPreferencesKey("flowArticleListTonalElevation") } - object FlowArticleListAlwaysHighlightStarred : DataStoreKeys() { + object FlowArticleListReadIndicator : DataStoreKeys() { override val key: Preferences.Key - get() = booleanPreferencesKey("flowArticleListAlwaysHighlightStarred") + get() = booleanPreferencesKey("flowArticleListReadIndicator") } // Reading page diff --git a/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleItem.kt b/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleItem.kt index 5fa3e3cd2..a9124f121 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleItem.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleItem.kt @@ -42,7 +42,7 @@ 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 @@ -50,8 +50,19 @@ fun ArticleItem( .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( @@ -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, @@ -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) } diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/color/flow/FlowPageStylePage.kt b/app/src/main/java/me/ash/reader/ui/page/settings/color/flow/FlowPageStylePage.kt index 5c90010dc..781c4b1bc 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/color/flow/FlowPageStylePage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/color/flow/FlowPageStylePage.kt @@ -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() @@ -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) } @@ -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", @@ -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 + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3467c03f9..a188c937e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -301,7 +301,6 @@ Tonal elevation for the top bar list is only available when scrolling Tonal elevation for the article list is only available in the light theme Tonal elevation for the group list is only available in the light theme - Always highlight starred articles Share Tap to play a video Text @@ -407,4 +406,7 @@ Include additional info Exclude 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\". + Grey out articles + All read + Read, excluding starred