More refactoring + more bug fixes

Such as when a manga picked has 0 chapters
This commit is contained in:
Jay 2020-01-04 22:19:47 -08:00
parent 142dc1c12a
commit 332e8c9487
6 changed files with 51 additions and 33 deletions

View File

@ -21,6 +21,8 @@ class MigratingManga(private val db: DatabaseHelper,
val migrationJob = parentContext + SupervisorJob() + Dispatchers.Default
var migrationStatus:Int = MigrationStatus.RUNNUNG
@Volatile
private var manga: Manga? = null
suspend fun manga(): Manga? {
@ -36,4 +38,12 @@ class MigratingManga(private val db: DatabaseHelper,
// Create the model object.
return MigrationProcessItem(this)
}
}
class MigrationStatus {
companion object {
val RUNNUNG = 0
val MANGA_FOUND = 1
val MANGA_NOT_FOUND = 2
}
}

View File

@ -9,6 +9,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.graphics.ColorUtils
import androidx.recyclerview.widget.LinearLayoutManager
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)
}
}
@ -281,34 +285,46 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle),
fun useMangaForMigration(manga: Manga, source: Source) {
val firstIndex = selectedPosition ?: return
val migratingManga = adapter?.getItem(firstIndex) ?: return
migratingManga.showSpinner()
migratingManga.manga.migrationStatus = MigrationStatus.RUNNUNG
adapter?.notifyItemChanged(firstIndex)
launchUI {
val result = CoroutineScope(migratingManga.manga.migrationJob).async {
val localManga = smartSearchEngine.networkToLocalManga(manga, source.id)
val chapters = source.fetchChapterList(localManga).toSingle().await(
Schedulers.io()
)
withContext(Dispatchers.IO) {
try {
syncChaptersWithSource(db, chapters, localManga, source)
}
catch (e: Exception) {
return@async null
}
localManga
}.await()
try {
val newManga =
sourceManager.getOrStub(result.source).fetchMangaDetails(result).toSingle()
.await()
result.copyFrom(newManga)
if (result != null) {
try {
val newManga =
sourceManager.getOrStub(result.source).fetchMangaDetails(result).toSingle()
.await()
result.copyFrom(newManga)
db.insertManga(result).executeAsBlocking()
} catch (e: CancellationException) {
// Ignore cancellations
throw e
} catch (e: Exception) {
db.insertManga(result).executeAsBlocking()
} catch (e: CancellationException) {
// Ignore cancellations
throw e
} 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()
}
}

View File

@ -45,12 +45,10 @@ class MigrationProcessAdapter(
if (allMangasDone()) menuItemListener.enableButtons()
}
fun allMangasDone() = (items.all { it.manga.searchResult.initialized || !it.manga.migrationJob
.isActive } && items.any { it.manga
.searchResult.content != null })
fun allMangasDone() = (items.all { it.manga.migrationStatus != MigrationStatus
.RUNNUNG } && items.any { it.manga.migrationStatus == MigrationStatus.MANGA_FOUND })
fun mangasSkipped() = (items.count { (!it.manga.searchResult.initialized || it.manga
.searchResult.content == null) })
fun mangasSkipped() = (items.count { it.manga.migrationStatus == MigrationStatus.MANGA_NOT_FOUND })
suspend fun performMigrations(copy: Boolean) {
withContext(Dispatchers.IO) {

View File

@ -87,7 +87,8 @@ class MigrationProcessHolder(
sourceManager.get(it)
}
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
}
if (searchResult != null && resultSource != null) {
@ -101,7 +102,8 @@ class MigrationProcessHolder(
}
} else {
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()
skip_manga.gone()
@ -111,10 +113,6 @@ class MigrationProcessHolder(
}
}
fun showSpinner() {
migration_manga_card_to.loading_group.visible()
}
private fun View.resetManga() {
loading_group.visible()
thumbnail.setImageDrawable(null)

View File

@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.R
class MigrationProcessItem(val manga: MigratingManga) :
AbstractFlexibleItem<MigrationProcessHolder>() {
var holder:MigrationProcessHolder? = null
override fun getLayoutRes(): Int {
return R.layout.migration_process_item
}
@ -23,8 +22,6 @@ class MigrationProcessItem(val manga: MigratingManga) :
holder: MigrationProcessHolder,
position: Int,
payloads: MutableList<Any?>?) {
this.holder = holder
holder.bind(this)
}
@ -36,10 +33,6 @@ class MigrationProcessItem(val manga: MigratingManga) :
return false
}
fun showSpinner() {
holder?.showSpinner()
}
override fun hashCode(): Int {
return manga.mangaId.toInt()
}

View File

@ -426,6 +426,9 @@
<string name="confirm_copy">Copy %1$d%2$s mangas?</string>
<string name="skipping_x">(skipping %1$d)</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 -->
<string name="manga_tracking_tab">Tracking</string>