mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 02:49:18 +01:00
Add ability to copy a genre/tag to clipboard by long-pressing it's chip (#6084)
* Allow copying a genre by long-pressing it's chip * Make chip click listeners nullable, and only attach if not-null
This commit is contained in:
parent
bb06895145
commit
2c76bc99fc
@ -167,17 +167,20 @@ inline fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView):
|
|||||||
*
|
*
|
||||||
* @param items List of strings that are shown as individual chips.
|
* @param items List of strings that are shown as individual chips.
|
||||||
* @param onClick Optional on click listener for each chip.
|
* @param onClick Optional on click listener for each chip.
|
||||||
|
* @param onLongClick Optional on long click listener for each chip.
|
||||||
*/
|
*/
|
||||||
inline fun ChipGroup.setChips(
|
inline fun ChipGroup.setChips(
|
||||||
items: List<String>?,
|
items: List<String>?,
|
||||||
noinline onClick: (item: String) -> Unit = {}
|
noinline onClick: ((item: String) -> Unit)? = null,
|
||||||
|
noinline onLongClick: ((item: String) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
removeAllViews()
|
removeAllViews()
|
||||||
|
|
||||||
items?.forEach { item ->
|
items?.forEach { item ->
|
||||||
val chip = Chip(context).apply {
|
val chip = Chip(context).apply {
|
||||||
text = item
|
text = item
|
||||||
setOnClickListener { onClick(item) }
|
if (onClick != null) { setOnClickListener { onClick(item) } }
|
||||||
|
if (onLongClick != null) { setOnLongClickListener { onLongClick(item); true } }
|
||||||
}
|
}
|
||||||
|
|
||||||
addView(chip)
|
addView(chip)
|
||||||
|
@ -64,8 +64,9 @@ class MangaSummaryView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun setTags(items: List<String>?, onClick: (item: String) -> Unit) {
|
fun setTags(items: List<String>?, onClick: (item: String) -> Unit) {
|
||||||
binding.tagChipsShrunk.setChips(items, onClick)
|
listOfNotNull(binding.tagChipsShrunk, binding.tagChipsExpanded).forEach { chips ->
|
||||||
binding.tagChipsExpanded.setChips(items, onClick)
|
chips.setChips(items, onClick) { tag -> context.copyToClipboard(tag, tag) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateExpandState() = binding.apply {
|
private fun updateExpandState() = binding.apply {
|
||||||
|
Loading…
Reference in New Issue
Block a user