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.ui.base.controller.NucleusController
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
class MigrationController :
@ -64,7 +69,10 @@ class MigrationController :
if (state.selectedSource == null) {
title = resources?.getString(R.string.label_migration)
if (adapter !is SourceAdapter) {
adapter = SourceAdapter(this)
adapter =
SourceAdapter(
this
)
binding.recycler.adapter = adapter
adapter?.fastScroller = binding.fastScroller
}
@ -72,7 +80,10 @@ class MigrationController :
} else {
title = state.selectedSource.toString()
if (adapter !is MangaAdapter) {
adapter = MangaAdapter(this)
adapter =
MangaAdapter(
this
)
binding.recycler.adapter = adapter
adapter?.fastScroller = binding.fastScroller
}
@ -84,7 +95,10 @@ class MigrationController :
val item = adapter?.getItem(position) ?: return false
if (item is MangaItem) {
val controller = SearchController(item.manga)
val controller =
SearchController(
item.manga
)
controller.targetController = this
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.SourceManager
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 rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
@ -58,11 +61,17 @@ class MigrationPresenter(
}
private fun findSourcesWithManga(library: List<Manga>): List<SourceItem> {
val header = SelectionHeader()
val header =
SelectionHeader()
return library.map { it.source }.toSet()
.mapNotNull { if (it != LocalSource.ID) sourceManager.getOrStub(it) else null }
.sortedBy { it.name }
.map { SourceItem(it, header) }
.map {
SourceItem(
it,
header
)
}
}
private fun libraryToMigrationItem(library: List<Manga>, sourceId: Long): List<MangaItem> {

View file

@ -1,6 +1,8 @@
package eu.kanade.tachiyomi.ui.browse.migration
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(
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.items.IFlexible
import eu.kanade.tachiyomi.ui.browse.migration.MigrationController
class MangaAdapter(controller: MigrationController) :
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 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 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 {
return MangaHolder(view, adapter)
return MangaHolder(
view,
adapter
)
}
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.os.Bundle
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
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.GlobalSearchPresenter
import eu.kanade.tachiyomi.util.view.gone
@ -21,7 +22,10 @@ class SearchController(
private var newManga: Manga? = null
override fun createPresenter(): GlobalSearchPresenter {
return SearchPresenter(initialQuery, manga!!)
return SearchPresenter(
initialQuery,
manga!!
)
}
override fun onSaveInstanceState(outState: Bundle) {
@ -52,7 +56,8 @@ class SearchController(
override fun onMangaClick(manga: Manga) {
newManga = manga
val dialog = MigrationDialog()
val dialog =
MigrationDialog()
dialog.targetController = this
dialog.showDialog(router)
}
@ -78,7 +83,10 @@ class SearchController(
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val prefValue = preferences.migrateFlags().get()
val preselected = MigrationFlags.getEnabledFlagsPositions(prefValue)
val preselected =
MigrationFlags.getEnabledFlagsPositions(
prefValue
)
return MaterialDialog(activity!!)
.message(R.string.migration_dialog_what_to_include)
@ -87,7 +95,10 @@ class SearchController(
initialSelection = preselected.toIntArray()
) { _, positions, _ ->
// Save current settings for the next time
val newValue = MigrationFlags.getFlagsFromPositions(positions.toTypedArray())
val newValue =
MigrationFlags.getFlagsFromPositions(
positions.toTypedArray()
)
preferences.migrateFlags().set(newValue)
}
.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 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.model.SChapter
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.GlobalSearchItem
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
@ -70,9 +71,18 @@ class SearchPresenter(
replace: Boolean
) {
val flags = preferences.migrateFlags().get()
val migrateChapters = MigrationFlags.hasChapters(flags)
val migrateCategories = MigrationFlags.hasCategories(flags)
val migrateTracks = MigrationFlags.hasTracks(flags)
val migrateChapters =
MigrationFlags.hasChapters(
flags
)
val migrateCategories =
MigrationFlags.hasCategories(
flags
)
val migrateTracks =
MigrationFlags.hasTracks(
flags
)
db.inTransaction {
// 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 androidx.recyclerview.widget.RecyclerView
@ -25,7 +25,10 @@ class SelectionHeader : AbstractHeaderItem<SelectionHeader.Holder>() {
* Creates a new view holder for this item.
*/
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.items.IFlexible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.browse.migration.MigrationController
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 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 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.
*/
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.ui.base.controller.NucleusController
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.globalsearch.GlobalSearchController
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.
*/
private fun migrateManga() {
val controller = SearchController(presenter.manga)
val controller =
SearchController(
presenter.manga
)
controller.targetController = this
parentController!!.router.pushController(controller.withFadeTransaction())
}