Skip to content

Commit

Permalink
Override select state property for GraphicControlTextView instead of …
Browse files Browse the repository at this point in the history
…re-implementing it.
  • Loading branch information
tuancoltech committed Aug 19, 2024
1 parent 15bde02 commit 044f267
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ class EditGraphicNotesFragment: BaseEditNoteFragment() {
private fun initBottomControls() {
val tvBrushSize = binding.layoutGraphicsControl.tvBrushSize
tvBrushSize.setOnClickListener {
tvBrushSize.setSelectState(!tvBrushSize.isSelectedState)
if (tvBrushSize.isSelectedState) {
tvBrushSize.isSelected = !tvBrushSize.isSelected
if (tvBrushSize.isSelected) {
binding.layoutGraphicsControl.layoutSizeChooser.root.visible()
showBrushSizeList()
binding.layoutGraphicsControl.layoutColorChooser.root.gone()
binding.layoutGraphicsControl.tvEraser.setSelectState(false)
binding.layoutGraphicsControl.tvBrushColor.setSelectState(false)
binding.layoutGraphicsControl.tvEraser.isSelected = false
binding.layoutGraphicsControl.tvBrushColor.isSelected = false
graphicNotesViewModel.setEraseMode(false)
} else {
binding.layoutGraphicsControl.layoutSizeChooser.root.gone()
Expand All @@ -175,29 +175,29 @@ class EditGraphicNotesFragment: BaseEditNoteFragment() {

val tvEraser = binding.layoutGraphicsControl.tvEraser
tvEraser.setOnClickListener {
tvEraser.setSelectState(!tvEraser.isSelectedState)
if (tvEraser.isSelectedState) {
tvEraser.isSelected = !tvEraser.isSelected
if (tvEraser.isSelected) {
binding.layoutGraphicsControl.layoutSizeChooser.root.visible()
showBrushSizeList(isEraseMode = true)
binding.layoutGraphicsControl.layoutColorChooser.root.gone()
binding.layoutGraphicsControl.tvBrushSize.setSelectState(false)
binding.layoutGraphicsControl.tvBrushColor.setSelectState(false)
binding.layoutGraphicsControl.tvBrushSize.isSelected = false
binding.layoutGraphicsControl.tvBrushColor.isSelected = false
} else {
binding.layoutGraphicsControl.layoutSizeChooser.root.gone()
graphicNotesViewModel.setEraseMode(false)
}
graphicNotesViewModel.setEraseMode(tvEraser.isSelectedState)
graphicNotesViewModel.setEraseMode(tvEraser.isSelected)
}

val tvColor = binding.layoutGraphicsControl.tvBrushColor
tvColor.setOnClickListener {
tvColor.setSelectState(!tvColor.isSelectedState)
if (tvColor.isSelectedState) {
tvColor.isSelected = !tvColor.isSelected
if (tvColor.isSelected) {
showBrushColorList()
binding.layoutGraphicsControl.layoutColorChooser.root.visible()
binding.layoutGraphicsControl.layoutSizeChooser.root.gone()
binding.layoutGraphicsControl.tvBrushSize.setSelectState(false)
binding.layoutGraphicsControl.tvEraser.setSelectState(false)
binding.layoutGraphicsControl.tvBrushSize.isSelected = false
binding.layoutGraphicsControl.tvEraser.isSelected = false
graphicNotesViewModel.setEraseMode(false)
} else {
binding.layoutGraphicsControl.layoutColorChooser.root.gone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class GraphicControlTextView @JvmOverloads constructor(
attrs: AttributeSet? = null,
) : androidx.appcompat.widget.AppCompatTextView(context, attrs) {

var isSelectedState = false
private var iconTintColor: Int

init {
Expand All @@ -29,12 +28,13 @@ class GraphicControlTextView @JvmOverloads constructor(
drawableResId.let {
this.setCompoundDrawablesWithIntrinsicBounds(drawableResId, 0, 0, 0)
}
setSelectState(isSelected)
setSelected(isSelected)

typedArray.recycle()
}

fun setSelectState(selected: Boolean) {
override fun setSelected(selected: Boolean) {
super.setSelected(selected)
if (selected) {
this.background = ContextCompat.getDrawable(
context, R.drawable.bg_graphic_control_text_selected
Expand All @@ -53,8 +53,6 @@ class GraphicControlTextView @JvmOverloads constructor(
this.setTextColor(selectedColor)
setDrawableTint(drawableColor)
}

isSelectedState = selected
}

private fun setDrawableTint(@ColorInt color: Int) {
Expand Down

0 comments on commit 044f267

Please sign in to comment.