Fix local favorite count not updating
This commit is contained in:
1 parent
39f76246c8
commit
4f23cf5d8d
3 files changed
+13
-1
No files matched your search
@@ -33,6 +33,7 @@ import com.hippo.ehviewer.dao.LocalFavoriteInfo
|
||||
import com.hippo.ehviewer.dao.QuickSearch
|
||||
import com.hippo.ehviewer.download.DownloadManager
|
||||
import com.hippo.ehviewer.util.sendTo
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import splitties.arch.room.roomDb
|
||||
|
||||
object EhDB {
|
||||
@@ -214,6 +215,9 @@ object EhDB {
|
||||
val localFavLazyList: PagingSource<Int, LocalFavoriteInfo>
|
||||
get() = db.localFavoritesDao().listLazy()
|
||||
|
||||
val localFavCount: Flow<Int>
|
||||
get() = db.localFavoritesDao().count()
|
||||
|
||||
fun searchLocalFav(keyword: String) = db.localFavoritesDao().listLazy("%$keyword%")
|
||||
|
||||
suspend fun putHistoryInfo(galleryInfo: GalleryInfo) {
|
||||
|
||||
@@ -4,9 +4,13 @@ import androidx.paging.PagingSource
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface LocalFavoritesDao {
|
||||
@Query("SELECT COUNT(*) FROM LOCAL_FAVORITES")
|
||||
fun count(): Flow<Int>
|
||||
|
||||
@Query("SELECT * FROM LOCAL_FAVORITES ORDER BY TIME DESC")
|
||||
suspend fun list(): List<LocalFavoriteInfo>
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.currentRecomposeScope
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -143,6 +145,7 @@ class VMStorage : ViewModel() {
|
||||
}
|
||||
}.flow.cachedIn(viewModelScope)
|
||||
fun dataflow() = if (urlBuilder.favCat == -2) localFavDataFlow else cloudDataFlow
|
||||
val localFavCount = EhDB.localFavCount
|
||||
}
|
||||
|
||||
class FavoritesScene : SearchBarScene() {
|
||||
@@ -413,6 +416,7 @@ class FavoritesScene : SearchBarScene() {
|
||||
savedInstanceState: Bundle?,
|
||||
) = ComposeView(inflater.context).apply {
|
||||
setMD3Content {
|
||||
val localFavCount by vm.localFavCount.collectAsState(0)
|
||||
ElevatedCard {
|
||||
TopAppBar(title = { Text(text = stringResource(id = R.string.collections)) })
|
||||
val scope = currentRecomposeScope
|
||||
@@ -422,7 +426,7 @@ class FavoritesScene : SearchBarScene() {
|
||||
}
|
||||
}
|
||||
val faves = arrayOf(
|
||||
stringResource(id = R.string.local_favorites) to Settings.favLocalCount,
|
||||
stringResource(id = R.string.local_favorites) to localFavCount,
|
||||
stringResource(id = R.string.cloud_favorites) to Settings.favCloudCount,
|
||||
*Settings.favCat.zip(Settings.favCount.toTypedArray()).toTypedArray(),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user