Change top bar title depending on current filter in TimelineTab

This commit is contained in:
Shinokuni 2024-02-21 21:53:11 +01:00
parent edc2094a6e
commit 09bcba7c5a
5 changed files with 30 additions and 11 deletions

View File

@ -43,6 +43,7 @@ import com.readrops.app.compose.item.ItemScreen
import com.readrops.app.compose.timelime.drawer.TimelineDrawer import com.readrops.app.compose.timelime.drawer.TimelineDrawer
import com.readrops.app.compose.util.components.CenteredColumn import com.readrops.app.compose.util.components.CenteredColumn
import com.readrops.app.compose.util.theme.spacing import com.readrops.app.compose.util.theme.spacing
import com.readrops.db.filters.FilterType
import org.koin.androidx.compose.getViewModel import org.koin.androidx.compose.getViewModel
@ -115,7 +116,18 @@ object TimelineTab : Tab {
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( TopAppBar(
title = { Text(text = stringResource(R.string.articles)) }, title = {
Text(
text = when (state.filters.filterType) {
FilterType.FEED_FILTER -> state.filterFeedName
FilterType.FOLDER_FILER -> state.filterFolderName
FilterType.READ_IT_LATER_FILTER -> stringResource(R.string.read_later)
FilterType.STARS_FILTER -> stringResource(R.string.favorites)
FilterType.NO_FILTER -> stringResource(R.string.articles)
FilterType.NEW -> stringResource(R.string.new_articles)
}
)
},
navigationIcon = { navigationIcon = {
IconButton( IconButton(
onClick = { viewModel.openDrawer() } onClick = { viewModel.openDrawer() }

View File

@ -115,31 +115,33 @@ class TimelineViewModel(
} }
} }
fun updateDrawerFolderSelection(folderId: Int) { fun updateDrawerFolderSelection(folder: Folder) {
_timelineState.update { _timelineState.update {
it.copy( it.copy(
filters = updateFilters { filters = updateFilters {
it.filters.copy( it.filters.copy(
filterType = FilterType.FOLDER_FILER, filterType = FilterType.FOLDER_FILER,
filterFolderId = folderId, filterFolderId = folder.id,
filterFeedId = 0 filterFeedId = 0
) )
}, },
filterFolderName = folder.name!!,
isDrawerOpen = false isDrawerOpen = false
) )
} }
} }
fun updateDrawerFeedSelection(feedId: Int) { fun updateDrawerFeedSelection(feed: Feed) {
_timelineState.update { _timelineState.update {
it.copy( it.copy(
filters = updateFilters { filters = updateFilters {
it.filters.copy( it.filters.copy(
filterType = FilterType.FEED_FILTER, filterType = FilterType.FEED_FILTER,
filterFeedId = feedId, filterFeedId = feed.id,
filterFolderId = 0 filterFolderId = 0
) )
}, },
filterFeedName = feed.name!!,
isDrawerOpen = false isDrawerOpen = false
) )
} }
@ -189,6 +191,8 @@ data class TimelineState(
val isDrawerOpen: Boolean = false, val isDrawerOpen: Boolean = false,
val endSynchronizing: Boolean = false, val endSynchronizing: Boolean = false,
val filters: QueryFilters = QueryFilters(), val filters: QueryFilters = QueryFilters(),
val filterFeedName: String = "",
val filterFolderName: String = "",
val foldersAndFeeds: Map<Folder?, List<Feed>> = emptyMap(), val foldersAndFeeds: Map<Folder?, List<Feed>> = emptyMap(),
val itemState: Flow<PagingData<ItemWithFeed>> = emptyFlow() val itemState: Flow<PagingData<ItemWithFeed>> = emptyFlow()
) )

View File

@ -46,7 +46,7 @@ fun DrawerFolderItem(
onClick: () -> Unit, onClick: () -> Unit,
feeds: List<Feed>, feeds: List<Feed>,
selectedFeed: Int, selectedFeed: Int,
onFeedClick: (Int) -> Unit, onFeedClick: (Feed) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val colors = NavigationDrawerItemDefaults.colors() val colors = NavigationDrawerItemDefaults.colors()
@ -131,7 +131,7 @@ fun DrawerFolderItem(
}, },
badge = { Text(feed.unreadCount.toString()) }, badge = { Text(feed.unreadCount.toString()) },
selected = feed.id == selectedFeed, selected = feed.id == selectedFeed,
onClick = { onFeedClick(feed.id) }, onClick = { onFeedClick(feed) },
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
) )
} }

View File

@ -26,14 +26,16 @@ import coil.compose.AsyncImage
import com.readrops.app.compose.R import com.readrops.app.compose.R
import com.readrops.app.compose.timelime.TimelineState import com.readrops.app.compose.timelime.TimelineState
import com.readrops.app.compose.util.theme.spacing import com.readrops.app.compose.util.theme.spacing
import com.readrops.db.entities.Feed
import com.readrops.db.entities.Folder
import com.readrops.db.filters.FilterType import com.readrops.db.filters.FilterType
@Composable @Composable
fun TimelineDrawer( fun TimelineDrawer(
state: TimelineState, state: TimelineState,
onClickDefaultItem: (FilterType) -> Unit, onClickDefaultItem: (FilterType) -> Unit,
onFolderClick: (Int) -> Unit, onFolderClick: (Folder) -> Unit,
onFeedClick: (Int) -> Unit, onFeedClick: (Feed) -> Unit,
) { ) {
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
@ -74,7 +76,7 @@ fun TimelineDrawer(
Text(folderEntry.value.sumOf { it.unreadCount }.toString()) Text(folderEntry.value.sumOf { it.unreadCount }.toString())
}, },
selected = state.filters.filterFolderId == folder.id, selected = state.filters.filterFolderId == folder.id,
onClick = { onFolderClick(folder.id) }, onClick = { onFolderClick(folder) },
feeds = folderEntry.value, feeds = folderEntry.value,
selectedFeed = state.filters.filterFeedId, selectedFeed = state.filters.filterFeedId,
onFeedClick = { onFeedClick(it) }, onFeedClick = { onFeedClick(it) },
@ -102,7 +104,7 @@ fun TimelineDrawer(
}, },
badge = { Text(feed.unreadCount.toString()) }, badge = { Text(feed.unreadCount.toString()) },
selected = feed.id == state.filters.filterFeedId, selected = feed.id == state.filters.filterFeedId,
onClick = { onFeedClick(feed.id) }, onClick = { onFeedClick(feed) },
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
) )
} }

View File

@ -146,4 +146,5 @@
<string name="theme_value_system" translatable="false">system</string> <string name="theme_value_system" translatable="false">system</string>
<string name="hide_feeds">Hide feeds without new items</string> <string name="hide_feeds">Hide feeds without new items</string>
<string name="mark_items_read">Mark items read on scroll</string> <string name="mark_items_read">Mark items read on scroll</string>
<string name="new_articles">New articles</string>
</resources> </resources>