Fix compilation error after bump preference-ktx from 1.1.1 to 1.2.0

This commit is contained in:
Benoit Marty 2022-05-10 15:00:44 +02:00
parent 48c126515c
commit 5ad2567633
5 changed files with 14 additions and 11 deletions

View file

@ -30,6 +30,11 @@ inline fun <T> T.ooi(block: (T) -> Unit): T = also(block)
*/
fun CharSequence.isEmail() = Patterns.EMAIL_ADDRESS.matcher(this).matches()
/**
* Return empty CharSequence if the CharSequence is null
*/
fun CharSequence?.orEmpty() = this ?: ""
/**
* Check if a CharSequence is a phone number
*/

View file

@ -33,6 +33,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import im.vector.app.R
import im.vector.app.features.themes.ThemeUtils
import org.matrix.android.sdk.api.extensions.orFalse
import timber.log.Timber
/**
@ -152,16 +153,12 @@ open class VectorPreference : Preference {
*/
private fun addClickListeners(view: View) {
view.setOnLongClickListener {
if (null != onPreferenceLongClickListener) {
onPreferenceLongClickListener!!.onPreferenceLongClick(this@VectorPreference)
} else false
onPreferenceLongClickListener?.onPreferenceLongClick(this@VectorPreference).orFalse()
}
view.setOnClickListener {
// call only the click listener
if (onPreferenceClickListener != null) {
onPreferenceClickListener.onPreferenceClick(this@VectorPreference)
}
onPreferenceClickListener?.onPreferenceClick(this@VectorPreference)
}
}
}

View file

@ -20,6 +20,7 @@ import android.os.Bundle
import androidx.preference.Preference
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.extensions.orEmpty
import im.vector.app.core.preference.VectorPreference
import im.vector.app.core.utils.FirstThrottler
import im.vector.app.core.utils.copyToClipboard
@ -72,7 +73,7 @@ class VectorSettingsHelpAboutFragment @Inject constructor(
}
it.setOnPreferenceClickListener { pref ->
copyToClipboard(requireContext(), pref.summary)
copyToClipboard(requireContext(), pref.summary.orEmpty())
true
}
}
@ -82,7 +83,7 @@ class VectorSettingsHelpAboutFragment @Inject constructor(
it.summary = Matrix.getSdkVersion()
it.setOnPreferenceClickListener { pref ->
copyToClipboard(requireContext(), pref.summary)
copyToClipboard(requireContext(), pref.summary.orEmpty())
true
}
}

View file

@ -151,7 +151,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
findPreference<VectorSwitchPreference>("SETTINGS_USER_ANALYTICS_CONSENT_KEY")!!
}
override fun onCreateRecyclerView(inflater: LayoutInflater?, parent: ViewGroup?, savedInstanceState: Bundle?): RecyclerView {
override fun onCreateRecyclerView(inflater: LayoutInflater, parent: ViewGroup, savedInstanceState: Bundle?): RecyclerView {
return super.onCreateRecyclerView(inflater, parent, savedInstanceState).also {
// Insert animation are really annoying the first time the list is shown
// due to the way preference fragment is done, it's not trivial to disable it for first appearance only..

View file

@ -352,8 +352,8 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor(
super.onDetach()
}
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
return when (preference?.key) {
override fun onPreferenceTreeClick(preference: Preference): Boolean {
return when (preference.key) {
VectorPreferences.SETTINGS_ENABLE_ALL_NOTIF_PREFERENCE_KEY -> {
updateEnabledForAccount(preference)
true