瀏覽代碼

Reorganize some migration classes

arkon 4 年之前
父節點
當前提交
3c4bc17065

+ 17 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationController.kt

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

+ 11 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationPresenter.kt

@@ -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> {

+ 2 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/ViewState.kt

@@ -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,

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MangaAdapter.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaAdapter.kt

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

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MangaHolder.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaHolder.kt

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

+ 5 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MangaItem.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaItem.kt

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

+ 16 - 5
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/SearchController.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt

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

+ 14 - 4
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/SearchPresenter.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchPresenter.kt

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

+ 5 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/SelectionHeader.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SelectionHeader.kt

@@ -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
+        )
     }
 
     /**

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/SourceAdapter.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SourceAdapter.kt

@@ -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
 
 /**

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/SourceHolder.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SourceHolder.kt

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

+ 5 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/SourceItem.kt → app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/sources/SourceItem.kt

@@ -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
+        )
     }
 
     /**

+ 5 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt

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