From 2c76bc99fc86005e91b6279c2ea1aa55a8e038b7 Mon Sep 17 00:00:00 2001 From: Hunter Nickel Date: Wed, 13 Oct 2021 07:23:59 -0600 Subject: [PATCH] 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 --- .../java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt | 7 +++++-- .../java/eu/kanade/tachiyomi/widget/MangaSummaryView.kt | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index b79e783dd..12b95d761 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -167,17 +167,20 @@ inline fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView): * * @param items List of strings that are shown as individual chips. * @param onClick Optional on click listener for each chip. + * @param onLongClick Optional on long click listener for each chip. */ inline fun ChipGroup.setChips( items: List?, - noinline onClick: (item: String) -> Unit = {} + noinline onClick: ((item: String) -> Unit)? = null, + noinline onLongClick: ((item: String) -> Unit)? = null ) { removeAllViews() items?.forEach { item -> val chip = Chip(context).apply { text = item - setOnClickListener { onClick(item) } + if (onClick != null) { setOnClickListener { onClick(item) } } + if (onLongClick != null) { setOnLongClickListener { onLongClick(item); true } } } addView(chip) diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/MangaSummaryView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/MangaSummaryView.kt index d16b814d5..39adc161c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/MangaSummaryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/MangaSummaryView.kt @@ -64,8 +64,9 @@ class MangaSummaryView @JvmOverloads constructor( } fun setTags(items: List?, onClick: (item: String) -> Unit) { - binding.tagChipsShrunk.setChips(items, onClick) - binding.tagChipsExpanded.setChips(items, onClick) + listOfNotNull(binding.tagChipsShrunk, binding.tagChipsExpanded).forEach { chips -> + chips.setChips(items, onClick) { tag -> context.copyToClipboard(tag, tag) } + } } private fun updateExpandState() = binding.apply {