From 142dc1c12a95534170517deb077c98896214a2d9 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 4 Jan 2020 18:52:06 -0800 Subject: [PATCH] Refactoring + fixes for auto-migrate --- .../tachiyomi/ui/library/LibraryController.kt | 4 +-- .../ui/migration/MigrationController.kt | 4 +-- .../manga/design/MigrationSourceAdapter.kt | 4 +-- ...ontroller.kt => PreMigrationController.kt} | 35 +++++++++++-------- ...oller.xml => pre_migration_controller.xml} | 0 5 files changed, 26 insertions(+), 21 deletions(-) rename app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/{MigrationDesignController.kt => PreMigrationController.kt} (82%) rename app/src/main/res/layout/{migration_design_controller.xml => pre_migration_controller.xml} (100%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 9154989115..b6e90c5b60 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -44,7 +44,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.migration.MigrationController import eu.kanade.tachiyomi.ui.migration.MigrationInterface -import eu.kanade.tachiyomi.ui.migration.manga.design.MigrationDesignController +import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig import eu.kanade.tachiyomi.util.doOnApplyWindowInsets @@ -478,7 +478,7 @@ class LibraryController( ) } else { - MigrationDesignController.create( selectedMangas.mapNotNull { it.id } ) + PreMigrationController.create( selectedMangas.mapNotNull { it.id } ) } .withFadeTransaction()) destroyActionModeIfNeeded() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt index 7b047bc50e..ab525375eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/MigrationController.kt @@ -17,7 +17,7 @@ import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction -import eu.kanade.tachiyomi.ui.migration.manga.design.MigrationDesignController +import eu.kanade.tachiyomi.ui.migration.manga.design.PreMigrationController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.util.RecyclerWindowInsetsListener import eu.kanade.tachiyomi.util.await @@ -147,7 +147,7 @@ class MigrationController : NucleusController(), MigrationProcedureConfig( sourceMangas, null) ) } - else { MigrationDesignController.create(sourceMangas) } + else { PreMigrationController.create(sourceMangas) } .withFadeTransaction()) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceAdapter.kt index 12807fe1d0..f35b3a5db3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationSourceAdapter.kt @@ -6,10 +6,10 @@ import eu.kanade.tachiyomi.source.SourceManager import uy.kohesive.injekt.injectLazy class MigrationSourceAdapter(var items: List, - val controller: MigrationDesignController + val controllerPre: PreMigrationController ): FlexibleAdapter( items, - controller, + controllerPre, true ) { override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationDesignController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt similarity index 82% rename from app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationDesignController.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt index 0e1d6707ce..aa05d4d437 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/MigrationDesignController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt @@ -7,6 +7,7 @@ import android.view.ViewGroup import android.widget.FrameLayout import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog import eu.davidea.flexibleadapter.FlexibleAdapter import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -21,11 +22,11 @@ import eu.kanade.tachiyomi.util.marginBottom import eu.kanade.tachiyomi.util.updateLayoutParams import eu.kanade.tachiyomi.util.updatePaddingRelative import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig -import kotlinx.android.synthetic.main.migration_design_controller.fab -import kotlinx.android.synthetic.main.migration_design_controller.recycler +import kotlinx.android.synthetic.main.pre_migration_controller.fab +import kotlinx.android.synthetic.main.pre_migration_controller.recycler import uy.kohesive.injekt.injectLazy -class MigrationDesignController(bundle: Bundle? = null) : BaseController(bundle), FlexibleAdapter +class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), FlexibleAdapter .OnItemClickListener, StartMigrationListener { private val sourceManager: SourceManager by injectLazy() private val prefs: PreferencesHelper by injectLazy() @@ -36,10 +37,12 @@ class MigrationDesignController(bundle: Bundle? = null) : BaseController(bundle) private var showingOptions = false + private var dialog:BottomSheetDialog? = null + override fun getTitle() = "Select target sources" override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { - return inflater.inflate(R.layout.migration_design_controller, container, false) + return inflater.inflate(R.layout.pre_migration_controller, container, false) } override fun onViewCreated(view: View) { @@ -55,7 +58,7 @@ class MigrationDesignController(bundle: Bundle? = null) : BaseController(bundle) recycler.adapter = ourAdapter ourAdapter.itemTouchHelperCallback = null // Reset adapter touch adapter to fix drag after rotation ourAdapter.isHandleDragEnabled = true - + dialog = null val fabBaseMarginBottom = fab?.marginBottom ?: 0 recycler.doOnApplyWindowInsets { v, insets, padding -> @@ -68,14 +71,16 @@ class MigrationDesignController(bundle: Bundle? = null) : BaseController(bundle) } fab.setOnClickListener { - val dialog = MigrationBottomSheetDialog(activity!!, R.style.SheetDialog, this) - dialog.show() - val bottomSheet = - dialog.findViewById(com.google.android.material.R.id - .design_bottom_sheet) - val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet) - behavior.state = BottomSheetBehavior.STATE_EXPANDED - behavior.skipCollapsed = true + if (dialog?.isShowing != true) { + dialog = MigrationBottomSheetDialog(activity!!, R.style.SheetDialog, this) + dialog?.show() + val bottomSheet = dialog?.findViewById( + com.google.android.material.R.id.design_bottom_sheet + ) + val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet) + behavior.state = BottomSheetBehavior.STATE_EXPANDED + behavior.skipCollapsed = true + } } } @@ -145,8 +150,8 @@ class MigrationDesignController(bundle: Bundle? = null) : BaseController(bundle) companion object { private const val MANGA_IDS_EXTRA = "manga_ids" - fun create(mangaIds: List): MigrationDesignController { - return MigrationDesignController(Bundle().apply { + fun create(mangaIds: List): PreMigrationController { + return PreMigrationController(Bundle().apply { putLongArray(MANGA_IDS_EXTRA, mangaIds.toLongArray()) }) } diff --git a/app/src/main/res/layout/migration_design_controller.xml b/app/src/main/res/layout/pre_migration_controller.xml similarity index 100% rename from app/src/main/res/layout/migration_design_controller.xml rename to app/src/main/res/layout/pre_migration_controller.xml