From 6ed3e8e7b55b61f05779011434312281cc00eb7f Mon Sep 17 00:00:00 2001 From: Ole-Morten Duesund Date: Fri, 27 Feb 2026 15:21:38 +0100 Subject: [PATCH] Propagate camera binding errors to UI Add an error StateFlow to CameraManager so camera binding failures are surfaced to the user instead of silently swallowed by e.printStackTrace(). CameraScreen collects this flow and displays errors using the existing red overlay UI. Added Log.e with proper TAG for logcat visibility. Co-Authored-By: Claude Opus 4.6 --- .../no/naiv/tiltshift/camera/CameraManager.kt | 16 ++++++++++++++-- .../java/no/naiv/tiltshift/ui/CameraScreen.kt | 11 +++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt b/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt index f70d6a4..ec5ff15 100644 --- a/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt +++ b/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt @@ -2,6 +2,7 @@ package no.naiv.tiltshift.camera import android.content.Context import android.graphics.SurfaceTexture +import android.util.Log import android.util.Size import android.view.Surface import androidx.camera.core.Camera @@ -24,6 +25,10 @@ import java.util.concurrent.Executor */ class CameraManager(private val context: Context) { + companion object { + private const val TAG = "CameraManager" + } + private var cameraProvider: ProcessCameraProvider? = null private var camera: Camera? = null private var preview: Preview? = null @@ -32,6 +37,13 @@ class CameraManager(private val context: Context) { val lensController = LensController() + private val _error = MutableStateFlow(null) + val error: StateFlow = _error.asStateFlow() + + fun clearError() { + _error.value = null + } + private val _zoomRatio = MutableStateFlow(1.0f) val zoomRatio: StateFlow = _zoomRatio.asStateFlow() @@ -117,8 +129,8 @@ class CameraManager(private val context: Context) { } } catch (e: Exception) { - // Camera binding failed - e.printStackTrace() + Log.e(TAG, "Camera binding failed", e) + _error.value = "Camera failed: ${e.message}" } } diff --git a/app/src/main/java/no/naiv/tiltshift/ui/CameraScreen.kt b/app/src/main/java/no/naiv/tiltshift/ui/CameraScreen.kt index c667bca..fb49038 100644 --- a/app/src/main/java/no/naiv/tiltshift/ui/CameraScreen.kt +++ b/app/src/main/java/no/naiv/tiltshift/ui/CameraScreen.kt @@ -104,6 +104,17 @@ fun CameraScreen( val minZoom by cameraManager.minZoomRatio.collectAsState() val maxZoom by cameraManager.maxZoomRatio.collectAsState() val isFrontCamera by cameraManager.isFrontCamera.collectAsState() + val cameraError by cameraManager.error.collectAsState() + + // Show camera errors via the existing error UI + LaunchedEffect(cameraError) { + cameraError?.let { message -> + showSaveError = message + cameraManager.clearError() + delay(2000) + showSaveError = null + } + } // Collect orientation updates LaunchedEffect(Unit) {