Aperture: Don't rely on shared prefs to set camera mode/facing
* We don't want intents and shortcuts to set persistent settings
* This also fixes multiple intents handling
Change-Id: I2502e504b8d5670db79cf8b847fe10fd69c2e042
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index fc077ce..84a8d1e 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -125,8 +125,8 @@
private lateinit var cameraController: LifecycleCameraController
- private val cameraMode: CameraMode
- get() = sharedPreferences.lastCameraMode
+ private lateinit var cameraMode: CameraMode
+ private lateinit var cameraFacing: CameraFacing
private var cameraState = CameraState.IDLE
set(value) {
@@ -233,15 +233,15 @@
private val shortcutActions = mapOf(
ShortcutsUtils.SHORTCUT_ID_SELFIE to {
- sharedPreferences.lastCameraMode = CameraMode.PHOTO
- sharedPreferences.lastCameraFacing = CameraFacing.FRONT
+ cameraMode = CameraMode.PHOTO
+ cameraFacing = CameraFacing.FRONT
},
ShortcutsUtils.SHORTCUT_ID_VIDEO to {
- sharedPreferences.lastCameraMode = CameraMode.VIDEO
- sharedPreferences.lastCameraFacing = CameraFacing.BACK
+ cameraMode = CameraMode.VIDEO
+ cameraFacing = CameraFacing.BACK
},
ShortcutsUtils.SHORTCUT_ID_QR to {
- sharedPreferences.lastCameraMode = CameraMode.QR
+ cameraMode = CameraMode.QR
},
)
@@ -276,6 +276,15 @@
// Initialize sounds utils
cameraSoundsUtils = CameraSoundsUtils(sharedPreferences)
+ // Initialize camera mode and facing
+ cameraMode = sharedPreferences.lastCameraMode
+ cameraFacing = sharedPreferences.lastCameraFacing
+
+ // Handle intent
+ intent.action?.let {
+ shortcutActions[it]?.invoke()
+ }
+
// Set secondary bar button callbacks
aspectRatioButton.setOnClickListener { cycleAspectRatio() }
videoQualityButton.setOnClickListener { cycleVideoQuality() }
@@ -401,11 +410,6 @@
}
}
- // Handle shortcut intent
- intent.action?.let {
- shortcutActions[it]?.invoke()
- }
-
// Initialize shutter drawable
when (cameraMode) {
CameraMode.PHOTO -> startShutterAnimation(ShutterAnimation.InitPhoto)
@@ -697,7 +701,7 @@
// Select front/back camera
var cameraSelector = when (cameraMode) {
CameraMode.QR -> CameraSelector.DEFAULT_BACK_CAMERA
- else -> when (sharedPreferences.lastCameraFacing) {
+ else -> when (cameraFacing) {
CameraFacing.FRONT -> CameraSelector.DEFAULT_FRONT_CAMERA
CameraFacing.BACK -> CameraSelector.DEFAULT_BACK_CAMERA
else -> CameraSelector.DEFAULT_BACK_CAMERA
@@ -818,7 +822,9 @@
else -> {}
}
+ this.cameraMode = cameraMode
sharedPreferences.lastCameraMode = cameraMode
+
bindCameraUseCases()
}
@@ -832,12 +838,13 @@
(flipCameraButton.drawable as AnimatedVectorDrawable).start()
- sharedPreferences.lastCameraFacing = when (cameraController.physicalCamera?.cameraFacing) {
+ cameraFacing = when (cameraFacing) {
// We can definitely do it better
CameraFacing.FRONT -> CameraFacing.BACK
CameraFacing.BACK -> CameraFacing.FRONT
else -> CameraFacing.BACK
}
+ sharedPreferences.lastCameraFacing = cameraFacing
bindCameraUseCases()
}