From 4e63e667881815d664c9dd4257a4240d65ceed36 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 12 Dec 2021 21:38:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/config/BackupConfigFragment.kt | 2 +- .../main/java/io/legado/app/ui/widget/prefs/Preference.kt | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index e1369a147..7d27e7596 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -123,7 +123,7 @@ class BackupConfigFragment : BasePreferenceFragment(), upPreferenceSummary(PreferKey.webDavPassword, getPrefString(PreferKey.webDavPassword)) upPreferenceSummary(PreferKey.backupPath, getPrefString(PreferKey.backupPath)) findPreference("web_dav_restore") - ?.onLongClick = { restoreDir.launch() } + ?.onLongClick { restoreDir.launch(); true } } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt index 42b83d0f9..1acc83afa 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/Preference.kt @@ -23,7 +23,7 @@ import kotlin.math.roundToInt class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Preference(context, attrs) { - var onLongClick: (() -> Unit)? = null + private var onLongClick: ((preference: Preference) -> Boolean)? = null private val isBottomBackground: Boolean init { @@ -117,8 +117,12 @@ class Preference(context: Context, attrs: AttributeSet) : ) super.onBindViewHolder(holder) holder.itemView.onLongClick { - onLongClick?.invoke() + onLongClick?.invoke(this) } } + fun onLongClick(listener: (preference: Preference) -> Boolean) { + onLongClick = listener + } + }