diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt index cbf35af9e..fd06b1c87 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SearchController.kt @@ -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()) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchController.kt new file mode 100644 index 000000000..cd21d66c9 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/search/SourceSearchController.kt @@ -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" + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index 5c6885c5a..7fcee032a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -86,7 +86,7 @@ open class BrowseSourceController(bundle: Bundle) : /** * Adapter containing the list of manga from the catalogue. */ - private var adapter: FlexibleAdapter>? = null + protected var adapter: FlexibleAdapter>? = null private var actionFab: ExtendedFloatingActionButton? = null private var actionFabScrollListener: RecyclerView.OnScrollListener? = null