Skip to content

Commit

Permalink
[bug] [Graphics] Initial click on Color button changes current color
Browse files Browse the repository at this point in the history
  • Loading branch information
tuancoltech committed Jul 15, 2024
1 parent eb976f4 commit 4b65f08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.arkbuilders.arkmemo.graphics

object ColorCode {
internal object ColorCode {
val black by lazy { android.graphics.Color.parseColor("#000000") }
val gray by lazy { android.graphics.Color.parseColor("#667085") }
val red by lazy { android.graphics.Color.parseColor("#F04438") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.util.AttributeSet
import androidx.annotation.ColorInt
import androidx.core.content.ContextCompat
import androidx.core.widget.TextViewCompat
import dev.arkbuilders.arkmemo.R
Expand Down Expand Up @@ -41,10 +42,7 @@ class GraphicControlTextView @JvmOverloads constructor(
val selectedColor = ContextCompat.getColor(context, R.color.warning_700)

this.setTextColor(selectedColor)
TextViewCompat.setCompoundDrawableTintList(
this,
ColorStateList.valueOf(selectedColor)
)
setDrawableTint(selectedColor)
} else {
this.background = ContextCompat.getDrawable(
context, R.drawable.bg_border_r8
Expand All @@ -53,12 +51,17 @@ class GraphicControlTextView @JvmOverloads constructor(
val drawableColor = if (iconTintColor != -1) iconTintColor else selectedColor

this.setTextColor(selectedColor)
TextViewCompat.setCompoundDrawableTintList(
this,
ColorStateList.valueOf(drawableColor)
)
setDrawableTint(drawableColor)
}

isSelectedState = selected
}

private fun setDrawableTint(@ColorInt color: Int) {
if (iconTintColor == -1) {
TextViewCompat.setCompoundDrawableTintList(this,
ColorStateList.valueOf(color)
)
}
}
}

0 comments on commit 4b65f08

Please sign in to comment.