Aperture: Properly handle QR scanner activity
* If we use changeCameraMode, we both write to shared preferences and we
initialize camera before onResume()
Change-Id: I898e7affd393bdddec4727955a94ec8d3f13a673
diff --git a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
index b10238d..faffcbc 100644
--- a/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/CameraActivity.kt
@@ -289,7 +289,7 @@
cameraSoundsUtils = CameraSoundsUtils(sharedPreferences)
// Initialize camera mode and facing
- cameraMode = sharedPreferences.lastCameraMode
+ cameraMode = overrideInitialCameraMode() ?: sharedPreferences.lastCameraMode
cameraFacing = sharedPreferences.lastCameraFacing
// Handle intent
@@ -539,6 +539,12 @@
}
}
+ /**
+ * This is a method that can be overridden to set the initial camera mode and facing.
+ * It's gonna have priority over shared preferences and intents.
+ */
+ protected open fun overrideInitialCameraMode(): CameraMode? = null
+
private fun startShutterAnimation(shutterAnimation: ShutterAnimation) {
// Get appropriate drawable
val drawable = ContextCompat.getDrawable(
diff --git a/app/src/main/java/org/lineageos/aperture/QrScannerActivity.kt b/app/src/main/java/org/lineageos/aperture/QrScannerActivity.kt
index e9e050e..42d46f8 100644
--- a/app/src/main/java/org/lineageos/aperture/QrScannerActivity.kt
+++ b/app/src/main/java/org/lineageos/aperture/QrScannerActivity.kt
@@ -13,8 +13,5 @@
@androidx.camera.core.ExperimentalZeroShutterLag
@androidx.camera.view.video.ExperimentalVideo
class QrScannerActivity : CameraActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- changeCameraMode(CameraMode.QR)
- }
+ override fun overrideInitialCameraMode() = CameraMode.QR
}