Simplify code

iterating through the views was really unnecessary
This commit is contained in:
Naveen 2022-10-14 22:29:59 +05:30
parent 24cc29162a
commit 4957e9a84e
1 changed files with 11 additions and 12 deletions

View File

@ -12,6 +12,7 @@ import android.os.Bundle
import android.provider.MediaStore
import android.view.WindowManager
import android.webkit.MimeTypeMap
import android.widget.ImageView
import android.widget.SeekBar
import android.widget.Toast
import androidx.print.PrintHelper
@ -409,18 +410,16 @@ class MainActivity : SimpleActivity(), CanvasListener {
private fun updateButtonStates() {
hideBrushSettings(isEyeDropperOn || isBucketFillOn)
arrayOf(
eraser to isEraserOn,
eye_dropper to isEyeDropperOn,
bucket_fill to isBucketFillOn
).forEach {
val view = it.first
val enabled = it.second
if (enabled) {
view.applyColorFilter(getProperPrimaryColor())
} else {
view.applyColorFilter(config.canvasBackgroundColor.getContrastColor())
}
updateButtonColor(eraser, isEraserOn)
updateButtonColor(eye_dropper, isEyeDropperOn)
updateButtonColor(bucket_fill, isBucketFillOn)
}
private fun updateButtonColor(view: ImageView, enabled: Boolean) {
if (enabled) {
view.applyColorFilter(getProperPrimaryColor())
} else {
view.applyColorFilter(config.canvasBackgroundColor.getContrastColor())
}
}