Let FavouriteStatusRouter handle historyDB as well

This commit is contained in:
tarsin committed 2023-07-04 10:39:03 +08:00
1 parent 0b1a0cade8
commit 2ba8640996
2 files changed
+12 -12

No files matched your search

+4 -11
View File
@@ -289,18 +289,11 @@ object EhDB {
}
@Synchronized
fun putHistoryInfoNonRefresh(info: GalleryInfo) {
fun modifyHistoryInfoFavslotNonRefresh(gid: Long, slot: Int) {
val dao = db.historyDao()
val i = dao.load(info.gid)
if (null != i) {
val historyInfo: HistoryInfo
if (info is HistoryInfo) {
historyInfo = info
} else {
historyInfo = HistoryInfo(info)
historyInfo.time = i.time
}
dao.update(historyInfo)
dao.load(gid)?.let {
it.favoriteSlot = slot
dao.update(it)
}
}
@@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.shareIn
import kotlinx.coroutines.flow.transform
import kotlinx.coroutines.launch
object FavouriteStatusRouter {
private val idGenerator = IntIdGenerator(Settings.dataMapNextId)
@@ -57,7 +58,13 @@ object FavouriteStatusRouter {
val globalFlow = callbackFlow<Pair<Long, Int>> {
collector = this
awaitClose { error("Unreachable!!!") }
}.shareIn(listenerScope, SharingStarted.Eagerly)
}.shareIn(listenerScope, SharingStarted.Eagerly).apply {
listenerScope.launch {
collect { (gid, slot) ->
EhDB.modifyHistoryInfoFavslotNonRefresh(gid, slot)
}
}
}
fun stateFlow(targetGid: Long) = globalFlow.transform { (gid, slot) -> if (targetGid == gid) emit(slot) }
}