Aperture: Move torch mode on photo mode to long press

Change-Id: I53d36bcdcbaf20d54121fb740b0fe002992ff9a3
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index 69c5ca2..e5f1176 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -435,6 +435,16 @@
         }
     }
 
+    private val forceTorchSnackbar by lazy {
+        Snackbar.make(
+            secondaryBottomBarLayout, R.string.force_torch_help, Snackbar.LENGTH_INDEFINITE
+        )
+            .setAnchorView(secondaryBottomBarLayout)
+            .setAction(android.R.string.ok) {
+                sharedPreferences.forceTorchHelpShown = true
+            }
+    }
+
     enum class ShutterAnimation(val resourceId: Int) {
         InitPhoto(R.drawable.avd_photo_capture),
         InitVideo(R.drawable.avd_mode_video_photo),
@@ -588,6 +598,14 @@
             secondaryTopBarLayout.slide()
         }
         flashButton.setOnClickListener { cycleFlashMode() }
+        flashButton.setOnLongClickListener {
+            if (cameraMode == CameraMode.PHOTO) {
+                toggleForceTorch()
+                true
+            } else {
+                false
+            }
+        }
 
         // Initialize camera mode highlight position
         (cameraModeHighlight.parent as View).doOnLayout {
@@ -1918,6 +1936,31 @@
             CameraMode.VIDEO -> sharedPreferences.videoFlashMode = newFlashMode
             else -> {}
         }
+
+        if (cameraMode == CameraMode.PHOTO && !sharedPreferences.forceTorchHelpShown &&
+            !forceTorchSnackbar.isShownOrQueued) {
+            forceTorchSnackbar.show()
+        }
+    }
+
+    /**
+     * Toggle torch mode on photo mode.
+     */
+    private fun toggleForceTorch() {
+        val currentFlashMode = flashMode
+
+        val newFlashMode = if (currentFlashMode != FlashMode.TORCH) {
+            FlashMode.TORCH
+        } else {
+            FlashMode.OFF
+        }
+
+        changeFlashMode(newFlashMode)
+
+        if (!sharedPreferences.forceTorchHelpShown) {
+            // The user figured it out by themself
+            sharedPreferences.forceTorchHelpShown = true
+        }
     }
 
     /**
diff --git a/app/src/main/java/org/lineageos/aperture/camera/FlashMode.kt b/app/src/main/java/org/lineageos/aperture/camera/FlashMode.kt
index 6cc9301..80adf8c 100644
--- a/app/src/main/java/org/lineageos/aperture/camera/FlashMode.kt
+++ b/app/src/main/java/org/lineageos/aperture/camera/FlashMode.kt
@@ -40,7 +40,6 @@
             OFF,
             AUTO,
             ON,
-            TORCH,
         )
 
         /**
diff --git a/app/src/main/java/org/lineageos/aperture/ext/SharedPreferences.kt b/app/src/main/java/org/lineageos/aperture/ext/SharedPreferences.kt
index cff16de..fffb960 100644
--- a/app/src/main/java/org/lineageos/aperture/ext/SharedPreferences.kt
+++ b/app/src/main/java/org/lineageos/aperture/ext/SharedPreferences.kt
@@ -436,3 +436,12 @@
         // Default to default
         else -> null
     }
+
+// Force torch mode help shown
+private const val FORCE_TORCH_HELP_SHOWN_KEY = "force_torch_help_shown"
+private const val FORCE_TORCH_HELP_SHOWN_DEFAULT = false
+internal var SharedPreferences.forceTorchHelpShown: Boolean
+    get() = getBoolean(FORCE_TORCH_HELP_SHOWN_KEY, FORCE_TORCH_HELP_SHOWN_DEFAULT)
+    set(value) = edit {
+        putBoolean(FORCE_TORCH_HELP_SHOWN_KEY, value)
+    }
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2b7f6d8..16e26ad 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -186,4 +186,7 @@
     <string name="thermal_status_critical">Critical thermal throttling, the app might be closed soon.</string>
     <string name="thermal_status_emergency">Emergency thermal throttling, the app will close now.</string>
     <string name="thermal_status_shutdown">Shutdown thermal throttling, the device will power off.</string>
+
+    <!-- Force torch help -->
+    <string name="force_torch_help">On photo mode, you can long press the flash button to switch into torch mode.</string>
 </resources>