Reorganize some migration classes

This commit is contained in:
arkon 2020-05-23 19:33:47 -04:00
parent 333d1c1ad9
commit 3c4bc17065
13 changed files with 86 additions and 26 deletions

View File

@ -10,6 +10,11 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.MigrationControllerBinding import eu.kanade.tachiyomi.databinding.MigrationControllerBinding
import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.browse.migration.manga.MangaAdapter
import eu.kanade.tachiyomi.ui.browse.migration.manga.MangaItem
import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController
import eu.kanade.tachiyomi.ui.browse.migration.sources.SourceAdapter
import eu.kanade.tachiyomi.ui.browse.migration.sources.SourceItem
import eu.kanade.tachiyomi.ui.browse.source.SourceDividerItemDecoration import eu.kanade.tachiyomi.ui.browse.source.SourceDividerItemDecoration
class MigrationController : class MigrationController :
@ -64,7 +69,10 @@ class MigrationController :
if (state.selectedSource == null) { if (state.selectedSource == null) {
title = resources?.getString(R.string.label_migration) title = resources?.getString(R.string.label_migration)
if (adapter !is SourceAdapter) { if (adapter !is SourceAdapter) {
adapter = SourceAdapter(this) adapter =
SourceAdapter(
this
)
binding.recycler.adapter = adapter binding.recycler.adapter = adapter
adapter?.fastScroller = binding.fastScroller adapter?.fastScroller = binding.fastScroller
} }
@ -72,7 +80,10 @@ class MigrationController :
} else { } else {
title = state.selectedSource.toString() title = state.selectedSource.toString()
if (adapter !is MangaAdapter) { if (adapter !is MangaAdapter) {
adapter = MangaAdapter(this) adapter =
MangaAdapter(
this
)
binding.recycler.adapter = adapter binding.recycler.adapter = adapter
adapter?.fastScroller = binding.fastScroller adapter?.fastScroller = binding.fastScroller
} }
@ -84,7 +95,10 @@ class MigrationController :
val item = adapter?.getItem(position) ?: return false val item = adapter?.getItem(position) ?: return false
if (item is MangaItem) { if (item is MangaItem) {
val controller = SearchController(item.manga) val controller =
SearchController(
item.manga
)
controller.targetController = this controller.targetController = this
parentController!!.router.pushController(controller.withFadeTransaction()) parentController!!.router.pushController(controller.withFadeTransaction())

View File

@ -8,6 +8,9 @@ import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.ui.browse.migration.manga.MangaItem
import eu.kanade.tachiyomi.ui.browse.migration.sources.SelectionHeader
import eu.kanade.tachiyomi.ui.browse.migration.sources.SourceItem
import eu.kanade.tachiyomi.util.lang.combineLatest import eu.kanade.tachiyomi.util.lang.combineLatest
import rx.android.schedulers.AndroidSchedulers import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers import rx.schedulers.Schedulers
@ -58,11 +61,17 @@ class MigrationPresenter(
} }
private fun findSourcesWithManga(library: List<Manga>): List<SourceItem> { private fun findSourcesWithManga(library: List<Manga>): List<SourceItem> {
val header = SelectionHeader() val header =
SelectionHeader()
return library.map { it.source }.toSet() return library.map { it.source }.toSet()
.mapNotNull { if (it != LocalSource.ID) sourceManager.getOrStub(it) else null } .mapNotNull { if (it != LocalSource.ID) sourceManager.getOrStub(it) else null }
.sortedBy { it.name } .sortedBy { it.name }
.map { SourceItem(it, header) } .map {
SourceItem(
it,
header
)
}
} }
private fun libraryToMigrationItem(library: List<Manga>, sourceId: Long): List<MangaItem> { private fun libraryToMigrationItem(library: List<Manga>, sourceId: Long): List<MangaItem> {

View File

@ -1,6 +1,8 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.ui.browse.migration.manga.MangaItem
import eu.kanade.tachiyomi.ui.browse.migration.sources.SourceItem
data class ViewState( data class ViewState(
val selectedSource: Source? = null, val selectedSource: Source? = null,

View File

@ -1,7 +1,8 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.manga
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.ui.browse.migration.MigrationController
class MangaAdapter(controller: MigrationController) : class MangaAdapter(controller: MigrationController) :
FlexibleAdapter<IFlexible<*>>(null, controller) { FlexibleAdapter<IFlexible<*>>(null, controller) {

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.manga
import android.view.View import android.view.View
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.manga
import android.view.View import android.view.View
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -15,7 +15,10 @@ class MangaItem(val manga: Manga) : AbstractFlexibleItem<MangaHolder>() {
} }
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): MangaHolder { override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): MangaHolder {
return MangaHolder(view, adapter) return MangaHolder(
view,
adapter
)
} }
override fun bindViewHolder( override fun bindViewHolder(

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.search
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.gone
@ -21,7 +22,10 @@ class SearchController(
private var newManga: Manga? = null private var newManga: Manga? = null
override fun createPresenter(): GlobalSearchPresenter { override fun createPresenter(): GlobalSearchPresenter {
return SearchPresenter(initialQuery, manga!!) return SearchPresenter(
initialQuery,
manga!!
)
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
@ -52,7 +56,8 @@ class SearchController(
override fun onMangaClick(manga: Manga) { override fun onMangaClick(manga: Manga) {
newManga = manga newManga = manga
val dialog = MigrationDialog() val dialog =
MigrationDialog()
dialog.targetController = this dialog.targetController = this
dialog.showDialog(router) dialog.showDialog(router)
} }
@ -78,7 +83,10 @@ class SearchController(
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val prefValue = preferences.migrateFlags().get() val prefValue = preferences.migrateFlags().get()
val preselected = MigrationFlags.getEnabledFlagsPositions(prefValue) val preselected =
MigrationFlags.getEnabledFlagsPositions(
prefValue
)
return MaterialDialog(activity!!) return MaterialDialog(activity!!)
.message(R.string.migration_dialog_what_to_include) .message(R.string.migration_dialog_what_to_include)
@ -87,7 +95,10 @@ class SearchController(
initialSelection = preselected.toIntArray() initialSelection = preselected.toIntArray()
) { _, positions, _ -> ) { _, positions, _ ->
// Save current settings for the next time // Save current settings for the next time
val newValue = MigrationFlags.getFlagsFromPositions(positions.toTypedArray()) val newValue =
MigrationFlags.getFlagsFromPositions(
positions.toTypedArray()
)
preferences.migrateFlags().set(newValue) preferences.migrateFlags().set(newValue)
} }
.positiveButton(R.string.migrate) { .positiveButton(R.string.migrate) {

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.search
import android.os.Bundle import android.os.Bundle
import com.jakewharton.rxrelay.BehaviorRelay import com.jakewharton.rxrelay.BehaviorRelay
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchCardItem import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchCardItem
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchItem import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchItem
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
@ -70,9 +71,18 @@ class SearchPresenter(
replace: Boolean replace: Boolean
) { ) {
val flags = preferences.migrateFlags().get() val flags = preferences.migrateFlags().get()
val migrateChapters = MigrationFlags.hasChapters(flags) val migrateChapters =
val migrateCategories = MigrationFlags.hasCategories(flags) MigrationFlags.hasChapters(
val migrateTracks = MigrationFlags.hasTracks(flags) flags
)
val migrateCategories =
MigrationFlags.hasCategories(
flags
)
val migrateTracks =
MigrationFlags.hasTracks(
flags
)
db.inTransaction { db.inTransaction {
// Update chapters read // Update chapters read

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.sources
import android.view.View import android.view.View
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -25,7 +25,10 @@ class SelectionHeader : AbstractHeaderItem<SelectionHeader.Holder>() {
* Creates a new view holder for this item. * Creates a new view holder for this item.
*/ */
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): Holder { override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): Holder {
return Holder(view, adapter) return Holder(
view,
adapter
)
} }
/** /**

View File

@ -1,8 +1,9 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.sources
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.ui.browse.migration.MigrationController
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
/** /**

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.sources
import android.view.View import android.view.View
import eu.kanade.tachiyomi.source.icon import eu.kanade.tachiyomi.source.icon

View File

@ -1,4 +1,4 @@
package eu.kanade.tachiyomi.ui.browse.migration package eu.kanade.tachiyomi.ui.browse.migration.sources
import android.view.View import android.view.View
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -28,7 +28,10 @@ data class SourceItem(val source: Source, val header: SelectionHeader? = null) :
* Creates a new view holder for this item. * Creates a new view holder for this item.
*/ */
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): SourceHolder { override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): SourceHolder {
return SourceHolder(view, adapter as SourceAdapter) return SourceHolder(
view,
adapter as SourceAdapter
)
} }
/** /**

View File

@ -24,7 +24,7 @@ import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.NucleusController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.browse.migration.SearchController import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
@ -554,7 +554,10 @@ class MangaInfoController(private val fromSource: Boolean = false) :
* Initiates source migration for the specific manga. * Initiates source migration for the specific manga.
*/ */
private fun migrateManga() { private fun migrateManga() {
val controller = SearchController(presenter.manga) val controller =
SearchController(
presenter.manga
)
controller.targetController = this controller.targetController = this
parentController!!.router.pushController(controller.withFadeTransaction()) parentController!!.router.pushController(controller.withFadeTransaction())
} }