Migration updates

When searching manually, the sources used for auto migration will also be used for searching
Can now migrate to the same source if it is the only source being used for migration (for those who cant stop using kakalot)

(cherry picked from commit a3305171d64a8dc4c2fa52d3e5257f45e92f29f1)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/globalsearch/GlobalSearchPresenter.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/process/MigrationListController.kt
This commit is contained in:
Jay 2020-05-23 16:28:07 -04:00 committed by Jobobby04
parent a9ef4bef8e
commit 2ed54eed73
6 changed files with 90 additions and 29 deletions

View File

@ -32,11 +32,12 @@ import uy.kohesive.injekt.injectLazy
* @param preferences manages the preference calls. * @param preferences manages the preference calls.
*/ */
open class GlobalSearchPresenter( open class GlobalSearchPresenter(
val initialQuery: String? = "", private val initialQuery: String? = "",
val initialExtensionFilter: String? = null, private val initialExtensionFilter: String? = null,
private val sourcesToUse: List<CatalogueSource>? = null,
val sourceManager: SourceManager = Injekt.get(), val sourceManager: SourceManager = Injekt.get(),
val db: DatabaseHelper = Injekt.get(), val db: DatabaseHelper = Injekt.get(),
val preferences: PreferencesHelper = Injekt.get() private val preferences: PreferencesHelper = Injekt.get()
) : BasePresenter<GlobalSearchController>() { ) : BasePresenter<GlobalSearchController>() {
/** /**
@ -105,13 +106,20 @@ open class GlobalSearchPresenter(
val hiddenCatalogues = preferences.hiddenCatalogues().get() val hiddenCatalogues = preferences.hiddenCatalogues().get()
val pinnedCatalogues = preferences.pinnedCatalogues().get() val pinnedCatalogues = preferences.pinnedCatalogues().get()
return sourceManager.getVisibleCatalogueSources() val list = sourceManager.getVisibleCatalogueSources()
.filter { it.lang in languages } .filter { it.lang in languages }
.filterNot { it.id.toString() in hiddenCatalogues } .filterNot { it.id.toString() in hiddenCatalogues }
.sortedWith(compareBy({ it.id.toString() !in pinnedCatalogues }, { "(${it.lang}) ${it.name}" })) .sortedBy { "(${it.lang}) ${it.name}" }
return if (preferences.searchPinnedSourcesOnly()) {
list.filter { it.id.toString() in pinnedCatalogues }
} else {
list.sortedBy { it.id.toString() !in pinnedCatalogues }
}
} }
private fun getSourcesToQuery(): List<CatalogueSource> { private fun getSourcesToQuery(): List<CatalogueSource> {
if (sourcesToUse != null) return sourcesToUse
val filter = extensionFilter val filter = extensionFilter
val enabledSources = getEnabledSources() val enabledSources = getEnabledSources()
var filteredSources: List<CatalogueSource>? = null var filteredSources: List<CatalogueSource>? = null

View File

@ -11,6 +11,7 @@ import com.afollestad.materialdialogs.list.listItemsMultiChoice
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.source.CatalogueSource
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
@ -25,7 +26,8 @@ import reactivecircus.flowbinding.appcompat.queryTextEvents
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class SearchController( class SearchController(
private var manga: Manga? = null private var manga: Manga? = null,
private var sources: List<CatalogueSource>? = null
) : GlobalSearchController(manga?.title) { ) : GlobalSearchController(manga?.title) {
private var newManga: Manga? = null private var newManga: Manga? = null
@ -48,7 +50,7 @@ class SearchController(
} }
override fun createPresenter(): GlobalSearchPresenter { override fun createPresenter(): GlobalSearchPresenter {
return SearchPresenter(initialQuery, manga!!) return SearchPresenter(initialQuery, manga!!, sources = sources)
} }
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
@ -71,6 +73,7 @@ class SearchController(
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS) menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
} }
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
1 -> { 1 -> {
@ -142,10 +145,10 @@ class SearchController(
return MaterialDialog(activity!!) return MaterialDialog(activity!!)
.message(R.string.data_to_include_in_migration) .message(R.string.data_to_include_in_migration)
.listItemsMultiChoice( .listItemsMultiChoice(
items = MigrationFlags.titles.map { resources?.getString(it) as CharSequence }, items = MigrationFlags.titles.map
{ resources?.getString(it) as CharSequence },
initialSelection = preselected.toIntArray() initialSelection = preselected.toIntArray()
) { _, positions, _ -> ) { _, positions, _ ->
// Save current settings for the next time
val newValue = MigrationFlags.getFlagsFromPositions(positions.toTypedArray()) val newValue = MigrationFlags.getFlagsFromPositions(positions.toTypedArray())
preferences.migrateFlags().set(newValue) preferences.migrateFlags().set(newValue)
} }
@ -155,7 +158,6 @@ class SearchController(
.negativeButton(R.string.copy) { .negativeButton(R.string.copy) {
(targetController as? SearchController)?.copyManga() (targetController as? SearchController)?.copyManga()
} }
.neutralButton(android.R.string.cancel)
} }
} }

View File

@ -8,8 +8,9 @@ import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
class SearchPresenter( class SearchPresenter(
initialQuery: String? = "", initialQuery: String? = "",
private val manga: Manga private val manga: Manga,
) : GlobalSearchPresenter(initialQuery) { sources: List<CatalogueSource>? = null
) : GlobalSearchPresenter(initialQuery, sourcesToUse = sources) {
override fun getEnabledSources(): List<CatalogueSource> { override fun getEnabledSources(): List<CatalogueSource> {
// Put the source of the selected manga at the top // Put the source of the selected manga at the top

View File

@ -96,7 +96,7 @@ class PreMigrationController(bundle: Bundle? = null) :
override fun startMigration(extraParam: String?) { override fun startMigration(extraParam: String?) {
val listOfSources = adapter?.items?.filter { val listOfSources = adapter?.items?.filter {
it.sourceEnabled it.sourceEnabled
}?.joinToString("/") { it.source.id.toString() } ?: "" }?.joinToString("/") { it.source.id.toString() } ?: ""
prefs.migrationSources().set(listOfSources) prefs.migrationSources().set(listOfSources)
router.replaceTopController( router.replaceTopController(

View File

@ -153,8 +153,10 @@ class MigrationListController(bundle: Bundle? = null) :
val result = try { val result = try {
CoroutineScope(manga.migrationJob).async { CoroutineScope(manga.migrationJob).async {
val validSources = sources.filter { val validSources = if (sources.size == 1) {
it.id != mangaSource.id sources
} else {
sources.filter { it.id != mangaSource.id }
} }
if (useSourceWithMost) { if (useSourceWithMost) {
val sourceSemaphore = Semaphore(3) val sourceSemaphore = Semaphore(3)
@ -165,12 +167,23 @@ class MigrationListController(bundle: Bundle? = null) :
sourceSemaphore.withPermit { sourceSemaphore.withPermit {
try { try {
val searchResult = if (useSmartSearch) { val searchResult = if (useSmartSearch) {
smartSearchEngine.smartSearch(source, mangaObj.title) smartSearchEngine.smartSearch(
source,
mangaObj.title
)
} else { } else {
smartSearchEngine.normalSearch(source, mangaObj.title) smartSearchEngine.normalSearch(
source,
mangaObj.title
)
} }
if (searchResult != null) { if (searchResult != null &&
!(
searchResult.url == mangaObj.url &&
source.id == mangaObj.source
)
) {
val localManga = val localManga =
smartSearchEngine.networkToLocalManga( smartSearchEngine.networkToLocalManga(
searchResult, searchResult,
@ -209,16 +222,25 @@ class MigrationListController(bundle: Bundle? = null) :
validSources.forEachIndexed { index, source -> validSources.forEachIndexed { index, source ->
val searchResult = try { val searchResult = try {
val searchResult = if (useSmartSearch) { val searchResult = if (useSmartSearch) {
smartSearchEngine.smartSearch(source, mangaObj.title) smartSearchEngine.smartSearch(
source,
mangaObj.title
)
} else { } else {
smartSearchEngine.normalSearch(source, mangaObj.title) smartSearchEngine.normalSearch(
source,
mangaObj.title
)
} }
if (searchResult != null) { if (searchResult != null) {
val localManga = smartSearchEngine.networkToLocalManga(searchResult, source.id) val localManga = smartSearchEngine.networkToLocalManga(
searchResult,
source.id
)
val chapters = try { val chapters = try {
source.fetchChapterList(localManga) source.fetchChapterList(localManga).toSingle()
.toSingle().await(Schedulers.io()) .await(Schedulers.io())
} catch (e: java.lang.Exception) { } catch (e: java.lang.Exception) {
Timber.e(e) Timber.e(e)
emptyList<SChapter>() emptyList<SChapter>()
@ -318,9 +340,18 @@ class MigrationListController(bundle: Bundle? = null) :
when (item.itemId) { when (item.itemId) {
R.id.action_search_manually -> { R.id.action_search_manually -> {
launchUI { launchUI {
val manga = adapter?.getItem(position) ?: return@launchUI val manga = adapter?.getItem(position)?.manga?.manga() ?: return@launchUI
selectedPosition = position selectedPosition = position
val searchController = SearchController(manga.manga.manga()) val sources = preferences.migrationSources().get().split("/").mapNotNull {
val value = it.toLongOrNull() ?: return@mapNotNull null
sourceManager.get(value) as? CatalogueSource
}
val validSources = if (sources.size == 1) {
sources
} else {
sources.filter { it.id != manga.source }
}
val searchController = SearchController(manga, validSources)
searchController.targetController = this@MigrationListController searchController.targetController = this@MigrationListController
router.pushController(searchController.withFadeTransaction()) router.pushController(searchController.withFadeTransaction())
} }
@ -421,13 +452,14 @@ class MigrationListController(bundle: Bundle? = null) :
override fun handleBack(): Boolean { override fun handleBack(): Boolean {
activity?.let { activity?.let {
MaterialDialog(it).title(R.string.stop_migrating) MaterialDialog(it).show {
.positiveButton(R.string.action_stop) { title(R.string.stop_migrating)
positiveButton(R.string.action_stop) {
router.popCurrentController() router.popCurrentController()
migrationsJob?.cancel() migrationsJob?.cancel()
} }
.negativeButton(android.R.string.cancel) negativeButton(android.R.string.cancel)
.show() }
} }
return true return true
} }
@ -484,6 +516,23 @@ class MigrationListController(bundle: Bundle? = null) :
} }
return true return true
} }
/*
override fun canChangeTabs(block: () -> Unit): Boolean {
if (migrationsJob?.isCancelled == false || adapter?.allMangasDone() == true) {
activity?.let {
MaterialDialog(it).show {
title(R.string.stop_migrating)
positiveButton(R.string.action_stop) {
block()
migrationsJob?.cancel()
}
negativeButton(android.R.string.cancel)
}
}
return false
}
return true
}*/
companion object { companion object {
const val CONFIG_EXTRA = "config_extra" const val CONFIG_EXTRA = "config_extra"

View File

@ -75,6 +75,7 @@
<item quantity="one">%d manga migrated</item> <item quantity="one">%d manga migrated</item>
<item quantity="other">%d manga migrated</item> <item quantity="other">%d manga migrated</item>
</plurals> </plurals>
<string name="select_sources">Select target sources</string>
<!-- EXH --> <!-- EXH -->
<string name="label_login">Login</string> <string name="label_login">Login</string>