mirror of
https://github.com/mihonapp/mihon.git
synced 2025-06-27 03:27:51 +02:00
Speed up migration cancellation
Allow migrating an entire source of manga
This commit is contained in:
@ -10,16 +10,27 @@ import com.afollestad.materialdialogs.MaterialDialog
|
|||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.R
|
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.Manga
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag
|
import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
|
import exh.ui.migration.manga.design.MigrationDesignController
|
||||||
|
import exh.util.await
|
||||||
import kotlinx.android.synthetic.main.migration_controller.*
|
import kotlinx.android.synthetic.main.migration_controller.*
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import rx.schedulers.Schedulers
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
class MigrationController : NucleusController<MigrationPresenter>(),
|
class MigrationController : NucleusController<MigrationPresenter>(),
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
SourceAdapter.OnSelectClickListener {
|
SourceAdapter.OnSelectClickListener,
|
||||||
|
SourceAdapter.OnAutoClickListener {
|
||||||
|
|
||||||
private var adapter: FlexibleAdapter<IFlexible<*>>? = null
|
private var adapter: FlexibleAdapter<IFlexible<*>>? = null
|
||||||
|
|
||||||
@ -109,6 +120,18 @@ class MigrationController : NucleusController<MigrationPresenter>(),
|
|||||||
onItemClick(null, position)
|
onItemClick(null, position)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onAutoClick(position: Int) {
|
||||||
|
val item = adapter?.getItem(position) as? SourceItem ?: return
|
||||||
|
|
||||||
|
GlobalScope.launch {
|
||||||
|
val manga = Injekt.get<DatabaseHelper>().getFavoriteMangas().asRxSingle().await(Schedulers.io())
|
||||||
|
val sourceMangas = manga.asSequence().filter { it.source == item.source.id }.map { it.id!! }.toList()
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
router.pushController(MigrationDesignController.create(sourceMangas).withFadeTransaction())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun migrateManga(prevManga: Manga, manga: Manga) {
|
fun migrateManga(prevManga: Manga, manga: Manga) {
|
||||||
presenter.migrateManga(prevManga, manga, replace = true)
|
presenter.migrateManga(prevManga, manga, replace = true)
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,20 @@ class SourceAdapter(val controller: MigrationController) :
|
|||||||
setDisplayHeadersAtStartUp(true)
|
setDisplayHeadersAtStartUp(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EXH -->
|
||||||
|
/**
|
||||||
|
* Listener for auto item clicks.
|
||||||
|
*/
|
||||||
|
val autoClickListener: OnAutoClickListener? = controller
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener which should be called when user clicks select.
|
||||||
|
*/
|
||||||
|
interface OnAutoClickListener {
|
||||||
|
fun onAutoClick(position: Int)
|
||||||
|
}
|
||||||
|
// EXH <--
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for browse item clicks.
|
* Listener for browse item clicks.
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,10 @@ class SourceHolder(view: View, override val adapter: SourceAdapter) :
|
|||||||
get() = card
|
get() = card
|
||||||
|
|
||||||
init {
|
init {
|
||||||
source_latest.gone()
|
source_latest.text = "Auto"
|
||||||
|
source_latest.setOnClickListener {
|
||||||
|
adapter.autoClickListener?.onAutoClick(adapterPosition)
|
||||||
|
}
|
||||||
source_browse.setText(R.string.select)
|
source_browse.setText(R.string.select)
|
||||||
source_browse.setOnClickListener {
|
source_browse.setOnClickListener {
|
||||||
adapter.selectClickListener?.onSelectClick(adapterPosition)
|
adapter.selectClickListener?.onSelectClick(adapterPosition)
|
||||||
|
@ -93,6 +93,7 @@ class MigrationProcedureController(bundle: Bundle? = null) : BaseExhController(b
|
|||||||
applicationContext?.toast("All migrations complete!")
|
applicationContext?.toast("All migrations complete!")
|
||||||
router.popCurrentController()
|
router.popCurrentController()
|
||||||
} else {
|
} else {
|
||||||
|
adapter.migratingManga[pager.currentItem].migrationJob.cancel()
|
||||||
pager.setCurrentItem(pager.currentItem + 1, true)
|
pager.setCurrentItem(pager.currentItem + 1, true)
|
||||||
launch(Dispatchers.Main) {
|
launch(Dispatchers.Main) {
|
||||||
updateTitle()
|
updateTitle()
|
||||||
@ -155,6 +156,9 @@ class MigrationProcedureController(bundle: Bundle? = null) : BaseExhController(b
|
|||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
} catch(e: CancellationException) {
|
||||||
|
// Ignore cancellations
|
||||||
|
throw e
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
logger.e("Failed to search in source: ${source.id}!", e)
|
logger.e("Failed to search in source: ${source.id}!", e)
|
||||||
null
|
null
|
||||||
@ -179,6 +183,9 @@ class MigrationProcedureController(bundle: Bundle? = null) : BaseExhController(b
|
|||||||
}
|
}
|
||||||
localManga
|
localManga
|
||||||
} else null
|
} else null
|
||||||
|
} catch(e: CancellationException) {
|
||||||
|
// Ignore cancellations
|
||||||
|
throw e
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
logger.e("Failed to search in source: ${source.id}!", e)
|
logger.e("Failed to search in source: ${source.id}!", e)
|
||||||
null
|
null
|
||||||
@ -206,6 +213,9 @@ class MigrationProcedureController(bundle: Bundle? = null) : BaseExhController(b
|
|||||||
result.copyFrom(newManga)
|
result.copyFrom(newManga)
|
||||||
|
|
||||||
db.insertManga(result).await()
|
db.insertManga(result).await()
|
||||||
|
} catch(e: CancellationException) {
|
||||||
|
// Ignore cancellations
|
||||||
|
throw e
|
||||||
} catch(e: Exception) {
|
} catch(e: Exception) {
|
||||||
logger.e("Could not load search manga details", e)
|
logger.e("Could not load search manga details", e)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user