From 14c80436fcb92d22f0691b7b68caf524fd09cab5 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 5 Jan 2020 16:23:37 -0800 Subject: [PATCH] Fixed crash when rapidly trying to skip manga --- .../manga/process/MigrationListController.kt | 14 ++++++++++---- .../manga/process/MigrationProcessAdapter.kt | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index 8a8671e00d..19520d15dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -17,6 +17,7 @@ import com.afollestad.materialdialogs.MaterialDialog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Manga +import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.smartsearch.SmartSearchEngine @@ -254,11 +255,16 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), activity?.invalidateOptionsMenu() } - override fun removeManga(position: Int) { + override fun removeManga(item: MigrationProcessItem) { val ids = config?.mangaIds?.toMutableList() ?: return - ids.removeAt(position) - migratingManga?.removeAt(position) - config.mangaIds = ids + val index = ids.indexOf(item.manga.mangaId) + if (index > -1) { + ids.removeAt(index) + config.mangaIds = ids + val index2 = migratingManga?.indexOf(item.manga) ?: return + if (index2 > -1) + migratingManga?.removeAt(index2) + } } override fun noMigration() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt index 822a747520..d70f91e687 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationProcessAdapter.kt @@ -36,7 +36,7 @@ class MigrationProcessAdapter( interface MigrationProcessInterface { fun onMenuItemClick(position: Int, item: MenuItem) fun enableButtons() - fun removeManga(position: Int) + fun removeManga(item: MigrationProcessItem) fun noMigration() } @@ -84,8 +84,9 @@ class MigrationProcessAdapter( } fun removeManga(position: Int) { - menuItemListener.removeManga(position) - getItem(position)?.manga?.migrationJob?.cancel() + val item = getItem(position) ?: return + menuItemListener.removeManga(item) + item?.manga?.migrationJob?.cancel() removeItem(position) items = currentItems sourceFinished()