mirror of
https://github.com/readrops/Readrops.git
synced 2025-02-02 03:36:52 +01:00
Display unread new items count in TimelineDrawer
This commit is contained in:
parent
ea51df49bc
commit
8566b55e3f
@ -23,15 +23,18 @@ import com.readrops.db.queries.ItemsQueryBuilder
|
||||
import com.readrops.db.queries.QueryFilters
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import kotlinx.coroutines.flow.flatMapConcat
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class TimelineScreenModel(
|
||||
private val database: Database,
|
||||
private val getFoldersWithFeeds: GetFoldersWithFeeds,
|
||||
@ -76,8 +79,18 @@ class TimelineScreenModel(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
screenModelScope.launch(dispatcher) {
|
||||
accountEvent.flatMapConcat { database.newItemDao().selectUnreadNewItemsCount(it.id) }
|
||||
.collectLatest { count ->
|
||||
_timelineState.update {
|
||||
it.copy(unreadNewItemsCount = count)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshTimeline() {
|
||||
@ -289,6 +302,7 @@ data class TimelineState(
|
||||
val isRefreshing: Boolean = false,
|
||||
val isDrawerOpen: Boolean = false,
|
||||
val currentFeed: String = "",
|
||||
val unreadNewItemsCount: Int = 0,
|
||||
val feedCount: Int = 0,
|
||||
val feedMax: Int = 0,
|
||||
val endSynchronizing: Boolean = false,
|
||||
|
@ -48,6 +48,7 @@ fun TimelineDrawer(
|
||||
|
||||
DrawerDefaultItems(
|
||||
selectedItem = state.filters.mainFilter,
|
||||
unreadNewItemsCount = state.unreadNewItemsCount,
|
||||
onClick = { onClickDefaultItem(it) }
|
||||
)
|
||||
|
||||
@ -62,7 +63,7 @@ fun TimelineDrawer(
|
||||
label = {
|
||||
Text(
|
||||
text = folder.name!!,
|
||||
maxLines = 1,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
},
|
||||
@ -118,6 +119,7 @@ fun TimelineDrawer(
|
||||
@Composable
|
||||
fun DrawerDefaultItems(
|
||||
selectedItem: MainFilter,
|
||||
unreadNewItemsCount: Int,
|
||||
onClick: (MainFilter) -> Unit,
|
||||
) {
|
||||
NavigationDrawerItem(
|
||||
@ -134,7 +136,7 @@ fun DrawerDefaultItems(
|
||||
)
|
||||
|
||||
NavigationDrawerItem(
|
||||
label = { Text("New articles") },
|
||||
label = { Text("New articles ($unreadNewItemsCount)") },
|
||||
icon = {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_new),
|
||||
|
@ -45,4 +45,8 @@ abstract class NewItemDao : NewBaseDao<Item> {
|
||||
@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)
|
||||
|
||||
@Query("Select count(*) From Item Inner Join Feed On Item.feed_id = Feed.id Where read = 0 and account_id = :accountId " +
|
||||
"And DateTime(Round(Item.pub_date / 1000), 'unixepoch') Between DateTime(DateTime(\"now\"), \"-24 hour\") And DateTime(\"now\")")
|
||||
abstract fun selectUnreadNewItemsCount(accountId: Int): Flow<Int>
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user