mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 16:01:49 +01:00
Open manga when clicking thumbnail in migration list (closes #4152)
This commit is contained in:
parent
291168f4de
commit
545bc0e605
@ -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")
|
||||
}
|
||||
|
@ -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<IFlexible<*>>(null, controller, true) {
|
||||
|
||||
val coverClickListener: OnCoverClickListener = controller
|
||||
|
||||
interface OnCoverClickListener {
|
||||
fun onCoverClick(position: Int)
|
||||
}
|
||||
}
|
@ -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<MigrationMangaControllerBinding, MigrationMangaPresenter>,
|
||||
FlexibleAdapter.OnItemClickListener {
|
||||
FlexibleAdapter.OnItemClickListener,
|
||||
MigrationMangaAdapter.OnCoverClickListener {
|
||||
|
||||
private var adapter: FlexibleAdapter<IFlexible<*>>? = 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<IFlexible<*>>(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<MangaItem>) {
|
||||
fun setManga(manga: List<MigrationMangaItem>) {
|
||||
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"
|
||||
|
@ -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)
|
@ -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<MangaHolder>(), Parcelable {
|
||||
class MigrationMangaItem(val manga: Manga) : AbstractFlexibleItem<MigrationMangaHolder>() {
|
||||
|
||||
override fun getLayoutRes(): Int {
|
||||
return R.layout.source_list_item
|
||||
}
|
||||
|
||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): MangaHolder {
|
||||
return MangaHolder(
|
||||
view,
|
||||
adapter
|
||||
)
|
||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): MigrationMangaHolder {
|
||||
return MigrationMangaHolder(view, adapter as MigrationMangaAdapter)
|
||||
}
|
||||
|
||||
override fun bindViewHolder(
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
||||
holder: MangaHolder,
|
||||
holder: MigrationMangaHolder,
|
||||
position: Int,
|
||||
payloads: List<Any?>?
|
||||
) {
|
||||
@ -34,7 +28,7 @@ class MangaItem(val manga: Manga) : AbstractFlexibleItem<MangaHolder>(), Parcela
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other is MangaItem) {
|
||||
if (other is MigrationMangaItem) {
|
||||
return manga.id == other.manga.id
|
||||
}
|
||||
return false
|
@ -23,9 +23,9 @@ class MigrationMangaPresenter(
|
||||
.subscribeLatestCache(MigrationMangaController::setManga)
|
||||
}
|
||||
|
||||
private fun libraryToMigrationItem(library: List<Manga>): List<MangaItem> {
|
||||
private fun libraryToMigrationItem(library: List<Manga>): List<MigrationMangaItem> {
|
||||
return library.filter { it.source == sourceId }
|
||||
.sortedBy { it.title }
|
||||
.map { MangaItem(it) }
|
||||
.map { MigrationMangaItem(it) }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user