Fix more info crash
This commit is contained in:
parent
3b0523268a
commit
7ffe1794d9
@ -480,7 +480,6 @@ class MangaController :
|
|||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
destroyActionModeIfNeeded()
|
destroyActionModeIfNeeded()
|
||||||
binding.actionToolbar.destroy()
|
binding.actionToolbar.destroy()
|
||||||
mangaInfoAdapter?.onDestroyView()
|
|
||||||
mangaInfoAdapter = null
|
mangaInfoAdapter = null
|
||||||
chaptersHeaderAdapter = null
|
chaptersHeaderAdapter = null
|
||||||
chaptersAdapter = null
|
chaptersAdapter = null
|
||||||
|
@ -568,11 +568,4 @@ class MangaInfoHeaderAdapter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDestroyView() {
|
|
||||||
metaInfoAdapter = null
|
|
||||||
mangaTagsInfoAdapter = null
|
|
||||||
binding.metadataView.adapter = null
|
|
||||||
binding.genreGroups.adapter = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,53 +7,42 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import eu.kanade.tachiyomi.databinding.MetadataViewItemBinding
|
import eu.kanade.tachiyomi.databinding.MetadataViewItemBinding
|
||||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||||
|
|
||||||
class MetadataViewAdapter(private var data: List<Pair<String, String>>) :
|
class MetadataViewAdapter :
|
||||||
RecyclerView.Adapter<MetadataViewAdapter.ViewHolder>() {
|
RecyclerView.Adapter<MetadataViewAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private lateinit var binding: MetadataViewItemBinding
|
private lateinit var binding: MetadataViewItemBinding
|
||||||
|
|
||||||
|
var items: List<Pair<String, String>> = emptyList()
|
||||||
|
set(value) {
|
||||||
|
if (field !== value) {
|
||||||
|
field = value
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MetadataViewAdapter.ViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MetadataViewAdapter.ViewHolder {
|
||||||
binding = MetadataViewItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
binding = MetadataViewItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
return ViewHolder(binding.root)
|
return ViewHolder(binding.root)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun update(data: List<Pair<String, String>>) {
|
|
||||||
this.data = data
|
|
||||||
notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
// binds the data to the TextView in each cell
|
// binds the data to the TextView in each cell
|
||||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
holder.bind(position)
|
holder.bind(items[position].first, items[position].second)
|
||||||
}
|
}
|
||||||
|
|
||||||
// total number of cells
|
// total number of cells
|
||||||
override fun getItemCount(): Int = data.size
|
override fun getItemCount(): Int {
|
||||||
|
return items.size
|
||||||
|
}
|
||||||
|
|
||||||
// stores and recycles views as they are scrolled off screen
|
// stores and recycles views as they are scrolled off screen
|
||||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||||
fun bind(position: Int) {
|
fun bind(title: String, text: String) {
|
||||||
binding.infoTitle.text = data[position].first
|
binding.infoTitle.text = title
|
||||||
binding.infoText.text = data[position].second
|
binding.infoText.text = text
|
||||||
binding.infoText.setOnClickListener {
|
binding.infoText.setOnClickListener {
|
||||||
itemView.context.copyToClipboard(data[position].second, data[position].second)
|
itemView.context.copyToClipboard(title, text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
return binding.infoText.hashCode() == other.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return binding.infoText.hashCode()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
|
||||||
return super.equals(other)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
|
||||||
return super.hashCode()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,6 @@ class MetadataViewController : NucleusController<MetadataViewControllerBinding,
|
|||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
constructor(bundle: Bundle) : this(bundle.getLong(MangaController.MANGA_EXTRA))
|
constructor(bundle: Bundle) : this(bundle.getLong(MangaController.MANGA_EXTRA))
|
||||||
|
|
||||||
var data = emptyList<Pair<String, String>>()
|
|
||||||
|
|
||||||
var adapter: MetadataViewAdapter? = null
|
var adapter: MetadataViewAdapter? = null
|
||||||
|
|
||||||
var manga: Manga? = null
|
var manga: Manga? = null
|
||||||
@ -69,14 +67,14 @@ class MetadataViewController : NucleusController<MetadataViewControllerBinding,
|
|||||||
|
|
||||||
if (manga == null || source == null) return
|
if (manga == null || source == null) return
|
||||||
binding.recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.VERTICAL, false)
|
binding.recycler.layoutManager = LinearLayoutManager(view.context, LinearLayoutManager.VERTICAL, false)
|
||||||
adapter = MetadataViewAdapter(data)
|
adapter = MetadataViewAdapter()
|
||||||
binding.recycler.adapter = adapter
|
binding.recycler.adapter = adapter
|
||||||
binding.recycler.setHasFixedSize(true)
|
binding.recycler.setHasFixedSize(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onNextMangaInfo(meta: RaisedSearchMetadata?) {
|
fun onNextMangaInfo(meta: RaisedSearchMetadata?) {
|
||||||
|
val adapter = adapter ?: return
|
||||||
val context = view?.context ?: return
|
val context = view?.context ?: return
|
||||||
data = meta?.getExtraInfoPairs(context).orEmpty()
|
adapter.items = meta?.getExtraInfoPairs(context).orEmpty()
|
||||||
adapter?.update(data)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user