Fix BottomBarState not being updated in ItemScreen

This commit is contained in:
Shinokuni 2024-04-26 15:55:09 +02:00
parent 45dc199ea2
commit c55a9dc5e4
3 changed files with 19 additions and 8 deletions

View File

@ -141,7 +141,7 @@ class ItemScreen(
snackbarHost = { SnackbarHost(snackbarHostState) },
bottomBar = {
ItemScreenBottomBar(
item = item,
state = state.bottomBarState,
accentColor = accentColor,
modifier = Modifier
.height(bottomBarHeight)

View File

@ -18,11 +18,15 @@ import androidx.compose.ui.res.painterResource
import com.readrops.app.compose.R
import com.readrops.app.compose.util.FeedColors
import com.readrops.app.compose.util.theme.spacing
import com.readrops.db.entities.Item
data class BottomBarState(
val isRead: Boolean = false,
val isStarred: Boolean = false
)
@Composable
fun ItemScreenBottomBar(
item: Item,
state: BottomBarState,
accentColor: Color,
onShare: () -> Unit,
onOpenUrl: () -> Unit,
@ -44,11 +48,11 @@ fun ItemScreenBottomBar(
modifier = Modifier.padding(MaterialTheme.spacing.shortSpacing)
) {
IconButton(
onClick = { onChangeReadState(!item.isRead) }
onClick = { onChangeReadState(!state.isRead) }
) {
Icon(
painter = painterResource(
id = if (item.isRead)
id = if (state.isRead)
R.drawable.ic_remove_done
else R.drawable.ic_done_all
),
@ -58,11 +62,11 @@ fun ItemScreenBottomBar(
}
IconButton(
onClick = { onChangeStarState(!item.isStarred) }
onClick = { onChangeStarState(!state.isStarred) }
) {
Icon(
painter = painterResource(
id = if (item.isStarred)
id = if (state.isStarred)
R.drawable.ic_star
else R.drawable.ic_star_outline
),

View File

@ -53,7 +53,13 @@ class ItemScreenModel(
database.newItemDao().selectItemById(query)
.collect { itemWithFeed ->
mutableState.update {
it.copy(itemWithFeed = itemWithFeed)
it.copy(
itemWithFeed = itemWithFeed,
bottomBarState = BottomBarState(
isRead = itemWithFeed.item.isRead,
isStarred = itemWithFeed.item.isStarred
)
)
}
}
}
@ -150,6 +156,7 @@ class ItemScreenModel(
@Stable
data class ItemState(
val itemWithFeed: ItemWithFeed? = null,
val bottomBarState: BottomBarState = BottomBarState(),
val imageDialogUrl: String? = null,
val fileDownloadedEvent: Boolean = false
)