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