diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt index 2cd28f2311..f069ff98de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt @@ -13,17 +13,19 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.base.controller.DialogController -import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController -import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchPresenter import eu.kanade.tachiyomi.ui.main.BottomNavBarInterface import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController +import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController +import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchPresenter import eu.kanade.tachiyomi.util.view.withFadeTransaction import uy.kohesive.injekt.injectLazy class SearchController( - private var manga: Manga? = null + private var manga: Manga? = null, + private var sources: List? = null ) : GlobalSearchController(manga?.title), BottomNavBarInterface { private var newManga: Manga? = null @@ -45,7 +47,7 @@ class SearchController( } override fun createPresenter(): GlobalSearchPresenter { - return SearchPresenter(initialQuery, manga!!) + return SearchPresenter(initialQuery, manga!!, sources = sources) } override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt index 040fbb310e..4dea5351b4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt @@ -2,14 +2,15 @@ package eu.kanade.tachiyomi.ui.migration import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.source.CatalogueSource -import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchMangaItem import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchItem +import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchMangaItem import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchPresenter class SearchPresenter( initialQuery: String? = "", - private val manga: Manga -) : GlobalSearchPresenter(initialQuery) { + private val manga: Manga, + sources: List? = null +) : GlobalSearchPresenter(initialQuery, sourcesToUse = sources) { override fun getEnabledSources(): List { // Put the source of the selected manga at the top 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 8e8996846a..461cee7191 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 @@ -151,8 +151,10 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), val result = try { CoroutineScope(manga.migrationJob).async { - val validSources = sources.filter { - it.id != mangaSource.id + val validSources = if (sources.size == 1) { + sources + } else { + sources.filter { it.id != mangaSource.id } } if (useSourceWithMost) { val sourceSemaphore = Semaphore(3) @@ -162,15 +164,14 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), async { sourceSemaphore.withPermit { try { - /* val searchResult = if (useSmartSearch) { - smartSearchEngine.smartSearch(source, mangaObj.title) - } else {*/ val searchResult = smartSearchEngine.normalSearch( source, mangaObj.title ) - if (searchResult != null) { + if (searchResult != null && + !(searchResult.url == mangaObj.url && + source.id == mangaObj.source)) { val localManga = smartSearchEngine.networkToLocalManga( searchResult, @@ -321,9 +322,18 @@ class MigrationListController(bundle: Bundle? = null) : BaseController(bundle), when (item.itemId) { R.id.action_search_manually -> { launchUI { - val manga = adapter?.getItem(position) ?: return@launchUI + val manga = adapter?.getItem(position)?.manga?.manga() ?: return@launchUI 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 router.pushController(searchController.withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt index 1fa01ef3ae..5e08aab526 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchPresenter.kt @@ -35,6 +35,7 @@ import uy.kohesive.injekt.injectLazy open class GlobalSearchPresenter( private val initialQuery: String? = "", private val initialExtensionFilter: String? = null, + private val sourcesToUse: List? = null, val sourceManager: SourceManager = Injekt.get(), val db: DatabaseHelper = Injekt.get(), private val preferencesHelper: PreferencesHelper = Injekt.get() @@ -117,6 +118,7 @@ open class GlobalSearchPresenter( } private fun getSourcesToQuery(): List { + if (sourcesToUse != null) return sourcesToUse val filter = extensionFilter val enabledSources = getEnabledSources() if (filter.isNullOrEmpty()) {