From 545bc0e605d380fd47f5c4d930a6613b7ec78266 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 8 Feb 2021 17:47:44 -0500 Subject: [PATCH] Open manga when clicking thumbnail in migration list (closes #4152) --- app/build.gradle.kts | 1 - .../migration/manga/MigrationMangaAdapter.kt | 14 ++++++++++++++ .../manga/MigrationMangaController.kt | 18 ++++++++++++------ ...{MangaHolder.kt => MigrationMangaHolder.kt} | 18 ++++++++---------- .../{MangaItem.kt => MigrationMangaItem.kt} | 16 +++++----------- .../migration/manga/MigrationMangaPresenter.kt | 4 ++-- 6 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaAdapter.kt rename app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/{MangaHolder.kt => MigrationMangaHolder.kt} (79%) rename app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/{MangaItem.kt => MigrationMangaItem.kt} (72%) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1d07cf84fd..0a9fa8538b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -9,7 +9,6 @@ plugins { id("com.mikepenz.aboutlibraries.plugin") kotlin("android") kotlin("kapt") - kotlin("plugin.parcelize") kotlin("plugin.serialization") id("com.github.zellius.shortcut-helper") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaAdapter.kt new file mode 100644 index 0000000000..389b76f728 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaAdapter.kt @@ -0,0 +1,14 @@ +package eu.kanade.tachiyomi.ui.browse.migration.manga + +import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.davidea.flexibleadapter.items.IFlexible + +class MigrationMangaAdapter(controller: MigrationMangaController) : + FlexibleAdapter>(null, controller, true) { + + val coverClickListener: OnCoverClickListener = controller + + interface OnCoverClickListener { + fun onCoverClick(position: Int) + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt index 548208ce3a..386b2c768a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaController.kt @@ -7,17 +7,18 @@ import android.view.ViewGroup import androidx.core.os.bundleOf import androidx.recyclerview.widget.LinearLayoutManager import eu.davidea.flexibleadapter.FlexibleAdapter -import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.databinding.MigrationMangaControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController +import eu.kanade.tachiyomi.ui.manga.MangaController class MigrationMangaController : NucleusController, - FlexibleAdapter.OnItemClickListener { + FlexibleAdapter.OnItemClickListener, + MigrationMangaAdapter.OnCoverClickListener { - private var adapter: FlexibleAdapter>? = null + private var adapter: MigrationMangaAdapter? = null constructor(sourceId: Long, sourceName: String?) : super( bundleOf( @@ -51,7 +52,7 @@ class MigrationMangaController : override fun onViewCreated(view: View) { super.onViewCreated(view) - adapter = FlexibleAdapter>(null, this) + adapter = MigrationMangaAdapter(this) binding.recycler.layoutManager = LinearLayoutManager(view.context) binding.recycler.adapter = adapter adapter?.fastScroller = binding.fastScroller @@ -62,17 +63,22 @@ class MigrationMangaController : super.onDestroyView(view) } - fun setManga(manga: List) { + fun setManga(manga: List) { adapter?.updateDataSet(manga) } override fun onItemClick(view: View, position: Int): Boolean { - val item = adapter?.getItem(position) as? MangaItem ?: return false + val item = adapter?.getItem(position) as? MigrationMangaItem ?: return false val controller = SearchController(item.manga) router.pushController(controller.withFadeTransaction()) return false } + override fun onCoverClick(position: Int) { + val mangaItem = adapter?.getItem(position) as? MigrationMangaItem ?: return + router.pushController(MangaController(mangaItem.manga).withFadeTransaction()) + } + companion object { const val SOURCE_ID_EXTRA = "source_id_extra" const val SOURCE_NAME_EXTRA = "source_name_extra" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaHolder.kt similarity index 79% rename from app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaHolder.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaHolder.kt index 47299a8bdf..c979f755ef 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaHolder.kt @@ -5,29 +5,27 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.resource.bitmap.CenterCrop import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.request.RequestOptions -import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.viewholders.FlexibleViewHolder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.toMangaThumbnail import eu.kanade.tachiyomi.databinding.SourceListItemBinding -class MangaHolder( +class MigrationMangaHolder( view: View, - adapter: FlexibleAdapter<*> + private val adapter: MigrationMangaAdapter ) : FlexibleViewHolder(view, adapter) { private val binding = SourceListItemBinding.bind(view) - fun bind(item: MangaItem) { - // Update the title of the manga. - binding.title.text = item.manga.title - - // Create thumbnail onclick to simulate long click + init { binding.thumbnail.setOnClickListener { - // Simulate long click on this view to enter selection mode - onLongClick(itemView) + adapter.coverClickListener.onCoverClick(bindingAdapterPosition) } + } + + fun bind(item: MigrationMangaItem) { + binding.title.text = item.manga.title // Update the cover. GlideApp.with(itemView.context).clear(binding.thumbnail) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaItem.kt similarity index 72% rename from app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaItem.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaItem.kt index 770fc84925..3af0924cd7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MangaItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaItem.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.browse.migration.manga -import android.os.Parcelable import android.view.View import androidx.recyclerview.widget.RecyclerView import eu.davidea.flexibleadapter.FlexibleAdapter @@ -8,25 +7,20 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga -import kotlinx.parcelize.Parcelize -@Parcelize -class MangaItem(val manga: Manga) : AbstractFlexibleItem(), Parcelable { +class MigrationMangaItem(val manga: Manga) : AbstractFlexibleItem() { override fun getLayoutRes(): Int { return R.layout.source_list_item } - override fun createViewHolder(view: View, adapter: FlexibleAdapter>): MangaHolder { - return MangaHolder( - view, - adapter - ) + override fun createViewHolder(view: View, adapter: FlexibleAdapter>): MigrationMangaHolder { + return MigrationMangaHolder(view, adapter as MigrationMangaAdapter) } override fun bindViewHolder( adapter: FlexibleAdapter>, - holder: MangaHolder, + holder: MigrationMangaHolder, position: Int, payloads: List? ) { @@ -34,7 +28,7 @@ class MangaItem(val manga: Manga) : AbstractFlexibleItem(), Parcela } override fun equals(other: Any?): Boolean { - if (other is MangaItem) { + if (other is MigrationMangaItem) { return manga.id == other.manga.id } return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt index 5d17a68d82..a2cc2800e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/manga/MigrationMangaPresenter.kt @@ -23,9 +23,9 @@ class MigrationMangaPresenter( .subscribeLatestCache(MigrationMangaController::setManga) } - private fun libraryToMigrationItem(library: List): List { + private fun libraryToMigrationItem(library: List): List { return library.filter { it.source == sourceId } .sortedBy { it.title } - .map { MangaItem(it) } + .map { MigrationMangaItem(it) } } }