mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-09 08:28:39 +01:00
Add TimelineItemSize preference in TimelineTab
This commit is contained in:
parent
273868d270
commit
c7ccdcd3e3
@ -36,7 +36,7 @@ import org.koin.dsl.module
|
||||
|
||||
val composeAppModule = module {
|
||||
|
||||
factory { TimelineScreenModel(get(), get()) }
|
||||
factory { TimelineScreenModel(get(), get(), get()) }
|
||||
|
||||
factory { FeedScreenModel(get(), get(), get(), androidContext()) }
|
||||
|
||||
|
@ -98,6 +98,18 @@ class PreferencesScreen : AndroidScreen() {
|
||||
|
||||
PreferenceHeader(text = stringResource(id = R.string.timeline))
|
||||
|
||||
ListPreferenceWidget(
|
||||
preference = loadedState.timelineItemSize.second,
|
||||
selectedKey = loadedState.timelineItemSize.first,
|
||||
entries = mapOf(
|
||||
"compact" to stringResource(id = R.string.compact),
|
||||
"regular" to stringResource(id = R.string.regular),
|
||||
"large" to stringResource(id = R.string.large)
|
||||
),
|
||||
title = stringResource(id = R.string.item_size),
|
||||
onValueChange = {}
|
||||
)
|
||||
|
||||
SwitchPreferenceWidget(
|
||||
preference = loadedState.hideReadFeeds.second,
|
||||
isChecked = loadedState.hideReadFeeds.first,
|
||||
|
@ -19,24 +19,29 @@ class PreferencesScreenModel(
|
||||
|
||||
init {
|
||||
screenModelScope.launch(dispatcher) {
|
||||
combine(
|
||||
val flows = listOf(
|
||||
preferences.theme.flow,
|
||||
preferences.backgroundSynchronization.flow,
|
||||
preferences.scrollRead.flow,
|
||||
preferences.hideReadFeeds.flow,
|
||||
preferences.openLinksWith.flow
|
||||
) { (theme, backgroundSync, scrollRead, hideReadFeeds, openLinksWith) ->
|
||||
preferences.openLinksWith.flow,
|
||||
preferences.timelineItemSize.flow
|
||||
)
|
||||
|
||||
combine(
|
||||
flows
|
||||
) { list ->
|
||||
PreferencesScreenState.Loaded(
|
||||
themePref = (theme as String) to preferences.theme,
|
||||
backgroundSyncPref = (backgroundSync as String) to preferences.backgroundSynchronization,
|
||||
scrollReadPref = (scrollRead as Boolean) to preferences.scrollRead,
|
||||
hideReadFeeds = (hideReadFeeds as Boolean) to preferences.hideReadFeeds,
|
||||
openLinksWith = (openLinksWith as String) to preferences.openLinksWith
|
||||
themePref = (list[0] as String) to preferences.theme,
|
||||
backgroundSyncPref = (list[1] as String) to preferences.backgroundSynchronization,
|
||||
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
|
||||
)
|
||||
}.collect { theme ->
|
||||
mutableState.update { theme }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +56,8 @@ sealed class PreferencesScreenState {
|
||||
val backgroundSyncPref: PreferenceState<String>,
|
||||
val scrollReadPref: PreferenceState<Boolean>,
|
||||
val hideReadFeeds: PreferenceState<Boolean>,
|
||||
val openLinksWith: PreferenceState<String>
|
||||
val openLinksWith: PreferenceState<String>,
|
||||
val timelineItemSize: PreferenceState<String>
|
||||
) : PreferencesScreenState()
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import com.readrops.app.base.TabScreenModel
|
||||
import com.readrops.app.repositories.ErrorResult
|
||||
import com.readrops.app.repositories.GetFoldersWithFeeds
|
||||
import com.readrops.app.sync.SyncWorker
|
||||
import com.readrops.app.util.Preferences
|
||||
import com.readrops.db.Database
|
||||
import com.readrops.db.entities.Feed
|
||||
import com.readrops.db.entities.Folder
|
||||
@ -40,6 +41,7 @@ import kotlinx.coroutines.launch
|
||||
class TimelineScreenModel(
|
||||
private val database: Database,
|
||||
private val getFoldersWithFeeds: GetFoldersWithFeeds,
|
||||
private val preferences: Preferences,
|
||||
private val dispatcher: CoroutineDispatcher = Dispatchers.IO
|
||||
) : TabScreenModel(database) {
|
||||
|
||||
@ -106,6 +108,20 @@ class TimelineScreenModel(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
screenModelScope.launch(dispatcher) {
|
||||
preferences.timelineItemSize.flow
|
||||
.collect { itemSize ->
|
||||
_timelineState.update {
|
||||
it.copy(
|
||||
itemSize = when (itemSize) {
|
||||
"compact" -> TimelineItemSize.COMPACT
|
||||
"regular" -> TimelineItemSize.REGULAR
|
||||
else -> TimelineItemSize.LARGE
|
||||
}
|
||||
) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshTimeline(context: Context) {
|
||||
@ -362,7 +378,8 @@ data class TimelineState(
|
||||
val itemState: Flow<PagingData<ItemWithFeed>> = emptyFlow(),
|
||||
val dialog: DialogState? = null,
|
||||
val isAccountLocal: Boolean = false,
|
||||
val hideReadAllFAB: Boolean = false
|
||||
val hideReadAllFAB: Boolean = false,
|
||||
val itemSize: TimelineItemSize = TimelineItemSize.LARGE
|
||||
) {
|
||||
|
||||
val showSubtitle = filters.subFilter != SubFilter.ALL
|
||||
|
@ -41,6 +41,7 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.paging.LoadState
|
||||
import androidx.paging.compose.LazyPagingItems
|
||||
@ -87,7 +88,8 @@ object TimelineTab : Tab {
|
||||
val lazyListState = rememberLazyListState()
|
||||
val pullToRefreshState = rememberPullToRefreshState()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val topAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
|
||||
val topAppBarScrollBehavior =
|
||||
TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
|
||||
|
||||
LaunchedEffect(state.isRefreshing) {
|
||||
if (state.isRefreshing) {
|
||||
@ -337,7 +339,12 @@ object TimelineTab : Tab {
|
||||
LazyColumn(
|
||||
state = lazyListState,
|
||||
contentPadding = PaddingValues(vertical = MaterialTheme.spacing.shortSpacing),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.shortSpacing)
|
||||
verticalArrangement = Arrangement.spacedBy(
|
||||
if (state.itemSize == TimelineItemSize.COMPACT) {
|
||||
0.dp
|
||||
} else
|
||||
MaterialTheme.spacing.shortSpacing
|
||||
)
|
||||
) {
|
||||
items(
|
||||
count = items.itemCount,
|
||||
@ -358,7 +365,7 @@ object TimelineTab : Tab {
|
||||
onShare = {
|
||||
viewModel.shareItem(itemWithFeed.item, context)
|
||||
},
|
||||
size = TimelineItemSize.LARGE
|
||||
size = state.itemSize
|
||||
)
|
||||
|
||||
}
|
||||
|
@ -54,6 +54,12 @@ class Preferences(
|
||||
key = stringPreferencesKey("open_links_with"),
|
||||
default = "navigator_view"
|
||||
)
|
||||
|
||||
val timelineItemSize = Preference(
|
||||
dataStore = dataStore,
|
||||
key = stringPreferencesKey("timeline_item_size"),
|
||||
default = "large"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
@ -180,4 +180,8 @@
|
||||
<string name="item_view">Vue article</string>
|
||||
<string name="timeline">Timeline</string>
|
||||
<string name="hide_feeds_subtitle">Les flux sans nouveaux articles disparaîtront du menu tiroir</string>
|
||||
<string name="compact">Compact</string>
|
||||
<string name="regular">Normal</string>
|
||||
<string name="large">Large</string>
|
||||
<string name="item_size">Taille des items</string>
|
||||
</resources>
|
@ -189,4 +189,8 @@
|
||||
<string name="item_view">Article view</string>
|
||||
<string name="timeline">Timeline</string>
|
||||
<string name="hide_feeds_subtitle">Feeds with no left unread items will be hidden in the drawer</string>
|
||||
<string name="compact">Compact</string>
|
||||
<string name="regular">Regular</string>
|
||||
<string name="large">Large</string>
|
||||
<string name="item_size">Item size</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user