Verify library state before syncing
This commit is contained in:
parent
77c07d13c0
commit
2545b22ab1
@ -585,6 +585,25 @@ class LibraryController(
|
|||||||
favSyncDialog?.dismiss()
|
favSyncDialog?.dismiss()
|
||||||
favSyncDialog = null
|
favSyncDialog = null
|
||||||
}
|
}
|
||||||
|
is FavoritesSyncStatus.BadLibraryState.MangaInMultipleCategories -> {
|
||||||
|
releaseSyncLocks()
|
||||||
|
|
||||||
|
favSyncDialog?.dismiss()
|
||||||
|
favSyncDialog = buildDialog()
|
||||||
|
?.title("Favorites sync error")
|
||||||
|
?.content(status.message + " Sync will not start until the gallery is in only one category.")
|
||||||
|
?.cancelable(false)
|
||||||
|
?.positiveText("Show gallery")
|
||||||
|
?.onPositive { _, _ ->
|
||||||
|
openManga(status.manga)
|
||||||
|
presenter.favoritesSync.status.onNext(FavoritesSyncStatus.Idle())
|
||||||
|
}
|
||||||
|
?.negativeText("Ok")
|
||||||
|
?.onNegative { _, _ ->
|
||||||
|
presenter.favoritesSync.status.onNext(FavoritesSyncStatus.Idle())
|
||||||
|
}
|
||||||
|
?.show()
|
||||||
|
}
|
||||||
is FavoritesSyncStatus.Error -> {
|
is FavoritesSyncStatus.Error -> {
|
||||||
releaseSyncLocks()
|
releaseSyncLocks()
|
||||||
|
|
||||||
|
@ -69,6 +69,24 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate library state
|
||||||
|
status.onNext(FavoritesSyncStatus.Processing("Verifying local library"))
|
||||||
|
val libraryManga = db.getLibraryMangas().executeAsBlocking()
|
||||||
|
val seenManga = HashSet<Long>(libraryManga.size)
|
||||||
|
libraryManga.forEach {
|
||||||
|
if(it.source != EXH_SOURCE_ID && it.source != EH_SOURCE_ID) return@forEach
|
||||||
|
|
||||||
|
if(it.id in seenManga) {
|
||||||
|
val inCategories = db.getCategoriesForManga(it).executeAsBlocking()
|
||||||
|
status.onNext(FavoritesSyncStatus.BadLibraryState
|
||||||
|
.MangaInMultipleCategories(it, inCategories))
|
||||||
|
logger.w("Manga %s is in multiple categories!", it.id)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
seenManga += it.id!!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Download remote favorites
|
//Download remote favorites
|
||||||
val favorites = try {
|
val favorites = try {
|
||||||
status.onNext(FavoritesSyncStatus.Processing("Downloading favorites from remote server"))
|
status.onNext(FavoritesSyncStatus.Processing("Downloading favorites from remote server"))
|
||||||
@ -387,6 +405,11 @@ class FavoritesSyncHelper(val context: Context) {
|
|||||||
sealed class FavoritesSyncStatus(val message: String) {
|
sealed class FavoritesSyncStatus(val message: String) {
|
||||||
class Error(message: String) : FavoritesSyncStatus(message)
|
class Error(message: String) : FavoritesSyncStatus(message)
|
||||||
class Idle : FavoritesSyncStatus("Waiting for sync to start")
|
class Idle : FavoritesSyncStatus("Waiting for sync to start")
|
||||||
|
sealed class BadLibraryState(message: String) : FavoritesSyncStatus(message) {
|
||||||
|
class MangaInMultipleCategories(val manga: Manga,
|
||||||
|
val categories: List<Category>):
|
||||||
|
BadLibraryState("The gallery: ${manga.title} is in more than one category (${categories.joinToString { it.name }})!")
|
||||||
|
}
|
||||||
class Initializing : FavoritesSyncStatus("Initializing sync")
|
class Initializing : FavoritesSyncStatus("Initializing sync")
|
||||||
class Processing(message: String, isThrottle: Boolean = false) : FavoritesSyncStatus(if(isThrottle)
|
class Processing(message: String, isThrottle: Boolean = false) : FavoritesSyncStatus(if(isThrottle)
|
||||||
"$message\n\nSync is currently throttling (to avoid being banned from ExHentai) and may take a long time to complete."
|
"$message\n\nSync is currently throttling (to avoid being banned from ExHentai) and may take a long time to complete."
|
||||||
|
@ -115,14 +115,17 @@ class LocalFavoritesStorage {
|
|||||||
token = EHentaiSearchMetadata.galleryToken(it.second.url)
|
token = EHentaiSearchMetadata.galleryToken(it.second.url)
|
||||||
category = it.first
|
category = it.first
|
||||||
|
|
||||||
// TODO Throw error here
|
if(this.category > MAX_CATEGORIES)
|
||||||
if(this.category > 9)
|
|
||||||
return@mapNotNull null
|
return@mapNotNull null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun validateDbManga(manga: Manga)
|
private fun validateDbManga(manga: Manga)
|
||||||
= manga.favorite && (manga.source == EH_SOURCE_ID || manga.source == EXH_SOURCE_ID)
|
= manga.favorite && (manga.source == EH_SOURCE_ID || manga.source == EXH_SOURCE_ID)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val MAX_CATEGORIES = 9
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ChangeSet(val added: List<FavoriteEntry>,
|
data class ChangeSet(val added: List<FavoriteEntry>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user