Skip to content

Commit 90c6cd2

Browse files
committed
Aperture: Fix RAW capture when permissions are granted after app launch
I don't wanna know why. Change-Id: I96c79283471b9542af4d8be24add5ba533b5248b
1 parent c30b723 commit 90c6cd2

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

app/src/main/java/org/lineageos/aperture/CameraActivity.kt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,6 @@ open class CameraActivity : AppCompatActivity(R.layout.activity_camera) {
466466
flashButton.setOnClickListener { viewModel.cycleFlashMode(false) }
467467
flashButton.setOnLongClickListener { viewModel.cycleFlashMode(true) }
468468

469-
// Attach CameraController to PreviewView
470-
viewFinder.controller = viewModel.cameraController
471-
472-
// Attach CameraController to ScreenFlashView
473-
screenFlashView.setController(viewModel.cameraController)
474-
screenFlashView.setScreenFlashWindow(window)
475-
476469
// Observe manual focus
477470
viewFinder.setOnTouchListener { _, event ->
478471
if (zoomGestureDetector.onTouchEvent(event) && zoomGestureDetectorIsInProgress) {
@@ -646,6 +639,11 @@ open class CameraActivity : AppCompatActivity(R.layout.activity_camera) {
646639
}
647640
}
648641
}
642+
643+
// Initialize stuff after camera permissions are granted
644+
lifecycleScope.launch {
645+
queueSetupWithCameraPermissions()
646+
}
649647
}
650648

651649
override fun onDestroy() {
@@ -1397,6 +1395,23 @@ open class CameraActivity : AppCompatActivity(R.layout.activity_camera) {
13971395
}
13981396
}
13991397

1398+
private suspend fun queueSetupWithCameraPermissions() {
1399+
var initialized = false
1400+
1401+
permissionsManager.permissionStateFlow(Permission.CAMERA).collect { permissionState ->
1402+
if (permissionState == PermissionState.GRANTED && !initialized) {
1403+
// Attach CameraController to PreviewView
1404+
viewFinder.controller = viewModel.cameraController
1405+
1406+
// Attach CameraController to ScreenFlashView
1407+
screenFlashView.setController(viewModel.cameraController)
1408+
screenFlashView.setScreenFlashWindow(window)
1409+
1410+
initialized = true
1411+
}
1412+
}
1413+
}
1414+
14001415
private fun startShutterAnimation(shutterAnimation: ShutterAnimation) {
14011416
// Get appropriate drawable
14021417
val drawable = ContextCompat.getDrawable(

0 commit comments

Comments
 (0)