Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): grey out read articles even if starred #547

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +49,7 @@ fun Preferences.toSettings(): Settings {
flowArticleListDateStickyHeader = FlowArticleListDateStickyHeaderPreference.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,6 +49,7 @@ data class Settings(
val flowArticleListTime: FlowArticleListTimePreference = FlowArticleListTimePreference.default,
val flowArticleListDateStickyHeader: FlowArticleListDateStickyHeaderPreference = FlowArticleListDateStickyHeaderPreference.default,
val flowArticleListTonalElevation: FlowArticleListTonalElevationPreference = FlowArticleListTonalElevationPreference.default,
val flowArticleListReadIndicator: FlowArticleReadIndicatorPreference = FlowArticleReadIndicatorPreference.default,

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

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

// Reading page
LocalReadingTheme provides settings.readingTheme,
Expand Down
6 changes: 6 additions & 0 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,6 +270,12 @@ sealed class DataStoreKeys<T> {
get() = intPreferencesKey("flowArticleListTonalElevation")
}

object FlowArticleListReadIndicator : DataStoreKeys<Boolean>() {

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

// Reading page
object ReadingDarkTheme : DataStoreKeys<Int>() {

Expand Down
48 changes: 33 additions & 15 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,14 +42,27 @@ fun ArticleItem(
val articleListImage = LocalFlowArticleListImage.current
val articleListDesc = LocalFlowArticleListDesc.current
val articleListDate = LocalFlowArticleListTime.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.isStarred || articleWithFeed.article.isUnread) 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 @@ -157,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 @@ -209,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,6 +39,7 @@ fun FlowPageStylePage(
val articleListTime = LocalFlowArticleListTime.current
val articleListStickyDate = LocalFlowArticleListDateStickyHeader.current
val articleListTonalElevation = LocalFlowArticleListTonalElevation.current
val articleListReadIndicator = LocalFlowArticleListReadIndicator.current

val scope = rememberCoroutineScope()

Expand All @@ -47,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 @@ -183,6 +185,13 @@ fun FlowPageStylePage(
(!articleListStickyDate).put(context, scope)
}
}
SettingItem(
title = stringResource(R.string.grey_out_articles),
desc = articleListReadIndicator.description,
onClick = {
articleListReadIndicatorDialogVisible = true
}
)
SettingItem(
title = stringResource(R.string.tonal_elevation),
desc = "${articleListTonalElevation.value}dp",
Expand Down Expand Up @@ -317,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
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -406,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>
Loading