Fix local favorites scroll state loss
This commit is contained in:
1 parent
1238edfe2b
commit
c4be269fb7
5 files changed
+19
-9
No files matched your search
@@ -38,8 +38,13 @@ import splitties.arch.room.roomDb
|
|||||||
object EhDB {
|
object EhDB {
|
||||||
private val db = roomDb<EhDatabase>("eh.db")
|
private val db = roomDb<EhDatabase>("eh.db")
|
||||||
|
|
||||||
private suspend fun putGalleryInfo(galleryInfo: BaseGalleryInfo) {
|
private suspend fun putGalleryInfo(galleryInfo: BaseGalleryInfo, update: Boolean = false) {
|
||||||
db.galleryDao().upsert(galleryInfo)
|
val dao = db.galleryDao()
|
||||||
|
if (update) {
|
||||||
|
dao.upsert(galleryInfo)
|
||||||
|
} else {
|
||||||
|
dao.insertOrIgnore(galleryInfo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun deleteGalleryInfo(galleryInfo: BaseGalleryInfo) {
|
private suspend fun deleteGalleryInfo(galleryInfo: BaseGalleryInfo) {
|
||||||
@@ -190,12 +195,12 @@ object EhDB {
|
|||||||
|
|
||||||
fun searchLocalFav(keyword: String) = db.localFavoritesDao().joinListLazy("%$keyword%")
|
fun searchLocalFav(keyword: String) = db.localFavoritesDao().joinListLazy("%$keyword%")
|
||||||
|
|
||||||
suspend fun putHistoryInfo(galleryInfo: BaseGalleryInfo) {
|
suspend fun putHistoryInfo(galleryInfo: BaseGalleryInfo, updateGalleryInfo: Boolean = false) {
|
||||||
putGalleryInfo(galleryInfo)
|
putGalleryInfo(galleryInfo, updateGalleryInfo)
|
||||||
db.historyDao().upsert(HistoryInfo(galleryInfo.gid))
|
db.historyDao().upsert(HistoryInfo(galleryInfo.gid))
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun modifyHistoryInfoFavslotNonRefresh(gid: Long, slot: Int) {
|
suspend fun updateFavoriteSlot(gid: Long, slot: Int) {
|
||||||
val dao = db.galleryDao()
|
val dao = db.galleryDao()
|
||||||
dao.load(gid)?.let {
|
dao.load(gid)?.let {
|
||||||
it.favoriteSlot = slot
|
it.favoriteSlot = slot
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ interface GalleryDao {
|
|||||||
@Query("SELECT * FROM GALLERIES")
|
@Query("SELECT * FROM GALLERIES")
|
||||||
suspend fun list(): List<BaseGalleryInfo>
|
suspend fun list(): List<BaseGalleryInfo>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
suspend fun insertOrIgnore(galleryInfo: BaseGalleryInfo)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
suspend fun insertOrIgnore(galleryInfoList: List<BaseGalleryInfo>)
|
suspend fun insertOrIgnore(galleryInfoList: List<BaseGalleryInfo>)
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class VMStorage : ViewModel() {
|
|||||||
EhDB.searchLocalFav(keyword)
|
EhDB.searchLocalFav(keyword)
|
||||||
}
|
}
|
||||||
}.flow.cachedIn(viewModelScope)
|
}.flow.cachedIn(viewModelScope)
|
||||||
fun dataflow() = if (urlBuilder.favCat == -2) localFavDataFlow else cloudDataFlow
|
fun dataflow() = if (urlBuilder.favCat == FavListUrlBuilder.FAV_CAT_LOCAL) localFavDataFlow else cloudDataFlow
|
||||||
val localFavCount = EhDB.localFavCount
|
val localFavCount = EhDB.localFavCount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -222,7 +222,6 @@ class GalleryDetailScene : BaseScene() {
|
|||||||
mAction = action
|
mAction = action
|
||||||
if (ACTION_GALLERY_INFO == action) {
|
if (ACTION_GALLERY_INFO == action) {
|
||||||
composeBindingGI = args.getParcelableCompat(KEY_GALLERY_INFO)
|
composeBindingGI = args.getParcelableCompat(KEY_GALLERY_INFO)
|
||||||
composeBindingGI?.let { lifecycleScope.launchIO { EhDB.putHistoryInfo(it) } }
|
|
||||||
} else if (ACTION_GID_TOKEN == action) {
|
} else if (ACTION_GID_TOKEN == action) {
|
||||||
mGid = args.getLong(KEY_GID)
|
mGid = args.getLong(KEY_GID)
|
||||||
mToken = args.getString(KEY_TOKEN)
|
mToken = args.getString(KEY_TOKEN)
|
||||||
@@ -867,7 +866,10 @@ class GalleryDetailScene : BaseScene() {
|
|||||||
EhEngine.getGalleryDetail(url)
|
EhEngine.getGalleryDetail(url)
|
||||||
}.onSuccess { galleryDetail ->
|
}.onSuccess { galleryDetail ->
|
||||||
galleryDetailCache.put(galleryDetail.gid, galleryDetail)
|
galleryDetailCache.put(galleryDetail.gid, galleryDetail)
|
||||||
EhDB.putHistoryInfo(galleryDetail.galleryInfo)
|
// Don't update gallery info in database if previous destination is favorites,
|
||||||
|
// since it will invalidate local favorites PagingSource and lose scroll state
|
||||||
|
val previousDestinationId = findNavController().previousBackStackEntry?.destination?.id
|
||||||
|
EhDB.putHistoryInfo(galleryDetail.galleryInfo, previousDestinationId != R.id.nav_favourite)
|
||||||
if (Settings.preloadThumbAggressively) {
|
if (Settings.preloadThumbAggressively) {
|
||||||
lifecycleScope.launchIO {
|
lifecycleScope.launchIO {
|
||||||
galleryDetail.previewList.forEach {
|
galleryDetail.previewList.forEach {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ object FavouriteStatusRouter {
|
|||||||
private val _globalFlow = MutableSharedFlow<Pair<Long, Int>>(extraBufferCapacity = 1).apply {
|
private val _globalFlow = MutableSharedFlow<Pair<Long, Int>>(extraBufferCapacity = 1).apply {
|
||||||
listenerScope.launch {
|
listenerScope.launch {
|
||||||
collect { (gid, slot) ->
|
collect { (gid, slot) ->
|
||||||
EhDB.modifyHistoryInfoFavslotNonRefresh(gid, slot)
|
EhDB.updateFavoriteSlot(gid, slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user