mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-30 22:07:57 +01:00 
			
		
		
		
	More refactoring + more bug fixes
Such as when a manga picked has 0 chapters (cherry picked from commit 332e8c9487b2e5e39a3a90705b2def80183bcc04)
This commit is contained in:
		| @@ -23,6 +23,8 @@ class MigratingManga( | ||||
|  | ||||
|     val migrationJob = parentContext + SupervisorJob() + Dispatchers.Default | ||||
|  | ||||
|     var migrationStatus: Int = MigrationStatus.RUNNUNG | ||||
|  | ||||
|     @Volatile | ||||
|     private var manga: Manga? = null | ||||
|     suspend fun manga(): Manga? { | ||||
| @@ -39,3 +41,11 @@ class MigratingManga( | ||||
|         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.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,44 @@ 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() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -12,7 +12,6 @@ import eu.kanade.tachiyomi.ui.migration.MigrationFlags | ||||
| import eu.kanade.tachiyomi.util.lang.launchUI | ||||
| import kotlinx.coroutines.Dispatchers | ||||
| import kotlinx.coroutines.cancel | ||||
| import kotlinx.coroutines.isActive | ||||
| import kotlinx.coroutines.withContext | ||||
| import uy.kohesive.injekt.injectLazy | ||||
|  | ||||
| @@ -44,12 +43,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) { | ||||
|   | ||||
| @@ -86,7 +86,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) { | ||||
| @@ -100,7 +101,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() | ||||
| @@ -110,10 +112,6 @@ class MigrationProcessHolder( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fun showSpinner() { | ||||
|         migration_manga_card_to.loading_group.visible() | ||||
|     } | ||||
|  | ||||
|     private fun View.resetManga() { | ||||
|         loading_group.visible() | ||||
|         thumbnail.setImageDrawable(null) | ||||
|   | ||||
| @@ -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 | ||||
|     } | ||||
| @@ -25,8 +24,6 @@ class MigrationProcessItem(val manga: MigratingManga) : | ||||
|         position: Int, | ||||
|         payloads: MutableList<Any?>? | ||||
|     ) { | ||||
|  | ||||
|         this.holder = holder | ||||
|         holder.bind(this) | ||||
|     } | ||||
|  | ||||
| @@ -38,10 +35,6 @@ class MigrationProcessItem(val manga: MigratingManga) : | ||||
|         return false | ||||
|     } | ||||
|  | ||||
|     fun showSpinner() { | ||||
|         holder?.showSpinner() | ||||
|     } | ||||
|  | ||||
|     override fun hashCode(): Int { | ||||
|         return manga.mangaId.toInt() | ||||
|     } | ||||
|   | ||||
| @@ -492,6 +492,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> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user