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)
This commit is contained in:
Jay 2020-05-23 16:28:07 -04:00
parent c4f1183dc4
commit a3305171d6
4 changed files with 30 additions and 15 deletions

View File

@ -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<CatalogueSource>? = 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) {

View File

@ -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<CatalogueSource>? = null
) : GlobalSearchPresenter(initialQuery, sourcesToUse = sources) {
override fun getEnabledSources(): List<CatalogueSource> {
// Put the source of the selected manga at the top

View File

@ -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())
}

View File

@ -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<CatalogueSource>? = 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<CatalogueSource> {
if (sourcesToUse != null) return sourcesToUse
val filter = extensionFilter
val enabledSources = getEnabledSources()
if (filter.isNullOrEmpty()) {