From 59c2da3f91052dfb0a292cb23ccb9d39055aadc7 Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 23 May 2020 17:07:52 -0400 Subject: [PATCH] Batch select sources for pre migrations Select none/all, pinned sources, enabled sources from the list --- .../manga/design/PreMigrationController.kt | 53 ++++++++++++++++--- .../manga/process/MigrationListController.kt | 4 +- .../main/res/drawable/ic_select_all_24dp.xml | 11 ++++ .../main/res/drawable/ic_select_none_24dp.xml | 11 ++++ app/src/main/res/menu/migration_list.xml | 4 +- app/src/main/res/menu/pre_migration.xml | 25 +++++++++ app/src/main/res/values/strings.xml | 3 +- 7 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 app/src/main/res/drawable/ic_select_all_24dp.xml create mode 100644 app/src/main/res/drawable/ic_select_none_24dp.xml create mode 100644 app/src/main/res/menu/pre_migration.xml 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 2cdd26713a..23d97cab6a 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 @@ -18,9 +21,9 @@ import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig -import eu.kanade.tachiyomi.util.view.applyWindowInsetsForController import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.liftAppbarWith import eu.kanade.tachiyomi.util.view.marginBottom import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative @@ -41,7 +44,7 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F private var dialog: BottomSheetDialog? = null - override fun getTitle() = view?.context?.getString(R.string.select_target_sources) + override fun getTitle() = view?.context?.getString(R.string.select_sources) override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View { return inflater.inflate(R.layout.pre_migration_controller, container, false) @@ -49,7 +52,7 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F override fun onViewCreated(view: View) { super.onViewCreated(view) - view.applyWindowInsetsForController() + liftAppbarWith(recycler) val ourAdapter = adapter ?: MigrationSourceAdapter( getEnabledSources().map { MigrationSourceItem(it, isEnabled(it.id.toString())) }, @@ -68,9 +71,13 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F fab?.updateLayoutParams { bottomMargin = fabBaseMarginBottom + insets.systemWindowInsetBottom } - // offset the recycler by the fab's inset + some inset on top - v.updatePaddingRelative(bottom = padding.bottom + (fab?.marginBottom ?: 0) + - fabBaseMarginBottom + (fab?.height ?: 0)) + v.post { + // offset the recycler by the fab's inset + some inset on top + v.updatePaddingRelative( + bottom = insets.systemWindowInsetBottom + (fab?.marginBottom + ?: 0) + (fab?.height ?: 0) + ) + } } fab.setOnClickListener { @@ -151,6 +158,40 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F 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.hiddenSources().getOrDefault().mapNotNull { it.toLongOrNull() } + } else { + prefs.pinnedCatalogues().get()?.mapNotNull { it.toLongOrNull() } ?: emptyList() + } + 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 461cee7191..18979e6a94 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 @@ -38,7 +38,7 @@ import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener -import eu.kanade.tachiyomi.util.view.applyWindowInsetsForController +import eu.kanade.tachiyomi.util.view.liftAppbarWith import eu.kanade.tachiyomi.util.view.withFadeTransaction import kotlinx.android.synthetic.main.migration_list_controller.* import kotlinx.coroutines.CancellationException @@ -95,7 +95,7 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), override fun onViewCreated(view: View) { super.onViewCreated(view) - view.applyWindowInsetsForController() + liftAppbarWith(recycler) setTitle() val config = this.config ?: return diff --git a/app/src/main/res/drawable/ic_select_all_24dp.xml b/app/src/main/res/drawable/ic_select_all_24dp.xml new file mode 100644 index 0000000000..23d025e46d --- /dev/null +++ b/app/src/main/res/drawable/ic_select_all_24dp.xml @@ -0,0 +1,11 @@ + + + + \ 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 0000000000..04894a7259 --- /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/menu/migration_list.xml b/app/src/main/res/menu/migration_list.xml index 47c8fd9dcd..cdfa14b02b 100644 --- a/app/src/main/res/menu/migration_list.xml +++ b/app/src/main/res/menu/migration_list.xml @@ -6,10 +6,10 @@ android:id="@+id/action_copy_manga" android:icon="@drawable/ic_content_copy_24dp" android:title="@string/copy" - app:showAsAction="always" /> + 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 0000000000..3c2e17f8bf --- /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.xml b/app/src/main/res/values/strings.xml index 63514b0526..a561407644 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -423,7 +423,7 @@ Add tracking - Select target sources + Select sources Source migration Migration Skip pre-migration @@ -738,6 +738,7 @@ Save Search Select all + Select none Share Sort Sort & Filter