Fix bad color for settings icon on Android < 24 (#1786)

This commit is contained in:
Benoit Marty 2020-08-26 12:55:49 +02:00
parent 9f3f981ab0
commit 249f268fb5
3 changed files with 30 additions and 1 deletions

View File

@ -9,6 +9,7 @@ Improvements 🙌:
Bugfix 🐛: Bugfix 🐛:
- Display name not shown under Settings/General (#1926) - Display name not shown under Settings/General (#1926)
- Fix bad color for settings icon on Android < 24 (#1786)
Translations 🗣: Translations 🗣:
- -

View File

@ -20,12 +20,15 @@ import android.animation.Animator
import android.animation.ArgbEvaluator import android.animation.ArgbEvaluator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.graphics.Typeface import android.graphics.Typeface
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.core.animation.doOnEnd import androidx.core.animation.doOnEnd
import androidx.core.widget.ImageViewCompat
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder import androidx.preference.PreferenceViewHolder
import im.vector.app.R import im.vector.app.R
@ -76,6 +79,12 @@ open class VectorPreference : Preference {
notifyChanged() notifyChanged()
} }
var tintIcon = false
set(value) {
field = value
notifyChanged()
}
var currentHighlightAnimator: Animator? = null var currentHighlightAnimator: Animator? = null
override fun onBindViewHolder(holder: PreferenceViewHolder) { override fun onBindViewHolder(holder: PreferenceViewHolder) {
@ -93,6 +102,14 @@ open class VectorPreference : Preference {
summary?.setTypeface(null, mTypeface) summary?.setTypeface(null, mTypeface)
if (tintIcon) {
// Tint icons (See #1786)
val icon = holder.findViewById(android.R.id.icon) as? ImageView
icon?.let {
val color = ThemeUtils.getColor(context, R.attr.riotx_header_panel_text_secondary)
ImageViewCompat.setImageTintList(it, ColorStateList.valueOf(color))
}
} }
// cancel existing animation (find a way to resume if happens during anim?) // cancel existing animation (find a way to resume if happens during anim?)

View File

@ -16,7 +16,9 @@
package im.vector.app.features.settings package im.vector.app.features.settings
import android.os.Build
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.preference.VectorPreference
import javax.inject.Inject import javax.inject.Inject
class VectorSettingsRootFragment @Inject constructor() : VectorSettingsBaseFragment() { class VectorSettingsRootFragment @Inject constructor() : VectorSettingsBaseFragment() {
@ -25,6 +27,15 @@ class VectorSettingsRootFragment @Inject constructor() : VectorSettingsBaseFragm
override val preferenceXmlRes = R.xml.vector_settings_root override val preferenceXmlRes = R.xml.vector_settings_root
override fun bindPref() { override fun bindPref() {
// Nothing to do // Tint icon on API < 24
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
tintIcons()
}
}
private fun tintIcons() {
for (i in 0 until preferenceScreen.preferenceCount) {
(preferenceScreen.getPreference(i) as? VectorPreference)?.let { it.tintIcon = true }
}
} }
} }