Add favorite entry alternative handling, allowing parennt versions to take priority for favorites sync

This commit is contained in:
Jobobby04
2023-05-12 22:50:23 -04:00
parent e9a3463455
commit 282a0c4e16
12 changed files with 333 additions and 34 deletions
@@ -2,13 +2,14 @@ package tachiyomi.data.manga
import tachiyomi.domain.manga.model.FavoriteEntry
val favoriteEntryMapper: (Long, String, String, String, Long) -> FavoriteEntry =
{ id, title, gid, token, category ->
val favoriteEntryMapper: (String, String, String, Long, String?, String?) -> FavoriteEntry =
{ gid, token, title, category, otherGid, otherToken ->
FavoriteEntry(
id = id,
title = title,
gid = gid,
token = token,
title = title,
category = category.toInt(),
otherGid = otherGid,
otherToken = otherToken,
)
}
@@ -2,6 +2,7 @@ package tachiyomi.data.manga
import tachiyomi.data.DatabaseHandler
import tachiyomi.domain.manga.model.FavoriteEntry
import tachiyomi.domain.manga.model.FavoriteEntryAlternative
import tachiyomi.domain.manga.repository.FavoritesEntryRepository
class FavoritesEntryRepositoryImpl(
@@ -14,7 +15,12 @@ class FavoritesEntryRepositoryImpl(
override suspend fun insertAll(favoriteEntries: List<FavoriteEntry>) {
handler.await(true) {
favoriteEntries.forEach {
eh_favoritesQueries.insertEhFavorites(it.id, it.title, it.gid, it.token, it.category.toLong())
eh_favoritesQueries.insertEhFavorites(
title = it.title,
gid = it.gid,
token = it.token,
category = it.category.toLong(),
)
}
}
}
@@ -22,4 +28,15 @@ class FavoritesEntryRepositoryImpl(
override suspend fun selectAll(): List<FavoriteEntry> {
return handler.awaitList { eh_favoritesQueries.selectAll(favoriteEntryMapper) }
}
override suspend fun addAlternative(favoriteEntryAlternative: FavoriteEntryAlternative) {
handler.await {
eh_favoritesQueries.addAlternative(
otherGid = favoriteEntryAlternative.otherGid,
otherToken = favoriteEntryAlternative.otherToken,
gid = favoriteEntryAlternative.gid,
token = favoriteEntryAlternative.token,
)
}
}
}