photos: (feat) basic editor
- Commit
14f20cb229263461277a235b6844475891e0e250- Author
- Vayun Mathur <[email protected]>
- When
- 2026-04-13 05:10 UTC (7 months ago)
- Parents
fc29749
Diff
.idea/deploymentTargetSelector.xml
diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xmlindex a3d598e158..f0f38be0b1 100644--- a/.idea/deploymentTargetSelector.xml+++ b/.idea/deploymentTargetSelector.xml@@ -69,6 +69,14 @@ </SelectionState> <SelectionState runConfigName="photos"> <option name="selectionMode" value="DROPDOWN" />+ <DropdownSelection timestamp="2026-04-13T03:55:05.549332400Z">+ <Target type="DEFAULT_BOOT">+ <handle>+ <DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Vayun\.android\avd\Medium_Phone.avd" />+ </handle>+ </Target>+ </DropdownSelection>+ <DialogSelection /> </SelectionState> <SelectionState runConfigName="health"> <option name="selectionMode" value="DROPDOWN" />
library/src/main/java/com/vayunmathur/library/ui/Icons.kt
diff --git a/library/src/main/java/com/vayunmathur/library/ui/Icons.kt b/library/src/main/java/com/vayunmathur/library/ui/Icons.ktindex 306857f8cb..b22c6968fb 100644--- a/library/src/main/java/com/vayunmathur/library/ui/Icons.kt+++ b/library/src/main/java/com/vayunmathur/library/ui/Icons.kt@@ -60,6 +60,21 @@ fun IconCopy(tint: Color = LocalContentColor.current) { Icon(painterResource(R.drawable.outline_content_copy_24), "Copy", tint = tint) } +@Composable+fun IconCrop(tint: Color = LocalContentColor.current) {+ Icon(painterResource(R.drawable.crop_24px), "Crop", tint = tint)+}++@Composable+fun IconRotateLeft(tint: Color = LocalContentColor.current) {+ Icon(painterResource(R.drawable.rotate_left_24px), "Rotate Left", tint = tint)+}++@Composable+fun IconRotateRight(tint: Color = LocalContentColor.current) {+ Icon(painterResource(R.drawable.rotate_right_24px), "Rotate Right", tint = tint)+}+ @Composable fun IconNavigation(navBack: () -> Unit) { IconButton({
library/src/main/java/com/vayunmathur/library/util/RoomViewModel.kt
diff --git a/library/src/main/java/com/vayunmathur/library/util/RoomViewModel.kt b/library/src/main/java/com/vayunmathur/library/util/RoomViewModel.ktindex b1bc871b29..cf85bfe88b 100644--- a/library/src/main/java/com/vayunmathur/library/util/RoomViewModel.kt+++ b/library/src/main/java/com/vayunmathur/library/util/RoomViewModel.kt@@ -176,26 +176,27 @@ class DatabaseViewModel(val database: RoomDatabase, vararg daos: Pair<KClass<*>, @Suppress("UNCHECKED_CAST") inline fun <reified E : DatabaseItem> data(filterQuery: String? = null): StateFlow<List<E>> {- return runBlocking {- dataStateCache.getOrPut(Pair(E::class, filterQuery)) {- val tableName = E::class.simpleName!!-- callbackFlow<List<E>> {- // 1. Create an observer for the specific table name- val observer = object : InvalidationTracker.Observer(tableName) {- override fun onInvalidated(tables: Set<String>) {- // When the table changes, re-fetch the data- launch { send(getAll<E>(filterQuery)) }- }+ return dataStateCache.getOrPut(Pair(E::class, filterQuery)) {+ val tableName = E::class.simpleName!!++ callbackFlow<List<E>> {+ // Fetch initial data+ send(getAll<E>(filterQuery))++ // 1. Create an observer for the specific table name+ val observer = object : InvalidationTracker.Observer(tableName) {+ override fun onInvalidated(tables: Set<String>) {+ // When the table changes, re-fetch the data+ launch { send(getAll<E>(filterQuery)) } }+ } - database.invalidationTracker.addObserver(observer)+ database.invalidationTracker.addObserver(observer) - // 3. Clean up the observer when the UI stops listening- awaitClose { database.invalidationTracker.removeObserver(observer) }- }.stateIn(viewModelScope, SharingStarted.Eagerly, getAll<E>())- } as StateFlow<List<E>>- }+ // 3. Clean up the observer when the UI stops listening+ awaitClose { database.invalidationTracker.removeObserver(observer) }+ }.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())+ } as StateFlow<List<E>> } inline fun <reified E: DatabaseItem> upsertAll(items: List<E>) {
library/src/main/res/drawable/crop_24px.xml
diff --git a/library/src/main/res/drawable/crop_24px.xml b/library/src/main/res/drawable/crop_24px.xmlnew file mode 100644index 0000000000..e406abbd31--- /dev/null+++ b/library/src/main/res/drawable/crop_24px.xml@@ -0,0 +1,3 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">+ <path android:fillColor="@android:color/white" android:pathData="M760,880L760,800L880,800L880,720L760,720L760,200L240,200L240,80L160,80L160,200L80,200L80,280L160,280L160,720Q160,753 183.5,776.5Q207,800 240,800L680,800L680,880L760,880ZM240,720L240,280L680,280L680,720L240,720ZM760,200L760,200L760,200ZM240,720L240,720L240,720Z"/>+</vector>
library/src/main/res/drawable/rotate_left_24px.xml
diff --git a/library/src/main/res/drawable/rotate_left_24px.xml b/library/src/main/res/drawable/rotate_left_24px.xmlnew file mode 100644index 0000000000..111b89bfe5--- /dev/null+++ b/library/src/main/res/drawable/rotate_left_24px.xml@@ -0,0 +1,3 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">+ <path android:fillColor="@android:color/white" android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q560,80 630.5,109Q701,138 756,190L840,106L840,360L586,360L690,256Q649,219 598,199.5Q547,180 480,180Q355,180 267.5,267.5Q180,355 180,480Q180,605 267.5,692.5Q355,780 480,780Q563,780 632,739.5Q701,699 743,630L827,665Q772,754 686.5,817Q601,880 480,880Z"/>+</vector>
library/src/main/res/drawable/rotate_right_24px.xml
diff --git a/library/src/main/res/drawable/rotate_right_24px.xml b/library/src/main/res/drawable/rotate_right_24px.xmlnew file mode 100644index 0000000000..6a97c7d6c2--- /dev/null+++ b/library/src/main/res/drawable/rotate_right_24px.xml@@ -0,0 +1,3 @@+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">+ <path android:fillColor="@android:color/white" android:pathData="M480,880Q359,880 273.5,817Q188,754 133,665L217,630Q259,699 328,739.5Q397,780 480,780Q605,780 692.5,692.5Q780,605 780,480Q780,355 692.5,267.5Q605,180 480,180Q413,180 362,199.5Q311,219 270,256L374,360L120,360L120,106L204,190Q259,138 329.5,109Q400,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880Z"/>+</vector>
maps/src/main/assets/world_map.jpg
diff --git a/maps/src/main/assets/world_map.jpg b/maps/src/main/assets/world_map.jpgnew file mode 100644index 0000000000..cda1cde0c7Binary files /dev/null and b/maps/src/main/assets/world_map.jpg differ
maps/src/main/assets/world_map.png
diff --git a/maps/src/main/assets/world_map.png b/maps/src/main/assets/world_map.pngdeleted file mode 100644index b012e0704e..0000000000Binary files a/maps/src/main/assets/world_map.png and /dev/null differ
photos/src/main/java/com/vayunmathur/photos/MainActivity.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/MainActivity.kt b/photos/src/main/java/com/vayunmathur/photos/MainActivity.ktindex efe6b3d232..e6ab16509e 100644--- a/photos/src/main/java/com/vayunmathur/photos/MainActivity.kt+++ b/photos/src/main/java/com/vayunmathur/photos/MainActivity.kt@@ -26,6 +26,7 @@ import com.vayunmathur.photos.data.MIGRATION_1_2 import com.vayunmathur.photos.ui.GalleryPage import com.vayunmathur.photos.ui.MapPage import com.vayunmathur.photos.ui.PhotoPage+import com.vayunmathur.photos.ui.EditPhotoPage import kotlinx.serialization.Serializable class MainActivity : ComponentActivity() {@@ -69,6 +70,9 @@ sealed interface Route: NavKey { @Serializable data class PhotoPage(val id: Long, val overridePhotosList: List<Photo>?): Route + @Serializable+ data class EditPhoto(val id: Long): Route+ @Serializable data object Map: Route }@@ -86,7 +90,11 @@ fun Navigation(viewModel: DatabaseViewModel) { } entry<Route.PhotoPage> {- PhotoPage(viewModel, it.id, it.overridePhotosList)+ PhotoPage(backStack, viewModel, it.id, it.overridePhotosList)+ }++ entry<Route.EditPhoto> {+ EditPhotoPage(backStack, viewModel, it.id) } } }
photos/src/main/java/com/vayunmathur/photos/ui/EditPhotoPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/EditPhotoPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/EditPhotoPage.ktnew file mode 100644index 0000000000..de41cda026--- /dev/null+++ b/photos/src/main/java/com/vayunmathur/photos/ui/EditPhotoPage.kt@@ -0,0 +1,343 @@+package com.vayunmathur.photos.ui++import android.content.ContentValues+import android.graphics.Bitmap+import android.graphics.BitmapFactory+import android.graphics.Matrix+import android.net.Uri+import android.os.Build+import android.os.Environment+import android.provider.MediaStore+import androidx.compose.foundation.Canvas+import androidx.compose.foundation.background+import androidx.compose.foundation.gestures.detectDragGestures+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxWithConstraints+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.offset+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.shape.CircleShape+import androidx.compose.material3.DropdownMenu+import androidx.compose.material3.DropdownMenuItem+import androidx.compose.material3.ExperimentalMaterial3Api+import androidx.compose.material3.IconButton+import androidx.compose.material3.Scaffold+import androidx.compose.material3.Text+import androidx.compose.material3.TopAppBar+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableFloatStateOf+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.geometry.Rect+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.drawscope.Stroke+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.input.pointer.pointerInput+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.unit.IntOffset+import androidx.compose.ui.unit.dp+import androidx.core.net.toUri+import coil.compose.AsyncImage+import com.vayunmathur.library.ui.IconCheck+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.IconCrop+import com.vayunmathur.library.ui.IconNavigation+import com.vayunmathur.library.ui.IconRotateLeft+import com.vayunmathur.library.ui.IconRotateRight+import com.vayunmathur.library.ui.IconSave+import com.vayunmathur.library.util.DatabaseViewModel+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.photos.Route+import com.vayunmathur.photos.data.Photo+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.launch+import kotlinx.coroutines.withContext+import java.io.InputStream+import kotlin.math.roundToInt++@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun EditPhotoPage(backStack: NavBackStack<Route>, viewModel: DatabaseViewModel, id: Long) {+ val context = LocalContext.current+ val photo by viewModel.getNullable<Photo>(id)+ val scope = rememberCoroutineScope()++ var isCropping by remember { mutableStateOf(false) }+ var rotation by remember { mutableFloatStateOf(0f) }+ var cropRect by remember { mutableStateOf(Rect(0f, 0f, 1f, 1f)) }+ var showSaveMenu by remember { mutableStateOf(false) }++ Scaffold(+ topBar = {+ TopAppBar(+ title = { Text("Edit Photo") },+ navigationIcon = {+ IconNavigation(backStack)+ },+ actions = {+ if (isCropping) {+ IconButton(onClick = { isCropping = false }) {+ IconCheck()+ }+ IconButton(onClick = {+ cropRect = Rect(0f, 0f, 1f, 1f)+ isCropping = false+ }) {+ IconClose()+ }+ } else {+ IconButton(onClick = { isCropping = true }) {+ IconCrop()+ }+ IconButton(onClick = { rotation -= 90f }) {+ IconRotateLeft()+ }+ IconButton(onClick = { rotation += 90f }) {+ IconRotateRight()+ }+ Box {+ IconButton(onClick = { showSaveMenu = true }) {+ IconSave()+ }+ DropdownMenu(+ expanded = showSaveMenu,+ onDismissRequest = { showSaveMenu = false }+ ) {+ DropdownMenuItem(+ text = { Text("Save") },+ onClick = {+ showSaveMenu = false+ photo?.let {+ scope.launch {+ savePhoto(context, viewModel, it, rotation, cropRect, false)+ backStack.pop()+ }+ }+ }+ )+ DropdownMenuItem(+ text = { Text("Save as Copy") },+ onClick = {+ showSaveMenu = false+ photo?.let {+ scope.launch {+ savePhoto(context, viewModel, it, rotation, cropRect, true)+ backStack.pop()+ }+ }+ }+ )+ }+ }+ }+ }+ )+ }+ ) { paddingValues ->+ Column(+ modifier = Modifier+ .fillMaxSize()+ .padding(paddingValues)+ .background(Color.Black)+ ) {+ BoxWithConstraints(+ modifier = Modifier+ .weight(1f)+ .fillMaxWidth(),+ contentAlignment = Alignment.Center+ ) {+ val maxWidth = constraints.maxWidth.toFloat()+ val maxHeight = constraints.maxHeight.toFloat()++ photo?.let { p ->+ val isFlipped = (rotation / 90f).roundToInt() % 2 != 0+ val photoRatio = if (isFlipped) p.height.toFloat() / p.width.toFloat() else p.width.toFloat() / p.height.toFloat()+ val containerRatio = maxWidth / maxHeight++ val (imageWidth, imageHeight) = if (photoRatio > containerRatio) {+ maxWidth to (maxWidth / photoRatio)+ } else {+ (maxHeight * photoRatio) to maxHeight+ }++ Box(modifier = Modifier.size(imageWidth.dp, imageHeight.dp)) {+ AsyncImage(+ model = p.uri.toUri(),+ contentDescription = null,+ modifier = Modifier+ .fillMaxSize()+ .graphicsLayer {+ rotationZ = rotation+ },+ contentScale = ContentScale.Fit+ )++ if (isCropping) {+ CropOverlay(+ cropRect = cropRect,+ onCropRectChange = { cropRect = it }+ )+ }+ }+ }+ }+ }+ }+}++@Composable+fun CropOverlay(+ cropRect: Rect,+ onCropRectChange: (Rect) -> Unit+) {+ BoxWithConstraints(modifier = Modifier.fillMaxSize()) {+ val width = constraints.maxWidth.toFloat()+ val height = constraints.maxHeight.toFloat()++ Canvas(modifier = Modifier.fillMaxSize()) {+ val rect = Rect(+ left = cropRect.left * width,+ top = cropRect.top * height,+ right = cropRect.right * width,+ bottom = cropRect.bottom * height+ )+ + drawRect(+ color = Color.White,+ topLeft = Offset(rect.left, rect.top),+ size = androidx.compose.ui.geometry.Size(rect.width, rect.height),+ style = Stroke(width = 2.dp.toPx())+ )+ }++ Handle(+ offset = Offset(cropRect.left * width, cropRect.top * height),+ onDrag = { delta ->+ val newLeft = (cropRect.left + delta.x / width).coerceIn(0f, cropRect.right - 0.1f)+ val newTop = (cropRect.top + delta.y / height).coerceIn(0f, cropRect.bottom - 0.1f)+ onCropRectChange(cropRect.copy(left = newLeft, top = newTop))+ }+ )+ Handle(+ offset = Offset(cropRect.right * width, cropRect.top * height),+ onDrag = { delta ->+ val newRight = (cropRect.right + delta.x / width).coerceIn(cropRect.left + 0.1f, 1f)+ val newTop = (cropRect.top + delta.y / height).coerceIn(0f, cropRect.bottom - 0.1f)+ onCropRectChange(cropRect.copy(right = newRight, top = newTop))+ }+ )+ Handle(+ offset = Offset(cropRect.left * width, cropRect.bottom * height),+ onDrag = { delta ->+ val newLeft = (cropRect.left + delta.x / width).coerceIn(0f, cropRect.right - 0.1f)+ val newBottom = (cropRect.bottom + delta.y / height).coerceIn(cropRect.top + 0.1f, 1f)+ onCropRectChange(cropRect.copy(left = newLeft, bottom = newBottom))+ }+ )+ Handle(+ offset = Offset(cropRect.right * width, cropRect.bottom * height),+ onDrag = { delta ->+ val newRight = (cropRect.right + delta.x / width).coerceIn(cropRect.left + 0.1f, 1f)+ val newBottom = (cropRect.bottom + delta.y / height).coerceIn(cropRect.top + 0.1f, 1f)+ onCropRectChange(cropRect.copy(right = newRight, bottom = newBottom))+ }+ )+ }+}++@Composable+fun Handle(offset: Offset, onDrag: (Offset) -> Unit) {+ val density = LocalDensity.current+ val handleSize = 30.dp+ val handleRadiusPx = with(density) { (handleSize / 2).toPx() }++ Box(+ modifier = Modifier+ .offset {+ IntOffset(+ (offset.x - handleRadiusPx).roundToInt(),+ (offset.y - handleRadiusPx).roundToInt()+ )+ }+ .size(handleSize)+ .background(Color.White, CircleShape)+ .pointerInput(Unit) {+ detectDragGestures { change, dragAmount ->+ change.consume()+ onDrag(dragAmount)+ }+ }+ )+}++suspend fun savePhoto(+ context: android.content.Context,+ viewModel: DatabaseViewModel,+ photo: Photo,+ rotation: Float,+ cropRect: Rect,+ asCopy: Boolean+) = withContext(Dispatchers.IO) {+ val inputStream: InputStream? = context.contentResolver.openInputStream(photo.uri.toUri())+ val originalBitmap = BitmapFactory.decodeStream(inputStream) ?: return@withContext+ + val matrix = Matrix()+ matrix.postRotate(rotation)+ + var transformedBitmap = Bitmap.createBitmap(+ originalBitmap,+ 0, 0, originalBitmap.width, originalBitmap.height,+ matrix, true+ )+ + val left = (cropRect.left * transformedBitmap.width).roundToInt().coerceIn(0, transformedBitmap.width - 1)+ val top = (cropRect.top * transformedBitmap.height).roundToInt().coerceIn(0, transformedBitmap.height - 1)+ val width = ((cropRect.right - cropRect.left) * transformedBitmap.width).roundToInt().coerceAtMost(transformedBitmap.width - left)+ val height = ((cropRect.bottom - cropRect.top) * transformedBitmap.height).roundToInt().coerceAtMost(transformedBitmap.height - top)+ + if (width > 0 && height > 0) {+ transformedBitmap = Bitmap.createBitmap(transformedBitmap, left, top, width, height)+ }++ val resolver = context.contentResolver+ + if (asCopy) {+ val contentValues = ContentValues().apply {+ put(MediaStore.Images.Media.DISPLAY_NAME, "Edited_${photo.name}")+ put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg")+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {+ put(MediaStore.Images.Media.RELATIVE_PATH, Environment.DIRECTORY_PICTURES)+ }+ }+ val uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)+ uri?.let {+ resolver.openOutputStream(it)?.use { out ->+ transformedBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)+ }+ }+ } else {+ // Overwrite+ val uri = photo.uri.toUri()+ try {+ resolver.openOutputStream(uri, "rwt")?.use { out ->+ transformedBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)+ }+ } catch (e: Exception) {+ e.printStackTrace()+ }+ }+ + syncPhotos(context, viewModel)+}
photos/src/main/java/com/vayunmathur/photos/ui/GalleryPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/GalleryPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/GalleryPage.ktindex 0550697f76..d2d86bd19f 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/GalleryPage.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/GalleryPage.kt@@ -166,7 +166,7 @@ suspend fun syncPhotos(context: Context, viewModel: DatabaseViewModel) { val videoData = if (isVideo) VideoData(cursor.getLong(durationColumn)) else null val existing = existingPhotos[id]- if (existing == null || existing.date != date || existing.uri != contentUri || existing.videoData != videoData) {+ if (existing == null || existing.date != date || existing.uri != contentUri || existing.videoData != videoData || existing.width != width || existing.height != height) { newOrUpdatedPhotos += Photo(id, name, contentUri, date, width, height, existing?.exifSet ?: false, existing?.lat, existing?.long, videoData) } }
photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.ktindex 43227c37d9..457ae26fd9 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/PhotoPage.kt@@ -59,8 +59,11 @@ import androidx.media3.ui.compose.PlayerSurface import androidx.media3.ui.compose.SURFACE_TYPE_TEXTURE_VIEW import coil.compose.AsyncImage import coil.request.ImageRequest+import com.vayunmathur.library.ui.IconEdit import com.vayunmathur.library.util.DatabaseViewModel+import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.photos.R+import com.vayunmathur.photos.Route import com.vayunmathur.photos.data.Photo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.distinctUntilChanged@@ -75,7 +78,7 @@ import kotlin.time.Instant data class ZoomState(val scale: Float = 1f, val offset: Offset = Offset.Zero) @Composable-fun PhotoPage(viewModel: DatabaseViewModel, id: Long, overridePhotosList: List<Photo>?) {+fun PhotoPage(backStack: NavBackStack<Route>, viewModel: DatabaseViewModel, id: Long, overridePhotosList: List<Photo>?) { val photosAll by viewModel.data<Photo>().collectAsState(initial = emptyList()) val photos = overridePhotosList ?: photosAll val context = LocalContext.current@@ -116,7 +119,8 @@ fun PhotoPage(viewModel: DatabaseViewModel, id: Long, overridePhotosList: List<P isMetadataVisible = isMetadataVisible, currentZoom = zoomState, onZoomUpdate = { newState -> zoomStates[photo.id] = newState },- onToggleMetadata = { isMetadataVisible = !isMetadataVisible }+ onToggleMetadata = { isMetadataVisible = !isMetadataVisible },+ onEditPhoto = { backStack.add(Route.EditPhoto(photo.id)) } ) } }@@ -133,7 +137,8 @@ fun PhotoDetailView( isMetadataVisible: Boolean, currentZoom: ZoomState, onZoomUpdate: (ZoomState) -> Unit,- onToggleMetadata: () -> Unit+ onToggleMetadata: () -> Unit,+ onEditPhoto: () -> Unit ) { var countryName by remember(photo.id) { mutableStateOf<String?>(null) } var size by remember { mutableStateOf(IntSize.Zero) }@@ -291,6 +296,15 @@ fun PhotoDetailView( Text(text = "Location: ${countryName ?: "Detecting..."}", color = Color.LightGray) } Text(text = "Resolution: ${photo.width} x ${photo.height}", color = Color.LightGray)++ if (photo.videoData == null) {+ IconButton(+ onClick = onEditPhoto,+ modifier = Modifier.align(Alignment.End)+ ) {+ IconEdit(tint = Color.White)+ }+ } } } }@@ -387,4 +401,4 @@ fun VideoPlayer( } } }-}\ No newline at end of file+}