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 + } + }