Add parameter to set default main filter in TimelineTab

This commit is contained in:
Shinokuni 2025-01-09 17:07:59 +01:00
parent c520a3396e
commit a43415af6a
6 changed files with 49 additions and 14 deletions

View File

@ -155,6 +155,18 @@ class PreferencesScreen : AndroidScreen() {
PreferenceHeader(text = stringResource(id = R.string.timeline))
ListPreferenceWidget(
preference = loadedState.mainFilterPref.second,
selectedKey = loadedState.mainFilterPref.first,
entries = mapOf(
"ALL" to stringResource(R.string.articles),
"NEW" to stringResource(R.string.new_articles),
"STARS" to stringResource(R.string.favorites)
),
title = stringResource(R.string.default_category),
onValueChange = {}
)
ListPreferenceWidget(
preference = loadedState.timelineItemSize.second,
selectedKey = loadedState.timelineItemSize.first,

View File

@ -25,7 +25,8 @@ class PreferencesScreenModel(
preferences.scrollRead.flow,
preferences.hideReadFeeds.flow,
preferences.openLinksWith.flow,
preferences.timelineItemSize.flow
preferences.timelineItemSize.flow,
preferences.mainFilter.flow
)
combine(
@ -37,7 +38,8 @@ class PreferencesScreenModel(
scrollReadPref = (list[2] as Boolean) to preferences.scrollRead,
hideReadFeeds = (list[3] as Boolean) to preferences.hideReadFeeds,
openLinksWith = (list[4] as String) to preferences.openLinksWith,
timelineItemSize = (list[5] as String) to preferences.timelineItemSize
timelineItemSize = (list[5] as String) to preferences.timelineItemSize,
mainFilterPref = (list[6] as String) to preferences.mainFilter
)
}.collect { theme ->
mutableState.update { theme }
@ -57,7 +59,8 @@ sealed class PreferencesScreenState {
val scrollReadPref: PreferenceState<Boolean>,
val hideReadFeeds: PreferenceState<Boolean>,
val openLinksWith: PreferenceState<String>,
val timelineItemSize: PreferenceState<String>
val timelineItemSize: PreferenceState<String>,
val mainFilterPref: PreferenceState<String>,
) : PreferencesScreenState()
}

View File

@ -39,6 +39,7 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.update
@ -65,6 +66,17 @@ class TimelineScreenModel(
init {
screenModelScope.launch(dispatcher) {
val mainFilter = MainFilter.valueOf(preferences.mainFilter.flow.first())
_timelineState.update {
it.copy(
filters = updateFilters {
it.filters.copy(
mainFilter = mainFilter
)
}
)
}
combine(
accountEvent,
filters
@ -123,17 +135,17 @@ class TimelineScreenModel(
}
}
private fun getTimelinePreferences(): Flow<TimelinePreferences> {
private fun getTimelinePreferences(): Flow<TimelinePreferences> = with(preferences) {
return combine(
preferences.timelineItemSize.flow,
preferences.scrollRead.flow,
preferences.displayNotificationsPermission.flow,
preferences.showReadItems.flow,
preferences.orderField.flow,
preferences.orderType.flow,
preferences.theme.flow,
preferences.openLinksWith.flow,
preferences.globalOpenInAsk.flow,
timelineItemSize.flow,
scrollRead.flow,
displayNotificationsPermission.flow,
showReadItems.flow,
orderField.flow,
orderType.flow,
theme.flow,
openLinksWith.flow,
globalOpenInAsk.flow,
transform = {
TimelinePreferences(
itemSize = when (it[0]) {
@ -148,7 +160,7 @@ class TimelineScreenModel(
orderType = OrderType.valueOf(it[5] as String),
theme = it[6] as String,
openInExternalBrowser = it[7] as String == "external_navigator",
openInAsk = it[8] as Boolean
openInAsk = it[8] as Boolean,
)
}
)

View File

@ -97,6 +97,12 @@ class Preferences(
key = booleanPreferencesKey("open_in_ask"),
default = true
)
val mainFilter = Preference(
dataStore = dataStore,
key = stringPreferencesKey("main_filter"),
default = "ALL" // uppercase important, used with Enum.valueOf()
)
}

View File

@ -192,4 +192,5 @@
<string name="local_view">Vue locale</string>
<string name="external_view">Vue externe</string>
<string name="do_not_ask_again_next_feeds">Ne pas me redemander pour les autres flux</string>
<string name="default_category">Catégorie par défaut</string>
</resources>

View File

@ -201,4 +201,5 @@
<string name="local_view">Local view</string>
<string name="external_view">External view</string>
<string name="do_not_ask_again_next_feeds">Do not ask me again for next feeds</string>
<string name="default_category">Default category</string>
</resources>