Skip to content

Commit

Permalink
Fix toolbar color button not updated when cursor change
Browse files Browse the repository at this point in the history
  • Loading branch information
starshipcoder committed Jun 17, 2021
1 parent bd6aa80 commit 51e7d49
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions aztec/src/main/kotlin/org/wordpress/aztec/toolbar/AztecToolbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {

editor.setSpanColor(color)
colorPickerView?.setColor(color)
updateToolbarColorButton(color)
}
})

Expand All @@ -407,16 +408,7 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
this.colorPickerView = colorPickerView
colorPickerView.setColorPickerListener(object : ColorPickerListener {
override fun onPickColor(color: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
findViewById<View>(ToolbarAction.TEXTCOLOR.buttonId).apply {
when (this) {
is ImageButton -> {
this.imageTintList = ColorStateList.valueOf(color)
}
else -> this.setBackgroundColor(color)
}
}
}
updateToolbarColorButton(color)

editor?.let {

Expand Down Expand Up @@ -458,6 +450,18 @@ class AztecToolbar : FrameLayout, IAztecToolbar, OnMenuItemClickListener {
})
}

private fun updateToolbarColorButton(color: Int?) {
val color2 = color ?: Color.BLACK
findViewById<View>(ToolbarAction.TEXTCOLOR.buttonId).apply {
when (this) {
is ImageButton -> {
this.imageTintList = ColorStateList.valueOf(color2)
}
else -> this.setBackgroundColor(color2)
}
}
}

private fun initView(attrs: AttributeSet?) {
val styles = context.obtainStyledAttributes(attrs, R.styleable.AztecToolbar, 0, R.style.AztecToolbarStyle)
isAdvanced = styles.getBoolean(R.styleable.AztecToolbar_advanced, false)
Expand Down

0 comments on commit 51e7d49

Please sign in to comment.