mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-23 06:08:52 +01:00
Fix EditMode preview for QkTextView and QkEditTextView
This commit is contained in:
@@ -22,6 +22,10 @@ import android.graphics.Typeface
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
|
import common.util.TextViewStyler.Companion.SIZE_PRIMARY
|
||||||
|
import common.util.TextViewStyler.Companion.SIZE_SECONDARY
|
||||||
|
import common.util.TextViewStyler.Companion.SIZE_TERTIARY
|
||||||
|
import common.util.TextViewStyler.Companion.SIZE_TOOLBAR
|
||||||
import common.util.extensions.getColorCompat
|
import common.util.extensions.getColorCompat
|
||||||
import common.util.extensions.resolveThemeColor
|
import common.util.extensions.resolveThemeColor
|
||||||
import common.widget.QkEditText
|
import common.widget.QkEditText
|
||||||
@@ -48,72 +52,91 @@ class TextViewStyler @Inject constructor(
|
|||||||
const val SIZE_SECONDARY = 1
|
const val SIZE_SECONDARY = 1
|
||||||
const val SIZE_TERTIARY = 2
|
const val SIZE_TERTIARY = 2
|
||||||
const val SIZE_TOOLBAR = 3
|
const val SIZE_TOOLBAR = 3
|
||||||
}
|
|
||||||
|
|
||||||
fun applyAttributes(textView: TextView, attrs: AttributeSet?) {
|
fun applyEditModeAttributes(textView: TextView, attrs: AttributeSet?) {
|
||||||
textView.run {
|
textView.run {
|
||||||
when (this) {
|
var colorAttr = 0
|
||||||
is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
var textSizeAttr = 0
|
||||||
val colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
|
||||||
val textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
when (this) {
|
||||||
applyAttributes(textView, colorAttr, textSizeAttr)
|
is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||||
recycle()
|
colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||||
|
textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||||
|
recycle()
|
||||||
|
}
|
||||||
|
|
||||||
|
is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||||
|
colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
||||||
|
textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
||||||
|
recycle()
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> return
|
||||||
}
|
}
|
||||||
|
setTextColor(when (colorAttr) {
|
||||||
is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
COLOR_PRIMARY -> context.getColorCompat(R.color.textPrimary)
|
||||||
val colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
COLOR_SECONDARY -> context.getColorCompat(R.color.textSecondary)
|
||||||
val textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
COLOR_TERTIARY -> context.getColorCompat(R.color.textTertiary)
|
||||||
applyAttributes(textView, colorAttr, textSizeAttr)
|
COLOR_PRIMARY_ON_THEME -> context.getColorCompat(R.color.textPrimaryDark)
|
||||||
recycle()
|
COLOR_SECONDARY_ON_THEME -> context.getColorCompat(R.color.textSecondaryDark)
|
||||||
}
|
COLOR_TERTIARY_ON_THEME -> context.getColorCompat(R.color.textTertiaryDark)
|
||||||
}
|
COLOR_THEME -> context.getColorCompat(R.color.tools_theme)
|
||||||
|
else -> currentTextColor
|
||||||
if (!prefs.systemFont.get()) {
|
})
|
||||||
fontProvider.getLato { lato ->
|
|
||||||
setTypeface(lato, typeface?.style ?: Typeface.NORMAL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun applyAttributes(textView: TextView, colorAttr: Int, textSizeAttr: Int) {
|
|
||||||
textView.run {
|
|
||||||
if (isInEditMode) {
|
|
||||||
setTextColor(context.getColorCompat(when (colorAttr) {
|
|
||||||
COLOR_PRIMARY -> R.color.textPrimary
|
|
||||||
COLOR_SECONDARY -> R.color.textSecondary
|
|
||||||
COLOR_TERTIARY -> R.color.textTertiary
|
|
||||||
COLOR_PRIMARY_ON_THEME -> R.color.textPrimaryDark
|
|
||||||
COLOR_SECONDARY_ON_THEME -> R.color.textSecondaryDark
|
|
||||||
COLOR_TERTIARY_ON_THEME -> R.color.textTertiaryDark
|
|
||||||
COLOR_THEME -> R.color.tools_theme
|
|
||||||
else -> R.color.textPrimary
|
|
||||||
}))
|
|
||||||
|
|
||||||
textSize = when (textSizeAttr) {
|
textSize = when (textSizeAttr) {
|
||||||
SIZE_PRIMARY -> 16f
|
SIZE_PRIMARY -> 16f
|
||||||
SIZE_SECONDARY -> 14f
|
SIZE_SECONDARY -> 14f
|
||||||
SIZE_TERTIARY -> 12f
|
SIZE_TERTIARY -> 12f
|
||||||
SIZE_TOOLBAR -> 20f
|
SIZE_TOOLBAR -> 20f
|
||||||
else -> textSize
|
else -> textSize / paint.density
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
setTextColor(when (colorAttr) {
|
|
||||||
COLOR_PRIMARY -> context.resolveThemeColor(android.R.attr.textColorPrimary)
|
|
||||||
COLOR_SECONDARY -> context.resolveThemeColor(android.R.attr.textColorSecondary)
|
|
||||||
COLOR_TERTIARY -> context.resolveThemeColor(android.R.attr.textColorTertiary)
|
|
||||||
COLOR_PRIMARY_ON_THEME -> colors.theme().textPrimary
|
|
||||||
COLOR_SECONDARY_ON_THEME -> colors.theme().textSecondary
|
|
||||||
COLOR_TERTIARY_ON_THEME -> colors.theme().textTertiary
|
|
||||||
COLOR_THEME -> colors.theme().theme
|
|
||||||
else -> currentTextColor
|
|
||||||
})
|
|
||||||
|
|
||||||
setTextSize(textView, textSizeAttr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun applyAttributes(textView: TextView, attrs: AttributeSet?) {
|
||||||
|
textView.run {
|
||||||
|
var colorAttr = 0
|
||||||
|
var textSizeAttr = 0
|
||||||
|
|
||||||
|
if (!prefs.systemFont.get()) {
|
||||||
|
fontProvider.getLato { lato ->
|
||||||
|
setTypeface(lato, typeface?.style ?: Typeface.NORMAL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
when (this) {
|
||||||
|
is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
|
||||||
|
colorAttr = getInt(R.styleable.QkTextView_textColor, -1)
|
||||||
|
textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1)
|
||||||
|
recycle()
|
||||||
|
}
|
||||||
|
|
||||||
|
is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
|
||||||
|
colorAttr = getInt(R.styleable.QkEditText_textColor, -1)
|
||||||
|
textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1)
|
||||||
|
recycle()
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
|
|
||||||
|
setTextColor(when (colorAttr) {
|
||||||
|
COLOR_PRIMARY -> context.resolveThemeColor(android.R.attr.textColorPrimary)
|
||||||
|
COLOR_SECONDARY -> context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||||
|
COLOR_TERTIARY -> context.resolveThemeColor(android.R.attr.textColorTertiary)
|
||||||
|
COLOR_PRIMARY_ON_THEME -> colors.theme().textPrimary
|
||||||
|
COLOR_SECONDARY_ON_THEME -> colors.theme().textSecondary
|
||||||
|
COLOR_TERTIARY_ON_THEME -> colors.theme().textTertiary
|
||||||
|
COLOR_THEME -> colors.theme().theme
|
||||||
|
else -> currentTextColor
|
||||||
|
})
|
||||||
|
|
||||||
|
setTextSize(textView, textSizeAttr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see SIZE_PRIMARY
|
* @see SIZE_PRIMARY
|
||||||
* @see SIZE_SECONDARY
|
* @see SIZE_SECONDARY
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet
|
|||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
textViewStyler.applyAttributes(this, attrs)
|
textViewStyler.applyAttributes(this, attrs)
|
||||||
|
} else {
|
||||||
|
TextViewStyler.applyEditModeAttributes(this, attrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ open class QkTextView @JvmOverloads constructor(context: Context, attrs: Attribu
|
|||||||
if (!isInEditMode) {
|
if (!isInEditMode) {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
textViewStyler.applyAttributes(this, attrs)
|
textViewStyler.applyAttributes(this, attrs)
|
||||||
|
} else {
|
||||||
|
TextViewStyler.applyEditModeAttributes(this, attrs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user