Add mark all read items action for some filters in TimelineTab
This commit is contained in:
parent
09bcba7c5a
commit
adb56cdacf
@ -64,4 +64,20 @@ abstract class BaseRepository(
|
||||
open suspend fun setItemStarState(item: Item) {
|
||||
database.newItemDao().updateStarState(item.id, item.isStarred)
|
||||
}
|
||||
|
||||
open suspend fun setAllItemsRead(accountId: Int) {
|
||||
database.newItemDao().setAllItemsRead(accountId)
|
||||
}
|
||||
|
||||
open suspend fun setAllStarredItemsRead(accountId: Int) {
|
||||
database.newItemDao().setAllStarredItemsRead(accountId)
|
||||
}
|
||||
|
||||
open suspend fun setAllItemsReadByFeed(feedId: Int, accountId: Int) {
|
||||
database.newItemDao().setAllItemsReadByFeed(feedId, accountId)
|
||||
}
|
||||
|
||||
open suspend fun setAllItemsReadByFolder(folderId: Int, accountId: Int) {
|
||||
database.newItemDao().setAllItemsReadByFolder(folderId, accountId)
|
||||
}
|
||||
}
|
@ -42,6 +42,7 @@ import com.readrops.app.compose.R
|
||||
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.components.TwoChoicesDialog
|
||||
import com.readrops.app.compose.util.theme.spacing
|
||||
import com.readrops.db.filters.FilterType
|
||||
import org.koin.androidx.compose.getViewModel
|
||||
@ -96,6 +97,21 @@ object TimelineTab : Tab {
|
||||
}
|
||||
}
|
||||
|
||||
if (state.confirmDialog) {
|
||||
TwoChoicesDialog(
|
||||
title = "Mark all items as read",
|
||||
text = "Do you really want to mark all items as read?",
|
||||
icon = painterResource(id = R.drawable.ic_rss_feed_grey),
|
||||
confirmText = "Validate",
|
||||
dismissText = "Cancel",
|
||||
onDismiss = { viewModel.closeConfirmDialog() },
|
||||
onConfirm = {
|
||||
viewModel.closeConfirmDialog()
|
||||
viewModel.setAllItemsRead()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
drawerContent = {
|
||||
@ -158,7 +174,15 @@ object TimelineTab : Tab {
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(onClick = { }) {
|
||||
FloatingActionButton(
|
||||
onClick = {
|
||||
if (state.filters.filterType == FilterType.NO_FILTER) {
|
||||
viewModel.openConfirmDialog()
|
||||
} else {
|
||||
viewModel.setAllItemsRead()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_done_all),
|
||||
contentDescription = null
|
||||
|
@ -183,6 +183,39 @@ class TimelineViewModel(
|
||||
context.startActivity(Intent.createChooser(it, null))
|
||||
}
|
||||
}
|
||||
|
||||
fun setAllItemsRead() {
|
||||
viewModelScope.launch(dispatcher) {
|
||||
when (_timelineState.value.filters.filterType) {
|
||||
FilterType.FEED_FILTER ->
|
||||
repository?.setAllItemsReadByFeed(
|
||||
_timelineState.value.filters.filterFeedId,
|
||||
currentAccount!!.id
|
||||
)
|
||||
|
||||
FilterType.FOLDER_FILER -> repository?.setAllItemsReadByFolder(
|
||||
_timelineState.value.filters.filterFolderId,
|
||||
currentAccount!!.id
|
||||
)
|
||||
FilterType.READ_IT_LATER_FILTER -> TODO()
|
||||
FilterType.STARS_FILTER -> repository?.setAllStarredItemsRead(currentAccount!!.id)
|
||||
FilterType.NO_FILTER -> repository?.setAllItemsRead(currentAccount!!.id)
|
||||
FilterType.NEW -> TODO()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun openConfirmDialog() {
|
||||
_timelineState.value = _timelineState.value.copy(
|
||||
confirmDialog = true
|
||||
)
|
||||
}
|
||||
|
||||
fun closeConfirmDialog() {
|
||||
_timelineState.value = _timelineState.value.copy(
|
||||
confirmDialog = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
@ -194,5 +227,6 @@ data class TimelineState(
|
||||
val filterFeedName: String = "",
|
||||
val filterFolderName: String = "",
|
||||
val foldersAndFeeds: Map<Folder?, List<Feed>> = emptyMap(),
|
||||
val itemState: Flow<PagingData<ItemWithFeed>> = emptyFlow()
|
||||
val itemState: Flow<PagingData<ItemWithFeed>> = emptyFlow(),
|
||||
val confirmDialog: Boolean = false
|
||||
)
|
||||
|
@ -22,4 +22,18 @@ abstract class NewItemDao : NewBaseDao<Item> {
|
||||
|
||||
@Query("Update Item Set starred = :starred Where id = :itemId")
|
||||
abstract suspend fun updateStarState(itemId: Int, starred: Boolean)
|
||||
|
||||
@Query("Update Item set read = 1 Where feed_id IN (Select id From Feed Where account_id = :accountId)")
|
||||
abstract suspend fun setAllItemsRead(accountId: Int)
|
||||
|
||||
@Query("Update Item set read = 1 Where starred = 1 And feed_id IN (Select id From Feed Where account_id = :accountId)")
|
||||
abstract suspend fun setAllStarredItemsRead(accountId: Int)
|
||||
|
||||
@Query("Update Item set read = 1 Where feed_id IN " +
|
||||
"(Select id From Feed Where id = :feedId And account_id = :accountId)")
|
||||
abstract suspend fun setAllItemsReadByFeed(feedId: Int, accountId: Int)
|
||||
|
||||
@Query("Update Item set read = 1 Where feed_id IN (Select Feed.id From Feed Inner Join Folder " +
|
||||
"On Feed.folder_id = Folder.id Where Folder.id = :folderId And Folder.account_id = :accountId)")
|
||||
abstract suspend fun setAllItemsReadByFolder(folderId: Int, accountId: Int)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user