Enable click to copy to clipboard in the more info
This commit is contained in:
parent
ef37811020
commit
525c3f84e4
@ -5,12 +5,20 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import eu.kanade.tachiyomi.databinding.MetadataViewItemBinding
|
||||
import eu.kanade.tachiyomi.util.system.copyToClipboard
|
||||
import kotlin.math.floor
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import reactivecircus.flowbinding.android.view.clicks
|
||||
|
||||
class MetadataViewAdapter(private var data: List<Pair<String, String>>) :
|
||||
RecyclerView.Adapter<MetadataViewAdapter.ViewHolder>() {
|
||||
|
||||
private lateinit var binding: MetadataViewItemBinding
|
||||
private val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MetadataViewAdapter.ViewHolder {
|
||||
binding = MetadataViewItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
@ -32,10 +40,32 @@ class MetadataViewAdapter(private var data: List<Pair<String, String>>) :
|
||||
|
||||
// stores and recycles views as they are scrolled off screen
|
||||
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
private var dataPosition: Int? = null
|
||||
fun bind(position: Int) {
|
||||
if (data.isEmpty()) return
|
||||
val dataPosition = floor(position / 2F).toInt()
|
||||
binding.infoText.text = if (position % 2 == 0) data[dataPosition].first else data[dataPosition].second
|
||||
if (data.isEmpty() || !binding.infoText.text.isNullOrBlank()) return
|
||||
dataPosition = floor(position / 2F).toInt()
|
||||
binding.infoText.text = if (position % 2 == 0) data[dataPosition!!].first else data[dataPosition!!].second
|
||||
binding.infoText.clicks()
|
||||
.onEach {
|
||||
itemView.context.copyToClipboard(data[dataPosition!!].second, data[dataPosition!!].second)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return dataPosition.hashCode() == other.hashCode()
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return dataPosition.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return super.equals(other)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return super.hashCode()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user