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")
|
id("com.mikepenz.aboutlibraries.plugin")
|
||||||
kotlin("android")
|
kotlin("android")
|
||||||
kotlin("kapt")
|
kotlin("kapt")
|
||||||
kotlin("plugin.parcelize")
|
|
||||||
kotlin("plugin.serialization")
|
kotlin("plugin.serialization")
|
||||||
id("com.github.zellius.shortcut-helper")
|
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.core.os.bundleOf
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
|
||||||
import eu.kanade.tachiyomi.databinding.MigrationMangaControllerBinding
|
import eu.kanade.tachiyomi.databinding.MigrationMangaControllerBinding
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController
|
import eu.kanade.tachiyomi.ui.browse.migration.search.SearchController
|
||||||
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
|
|
||||||
class MigrationMangaController :
|
class MigrationMangaController :
|
||||||
NucleusController<MigrationMangaControllerBinding, MigrationMangaPresenter>,
|
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(
|
constructor(sourceId: Long, sourceName: String?) : super(
|
||||||
bundleOf(
|
bundleOf(
|
||||||
@ -51,7 +52,7 @@ class MigrationMangaController :
|
|||||||
override fun onViewCreated(view: View) {
|
override fun onViewCreated(view: View) {
|
||||||
super.onViewCreated(view)
|
super.onViewCreated(view)
|
||||||
|
|
||||||
adapter = FlexibleAdapter<IFlexible<*>>(null, this)
|
adapter = MigrationMangaAdapter(this)
|
||||||
binding.recycler.layoutManager = LinearLayoutManager(view.context)
|
binding.recycler.layoutManager = LinearLayoutManager(view.context)
|
||||||
binding.recycler.adapter = adapter
|
binding.recycler.adapter = adapter
|
||||||
adapter?.fastScroller = binding.fastScroller
|
adapter?.fastScroller = binding.fastScroller
|
||||||
@ -62,17 +63,22 @@ class MigrationMangaController :
|
|||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setManga(manga: List<MangaItem>) {
|
fun setManga(manga: List<MigrationMangaItem>) {
|
||||||
adapter?.updateDataSet(manga)
|
adapter?.updateDataSet(manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(view: View, position: Int): Boolean {
|
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)
|
val controller = SearchController(item.manga)
|
||||||
router.pushController(controller.withFadeTransaction())
|
router.pushController(controller.withFadeTransaction())
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCoverClick(position: Int) {
|
||||||
|
val mangaItem = adapter?.getItem(position) as? MigrationMangaItem ?: return
|
||||||
|
router.pushController(MangaController(mangaItem.manga).withFadeTransaction())
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SOURCE_ID_EXTRA = "source_id_extra"
|
const val SOURCE_ID_EXTRA = "source_id_extra"
|
||||||
const val SOURCE_NAME_EXTRA = "source_name_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.CenterCrop
|
||||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
||||||
import eu.davidea.viewholders.FlexibleViewHolder
|
import eu.davidea.viewholders.FlexibleViewHolder
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||||
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
import eu.kanade.tachiyomi.data.glide.toMangaThumbnail
|
||||||
import eu.kanade.tachiyomi.databinding.SourceListItemBinding
|
import eu.kanade.tachiyomi.databinding.SourceListItemBinding
|
||||||
|
|
||||||
class MangaHolder(
|
class MigrationMangaHolder(
|
||||||
view: View,
|
view: View,
|
||||||
adapter: FlexibleAdapter<*>
|
private val adapter: MigrationMangaAdapter
|
||||||
) : FlexibleViewHolder(view, adapter) {
|
) : FlexibleViewHolder(view, adapter) {
|
||||||
|
|
||||||
private val binding = SourceListItemBinding.bind(view)
|
private val binding = SourceListItemBinding.bind(view)
|
||||||
|
|
||||||
fun bind(item: MangaItem) {
|
init {
|
||||||
// Update the title of the manga.
|
|
||||||
binding.title.text = item.manga.title
|
|
||||||
|
|
||||||
// Create thumbnail onclick to simulate long click
|
|
||||||
binding.thumbnail.setOnClickListener {
|
binding.thumbnail.setOnClickListener {
|
||||||
// Simulate long click on this view to enter selection mode
|
adapter.coverClickListener.onCoverClick(bindingAdapterPosition)
|
||||||
onLongClick(itemView)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(item: MigrationMangaItem) {
|
||||||
|
binding.title.text = item.manga.title
|
||||||
|
|
||||||
// Update the cover.
|
// Update the cover.
|
||||||
GlideApp.with(itemView.context).clear(binding.thumbnail)
|
GlideApp.with(itemView.context).clear(binding.thumbnail)
|
@ -1,6 +1,5 @@
|
|||||||
package eu.kanade.tachiyomi.ui.browse.migration.manga
|
package eu.kanade.tachiyomi.ui.browse.migration.manga
|
||||||
|
|
||||||
import android.os.Parcelable
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
@ -8,25 +7,20 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
|||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
import kotlinx.parcelize.Parcelize
|
|
||||||
|
|
||||||
@Parcelize
|
class MigrationMangaItem(val manga: Manga) : AbstractFlexibleItem<MigrationMangaHolder>() {
|
||||||
class MangaItem(val manga: Manga) : AbstractFlexibleItem<MangaHolder>(), Parcelable {
|
|
||||||
|
|
||||||
override fun getLayoutRes(): Int {
|
override fun getLayoutRes(): Int {
|
||||||
return R.layout.source_list_item
|
return R.layout.source_list_item
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): MangaHolder {
|
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): MigrationMangaHolder {
|
||||||
return MangaHolder(
|
return MigrationMangaHolder(view, adapter as MigrationMangaAdapter)
|
||||||
view,
|
|
||||||
adapter
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun bindViewHolder(
|
override fun bindViewHolder(
|
||||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
||||||
holder: MangaHolder,
|
holder: MigrationMangaHolder,
|
||||||
position: Int,
|
position: Int,
|
||||||
payloads: List<Any?>?
|
payloads: List<Any?>?
|
||||||
) {
|
) {
|
||||||
@ -34,7 +28,7 @@ class MangaItem(val manga: Manga) : AbstractFlexibleItem<MangaHolder>(), Parcela
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
if (other is MangaItem) {
|
if (other is MigrationMangaItem) {
|
||||||
return manga.id == other.manga.id
|
return manga.id == other.manga.id
|
||||||
}
|
}
|
||||||
return false
|
return false
|
@ -23,9 +23,9 @@ class MigrationMangaPresenter(
|
|||||||
.subscribeLatestCache(MigrationMangaController::setManga)
|
.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 }
|
return library.filter { it.source == sourceId }
|
||||||
.sortedBy { it.title }
|
.sortedBy { it.title }
|
||||||
.map { MangaItem(it) }
|
.map { MigrationMangaItem(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user