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.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)
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() {

View File

@ -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()