mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-05 01:15:14 +01:00
Implement migration for source search (#4657)
This commit is contained in:
parent
2145e878a4
commit
b6e6f490e9
@ -5,10 +5,13 @@ import android.os.Bundle
|
||||
import androidx.core.view.isVisible
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.list.listItemsMultiChoice
|
||||
import com.bluelinelabs.conductor.Controller
|
||||
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.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.ui.browse.migration.MigrationFlags
|
||||
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchController
|
||||
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchPresenter
|
||||
@ -39,16 +42,16 @@ class SearchController(
|
||||
newManga = savedInstanceState.getSerializable(::newManga.name) as? Manga
|
||||
}
|
||||
|
||||
fun migrateManga() {
|
||||
val manga = manga ?: return
|
||||
val newManga = newManga ?: return
|
||||
fun migrateManga(manga: Manga? = null, newManga: Manga?) {
|
||||
manga ?: return
|
||||
newManga ?: return
|
||||
|
||||
(presenter as? SearchPresenter)?.migrateManga(manga, newManga, true)
|
||||
}
|
||||
|
||||
fun copyManga() {
|
||||
val manga = manga ?: return
|
||||
val newManga = newManga ?: return
|
||||
fun copyManga(manga: Manga? = null, newManga: Manga?) {
|
||||
manga ?: return
|
||||
newManga ?: return
|
||||
|
||||
(presenter as? SearchPresenter)?.migrateManga(manga, newManga, false)
|
||||
}
|
||||
@ -56,7 +59,7 @@ class SearchController(
|
||||
override fun onMangaClick(manga: Manga) {
|
||||
newManga = manga
|
||||
val dialog =
|
||||
MigrationDialog()
|
||||
MigrationDialog(manga, newManga, this)
|
||||
dialog.targetController = this
|
||||
dialog.showDialog(router)
|
||||
}
|
||||
@ -75,7 +78,7 @@ class SearchController(
|
||||
}
|
||||
}
|
||||
|
||||
class MigrationDialog : DialogController() {
|
||||
class MigrationDialog(private val manga: Manga? = null, private val newManga: Manga? = null, private val callingController: Controller? = null) : DialogController() {
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
@ -101,12 +104,28 @@ class SearchController(
|
||||
preferences.migrateFlags().set(newValue)
|
||||
}
|
||||
.positiveButton(R.string.migrate) {
|
||||
(targetController as? SearchController)?.migrateManga()
|
||||
if (callingController != null) {
|
||||
if (callingController.javaClass == SourceSearchController::class.java) {
|
||||
router.popController(callingController)
|
||||
}
|
||||
}
|
||||
(targetController as? SearchController)?.migrateManga(manga, newManga)
|
||||
}
|
||||
.negativeButton(R.string.copy) {
|
||||
(targetController as? SearchController)?.copyManga()
|
||||
if (callingController != null) {
|
||||
if (callingController.javaClass == SourceSearchController::class.java) {
|
||||
router.popController(callingController)
|
||||
}
|
||||
}
|
||||
(targetController as? SearchController)?.copyManga(manga, newManga)
|
||||
}
|
||||
.neutralButton(android.R.string.cancel)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTitleClick(source: CatalogueSource) {
|
||||
presenter.preferences.lastUsedSource().set(source.id)
|
||||
|
||||
router.pushController(SourceSearchController(manga, source, presenter.query).withFadeTransaction())
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package eu.kanade.tachiyomi.ui.browse.migration.search
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.source.CatalogueSource
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourceController
|
||||
import eu.kanade.tachiyomi.ui.browse.source.browse.SourceItem
|
||||
|
||||
class SourceSearchController(
|
||||
bundle: Bundle
|
||||
) : BrowseSourceController(bundle) {
|
||||
|
||||
constructor(manga: Manga? = null, source: CatalogueSource, searchQuery: String? = null) : this(
|
||||
Bundle().apply {
|
||||
putLong(SOURCE_ID_KEY, source.id)
|
||||
putSerializable(MANGA_KEY, manga)
|
||||
if (searchQuery != null) {
|
||||
putString(SEARCH_QUERY_KEY, searchQuery)
|
||||
}
|
||||
}
|
||||
)
|
||||
private var oldManga: Manga? = args.getSerializable(MANGA_KEY) as Manga?
|
||||
private var newManga: Manga? = null
|
||||
|
||||
override fun onItemClick(view: View, position: Int): Boolean {
|
||||
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
||||
newManga = item.manga
|
||||
val searchController = router.backstack.findLast { it.controller().javaClass == SearchController::class.java }?.controller() as SearchController?
|
||||
val dialog =
|
||||
SearchController.MigrationDialog(oldManga, newManga, this)
|
||||
dialog.targetController = searchController
|
||||
dialog.showDialog(router)
|
||||
return true
|
||||
}
|
||||
private companion object {
|
||||
const val MANGA_KEY = "oldManga"
|
||||
}
|
||||
}
|
@ -86,7 +86,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
/**
|
||||
* Adapter containing the list of manga from the catalogue.
|
||||
*/
|
||||
private var adapter: FlexibleAdapter<IFlexible<*>>? = null
|
||||
protected var adapter: FlexibleAdapter<IFlexible<*>>? = null
|
||||
|
||||
private var actionFab: ExtendedFloatingActionButton? = null
|
||||
private var actionFabScrollListener: RecyclerView.OnScrollListener? = null
|
||||
|
Loading…
Reference in New Issue
Block a user