2026-01-28 15:26:41 +01:00
|
|
|
package no.naiv.tiltshift.ui
|
|
|
|
|
|
2026-03-03 22:32:11 +01:00
|
|
|
import android.content.Intent
|
|
|
|
|
import android.graphics.Bitmap
|
2026-01-28 15:26:41 +01:00
|
|
|
import android.graphics.SurfaceTexture
|
|
|
|
|
import android.opengl.GLSurfaceView
|
2026-03-05 11:56:29 +01:00
|
|
|
import android.util.Log
|
2026-01-28 15:26:41 +01:00
|
|
|
import android.view.Surface
|
|
|
|
|
import androidx.compose.animation.AnimatedVisibility
|
|
|
|
|
import androidx.compose.animation.fadeIn
|
|
|
|
|
import androidx.compose.animation.fadeOut
|
2026-03-03 22:32:11 +01:00
|
|
|
import androidx.compose.animation.scaleIn
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.border
|
|
|
|
|
import androidx.compose.foundation.clickable
|
2026-03-03 22:32:11 +01:00
|
|
|
import androidx.compose.foundation.systemGestureExclusion
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
|
|
import androidx.compose.foundation.layout.Spacer
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
|
|
import androidx.compose.foundation.layout.statusBarsPadding
|
2026-01-29 11:13:31 +01:00
|
|
|
import androidx.compose.foundation.layout.width
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.foundation.shape.CircleShape
|
2026-01-29 11:13:31 +01:00
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
2026-03-03 22:32:11 +01:00
|
|
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
|
|
|
|
import androidx.activity.result.PickVisualMediaRequest
|
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
2026-03-05 12:23:43 +01:00
|
|
|
import androidx.compose.foundation.Image
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
|
import androidx.compose.material.icons.filled.Check
|
|
|
|
|
import androidx.compose.material.icons.filled.Close
|
2026-01-29 11:13:31 +01:00
|
|
|
import androidx.compose.material.icons.filled.FlipCameraAndroid
|
2026-03-03 22:32:11 +01:00
|
|
|
import androidx.compose.material.icons.filled.PhotoLibrary
|
2026-03-05 12:23:43 +01:00
|
|
|
import androidx.compose.material.icons.filled.RestartAlt
|
|
|
|
|
import androidx.compose.material.icons.filled.Tune
|
|
|
|
|
import androidx.compose.material3.CircularProgressIndicator
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
|
import androidx.compose.material3.IconButton
|
2026-01-29 11:13:31 +01:00
|
|
|
import androidx.compose.material3.Slider
|
|
|
|
|
import androidx.compose.material3.SliderDefaults
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.material3.Text
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.DisposableEffect
|
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
|
|
import androidx.compose.runtime.remember
|
2026-01-29 16:36:35 +01:00
|
|
|
import androidx.compose.runtime.rememberUpdatedState
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.runtime.setValue
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.draw.clip
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
2026-03-03 22:32:11 +01:00
|
|
|
import androidx.compose.ui.graphics.asImageBitmap
|
|
|
|
|
import androidx.compose.ui.layout.ContentScale
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.ui.platform.LocalContext
|
2026-03-05 12:23:43 +01:00
|
|
|
import androidx.compose.ui.semantics.LiveRegionMode
|
|
|
|
|
import androidx.compose.ui.semantics.contentDescription
|
|
|
|
|
import androidx.compose.ui.semantics.liveRegion
|
|
|
|
|
import androidx.compose.ui.semantics.Role
|
|
|
|
|
import androidx.compose.ui.semantics.role
|
|
|
|
|
import androidx.compose.ui.semantics.semantics
|
|
|
|
|
import androidx.compose.ui.semantics.stateDescription
|
2026-01-28 15:26:41 +01:00
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
|
|
import androidx.compose.ui.viewinterop.AndroidView
|
2026-03-05 12:23:43 +01:00
|
|
|
import androidx.lifecycle.compose.LocalLifecycleOwner
|
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
2026-01-28 15:26:41 +01:00
|
|
|
import kotlinx.coroutines.flow.collectLatest
|
2026-01-29 11:13:31 +01:00
|
|
|
import no.naiv.tiltshift.effect.BlurMode
|
2026-01-28 15:26:41 +01:00
|
|
|
import no.naiv.tiltshift.effect.BlurParameters
|
|
|
|
|
import no.naiv.tiltshift.effect.TiltShiftRenderer
|
2026-03-05 12:23:43 +01:00
|
|
|
import no.naiv.tiltshift.ui.theme.AppColors
|
2026-01-28 15:26:41 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Main camera screen with tilt-shift controls.
|
2026-03-05 12:23:43 +01:00
|
|
|
* Uses CameraViewModel to survive configuration changes.
|
2026-01-28 15:26:41 +01:00
|
|
|
*/
|
|
|
|
|
@Composable
|
|
|
|
|
fun CameraScreen(
|
2026-03-05 12:23:43 +01:00
|
|
|
modifier: Modifier = Modifier,
|
|
|
|
|
viewModel: CameraViewModel = viewModel()
|
2026-01-28 15:26:41 +01:00
|
|
|
) {
|
|
|
|
|
val context = LocalContext.current
|
|
|
|
|
val lifecycleOwner = LocalLifecycleOwner.current
|
2026-03-05 12:23:43 +01:00
|
|
|
|
|
|
|
|
// GL state (view-layer, not in ViewModel)
|
2026-01-28 15:26:41 +01:00
|
|
|
var surfaceTexture by remember { mutableStateOf<SurfaceTexture?>(null) }
|
|
|
|
|
var renderer by remember { mutableStateOf<TiltShiftRenderer?>(null) }
|
|
|
|
|
var glSurfaceView by remember { mutableStateOf<GLSurfaceView?>(null) }
|
|
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Collect ViewModel state
|
|
|
|
|
val blurParams by viewModel.blurParams.collectAsState()
|
|
|
|
|
val isCapturing by viewModel.isCapturing.collectAsState()
|
|
|
|
|
val isProcessing by viewModel.isProcessing.collectAsState()
|
|
|
|
|
val showSaveSuccess by viewModel.showSaveSuccess.collectAsState()
|
|
|
|
|
val showSaveError by viewModel.showSaveError.collectAsState()
|
|
|
|
|
val showControls by viewModel.showControls.collectAsState()
|
|
|
|
|
val lastSavedUri by viewModel.lastSavedUri.collectAsState()
|
|
|
|
|
val lastThumbnailBitmap by viewModel.lastThumbnailBitmap.collectAsState()
|
2026-03-05 12:51:26 +01:00
|
|
|
val galleryPreviewBitmap by viewModel.galleryPreviewBitmap.collectAsState()
|
|
|
|
|
val isGalleryPreview = galleryPreviewBitmap != null
|
2026-03-05 11:46:05 +01:00
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
val zoomRatio by viewModel.cameraManager.zoomRatio.collectAsState()
|
|
|
|
|
val minZoom by viewModel.cameraManager.minZoomRatio.collectAsState()
|
|
|
|
|
val maxZoom by viewModel.cameraManager.maxZoomRatio.collectAsState()
|
|
|
|
|
val isFrontCamera by viewModel.cameraManager.isFrontCamera.collectAsState()
|
|
|
|
|
val cameraError by viewModel.cameraManager.error.collectAsState()
|
2026-01-28 15:26:41 +01:00
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Gallery picker
|
2026-03-03 22:32:11 +01:00
|
|
|
val galleryLauncher = rememberLauncherForActivityResult(
|
|
|
|
|
contract = ActivityResultContracts.PickVisualMedia()
|
|
|
|
|
) { uri ->
|
2026-03-05 12:23:43 +01:00
|
|
|
if (uri != null) {
|
|
|
|
|
viewModel.loadGalleryImage(uri)
|
2026-03-03 22:32:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Show camera errors
|
2026-02-27 15:21:38 +01:00
|
|
|
LaunchedEffect(cameraError) {
|
|
|
|
|
cameraError?.let { message ->
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.showCameraError(message)
|
|
|
|
|
viewModel.cameraManager.clearError()
|
2026-02-27 15:21:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
|
|
|
|
|
// Collect orientation updates
|
|
|
|
|
LaunchedEffect(Unit) {
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.orientationDetector.orientationFlow().collectLatest { rotation ->
|
|
|
|
|
viewModel.updateRotation(rotation)
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Collect location updates
|
|
|
|
|
LaunchedEffect(Unit) {
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.locationProvider.locationFlow().collectLatest { location ->
|
|
|
|
|
viewModel.updateLocation(location)
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update renderer with blur params
|
|
|
|
|
LaunchedEffect(blurParams) {
|
|
|
|
|
renderer?.updateParameters(blurParams)
|
|
|
|
|
glSurfaceView?.requestRender()
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 17:03:26 +01:00
|
|
|
// Update renderer when camera switches (front/back)
|
|
|
|
|
LaunchedEffect(isFrontCamera) {
|
|
|
|
|
renderer?.setFrontCamera(isFrontCamera)
|
|
|
|
|
glSurfaceView?.requestRender()
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 15:26:41 +01:00
|
|
|
// Start camera when surface texture is available
|
|
|
|
|
LaunchedEffect(surfaceTexture) {
|
|
|
|
|
surfaceTexture?.let {
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.cameraManager.startCamera(lifecycleOwner) { surfaceTexture }
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 13:44:12 +01:00
|
|
|
// Pause/resume GLSurfaceView when entering/leaving gallery preview
|
|
|
|
|
LaunchedEffect(isGalleryPreview) {
|
|
|
|
|
if (isGalleryPreview) {
|
|
|
|
|
glSurfaceView?.onPause()
|
|
|
|
|
} else {
|
|
|
|
|
glSurfaceView?.onResume()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cleanup GL resources on GL thread (ViewModel handles its own cleanup in onCleared)
|
2026-01-28 15:26:41 +01:00
|
|
|
DisposableEffect(Unit) {
|
|
|
|
|
onDispose {
|
2026-03-05 13:44:12 +01:00
|
|
|
glSurfaceView?.queueEvent { renderer?.release() }
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
|
modifier = modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.background(Color.Black)
|
|
|
|
|
) {
|
2026-03-05 11:46:05 +01:00
|
|
|
// Main view: gallery preview image or camera GL surface
|
|
|
|
|
if (isGalleryPreview) {
|
2026-03-05 12:51:26 +01:00
|
|
|
galleryPreviewBitmap?.let { bmp ->
|
2026-03-05 11:46:05 +01:00
|
|
|
Image(
|
|
|
|
|
bitmap = bmp.asImageBitmap(),
|
2026-03-05 12:51:26 +01:00
|
|
|
contentDescription = "Gallery image preview with tilt-shift effect. Adjust parameters then tap Apply.",
|
2026-03-05 11:46:05 +01:00
|
|
|
contentScale = ContentScale.Fit,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxSize()
|
|
|
|
|
.background(Color.Black)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// OpenGL Surface for camera preview with effect
|
|
|
|
|
AndroidView(
|
|
|
|
|
factory = { ctx ->
|
|
|
|
|
GLSurfaceView(ctx).apply {
|
|
|
|
|
setEGLContextClientVersion(2)
|
|
|
|
|
|
|
|
|
|
val newRenderer = TiltShiftRenderer(ctx) { st ->
|
|
|
|
|
surfaceTexture = st
|
|
|
|
|
}
|
|
|
|
|
renderer = newRenderer
|
2026-01-28 15:26:41 +01:00
|
|
|
|
2026-03-05 11:46:05 +01:00
|
|
|
setRenderer(newRenderer)
|
|
|
|
|
renderMode = GLSurfaceView.RENDERMODE_CONTINUOUSLY
|
2026-01-28 15:26:41 +01:00
|
|
|
|
2026-03-05 11:46:05 +01:00
|
|
|
glSurfaceView = this
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
modifier = Modifier.fillMaxSize()
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
|
|
|
|
|
// Tilt-shift overlay (gesture handling + visualization)
|
|
|
|
|
TiltShiftOverlay(
|
|
|
|
|
params = blurParams,
|
|
|
|
|
onParamsChange = { newParams ->
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.updateBlurParams(newParams)
|
2026-01-28 15:26:41 +01:00
|
|
|
},
|
|
|
|
|
onZoomChange = { zoomDelta ->
|
2026-03-05 11:46:05 +01:00
|
|
|
if (!isGalleryPreview) {
|
|
|
|
|
val newZoom = (zoomRatio * zoomDelta).coerceIn(minZoom, maxZoom)
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.cameraManager.setZoom(newZoom)
|
2026-03-05 11:46:05 +01:00
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
},
|
|
|
|
|
modifier = Modifier.fillMaxSize()
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-29 11:13:31 +01:00
|
|
|
// Top bar with controls
|
|
|
|
|
Column(
|
2026-01-28 15:26:41 +01:00
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.statusBarsPadding()
|
2026-01-29 11:13:31 +01:00
|
|
|
.padding(16.dp)
|
2026-01-28 15:26:41 +01:00
|
|
|
) {
|
2026-01-29 11:13:31 +01:00
|
|
|
Row(
|
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically
|
|
|
|
|
) {
|
2026-03-05 11:46:05 +01:00
|
|
|
if (!isGalleryPreview) {
|
|
|
|
|
ZoomIndicator(currentZoom = zoomRatio)
|
|
|
|
|
} else {
|
|
|
|
|
Spacer(modifier = Modifier.width(1.dp))
|
|
|
|
|
}
|
2026-01-29 11:13:31 +01:00
|
|
|
|
|
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
2026-03-05 11:46:05 +01:00
|
|
|
if (!isGalleryPreview) {
|
|
|
|
|
// Camera flip button
|
|
|
|
|
IconButton(
|
|
|
|
|
onClick = {
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.cameraManager.switchCamera()
|
|
|
|
|
viewModel.haptics.click()
|
2026-03-05 11:46:05 +01:00
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Default.FlipCameraAndroid,
|
2026-03-05 12:23:43 +01:00
|
|
|
contentDescription = "Switch between front and back camera",
|
2026-03-05 11:46:05 +01:00
|
|
|
tint = Color.White
|
|
|
|
|
)
|
2026-01-29 11:13:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Toggle controls button (tune icon instead of cryptic "Ctrl")
|
2026-01-29 11:13:31 +01:00
|
|
|
IconButton(
|
|
|
|
|
onClick = {
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.toggleControls()
|
|
|
|
|
viewModel.haptics.tick()
|
|
|
|
|
},
|
|
|
|
|
modifier = Modifier.semantics {
|
|
|
|
|
stateDescription = if (showControls) "Controls visible" else "Controls hidden"
|
2026-01-29 11:13:31 +01:00
|
|
|
}
|
|
|
|
|
) {
|
2026-03-05 12:23:43 +01:00
|
|
|
Icon(
|
|
|
|
|
imageVector = if (showControls) Icons.Default.Close else Icons.Default.Tune,
|
|
|
|
|
contentDescription = if (showControls) "Hide blur controls" else "Show blur controls",
|
|
|
|
|
tint = Color.White
|
2026-01-29 11:13:31 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Mode toggle
|
|
|
|
|
Row(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.fillMaxWidth()
|
|
|
|
|
.padding(top = 8.dp),
|
|
|
|
|
horizontalArrangement = Arrangement.Center
|
2026-01-28 15:26:41 +01:00
|
|
|
) {
|
2026-01-29 11:13:31 +01:00
|
|
|
ModeToggle(
|
|
|
|
|
currentMode = blurParams.mode,
|
|
|
|
|
onModeChange = { mode ->
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.updateBlurParams(blurParams.copy(mode = mode))
|
|
|
|
|
viewModel.haptics.click()
|
2026-01-29 11:13:31 +01:00
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 11:13:31 +01:00
|
|
|
// Control panel (sliders)
|
|
|
|
|
AnimatedVisibility(
|
|
|
|
|
visible = showControls,
|
|
|
|
|
enter = fadeIn(),
|
|
|
|
|
exit = fadeOut(),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.align(Alignment.CenterEnd)
|
|
|
|
|
.padding(end = 16.dp)
|
|
|
|
|
) {
|
|
|
|
|
ControlPanel(
|
|
|
|
|
params = blurParams,
|
|
|
|
|
onParamsChange = { newParams ->
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.updateBlurParams(newParams)
|
|
|
|
|
},
|
|
|
|
|
onReset = { viewModel.resetBlurParams() }
|
2026-01-29 11:13:31 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 15:26:41 +01:00
|
|
|
// Bottom controls
|
|
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.align(Alignment.BottomCenter)
|
|
|
|
|
.navigationBarsPadding()
|
2026-03-03 22:32:11 +01:00
|
|
|
.padding(bottom = 48.dp)
|
|
|
|
|
.systemGestureExclusion(),
|
2026-01-28 15:26:41 +01:00
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
2026-03-05 11:46:05 +01:00
|
|
|
if (isGalleryPreview) {
|
2026-03-05 12:23:43 +01:00
|
|
|
// Gallery preview mode: Cancel | Apply (matched layout to camera mode)
|
2026-03-05 11:46:05 +01:00
|
|
|
Row(
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
2026-03-05 12:23:43 +01:00
|
|
|
horizontalArrangement = Arrangement.spacedBy(24.dp)
|
2026-03-03 22:32:11 +01:00
|
|
|
) {
|
2026-03-05 12:23:43 +01:00
|
|
|
// Cancel button (same 52dp as gallery button for layout consistency)
|
2026-03-05 11:46:05 +01:00
|
|
|
IconButton(
|
2026-03-05 12:23:43 +01:00
|
|
|
onClick = { viewModel.cancelGalleryPreview() },
|
2026-03-05 11:46:05 +01:00
|
|
|
modifier = Modifier
|
2026-03-05 12:23:43 +01:00
|
|
|
.size(52.dp)
|
2026-03-05 11:46:05 +01:00
|
|
|
.clip(CircleShape)
|
2026-03-05 12:23:43 +01:00
|
|
|
.background(AppColors.OverlayDark)
|
|
|
|
|
.semantics { contentDescription = "Cancel gallery import" }
|
2026-03-05 11:46:05 +01:00
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Default.Close,
|
2026-03-05 12:23:43 +01:00
|
|
|
contentDescription = null,
|
2026-03-05 11:46:05 +01:00
|
|
|
tint = Color.White,
|
|
|
|
|
modifier = Modifier.size(28.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
2026-03-03 22:32:11 +01:00
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Apply button (same 72dp as capture button for layout consistency)
|
|
|
|
|
Box(
|
2026-03-05 11:46:05 +01:00
|
|
|
modifier = Modifier
|
2026-03-05 12:23:43 +01:00
|
|
|
.size(72.dp)
|
2026-03-05 11:46:05 +01:00
|
|
|
.clip(CircleShape)
|
2026-03-05 12:23:43 +01:00
|
|
|
.border(4.dp, Color.White, CircleShape)
|
|
|
|
|
.clickable(
|
|
|
|
|
enabled = !isCapturing,
|
|
|
|
|
role = Role.Button,
|
|
|
|
|
onClick = { viewModel.applyGalleryEffect() }
|
|
|
|
|
)
|
|
|
|
|
.semantics {
|
|
|
|
|
contentDescription = "Apply tilt-shift effect to gallery image"
|
|
|
|
|
if (isCapturing) stateDescription = "Processing"
|
|
|
|
|
},
|
|
|
|
|
contentAlignment = Alignment.Center
|
2026-03-05 11:46:05 +01:00
|
|
|
) {
|
2026-03-05 12:23:43 +01:00
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(if (isCapturing) 48.dp else 60.dp)
|
|
|
|
|
.clip(CircleShape)
|
|
|
|
|
.background(if (isCapturing) AppColors.Accent.copy(alpha = 0.5f) else AppColors.Accent),
|
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
if (isProcessing) {
|
|
|
|
|
CircularProgressIndicator(
|
|
|
|
|
modifier = Modifier.size(24.dp),
|
|
|
|
|
color = Color.Black,
|
|
|
|
|
strokeWidth = 3.dp
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Default.Check,
|
|
|
|
|
contentDescription = null,
|
|
|
|
|
tint = Color.Black,
|
|
|
|
|
modifier = Modifier.size(28.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-05 11:46:05 +01:00
|
|
|
}
|
2026-03-05 12:23:43 +01:00
|
|
|
|
|
|
|
|
// Spacer for visual symmetry
|
|
|
|
|
Spacer(modifier = Modifier.size(52.dp))
|
2026-03-05 11:46:05 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Camera mode: Zoom presets + Gallery | Capture | Spacer
|
|
|
|
|
if (!isFrontCamera) {
|
|
|
|
|
ZoomControl(
|
|
|
|
|
currentZoom = zoomRatio,
|
|
|
|
|
minZoom = minZoom,
|
|
|
|
|
maxZoom = maxZoom,
|
|
|
|
|
onZoomSelected = { zoom ->
|
2026-03-05 12:23:43 +01:00
|
|
|
viewModel.cameraManager.setZoom(zoom)
|
|
|
|
|
viewModel.haptics.click()
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
2026-03-05 11:46:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(24.dp))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Row(
|
|
|
|
|
verticalAlignment = Alignment.CenterVertically,
|
|
|
|
|
horizontalArrangement = Arrangement.spacedBy(24.dp)
|
|
|
|
|
) {
|
2026-03-05 12:23:43 +01:00
|
|
|
// Gallery picker button (with background for discoverability)
|
2026-03-05 11:46:05 +01:00
|
|
|
IconButton(
|
|
|
|
|
onClick = {
|
|
|
|
|
if (!isCapturing) {
|
|
|
|
|
galleryLauncher.launch(
|
|
|
|
|
PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
enabled = !isCapturing,
|
2026-03-05 12:23:43 +01:00
|
|
|
modifier = Modifier
|
|
|
|
|
.size(52.dp)
|
|
|
|
|
.clip(CircleShape)
|
|
|
|
|
.background(AppColors.OverlayDark)
|
2026-03-05 11:46:05 +01:00
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Default.PhotoLibrary,
|
2026-03-05 12:23:43 +01:00
|
|
|
contentDescription = "Pick image from gallery",
|
2026-03-05 11:46:05 +01:00
|
|
|
tint = Color.White,
|
|
|
|
|
modifier = Modifier.size(28.dp)
|
|
|
|
|
)
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
2026-03-03 22:32:11 +01:00
|
|
|
|
2026-03-05 11:46:05 +01:00
|
|
|
// Capture button
|
|
|
|
|
CaptureButton(
|
|
|
|
|
isCapturing = isCapturing,
|
2026-03-05 12:23:43 +01:00
|
|
|
isProcessing = isProcessing,
|
|
|
|
|
onClick = { viewModel.capturePhoto() }
|
2026-03-05 11:46:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Spacer for visual symmetry with gallery button
|
|
|
|
|
Spacer(modifier = Modifier.size(52.dp))
|
|
|
|
|
}
|
2026-03-03 22:32:11 +01:00
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
2026-03-05 11:46:05 +01:00
|
|
|
// Last captured photo thumbnail (hidden in gallery preview mode)
|
|
|
|
|
if (!isGalleryPreview) LastPhotoThumbnail(
|
2026-03-03 22:32:11 +01:00
|
|
|
thumbnail = lastThumbnailBitmap,
|
|
|
|
|
onTap = {
|
|
|
|
|
lastSavedUri?.let { uri ->
|
2026-03-05 11:56:29 +01:00
|
|
|
try {
|
|
|
|
|
val intent = Intent(Intent.ACTION_VIEW).apply {
|
|
|
|
|
setDataAndType(uri, "image/jpeg")
|
|
|
|
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
|
}
|
|
|
|
|
context.startActivity(intent)
|
|
|
|
|
} catch (e: android.content.ActivityNotFoundException) {
|
|
|
|
|
Log.w("CameraScreen", "No activity found to view image", e)
|
2026-03-05 13:44:12 +01:00
|
|
|
viewModel.showCameraError("No app available to view photos")
|
2026-03-03 22:32:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.align(Alignment.BottomEnd)
|
|
|
|
|
.navigationBarsPadding()
|
|
|
|
|
.padding(bottom = 48.dp, end = 16.dp)
|
|
|
|
|
)
|
|
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Success indicator (announced to accessibility)
|
2026-01-28 15:26:41 +01:00
|
|
|
AnimatedVisibility(
|
|
|
|
|
visible = showSaveSuccess,
|
|
|
|
|
enter = fadeIn(),
|
|
|
|
|
exit = fadeOut(),
|
2026-03-05 12:23:43 +01:00
|
|
|
modifier = Modifier
|
|
|
|
|
.align(Alignment.Center)
|
|
|
|
|
.semantics { liveRegion = LiveRegionMode.Polite }
|
2026-01-28 15:26:41 +01:00
|
|
|
) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(80.dp)
|
|
|
|
|
.clip(CircleShape)
|
2026-03-05 12:23:43 +01:00
|
|
|
.background(AppColors.Success),
|
2026-01-28 15:26:41 +01:00
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Default.Check,
|
2026-03-05 12:23:43 +01:00
|
|
|
contentDescription = "Photo saved successfully",
|
2026-01-28 15:26:41 +01:00
|
|
|
tint = Color.White,
|
|
|
|
|
modifier = Modifier.size(48.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Error indicator (announced to accessibility)
|
2026-01-28 15:26:41 +01:00
|
|
|
AnimatedVisibility(
|
|
|
|
|
visible = showSaveError != null,
|
|
|
|
|
enter = fadeIn(),
|
|
|
|
|
exit = fadeOut(),
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.align(Alignment.Center)
|
|
|
|
|
.padding(32.dp)
|
2026-03-05 12:23:43 +01:00
|
|
|
.semantics { liveRegion = LiveRegionMode.Assertive }
|
2026-01-28 15:26:41 +01:00
|
|
|
) {
|
|
|
|
|
Column(
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
|
|
modifier = Modifier
|
2026-01-29 11:13:31 +01:00
|
|
|
.clip(RoundedCornerShape(16.dp))
|
2026-03-05 12:23:43 +01:00
|
|
|
.background(AppColors.Error)
|
2026-01-28 15:26:41 +01:00
|
|
|
.padding(24.dp)
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Default.Close,
|
2026-03-05 12:23:43 +01:00
|
|
|
contentDescription = null,
|
2026-01-28 15:26:41 +01:00
|
|
|
tint = Color.White,
|
|
|
|
|
modifier = Modifier.size(32.dp)
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.height(8.dp))
|
|
|
|
|
Text(
|
|
|
|
|
text = showSaveError ?: "Error",
|
|
|
|
|
color = Color.White,
|
2026-03-05 12:23:43 +01:00
|
|
|
fontSize = 14.sp,
|
|
|
|
|
maxLines = 3
|
2026-01-28 15:26:41 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-05 12:23:43 +01:00
|
|
|
|
|
|
|
|
// Processing overlay
|
|
|
|
|
AnimatedVisibility(
|
|
|
|
|
visible = isProcessing,
|
|
|
|
|
enter = fadeIn(),
|
|
|
|
|
exit = fadeOut(),
|
|
|
|
|
modifier = Modifier.align(Alignment.Center)
|
|
|
|
|
) {
|
|
|
|
|
if (!showSaveSuccess) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(80.dp)
|
|
|
|
|
.clip(CircleShape)
|
|
|
|
|
.background(AppColors.OverlayDark),
|
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
CircularProgressIndicator(
|
|
|
|
|
color = AppColors.Accent,
|
|
|
|
|
strokeWidth = 3.dp,
|
|
|
|
|
modifier = Modifier.size(36.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 11:13:31 +01:00
|
|
|
/**
|
|
|
|
|
* Mode toggle for Linear / Radial blur modes.
|
|
|
|
|
*/
|
|
|
|
|
@Composable
|
|
|
|
|
private fun ModeToggle(
|
|
|
|
|
currentMode: BlurMode,
|
|
|
|
|
onModeChange: (BlurMode) -> Unit,
|
|
|
|
|
modifier: Modifier = Modifier
|
|
|
|
|
) {
|
|
|
|
|
Row(
|
|
|
|
|
modifier = modifier
|
|
|
|
|
.clip(RoundedCornerShape(20.dp))
|
2026-03-05 12:23:43 +01:00
|
|
|
.background(AppColors.OverlayDark)
|
2026-01-29 11:13:31 +01:00
|
|
|
.padding(4.dp),
|
|
|
|
|
horizontalArrangement = Arrangement.Center
|
|
|
|
|
) {
|
|
|
|
|
ModeButton(
|
|
|
|
|
text = "Linear",
|
|
|
|
|
isSelected = currentMode == BlurMode.LINEAR,
|
|
|
|
|
onClick = { onModeChange(BlurMode.LINEAR) }
|
|
|
|
|
)
|
|
|
|
|
Spacer(modifier = Modifier.width(4.dp))
|
|
|
|
|
ModeButton(
|
|
|
|
|
text = "Radial",
|
|
|
|
|
isSelected = currentMode == BlurMode.RADIAL,
|
|
|
|
|
onClick = { onModeChange(BlurMode.RADIAL) }
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
private fun ModeButton(
|
|
|
|
|
text: String,
|
|
|
|
|
isSelected: Boolean,
|
|
|
|
|
onClick: () -> Unit
|
|
|
|
|
) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.clip(RoundedCornerShape(16.dp))
|
2026-03-05 12:23:43 +01:00
|
|
|
.background(if (isSelected) AppColors.Accent else Color.Transparent)
|
|
|
|
|
.clickable(role = Role.Button, onClick = onClick)
|
|
|
|
|
.padding(horizontal = 16.dp, vertical = 12.dp)
|
|
|
|
|
.semantics {
|
|
|
|
|
stateDescription = if (isSelected) "Selected" else "Not selected"
|
|
|
|
|
contentDescription = "$text blur mode"
|
|
|
|
|
},
|
2026-01-29 11:13:31 +01:00
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = text,
|
|
|
|
|
color = if (isSelected) Color.Black else Color.White,
|
|
|
|
|
fontSize = 14.sp
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Control panel with sliders for blur parameters.
|
2026-03-05 12:23:43 +01:00
|
|
|
* Includes position/size/angle sliders as gesture alternatives for accessibility.
|
2026-01-29 11:13:31 +01:00
|
|
|
*/
|
|
|
|
|
@Composable
|
|
|
|
|
private fun ControlPanel(
|
|
|
|
|
params: BlurParameters,
|
|
|
|
|
onParamsChange: (BlurParameters) -> Unit,
|
2026-03-05 12:23:43 +01:00
|
|
|
onReset: () -> Unit,
|
2026-01-29 11:13:31 +01:00
|
|
|
modifier: Modifier = Modifier
|
|
|
|
|
) {
|
2026-01-29 16:36:35 +01:00
|
|
|
val currentParams by rememberUpdatedState(params)
|
|
|
|
|
val currentOnParamsChange by rememberUpdatedState(onParamsChange)
|
|
|
|
|
|
2026-01-29 11:13:31 +01:00
|
|
|
Column(
|
|
|
|
|
modifier = modifier
|
|
|
|
|
.width(200.dp)
|
|
|
|
|
.clip(RoundedCornerShape(16.dp))
|
2026-03-05 12:23:43 +01:00
|
|
|
.background(AppColors.OverlayDarker)
|
2026-01-29 11:13:31 +01:00
|
|
|
.padding(16.dp),
|
2026-03-05 12:23:43 +01:00
|
|
|
verticalArrangement = Arrangement.spacedBy(12.dp)
|
2026-01-29 11:13:31 +01:00
|
|
|
) {
|
2026-03-05 12:23:43 +01:00
|
|
|
// Reset button
|
|
|
|
|
Row(
|
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
horizontalArrangement = Arrangement.End
|
|
|
|
|
) {
|
|
|
|
|
IconButton(
|
|
|
|
|
onClick = onReset,
|
|
|
|
|
modifier = Modifier.size(32.dp)
|
|
|
|
|
) {
|
|
|
|
|
Icon(
|
|
|
|
|
imageVector = Icons.Default.RestartAlt,
|
|
|
|
|
contentDescription = "Reset all parameters to defaults",
|
|
|
|
|
tint = Color.White,
|
|
|
|
|
modifier = Modifier.size(18.dp)
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-29 11:13:31 +01:00
|
|
|
// Blur intensity slider
|
|
|
|
|
SliderControl(
|
|
|
|
|
label = "Blur",
|
|
|
|
|
value = params.blurAmount,
|
|
|
|
|
valueRange = BlurParameters.MIN_BLUR..BlurParameters.MAX_BLUR,
|
2026-03-05 12:23:43 +01:00
|
|
|
formatValue = { "${(it * 100).toInt()}%" },
|
2026-01-29 16:36:35 +01:00
|
|
|
onValueChange = { currentOnParamsChange(currentParams.copy(blurAmount = it)) }
|
2026-01-29 11:13:31 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Falloff slider
|
|
|
|
|
SliderControl(
|
|
|
|
|
label = "Falloff",
|
|
|
|
|
value = params.falloff,
|
|
|
|
|
valueRange = BlurParameters.MIN_FALLOFF..BlurParameters.MAX_FALLOFF,
|
2026-03-05 12:23:43 +01:00
|
|
|
formatValue = { "${(it * 100).toInt()}%" },
|
2026-01-29 16:36:35 +01:00
|
|
|
onValueChange = { currentOnParamsChange(currentParams.copy(falloff = it)) }
|
2026-01-29 11:13:31 +01:00
|
|
|
)
|
|
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Size slider (gesture alternative for pinch-to-resize)
|
|
|
|
|
SliderControl(
|
|
|
|
|
label = "Size",
|
|
|
|
|
value = params.size,
|
|
|
|
|
valueRange = BlurParameters.MIN_SIZE..BlurParameters.MAX_SIZE,
|
|
|
|
|
formatValue = { "${(it * 100).toInt()}%" },
|
|
|
|
|
onValueChange = { currentOnParamsChange(currentParams.copy(size = it)) }
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-29 11:13:31 +01:00
|
|
|
// Aspect ratio slider (radial mode only)
|
|
|
|
|
if (params.mode == BlurMode.RADIAL) {
|
|
|
|
|
SliderControl(
|
|
|
|
|
label = "Shape",
|
|
|
|
|
value = params.aspectRatio,
|
|
|
|
|
valueRange = BlurParameters.MIN_ASPECT..BlurParameters.MAX_ASPECT,
|
2026-03-05 12:23:43 +01:00
|
|
|
formatValue = { "%.1f:1".format(it) },
|
2026-01-29 16:36:35 +01:00
|
|
|
onValueChange = { currentOnParamsChange(currentParams.copy(aspectRatio = it)) }
|
2026-01-29 11:13:31 +01:00
|
|
|
)
|
|
|
|
|
}
|
2026-02-27 15:50:53 +01:00
|
|
|
|
2026-03-05 12:23:43 +01:00
|
|
|
// Angle slider (gesture alternative for two-finger rotate)
|
|
|
|
|
SliderControl(
|
|
|
|
|
label = "Angle",
|
|
|
|
|
value = params.angle,
|
|
|
|
|
valueRange = (-Math.PI.toFloat())..Math.PI.toFloat(),
|
|
|
|
|
formatValue = { "${(it * 180f / Math.PI.toFloat()).toInt()}°" },
|
|
|
|
|
onValueChange = { currentOnParamsChange(currentParams.copy(angle = it)) }
|
|
|
|
|
)
|
2026-01-29 11:13:31 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
private fun SliderControl(
|
|
|
|
|
label: String,
|
|
|
|
|
value: Float,
|
|
|
|
|
valueRange: ClosedFloatingPointRange<Float>,
|
2026-03-05 12:23:43 +01:00
|
|
|
formatValue: (Float) -> String = { "${(it * 100).toInt()}%" },
|
2026-01-29 11:13:31 +01:00
|
|
|
onValueChange: (Float) -> Unit
|
|
|
|
|
) {
|
|
|
|
|
Column {
|
|
|
|
|
Row(
|
|
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
|
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
|
|
|
) {
|
|
|
|
|
Text(
|
|
|
|
|
text = label,
|
|
|
|
|
color = Color.White,
|
|
|
|
|
fontSize = 12.sp
|
|
|
|
|
)
|
|
|
|
|
Text(
|
2026-03-05 12:23:43 +01:00
|
|
|
text = formatValue(value),
|
2026-01-29 11:13:31 +01:00
|
|
|
color = Color.White.copy(alpha = 0.7f),
|
|
|
|
|
fontSize = 12.sp
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
Slider(
|
|
|
|
|
value = value,
|
|
|
|
|
onValueChange = onValueChange,
|
|
|
|
|
valueRange = valueRange,
|
|
|
|
|
colors = SliderDefaults.colors(
|
2026-03-05 12:23:43 +01:00
|
|
|
thumbColor = AppColors.Accent,
|
|
|
|
|
activeTrackColor = AppColors.Accent,
|
2026-01-29 11:13:31 +01:00
|
|
|
inactiveTrackColor = Color.White.copy(alpha = 0.3f)
|
|
|
|
|
),
|
2026-03-05 12:23:43 +01:00
|
|
|
modifier = Modifier
|
|
|
|
|
.height(24.dp)
|
|
|
|
|
.semantics { contentDescription = "$label: ${formatValue(value)}" }
|
2026-01-29 11:13:31 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-28 15:26:41 +01:00
|
|
|
/**
|
2026-03-05 12:23:43 +01:00
|
|
|
* Capture button with processing indicator.
|
2026-01-28 15:26:41 +01:00
|
|
|
*/
|
|
|
|
|
@Composable
|
|
|
|
|
private fun CaptureButton(
|
|
|
|
|
isCapturing: Boolean,
|
2026-03-05 12:23:43 +01:00
|
|
|
isProcessing: Boolean,
|
2026-01-28 15:26:41 +01:00
|
|
|
onClick: () -> Unit,
|
|
|
|
|
modifier: Modifier = Modifier
|
|
|
|
|
) {
|
|
|
|
|
val outerSize = 72.dp
|
|
|
|
|
val innerSize = if (isCapturing) 48.dp else 60.dp
|
|
|
|
|
|
|
|
|
|
Box(
|
|
|
|
|
modifier = modifier
|
|
|
|
|
.size(outerSize)
|
|
|
|
|
.clip(CircleShape)
|
|
|
|
|
.border(4.dp, Color.White, CircleShape)
|
2026-03-05 12:23:43 +01:00
|
|
|
.clickable(
|
|
|
|
|
enabled = !isCapturing,
|
|
|
|
|
role = Role.Button,
|
|
|
|
|
onClick = onClick
|
|
|
|
|
)
|
|
|
|
|
.semantics {
|
|
|
|
|
contentDescription = "Capture photo with tilt-shift effect"
|
|
|
|
|
if (isCapturing) stateDescription = "Processing photo"
|
|
|
|
|
},
|
2026-01-28 15:26:41 +01:00
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
Box(
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(innerSize)
|
|
|
|
|
.clip(CircleShape)
|
2026-03-05 12:23:43 +01:00
|
|
|
.background(if (isCapturing) AppColors.Accent else Color.White),
|
|
|
|
|
contentAlignment = Alignment.Center
|
|
|
|
|
) {
|
|
|
|
|
if (isProcessing) {
|
|
|
|
|
CircularProgressIndicator(
|
|
|
|
|
modifier = Modifier.size(24.dp),
|
|
|
|
|
color = Color.Black,
|
|
|
|
|
strokeWidth = 3.dp
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-28 15:26:41 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-03-03 22:32:11 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Rounded thumbnail of the last captured photo.
|
|
|
|
|
* Tapping opens the image in the default photo viewer.
|
|
|
|
|
*/
|
|
|
|
|
@Composable
|
|
|
|
|
private fun LastPhotoThumbnail(
|
|
|
|
|
thumbnail: Bitmap?,
|
|
|
|
|
onTap: () -> Unit,
|
|
|
|
|
modifier: Modifier = Modifier
|
|
|
|
|
) {
|
|
|
|
|
AnimatedVisibility(
|
|
|
|
|
visible = thumbnail != null,
|
|
|
|
|
enter = fadeIn() + scaleIn(initialScale = 0.6f),
|
|
|
|
|
exit = fadeOut(),
|
|
|
|
|
modifier = modifier
|
|
|
|
|
) {
|
|
|
|
|
thumbnail?.let { bmp ->
|
|
|
|
|
Image(
|
|
|
|
|
bitmap = bmp.asImageBitmap(),
|
2026-03-05 12:23:43 +01:00
|
|
|
contentDescription = "Last captured photo. Tap to open in viewer.",
|
2026-03-03 22:32:11 +01:00
|
|
|
contentScale = ContentScale.Crop,
|
|
|
|
|
modifier = Modifier
|
|
|
|
|
.size(52.dp)
|
|
|
|
|
.clip(RoundedCornerShape(10.dp))
|
|
|
|
|
.border(2.dp, Color.White, RoundedCornerShape(10.dp))
|
2026-03-05 12:23:43 +01:00
|
|
|
.clickable(role = Role.Button, onClick = onTap)
|
2026-03-03 22:32:11 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|