Batch select sources for pre migrations

Select none/all, pinned sources, enabled sources from the list

(cherry picked from commit 59c2da3f91052dfb0a292cb23ccb9d39055aadc7)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt
#	app/src/main/res/drawable/ic_select_all_24dp.xml
#	app/src/main/res/values/strings.xml
This commit is contained in:
Jay 2020-05-23 17:07:52 -04:00 committed by Jobobby04
parent 2ed54eed73
commit 81ee1ce39a
8 changed files with 101 additions and 15 deletions

View File

@ -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<ViewGroup.MarginLayoutParams> {
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"

View File

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

View File

@ -0,0 +1,8 @@
<!-- drawable/pin.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M16,12V4H17V2H7V4H8V12L6,14V16H11.2V22H12.8V16H18V14L16,12Z" />
</vector>

View File

@ -0,0 +1,11 @@
<!-- drawable/select_off.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorOnPrimary"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000"
android:pathData="M1,4.27L2.28,3L21,21.72L19.73,23L17,20.27V21H15V19H15.73L5,8.27V9H3V7H3.73L1,4.27M20,3A1,1 0 0,1 21,4V5H19V3H20M15,5V3H17V5H15M11,5V3H13V5H11M7,5V3H9V5H7M11,21V19H13V21H11M7,21V19H9V21H7M4,21A1,1 0 0,1 3,20V19H5V21H4M3,15H5V17H3V15M21,15V17H19V15H21M3,11H5V13H3V11M21,11V13H19V11H21M21,7V9H19V7H21Z" />
</vector>

View File

@ -150,12 +150,14 @@
app:layout_constraintTop_toBottomOf="@+id/extra_search_param_text" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab"
style="@style/Theme.Widget.FAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_arrow_forward_24dp"
android:text="@string/action_migrate"
app:icon="@drawable/ic_arrow_forward_24dp"
app:layout_anchor="@id/constraintLayout"
app:layout_anchorGravity="bottom|end"
app:layout_constraintEnd_toEndOf="parent"

View File

@ -6,10 +6,10 @@
android:id="@+id/action_copy_manga"
android:icon="@drawable/ic_copy"
android:title="@string/copy"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_migrate_manga"
android:icon="@drawable/ic_done_all"
android:title="@string/migrate"
app:showAsAction="always" />
app:showAsAction="ifRoom" />
</menu>

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_select_none"
android:icon="@drawable/ic_select_none_24dp"
android:title="@string/select_none"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_select_all"
android:icon="@drawable/ic_select_all_24dp"
android:title="@string/action_select_all"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_match_enabled"
android:icon="@drawable/ic_explore_24dp"
android:title="@string/match_enabled_sources"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_match_pinned"
android:icon="@drawable/ic_pin_24dp"
android:title="@string/match_pinned_sources"
app:showAsAction="ifRoom" />
</menu>

View File

@ -34,6 +34,8 @@
<!-- Migration -->
<string name="select_sources">Select sources</string>
<string name="select_none">Select none</string>
<string name="source_migration">Source migration</string>
<string name="migration">Migration</string>
<string name="skip_pre_migration">Skip pre-migration</string>
@ -58,6 +60,8 @@
<!--<string name="migrate">Migrate</string>-->
<string name="migrate_">Migrate %1$s</string>
<string name="copy_value">Copy</string>
<string name="match_pinned_sources">Match pinned sources</string>
<string name="match_enabled_sources">Match enabled sources</string>
<string name="no_chapters_found_for_migration">No chapters found, this manga cannot be used for
migration</string>
<string name="no_alternatives_found">No Alternatives Found</string>
@ -75,7 +79,6 @@
<item quantity="one">%d manga migrated</item>
<item quantity="other">%d manga migrated</item>
</plurals>
<string name="select_sources">Select target sources</string>
<!-- EXH -->
<string name="label_login">Login</string>