diff --git a/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt b/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt index c45542df..ccfd1f99 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt @@ -19,7 +19,9 @@ package com.moez.QKSMS.common.util import android.graphics.Typeface +import android.os.Build import android.util.AttributeSet +import android.widget.EditText import android.widget.TextView import com.moez.QKSMS.R import com.moez.QKSMS.common.util.TextViewStyler.Companion.SIZE_PRIMARY @@ -32,6 +34,8 @@ import com.moez.QKSMS.common.widget.QkTextView import com.moez.QKSMS.util.Preferences import javax.inject.Inject + + class TextViewStyler @Inject constructor( private val prefs: Preferences, private val colors: Colors, @@ -93,40 +97,45 @@ class TextViewStyler @Inject constructor( } fun applyAttributes(textView: TextView, attrs: AttributeSet?) { - textView.run { - var colorAttr = 0 - var textSizeAttr = 0 + var colorAttr = 0 + var textSizeAttr = 0 - if (!prefs.systemFont.get()) { - fontProvider.getLato { lato -> - setTypeface(lato, typeface?.style ?: Typeface.NORMAL) - } + if (!prefs.systemFont.get()) { + fontProvider.getLato { lato -> + textView.setTypeface(lato, textView.typeface?.style ?: Typeface.NORMAL) + } + } + + when (textView) { + is QkTextView -> textView.context.obtainStyledAttributes(attrs, R.styleable.QkTextView).run { + colorAttr = getInt(R.styleable.QkTextView_textColor, -1) + textSizeAttr = getInt(R.styleable.QkTextView_textSize, -1) + recycle() } - 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 + is QkEditText -> textView.context.obtainStyledAttributes(attrs, R.styleable.QkEditText).run { + colorAttr = getInt(R.styleable.QkEditText_textColor, -1) + textSizeAttr = getInt(R.styleable.QkEditText_textSize, -1) + recycle() } - when (colorAttr) { - COLOR_THEME -> setTextColor(colors.theme().theme) - COLOR_PRIMARY_ON_THEME -> setTextColor(colors.theme().textPrimary) - COLOR_SECONDARY_ON_THEME -> setTextColor(colors.theme().textSecondary) - COLOR_TERTIARY_ON_THEME -> setTextColor(colors.theme().textTertiary) - } + else -> return + } - setTextSize(textView, textSizeAttr) + when (colorAttr) { + COLOR_THEME -> textView.setTextColor(colors.theme().theme) + COLOR_PRIMARY_ON_THEME -> textView.setTextColor(colors.theme().textPrimary) + COLOR_SECONDARY_ON_THEME -> textView.setTextColor(colors.theme().textSecondary) + COLOR_TERTIARY_ON_THEME -> textView.setTextColor(colors.theme().textTertiary) + } + + setTextSize(textView, textSizeAttr) + + if (textView is EditText) { + val drawable = textView.resources.getDrawable(R.drawable.cursor).apply { setTint(colors.theme().theme) } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + textView.textCursorDrawable = drawable + } } } diff --git a/presentation/src/main/res/drawable/cursor.xml b/presentation/src/main/res/drawable/cursor.xml new file mode 100644 index 00000000..3d6e9310 --- /dev/null +++ b/presentation/src/main/res/drawable/cursor.xml @@ -0,0 +1,24 @@ + + + + + +