From 09bcba7c5ad32c6a0694d8c330c1bec5e070e5ab Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Wed, 21 Feb 2024 21:53:11 +0100 Subject: [PATCH] Change top bar title depending on current filter in TimelineTab --- .../readrops/app/compose/timelime/TimelineTab.kt | 14 +++++++++++++- .../app/compose/timelime/TimelineViewModel.kt | 12 ++++++++---- .../compose/timelime/drawer/DrawerFolderItem.kt | 4 ++-- .../app/compose/timelime/drawer/TimelineDrawer.kt | 10 ++++++---- appcompose/src/main/res/values/strings.xml | 1 + 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt b/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt index f1307067..0fcb7339 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineTab.kt @@ -43,6 +43,7 @@ import com.readrops.app.compose.item.ItemScreen import com.readrops.app.compose.timelime.drawer.TimelineDrawer import com.readrops.app.compose.util.components.CenteredColumn import com.readrops.app.compose.util.theme.spacing +import com.readrops.db.filters.FilterType import org.koin.androidx.compose.getViewModel @@ -115,7 +116,18 @@ object TimelineTab : Tab { Scaffold( topBar = { 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 = { IconButton( onClick = { viewModel.openDrawer() } diff --git a/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineViewModel.kt b/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineViewModel.kt index 4d4b06c6..b6a220f2 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineViewModel.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/timelime/TimelineViewModel.kt @@ -115,31 +115,33 @@ class TimelineViewModel( } } - fun updateDrawerFolderSelection(folderId: Int) { + fun updateDrawerFolderSelection(folder: Folder) { _timelineState.update { it.copy( filters = updateFilters { it.filters.copy( filterType = FilterType.FOLDER_FILER, - filterFolderId = folderId, + filterFolderId = folder.id, filterFeedId = 0 ) }, + filterFolderName = folder.name!!, isDrawerOpen = false ) } } - fun updateDrawerFeedSelection(feedId: Int) { + fun updateDrawerFeedSelection(feed: Feed) { _timelineState.update { it.copy( filters = updateFilters { it.filters.copy( filterType = FilterType.FEED_FILTER, - filterFeedId = feedId, + filterFeedId = feed.id, filterFolderId = 0 ) }, + filterFeedName = feed.name!!, isDrawerOpen = false ) } @@ -189,6 +191,8 @@ data class TimelineState( val isDrawerOpen: Boolean = false, val endSynchronizing: Boolean = false, val filters: QueryFilters = QueryFilters(), + val filterFeedName: String = "", + val filterFolderName: String = "", val foldersAndFeeds: Map> = emptyMap(), val itemState: Flow> = emptyFlow() ) diff --git a/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/DrawerFolderItem.kt b/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/DrawerFolderItem.kt index ec4f101e..cb0f2926 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/DrawerFolderItem.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/DrawerFolderItem.kt @@ -46,7 +46,7 @@ fun DrawerFolderItem( onClick: () -> Unit, feeds: List, selectedFeed: Int, - onFeedClick: (Int) -> Unit, + onFeedClick: (Feed) -> Unit, modifier: Modifier = Modifier, ) { val colors = NavigationDrawerItemDefaults.colors() @@ -131,7 +131,7 @@ fun DrawerFolderItem( }, badge = { Text(feed.unreadCount.toString()) }, selected = feed.id == selectedFeed, - onClick = { onFeedClick(feed.id) }, + onClick = { onFeedClick(feed) }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) } diff --git a/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/TimelineDrawer.kt b/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/TimelineDrawer.kt index a534dcb6..bb2c14e9 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/TimelineDrawer.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/timelime/drawer/TimelineDrawer.kt @@ -26,14 +26,16 @@ import coil.compose.AsyncImage import com.readrops.app.compose.R import com.readrops.app.compose.timelime.TimelineState 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 @Composable fun TimelineDrawer( state: TimelineState, onClickDefaultItem: (FilterType) -> Unit, - onFolderClick: (Int) -> Unit, - onFeedClick: (Int) -> Unit, + onFolderClick: (Folder) -> Unit, + onFeedClick: (Feed) -> Unit, ) { val scrollState = rememberScrollState() @@ -74,7 +76,7 @@ fun TimelineDrawer( Text(folderEntry.value.sumOf { it.unreadCount }.toString()) }, selected = state.filters.filterFolderId == folder.id, - onClick = { onFolderClick(folder.id) }, + onClick = { onFolderClick(folder) }, feeds = folderEntry.value, selectedFeed = state.filters.filterFeedId, onFeedClick = { onFeedClick(it) }, @@ -102,7 +104,7 @@ fun TimelineDrawer( }, badge = { Text(feed.unreadCount.toString()) }, selected = feed.id == state.filters.filterFeedId, - onClick = { onFeedClick(feed.id) }, + onClick = { onFeedClick(feed) }, modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding) ) } diff --git a/appcompose/src/main/res/values/strings.xml b/appcompose/src/main/res/values/strings.xml index 07c22295..272ac80c 100644 --- a/appcompose/src/main/res/values/strings.xml +++ b/appcompose/src/main/res/values/strings.xml @@ -146,4 +146,5 @@ system Hide feeds without new items Mark items read on scroll + New articles \ No newline at end of file