From 9f3f981ab07fdf0813b860415949a459cc585a09 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Aug 2020 12:30:26 +0200 Subject: [PATCH] Use cached Views --- .../im/vector/app/core/preference/PushRulePreference.kt | 3 +-- .../app/core/preference/VectorEditTextPreference.kt | 2 +- .../im/vector/app/core/preference/VectorPreference.kt | 8 ++++---- .../app/core/preference/VectorPreferenceCategory.kt | 2 +- .../vector/app/core/preference/VectorSwitchPreference.kt | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/preference/PushRulePreference.kt b/vector/src/main/java/im/vector/app/core/preference/PushRulePreference.kt index 87584a9db0..9c4878ef06 100755 --- a/vector/src/main/java/im/vector/app/core/preference/PushRulePreference.kt +++ b/vector/src/main/java/im/vector/app/core/preference/PushRulePreference.kt @@ -20,7 +20,6 @@ import android.content.Context import android.util.AttributeSet import android.view.View import android.widget.RadioGroup -import android.widget.TextView import androidx.preference.PreferenceViewHolder import im.vector.app.R import org.matrix.android.sdk.api.pushrules.RuleSetKey @@ -162,7 +161,7 @@ class PushRulePreference : VectorPreference { override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) - holder.itemView.findViewById(android.R.id.summary)?.visibility = View.GONE + holder.findViewById(android.R.id.summary)?.visibility = View.GONE holder.itemView.setOnClickListener(null) holder.itemView.setOnLongClickListener(null) diff --git a/vector/src/main/java/im/vector/app/core/preference/VectorEditTextPreference.kt b/vector/src/main/java/im/vector/app/core/preference/VectorEditTextPreference.kt index 840e5fa510..348fcffc9b 100644 --- a/vector/src/main/java/im/vector/app/core/preference/VectorEditTextPreference.kt +++ b/vector/src/main/java/im/vector/app/core/preference/VectorEditTextPreference.kt @@ -45,7 +45,7 @@ class VectorEditTextPreference : EditTextPreference { override fun onBindViewHolder(holder: PreferenceViewHolder) { // display the title in multi-line to avoid ellipsis. try { - holder.itemView.findViewById(android.R.id.title)?.isSingleLine = false + (holder.findViewById(android.R.id.title) as? TextView)?.isSingleLine = false } catch (e: Exception) { Timber.e(e, "onBindView") } diff --git a/vector/src/main/java/im/vector/app/core/preference/VectorPreference.kt b/vector/src/main/java/im/vector/app/core/preference/VectorPreference.kt index 4a9bb6a6f5..dd887dba67 100755 --- a/vector/src/main/java/im/vector/app/core/preference/VectorPreference.kt +++ b/vector/src/main/java/im/vector/app/core/preference/VectorPreference.kt @@ -84,15 +84,15 @@ open class VectorPreference : Preference { // display the title in multi-line to avoid ellipsis. try { - val title = itemView.findViewById(android.R.id.title) - val summary = itemView.findViewById(android.R.id.summary) + val title = holder.findViewById(android.R.id.title) as? TextView + val summary = holder.findViewById(android.R.id.summary) as? TextView if (title != null) { title.isSingleLine = false title.setTypeface(null, mTypeface) } - if (title !== summary) { - summary.setTypeface(null, mTypeface) + summary?.setTypeface(null, mTypeface) + } // cancel existing animation (find a way to resume if happens during anim?) diff --git a/vector/src/main/java/im/vector/app/core/preference/VectorPreferenceCategory.kt b/vector/src/main/java/im/vector/app/core/preference/VectorPreferenceCategory.kt index e61cde8ebd..eb59da640d 100644 --- a/vector/src/main/java/im/vector/app/core/preference/VectorPreferenceCategory.kt +++ b/vector/src/main/java/im/vector/app/core/preference/VectorPreferenceCategory.kt @@ -45,7 +45,7 @@ class VectorPreferenceCategory : PreferenceCategory { override fun onBindViewHolder(holder: PreferenceViewHolder) { super.onBindViewHolder(holder) - val titleTextView = holder.itemView.findViewById(android.R.id.title) + val titleTextView = holder.findViewById(android.R.id.title) as? TextView titleTextView?.setTypeface(null, Typeface.BOLD) titleTextView?.setTextColor(ThemeUtils.getColor(context, R.attr.riotx_text_primary)) diff --git a/vector/src/main/java/im/vector/app/core/preference/VectorSwitchPreference.kt b/vector/src/main/java/im/vector/app/core/preference/VectorSwitchPreference.kt index c97991bfcb..346e8488b9 100644 --- a/vector/src/main/java/im/vector/app/core/preference/VectorSwitchPreference.kt +++ b/vector/src/main/java/im/vector/app/core/preference/VectorSwitchPreference.kt @@ -58,7 +58,7 @@ class VectorSwitchPreference : SwitchPreference { override fun onBindViewHolder(holder: PreferenceViewHolder) { // display the title in multi-line to avoid ellipsis. - holder.itemView.findViewById(android.R.id.title)?.isSingleLine = false + (holder.findViewById(android.R.id.title) as? TextView)?.isSingleLine = false // cancel existing animation (find a way to resume if happens during anim?) currentHighlightAnimator?.cancel()