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.
*/
open class GlobalSearchPresenter(
val initialQuery: String? = "",
val initialExtensionFilter: String? = null,
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(),
val preferences: PreferencesHelper = Injekt.get()
private val preferences: PreferencesHelper = Injekt.get()
) : BasePresenter<GlobalSearchController>() {
/**
@ -105,13 +106,20 @@ open class GlobalSearchPresenter(
val hiddenCatalogues = preferences.hiddenCatalogues().get()
val pinnedCatalogues = preferences.pinnedCatalogues().get()
return sourceManager.getVisibleCatalogueSources()
val list = sourceManager.getVisibleCatalogueSources()
.filter { it.lang in languages }
.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> {
if (sourcesToUse != null) return sourcesToUse
val filter = extensionFilter
val enabledSources = getEnabledSources()
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.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
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.base.controller.withFadeTransaction
@ -25,7 +26,8 @@ import reactivecircus.flowbinding.appcompat.queryTextEvents
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) {
private var newManga: Manga? = null
@ -48,7 +50,7 @@ class SearchController(
}
override fun createPresenter(): GlobalSearchPresenter {
return SearchPresenter(initialQuery, manga!!)
return SearchPresenter(initialQuery, manga!!, sources = sources)
}
override fun onSaveInstanceState(outState: Bundle) {
@ -71,6 +73,7 @@ class SearchController(
menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
1 -> {
@ -142,10 +145,10 @@ class SearchController(
return MaterialDialog(activity!!)
.message(R.string.data_to_include_in_migration)
.listItemsMultiChoice(
items = MigrationFlags.titles.map { resources?.getString(it) as CharSequence },
items = MigrationFlags.titles.map
{ resources?.getString(it) as CharSequence },
initialSelection = preselected.toIntArray()
) { _, positions, _ ->
// Save current settings for the next time
val newValue = MigrationFlags.getFlagsFromPositions(positions.toTypedArray())
preferences.migrateFlags().set(newValue)
}
@ -155,7 +158,6 @@ class SearchController(
.negativeButton(R.string.copy) {
(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(
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

@ -153,8 +153,10 @@ class MigrationListController(bundle: Bundle? = null) :
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)
@ -165,12 +167,23 @@ class MigrationListController(bundle: Bundle? = null) :
sourceSemaphore.withPermit {
try {
val searchResult = if (useSmartSearch) {
smartSearchEngine.smartSearch(source, mangaObj.title)
smartSearchEngine.smartSearch(
source,
mangaObj.title
)
} 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 =
smartSearchEngine.networkToLocalManga(
searchResult,
@ -209,16 +222,25 @@ class MigrationListController(bundle: Bundle? = null) :
validSources.forEachIndexed { index, source ->
val searchResult = try {
val searchResult = if (useSmartSearch) {
smartSearchEngine.smartSearch(source, mangaObj.title)
smartSearchEngine.smartSearch(
source,
mangaObj.title
)
} else {
smartSearchEngine.normalSearch(source, mangaObj.title)
smartSearchEngine.normalSearch(
source,
mangaObj.title
)
}
if (searchResult != null) {
val localManga = smartSearchEngine.networkToLocalManga(searchResult, source.id)
val localManga = smartSearchEngine.networkToLocalManga(
searchResult,
source.id
)
val chapters = try {
source.fetchChapterList(localManga)
.toSingle().await(Schedulers.io())
source.fetchChapterList(localManga).toSingle()
.await(Schedulers.io())
} catch (e: java.lang.Exception) {
Timber.e(e)
emptyList<SChapter>()
@ -318,9 +340,18 @@ class MigrationListController(bundle: Bundle? = null) :
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())
}
@ -421,13 +452,14 @@ class MigrationListController(bundle: Bundle? = null) :
override fun handleBack(): Boolean {
activity?.let {
MaterialDialog(it).title(R.string.stop_migrating)
.positiveButton(R.string.action_stop) {
MaterialDialog(it).show {
title(R.string.stop_migrating)
positiveButton(R.string.action_stop) {
router.popCurrentController()
migrationsJob?.cancel()
}
.negativeButton(android.R.string.cancel)
.show()
negativeButton(android.R.string.cancel)
}
}
return true
}
@ -484,6 +516,23 @@ class MigrationListController(bundle: Bundle? = null) :
}
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 {
const val CONFIG_EXTRA = "config_extra"

View File

@ -75,6 +75,7 @@
<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>