More refactoring + more bug fixes
Such as when a manga picked has 0 chapters
This commit is contained in:
parent
142dc1c12a
commit
332e8c9487
@ -21,6 +21,8 @@ class MigratingManga(private val db: DatabaseHelper,
|
|||||||
|
|
||||||
val migrationJob = parentContext + SupervisorJob() + Dispatchers.Default
|
val migrationJob = parentContext + SupervisorJob() + Dispatchers.Default
|
||||||
|
|
||||||
|
var migrationStatus:Int = MigrationStatus.RUNNUNG
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var manga: Manga? = null
|
private var manga: Manga? = null
|
||||||
suspend fun manga(): Manga? {
|
suspend fun manga(): Manga? {
|
||||||
@ -36,4 +38,12 @@ class MigratingManga(private val db: DatabaseHelper,
|
|||||||
// Create the model object.
|
// Create the model object.
|
||||||
return MigrationProcessItem(this)
|
return MigrationProcessItem(this)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MigrationStatus {
|
||||||
|
companion object {
|
||||||
|
val RUNNUNG = 0
|
||||||
|
val MANGA_FOUND = 1
|
||||||
|
val MANGA_NOT_FOUND = 2
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,6 +9,7 @@ import android.view.MenuInflater
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat
|
||||||
@ -233,6 +234,9 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
manga.migrationStatus = if (result == null) MigrationStatus.MANGA_NOT_FOUND else
|
||||||
|
MigrationStatus.MANGA_FOUND
|
||||||
|
adapter?.sourceFinished()
|
||||||
manga.searchResult.initialize(result?.id)
|
manga.searchResult.initialize(result?.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,34 +285,46 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle),
|
|||||||
fun useMangaForMigration(manga: Manga, source: Source) {
|
fun useMangaForMigration(manga: Manga, source: Source) {
|
||||||
val firstIndex = selectedPosition ?: return
|
val firstIndex = selectedPosition ?: return
|
||||||
val migratingManga = adapter?.getItem(firstIndex) ?: return
|
val migratingManga = adapter?.getItem(firstIndex) ?: return
|
||||||
migratingManga.showSpinner()
|
migratingManga.manga.migrationStatus = MigrationStatus.RUNNUNG
|
||||||
|
adapter?.notifyItemChanged(firstIndex)
|
||||||
launchUI {
|
launchUI {
|
||||||
val result = CoroutineScope(migratingManga.manga.migrationJob).async {
|
val result = CoroutineScope(migratingManga.manga.migrationJob).async {
|
||||||
val localManga = smartSearchEngine.networkToLocalManga(manga, source.id)
|
val localManga = smartSearchEngine.networkToLocalManga(manga, source.id)
|
||||||
val chapters = source.fetchChapterList(localManga).toSingle().await(
|
val chapters = source.fetchChapterList(localManga).toSingle().await(
|
||||||
Schedulers.io()
|
Schedulers.io()
|
||||||
)
|
)
|
||||||
withContext(Dispatchers.IO) {
|
try {
|
||||||
syncChaptersWithSource(db, chapters, localManga, source)
|
syncChaptersWithSource(db, chapters, localManga, source)
|
||||||
}
|
}
|
||||||
|
catch (e: Exception) {
|
||||||
|
return@async null
|
||||||
|
}
|
||||||
localManga
|
localManga
|
||||||
}.await()
|
}.await()
|
||||||
|
|
||||||
try {
|
if (result != null) {
|
||||||
val newManga =
|
try {
|
||||||
sourceManager.getOrStub(result.source).fetchMangaDetails(result).toSingle()
|
val newManga =
|
||||||
.await()
|
sourceManager.getOrStub(result.source).fetchMangaDetails(result).toSingle()
|
||||||
result.copyFrom(newManga)
|
.await()
|
||||||
|
result.copyFrom(newManga)
|
||||||
|
|
||||||
db.insertManga(result).executeAsBlocking()
|
db.insertManga(result).executeAsBlocking()
|
||||||
} catch (e: CancellationException) {
|
} catch (e: CancellationException) {
|
||||||
// Ignore cancellations
|
// Ignore cancellations
|
||||||
throw e
|
throw e
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
migratingManga.manga.migrationStatus = MigrationStatus.MANGA_FOUND
|
||||||
|
migratingManga.manga.searchResult.set(result.id)
|
||||||
|
adapter?.notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
migratingManga.manga.migrationStatus = MigrationStatus.MANGA_NOT_FOUND
|
||||||
|
activity?.toast(R.string.error_fetching_migration, Toast.LENGTH_LONG)
|
||||||
|
adapter?.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
migratingManga.manga.searchResult.set(result.id)
|
|
||||||
adapter?.notifyDataSetChanged()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +45,10 @@ class MigrationProcessAdapter(
|
|||||||
if (allMangasDone()) menuItemListener.enableButtons()
|
if (allMangasDone()) menuItemListener.enableButtons()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allMangasDone() = (items.all { it.manga.searchResult.initialized || !it.manga.migrationJob
|
fun allMangasDone() = (items.all { it.manga.migrationStatus != MigrationStatus
|
||||||
.isActive } && items.any { it.manga
|
.RUNNUNG } && items.any { it.manga.migrationStatus == MigrationStatus.MANGA_FOUND })
|
||||||
.searchResult.content != null })
|
|
||||||
|
|
||||||
fun mangasSkipped() = (items.count { (!it.manga.searchResult.initialized || it.manga
|
fun mangasSkipped() = (items.count { it.manga.migrationStatus == MigrationStatus.MANGA_NOT_FOUND })
|
||||||
.searchResult.content == null) })
|
|
||||||
|
|
||||||
suspend fun performMigrations(copy: Boolean) {
|
suspend fun performMigrations(copy: Boolean) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
@ -87,7 +87,8 @@ class MigrationProcessHolder(
|
|||||||
sourceManager.get(it)
|
sourceManager.get(it)
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (item.manga.mangaId != this@MigrationProcessHolder.item?.manga?.mangaId) {
|
if (item.manga.mangaId != this@MigrationProcessHolder.item?.manga?.mangaId ||
|
||||||
|
item.manga.migrationStatus == MigrationStatus.RUNNUNG) {
|
||||||
return@withContext
|
return@withContext
|
||||||
}
|
}
|
||||||
if (searchResult != null && resultSource != null) {
|
if (searchResult != null && resultSource != null) {
|
||||||
@ -101,7 +102,8 @@ class MigrationProcessHolder(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
migration_manga_card_to.loading_group.gone()
|
migration_manga_card_to.loading_group.gone()
|
||||||
migration_manga_card_to.title.text = "No Alternatives Found"
|
migration_manga_card_to.title.text = view.context.applicationContext
|
||||||
|
.getString(R.string.no_alternatives_found)
|
||||||
}
|
}
|
||||||
migration_menu.visible()
|
migration_menu.visible()
|
||||||
skip_manga.gone()
|
skip_manga.gone()
|
||||||
@ -111,10 +113,6 @@ class MigrationProcessHolder(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showSpinner() {
|
|
||||||
migration_manga_card_to.loading_group.visible()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun View.resetManga() {
|
private fun View.resetManga() {
|
||||||
loading_group.visible()
|
loading_group.visible()
|
||||||
thumbnail.setImageDrawable(null)
|
thumbnail.setImageDrawable(null)
|
||||||
|
@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.R
|
|||||||
class MigrationProcessItem(val manga: MigratingManga) :
|
class MigrationProcessItem(val manga: MigratingManga) :
|
||||||
AbstractFlexibleItem<MigrationProcessHolder>() {
|
AbstractFlexibleItem<MigrationProcessHolder>() {
|
||||||
|
|
||||||
var holder:MigrationProcessHolder? = null
|
|
||||||
override fun getLayoutRes(): Int {
|
override fun getLayoutRes(): Int {
|
||||||
return R.layout.migration_process_item
|
return R.layout.migration_process_item
|
||||||
}
|
}
|
||||||
@ -23,8 +22,6 @@ class MigrationProcessItem(val manga: MigratingManga) :
|
|||||||
holder: MigrationProcessHolder,
|
holder: MigrationProcessHolder,
|
||||||
position: Int,
|
position: Int,
|
||||||
payloads: MutableList<Any?>?) {
|
payloads: MutableList<Any?>?) {
|
||||||
|
|
||||||
this.holder = holder
|
|
||||||
holder.bind(this)
|
holder.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,10 +33,6 @@ class MigrationProcessItem(val manga: MigratingManga) :
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showSpinner() {
|
|
||||||
holder?.showSpinner()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
return manga.mangaId.toInt()
|
return manga.mangaId.toInt()
|
||||||
}
|
}
|
||||||
|
@ -426,6 +426,9 @@
|
|||||||
<string name="confirm_copy">Copy %1$d%2$s mangas?</string>
|
<string name="confirm_copy">Copy %1$d%2$s mangas?</string>
|
||||||
<string name="skipping_x">(skipping %1$d)</string>
|
<string name="skipping_x">(skipping %1$d)</string>
|
||||||
<string name="no_migrations">No manga migrated</string>
|
<string name="no_migrations">No manga migrated</string>
|
||||||
|
<string name="error_fetching_migration">No chapters found, this manga cannot be used for
|
||||||
|
migration</string>
|
||||||
|
<string name="no_alternatives_found">No Alternatives Found</string>
|
||||||
|
|
||||||
<!-- Tracking Screen -->
|
<!-- Tracking Screen -->
|
||||||
<string name="manga_tracking_tab">Tracking</string>
|
<string name="manga_tracking_tab">Tracking</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user