Aperture: Disable secondary bar buttons on activity

Change-Id: I0beb09f46f36d54fbf426776e8efc70a831908b7
diff --git a/app/src/main/java/org/lineageos/aperture/MainActivity.kt b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
index e66430f..7fadbf5 100644
--- a/app/src/main/java/org/lineageos/aperture/MainActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/MainActivity.kt
@@ -131,7 +131,11 @@
     private val cameraMode: CameraMode
         get() = sharedPreferences.lastCameraMode
 
-    private lateinit var cameraState: CameraState
+    private var cameraState = CameraState.IDLE
+        set(value) {
+            field = value
+            updateSecondaryBarButtons(value)
+        }
 
     private lateinit var camera: PhysicalCamera
 
@@ -841,6 +845,23 @@
         }
     }
 
+    /**
+     * Enable or disable secondary bar buttons
+     */
+    private fun updateSecondaryBarButtons(cameraState: CameraState) {
+        runOnUiThread {
+            timerButton.isEnabled = cameraState == CameraState.IDLE
+            aspectRatioButton.isEnabled = cameraState == CameraState.IDLE
+            videoQualityButton.isEnabled = cameraState == CameraState.IDLE
+            effectButton.isEnabled = cameraState == CameraState.IDLE
+            // Grid mode can be toggled at any time
+            // Torch mode can be toggled at any time
+            flashButton.isEnabled = cameraState == CameraState.IDLE
+            micButton.isEnabled = cameraState == CameraState.IDLE
+            settingsButton.isEnabled = cameraState == CameraState.IDLE
+        }
+    }
+
     private fun cycleAspectRatio() {
         if (!canRestartCamera()) {
             return
@@ -857,7 +878,6 @@
 
     private fun cycleVideoQuality() {
         if (!canRestartCamera()) {
-            updateVideoQualityIcon()
             return
         }
 
@@ -1051,10 +1071,6 @@
      */
     @SuppressLint("MissingPermission")
     private fun setMicrophoneMode(microphoneMode: Boolean) {
-        if (!canRestartCamera()) {
-            return
-        }
-
         audioConfig = AudioConfig.create(microphoneMode)
         updateMicrophoneModeIcon()
 
@@ -1103,10 +1119,6 @@
      * Cycle between supported photo camera effects
      */
     private fun cyclePhotoEffects() {
-        if (!canRestartCamera()) {
-            return
-        }
-
         setExtensionMode(
             if (extensionMode == supportedExtensionModes.last()) supportedExtensionModes.first()
             else supportedExtensionModes[supportedExtensionModes.indexOf(extensionMode) + 1]
@@ -1231,10 +1243,6 @@
     }
 
     private fun openSettings() {
-        if (!canRestartCamera()) {
-            return
-        }
-
         val intent = Intent(this, SettingsActivity::class.java)
         startActivity(intent)
     }
diff --git a/app/src/main/res/color/secondary_bar_button_icon.xml b/app/src/main/res/color/secondary_bar_button_icon.xml
new file mode 100644
index 0000000..dc495f7
--- /dev/null
+++ b/app/src/main/res/color/secondary_bar_button_icon.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:color="@color/white" android:state_enabled="true" />
+    <item android:color="@color/dark_grey" android:state_enabled="false" />
+</selector>
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 173ba14..f65ed53 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -40,10 +40,10 @@
 
     <!-- Secondary bar icons theme -->
     <style name="ApertureSecondaryBarButton">
-        <item name="tint">?attr/colorPrimary</item>
+        <item name="tint">@color/secondary_bar_button_icon</item>
         <item name="backgroundTint">?attr/colorOnPrimary</item>
         <item name="android:padding">0dp</item>
-        <item name="android:textColor">?attr/colorPrimary</item>
+        <item name="android:textColor">@color/secondary_bar_button_icon</item>
     </style>
 
     <!-- Camera mode bar icons theme -->