From 9a1bb6f6fce3c43a2940e6570f48e6ed30a565b7 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 9 Jul 2025 21:57:37 +0300 Subject: [PATCH] Fix long tap on old Android versions (close #1478) --- .../kotlin/org/koitharu/kotatsu/core/util/ext/View.kt | 10 +++++++++- .../org/koitharu/kotatsu/details/ui/DetailsActivity.kt | 3 ++- .../kotatsu/details/ui/adapter/ChapterGridItemAD.kt | 4 ++-- .../explore/ui/adapter/ExploreAdapterDelegates.kt | 4 ++-- .../kotatsu/list/ui/adapter/MangaGridItemAD.kt | 4 ++-- .../kotatsu/list/ui/adapter/MangaListItemAD.kt | 3 ++- .../koitharu/kotatsu/reader/ui/ReaderActionsView.kt | 3 ++- .../suggestion/adapter/SearchSuggestionsMangaListAD.kt | 3 ++- .../settings/storage/directories/DirectoryConfigAD.kt | 4 ++-- 9 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt index c1614396d..7f57f9a6b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/View.kt @@ -175,6 +175,14 @@ fun View.setOnContextClickListenerCompat(listener: OnContextClickListenerCompat) } } +fun View.setTooltipCompat(tooltip: CharSequence?) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + tooltipText = tooltip + } else if (!isLongClickable) { // don't use TooltipCompat if has a LongClickListener + TooltipCompat.setTooltipText(this, tooltip) + } +} + val Toolbar.menuView: ActionMenuView? get() { menu // to call ensureMenu() @@ -201,7 +209,7 @@ fun Chip.setProgressIcon() { fun View.setContentDescriptionAndTooltip(@StringRes resId: Int) { val text = resources.getString(resId) contentDescription = text - TooltipCompat.setTooltipText(this, text) + setTooltipCompat(text) } fun View.getWindowBounds(): Rect { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 38e4c3640..dcf001519 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -80,6 +80,7 @@ import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.core.util.ext.parentView +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.core.util.ext.start import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.core.util.ext.toUriOrNull @@ -455,7 +456,7 @@ class DetailsActivity : textViewSourceLabel.isVisible = false } else { textViewSource.textAndVisible = manga.source.getTitle(this@DetailsActivity) - TooltipCompat.setTooltipText(textViewSource, manga.source.getSummary(this@DetailsActivity)) + textViewSource.setTooltipCompat(manga.source.getSummary(this@DetailsActivity)) textViewSourceLabel.isVisible = textViewSource.isVisible == true } val faviconPlaceholderFactory = FaviconDrawable.Factory(R.style.FaviconDrawable_Chip) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterGridItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterGridItemAD.kt index 4bfc7b0d2..4d4092e4b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterGridItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/adapter/ChapterGridItemAD.kt @@ -1,12 +1,12 @@ package org.koitharu.kotatsu.details.ui.adapter import android.graphics.Typeface -import androidx.appcompat.widget.TooltipCompat import androidx.core.view.isVisible import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.ext.getThemeColorStateList +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.databinding.ItemChapterGridBinding import org.koitharu.kotatsu.details.ui.model.ChapterListItem import org.koitharu.kotatsu.list.ui.model.ListModel @@ -23,7 +23,7 @@ fun chapterGridItemAD( bind { payloads -> if (payloads.isEmpty()) { binding.textViewTitle.text = item.chapter.numberString() ?: "?" - TooltipCompat.setTooltipText(itemView, item.chapter.title) + itemView.setTooltipCompat(item.chapter.title) } binding.imageViewNew.isVisible = item.isNew binding.imageViewCurrent.isVisible = item.isCurrent diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/adapter/ExploreAdapterDelegates.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/adapter/ExploreAdapterDelegates.kt index c55797c4a..bbb115658 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/adapter/ExploreAdapterDelegates.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/ui/adapter/ExploreAdapterDelegates.kt @@ -15,6 +15,7 @@ import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.ext.drawableStart import org.koitharu.kotatsu.core.util.ext.recyclerView import org.koitharu.kotatsu.core.util.ext.setProgressIcon +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.databinding.ItemExploreButtonsBinding import org.koitharu.kotatsu.databinding.ItemExploreSourceGridBinding @@ -126,8 +127,7 @@ fun exploreSourceGridItemAD( bind { val title = item.source.getTitle(context) - TooltipCompat.setTooltipText( - itemView, + itemView.setTooltipCompat( buildSpannedString { bold { append(title) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaGridItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaGridItemAD.kt index 9a9944c98..9d732099b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaGridItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaGridItemAD.kt @@ -1,11 +1,11 @@ package org.koitharu.kotatsu.list.ui.adapter -import androidx.appcompat.widget.TooltipCompat import androidx.core.view.isVisible import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.databinding.ItemMangaGridBinding import org.koitharu.kotatsu.list.ui.ListModelDiffCallback.Companion.PAYLOAD_PROGRESS_CHANGED import org.koitharu.kotatsu.list.ui.model.ListModel @@ -24,7 +24,7 @@ fun mangaGridItemAD( sizeResolver.attachToView(itemView, binding.textViewTitle, binding.progressView) bind { payloads -> - TooltipCompat.setTooltipText(itemView, item.getSummary(context)) + itemView.setTooltipCompat(item.getSummary(context)) binding.textViewTitle.text = item.title binding.progressView.setProgress(item.progress, PAYLOAD_PROGRESS_CHANGED in payloads) with(binding.iconsView) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaListItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaListItemAD.kt index 5c7649dbe..8fcdab05a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaListItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/adapter/MangaListItemAD.kt @@ -5,6 +5,7 @@ import androidx.core.view.isVisible import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.databinding.ItemMangaListBinding import org.koitharu.kotatsu.list.ui.model.ListModel @@ -20,7 +21,7 @@ fun mangaListItemAD( AdapterDelegateClickListenerAdapter(this, clickListener, MangaCompactListModel::manga).attach(itemView) bind { - TooltipCompat.setTooltipText(itemView, item.getSummary(context)) + itemView.setTooltipCompat(item.getSummary(context)) binding.textViewTitle.text = item.title binding.textViewSubtitle.textAndVisible = item.subtitle binding.imageViewCover.setImageAsync(item.coverUrl, item.manga) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActionsView.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActionsView.kt index f51b91c6b..1f2250cad 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActionsView.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActionsView.kt @@ -24,6 +24,7 @@ import org.koitharu.kotatsu.core.prefs.ReaderControl import org.koitharu.kotatsu.core.util.ext.hasVisibleChildren import org.koitharu.kotatsu.core.util.ext.isRtl import org.koitharu.kotatsu.core.util.ext.setContentDescriptionAndTooltip +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.core.util.ext.setValueRounded import org.koitharu.kotatsu.databinding.LayoutReaderActionsBinding import org.koitharu.kotatsu.details.ui.pager.ChaptersPagesSheet @@ -254,7 +255,7 @@ class ReaderActionsView @JvmOverloads constructor( private fun Button.initAction() { setOnClickListener(this@ReaderActionsView) setOnLongClickListener(this@ReaderActionsView) - TooltipCompat.setTooltipText(this, contentDescription) + setTooltipCompat(contentDescription) } private fun isAutoRotationEnabled(): Boolean = Settings.System.getInt( diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionsMangaListAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionsMangaListAD.kt index 6bbd0489a..1a1452d39 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionsMangaListAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/search/ui/suggestion/adapter/SearchSuggestionsMangaListAD.kt @@ -10,6 +10,7 @@ import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.list.decor.SpacingItemDecoration import org.koitharu.kotatsu.core.util.RecyclerViewScrollCallback +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.databinding.ItemSearchSuggestionMangaGridBinding import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.search.ui.suggestion.SearchSuggestionListener @@ -47,7 +48,7 @@ private fun searchSuggestionMangaGridAD( } bind { - TooltipCompat.setTooltipText(itemView, item.title) + itemView.setTooltipCompat(item.title) binding.imageViewCover.setImageAsync(item.coverUrl, item.source) binding.textViewTitle.text = item.title } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/DirectoryConfigAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/DirectoryConfigAD.kt index 4b6f16c9e..57c6f9fca 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/DirectoryConfigAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/storage/directories/DirectoryConfigAD.kt @@ -1,12 +1,12 @@ package org.koitharu.kotatsu.settings.storage.directories -import androidx.appcompat.widget.TooltipCompat import androidx.core.content.ContextCompat import androidx.core.view.isVisible import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.ext.drawableStart +import org.koitharu.kotatsu.core.util.ext.setTooltipCompat import org.koitharu.kotatsu.core.util.ext.textAndVisible import org.koitharu.kotatsu.databinding.ItemStorageConfigBinding import org.koitharu.kotatsu.settings.storage.DirectoryModel @@ -18,7 +18,7 @@ fun directoryConfigAD( ) { binding.buttonRemove.setOnClickListener { v -> clickListener.onItemClick(item, v) } - TooltipCompat.setTooltipText(binding.buttonRemove, binding.buttonRemove.contentDescription) + binding.buttonRemove.setTooltipCompat(binding.buttonRemove.contentDescription) bind { binding.textViewTitle.text = item.title ?: getString(item.titleRes)