diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt index 0c5cd6006..0b676998f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt @@ -2,6 +2,9 @@ package eu.kanade.tachiyomi.ui.migration.manga.design import android.os.Bundle import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuInflater +import android.view.MenuItem import android.view.View import android.view.ViewGroup import android.widget.FrameLayout @@ -19,7 +22,6 @@ import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig -import exh.util.applyWindowInsetsForController import exh.util.doOnApplyWindowInsets import exh.util.marginBottom import exh.util.updateLayoutParams @@ -42,7 +44,7 @@ class PreMigrationController(bundle: Bundle? = null) : private var dialog: BottomSheetDialog? = null - override fun getTitle() = "Select target sources" + override fun getTitle() = view?.context?.getString(R.string.select_sources) override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { binding = PreMigrationControllerBinding.inflate(inflater) @@ -51,7 +53,6 @@ class PreMigrationController(bundle: Bundle? = null) : override fun onViewCreated(view: View) { super.onViewCreated(view) - view.applyWindowInsetsForController() val ourAdapter = adapter ?: MigrationSourceAdapter( getEnabledSources().map { MigrationSourceItem(it, isEnabled(it.id.toString())) }, @@ -70,11 +71,15 @@ class PreMigrationController(bundle: Bundle? = null) : binding.fab.updateLayoutParams { bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom } - // offset the recycler by the fab's inset + some inset on top - v.updatePaddingRelative( - bottom = padding.bottom + (binding.fab.marginBottom) + - fabBaseMarginBottom + (binding.fab.height) - ) + v.post { + // offset the recycler by the fab's inset + some inset on top + v.updatePaddingRelative( + bottom = insets.systemWindowInsetBottom + ( + binding.fab.marginBottom + ?: 0 + ) + (binding.fab.height ?: 0) + ) + } } binding.fab.setOnClickListener { @@ -159,6 +164,40 @@ class PreMigrationController(bundle: Bundle? = null) : else sourcesSaved.split("/").contains(id) } + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.pre_migration, menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_select_all, R.id.action_select_none -> { + adapter?.currentItems?.forEach { + it.sourceEnabled = item.itemId == R.id.action_select_all + } + adapter?.notifyDataSetChanged() + } + R.id.action_match_enabled, R.id.action_match_pinned -> { + val enabledSources = if (item.itemId == R.id.action_match_enabled) { + prefs.hiddenCatalogues().get().mapNotNull { it.toLongOrNull() } + } else { + prefs.pinnedCatalogues().get().mapNotNull { it.toLongOrNull() } + } + val items = adapter?.currentItems?.toList() ?: return true + items.forEach { + it.sourceEnabled = if (item.itemId == R.id.action_match_enabled) { + it.source.id !in enabledSources + } else { + it.source.id in enabledSources + } + } + val sortedItems = items.sortedBy { it.source.name }.sortedBy { !it.sourceEnabled } + adapter?.updateDataSet(sortedItems) + } + else -> return super.onOptionsItemSelected(item) + } + return true + } + companion object { private const val MANGA_IDS_EXTRA = "manga_ids" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt index 95d1cd3c8..2939f14b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt @@ -37,7 +37,6 @@ import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.toast import exh.smartsearch.SmartSearchEngine import exh.util.RecyclerWindowInsetsListener -import exh.util.applyWindowInsetsForController import exh.util.await import exh.util.executeOnIO import java.util.concurrent.atomic.AtomicInteger @@ -96,7 +95,6 @@ class MigrationListController(bundle: Bundle? = null) : override fun onViewCreated(view: View) { super.onViewCreated(view) - view.applyWindowInsetsForController() setTitle() val config = this.config ?: return diff --git a/app/src/main/res/drawable/ic_pin_24dp.xml b/app/src/main/res/drawable/ic_pin_24dp.xml new file mode 100644 index 000000000..fe0e5245a --- /dev/null +++ b/app/src/main/res/drawable/ic_pin_24dp.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_select_none_24dp.xml b/app/src/main/res/drawable/ic_select_none_24dp.xml new file mode 100644 index 000000000..04c1dafdc --- /dev/null +++ b/app/src/main/res/drawable/ic_select_none_24dp.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/migration_bottom_sheet.xml b/app/src/main/res/layout/migration_bottom_sheet.xml index 8c7e5f3ac..6f9a120c2 100644 --- a/app/src/main/res/layout/migration_bottom_sheet.xml +++ b/app/src/main/res/layout/migration_bottom_sheet.xml @@ -150,12 +150,14 @@ app:layout_constraintTop_toBottomOf="@+id/extra_search_param_text" /> - + app:showAsAction="ifRoom" /> + app:showAsAction="ifRoom" /> \ No newline at end of file diff --git a/app/src/main/res/menu/pre_migration.xml b/app/src/main/res/menu/pre_migration.xml new file mode 100644 index 000000000..7f6292d7d --- /dev/null +++ b/app/src/main/res/menu/pre_migration.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings_extra.xml b/app/src/main/res/values/strings_extra.xml index 816f56e22..6ca7fa433 100644 --- a/app/src/main/res/values/strings_extra.xml +++ b/app/src/main/res/values/strings_extra.xml @@ -34,6 +34,8 @@ + Select sources + Select none Source migration Migration Skip pre-migration @@ -58,6 +60,8 @@ Migrate %1$s Copy + Match pinned sources + Match enabled sources No chapters found, this manga cannot be used for migration No Alternatives Found @@ -75,7 +79,6 @@ %d manga migrated %d manga migrated - Select target sources Login