Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2526fde6 authored by moezbhatti's avatar moezbhatti
Browse files

Use theme colour for cursor

Fixes #888
parent 4d80e35c
Loading
Loading
Loading
Loading
+36 −27
Original line number Diff line number Diff line
@@ -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,24 +97,23 @@ class TextViewStyler @Inject constructor(
    }

    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)
                textView.setTypeface(lato, textView.typeface?.style ?: Typeface.NORMAL)
            }
        }

            when (this) {
                is QkTextView -> context.obtainStyledAttributes(attrs, R.styleable.QkTextView)?.run {
        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()
            }

                is QkEditText -> context.obtainStyledAttributes(attrs, R.styleable.QkEditText)?.run {
            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()
@@ -120,13 +123,19 @@ class TextViewStyler @Inject constructor(
        }

        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)
            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
            }
        }
    }

+24 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2019 Moez Bhatti <moez.bhatti@gmail.com>
  ~
  ~ This file is part of QKSMS.
  ~
  ~ QKSMS is free software: you can redistribute it and/or modify
  ~ it under the terms of the GNU General Public License as published by
  ~ the Free Software Foundation, either version 3 of the License, or
  ~ (at your option) any later version.
  ~
  ~ QKSMS is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ~ GNU General Public License for more details.
  ~
  ~ You should have received a copy of the GNU General Public License
  ~ along with QKSMS.  If not, see <http://www.gnu.org/licenses/>.
  -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/white" />
    <size android:width="2dp" />
</shape>