Aperture: CameraActivity: Get rid of update{PrimaryBar,CameraMode}Buttons()

Change-Id: I15d1c95f68894e7fd8baf5df9b11214ef818e82e
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index cbd6684..ed478ac 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -803,19 +803,53 @@
 
         // Observe camera mode
         model.cameraMode.observe(this) {
-            updateCameraModeButtons()
+            val cameraMode = it ?: return@observe
+
+            // Update camera mode buttons
+            qrModeButton.isEnabled = cameraMode != CameraMode.QR
+            photoModeButton.isEnabled = cameraMode != CameraMode.PHOTO
+            videoModeButton.isEnabled = cameraMode != CameraMode.VIDEO
+
+            // Animate camera mode change
+            (cameraModeHighlight.parent as View).doOnLayout {
+                ValueAnimator.ofFloat(
+                    cameraModeHighlight.x, when (cameraMode) {
+                        CameraMode.QR -> qrModeButton.x
+                        CameraMode.PHOTO -> photoModeButton.x
+                        CameraMode.VIDEO -> videoModeButton.x
+                    }
+                ).apply {
+                    addUpdateListener { valueAnimator ->
+                        cameraModeHighlight.x = valueAnimator.animatedValue as Float
+                    }
+                }.start()
+            }
         }
 
         // Observe single capture mode
         model.inSingleCaptureMode.observe(this) {
-            updatePrimaryBarButtons()
-            updateCameraModeButtons()
+            val inSingleCaptureMode = it ?: return@observe
+
+            // Update primary bar buttons
+            galleryButtonCardView.isInvisible = inSingleCaptureMode
+
+            // Update camera mode buttons
+            cameraModeHighlight.isInvisible = inSingleCaptureMode
+            photoModeButton.isInvisible = inSingleCaptureMode
+            videoModeButton.isInvisible = inSingleCaptureMode
+            qrModeButton.isInvisible = inSingleCaptureMode
         }
 
         // Observe camera state
         model.cameraState.observe(this) {
+            val cameraState = it ?: return@observe
+
             updateSecondaryBarButtons()
-            updatePrimaryBarButtons()
+
+            // Update primary bar buttons
+            galleryButton.isEnabled = cameraState == CameraState.IDLE
+            // Shutter button must stay enabled
+            flipCameraButton.isEnabled = cameraState == CameraState.IDLE
         }
 
         // Request camera permissions
@@ -1347,40 +1381,6 @@
     }
 
     /**
-     * Update the camera mode buttons reflecting the current mode
-     */
-    private fun updateCameraModeButtons() {
-        runOnUiThread {
-            val inSingleCaptureMode = model.inSingleCaptureMode.value ?: return@runOnUiThread
-            val cameraMode = model.cameraMode.value ?: return@runOnUiThread
-
-            cameraModeHighlight.isInvisible = inSingleCaptureMode
-            photoModeButton.isInvisible = inSingleCaptureMode
-            videoModeButton.isInvisible = inSingleCaptureMode
-            qrModeButton.isInvisible = inSingleCaptureMode
-
-            qrModeButton.isEnabled = cameraMode != CameraMode.QR
-            photoModeButton.isEnabled = cameraMode != CameraMode.PHOTO
-            videoModeButton.isEnabled = cameraMode != CameraMode.VIDEO
-
-            // Animate camera mode change
-            (cameraModeHighlight.parent as View).doOnLayout {
-                ValueAnimator.ofFloat(
-                    cameraModeHighlight.x, when (cameraMode) {
-                        CameraMode.QR -> qrModeButton.x
-                        CameraMode.PHOTO -> photoModeButton.x
-                        CameraMode.VIDEO -> videoModeButton.x
-                    }
-                ).apply {
-                    addUpdateListener {
-                        cameraModeHighlight.x = it.animatedValue as Float
-                    }
-                }.start()
-            }
-        }
-    }
-
-    /**
      * Enable or disable secondary bar buttons
      */
     private fun updateSecondaryBarButtons() {
@@ -1405,21 +1405,6 @@
         }
     }
 
-    /**
-     * Enable or disable primary bar buttons
-     */
-    private fun updatePrimaryBarButtons() {
-        runOnUiThread {
-            val inSingleCaptureMode = model.inSingleCaptureMode.value ?: return@runOnUiThread
-            val cameraState = model.cameraState.value ?: return@runOnUiThread
-
-            galleryButtonCardView.isInvisible = inSingleCaptureMode
-            galleryButton.isEnabled = cameraState == CameraState.IDLE
-            // Shutter button must stay enabled
-            flipCameraButton.isEnabled = cameraState == CameraState.IDLE
-        }
-    }
-
     private fun cycleAspectRatio() {
         if (!canRestartCamera()) {
             return