Fixed crash when rapidly trying to skip manga

This commit is contained in:
Jay 2020-01-05 16:23:37 -08:00
parent e342d4960c
commit 14c80436fc
2 changed files with 14 additions and 7 deletions

View file

@ -17,6 +17,7 @@ import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Manga 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.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.smartsearch.SmartSearchEngine import eu.kanade.tachiyomi.smartsearch.SmartSearchEngine
@ -254,11 +255,16 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle),
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
} }
override fun removeManga(position: Int) { override fun removeManga(item: MigrationProcessItem) {
val ids = config?.mangaIds?.toMutableList() ?: return val ids = config?.mangaIds?.toMutableList() ?: return
ids.removeAt(position) val index = ids.indexOf(item.manga.mangaId)
migratingManga?.removeAt(position) if (index > -1) {
ids.removeAt(index)
config.mangaIds = ids config.mangaIds = ids
val index2 = migratingManga?.indexOf(item.manga) ?: return
if (index2 > -1)
migratingManga?.removeAt(index2)
}
} }
override fun noMigration() { override fun noMigration() {

View file

@ -36,7 +36,7 @@ class MigrationProcessAdapter(
interface MigrationProcessInterface { interface MigrationProcessInterface {
fun onMenuItemClick(position: Int, item: MenuItem) fun onMenuItemClick(position: Int, item: MenuItem)
fun enableButtons() fun enableButtons()
fun removeManga(position: Int) fun removeManga(item: MigrationProcessItem)
fun noMigration() fun noMigration()
} }
@ -84,8 +84,9 @@ class MigrationProcessAdapter(
} }
fun removeManga(position: Int) { fun removeManga(position: Int) {
menuItemListener.removeManga(position) val item = getItem(position) ?: return
getItem(position)?.manga?.migrationJob?.cancel() menuItemListener.removeManga(item)
item?.manga?.migrationJob?.cancel()
removeItem(position) removeItem(position)
items = currentItems items = currentItems
sourceFinished() sourceFinished()