Aperture: Reduce reads of 'cameraMode'
While this may seem a standard variable it's
actually getting read each time from storage
Signed-off-by: Luca Stefani <luca.stefani.ge1@gmail.com>
Change-Id: Ib0c3bafca42ab3634cd994c163ce8444aff54317
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index 557cd96..60aae30 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -360,10 +360,10 @@
flipCameraButton.setOnClickListener { flipCamera() }
// Initialize shutter drawable
- if (cameraMode == CameraMode.PHOTO) {
- startShutterAnimation(ShutterAnimation.InitPhoto)
- } else if (cameraMode == CameraMode.VIDEO) {
- startShutterAnimation(ShutterAnimation.InitVideo)
+ when (cameraMode) {
+ CameraMode.PHOTO -> startShutterAnimation(ShutterAnimation.InitPhoto)
+ CameraMode.VIDEO -> startShutterAnimation(ShutterAnimation.InitVideo)
+ else -> {}
}
shutterButton.setOnClickListener {
@@ -765,9 +765,11 @@
* Update the camera mode buttons reflecting the current mode
*/
private fun updateCameraModeButtons() {
- qrModeButton.isEnabled = cameraMode != CameraMode.QR
- photoModeButton.isEnabled = cameraMode != CameraMode.PHOTO
- videoModeButton.isEnabled = cameraMode != CameraMode.VIDEO
+ cameraMode.let {
+ qrModeButton.isEnabled = it != CameraMode.QR
+ photoModeButton.isEnabled = it != CameraMode.PHOTO
+ videoModeButton.isEnabled = it != CameraMode.VIDEO
+ }
// Animate camera mode change
(cameraModeHighlight.parent as View).doOnLayout {