Modern Apps git

← Modern-Apps.git

photos: albums view (#705)

Commit
16bc8c25ccf820d6359d943aac52fc7d683d1805
Author
vayun-mathur <[email protected]>
When
2026-09-13 18:13 UTC (2 months ago)
Parents
a6f24e7

Diff

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 17f0ff25fa..a8316696d2 100644--- a/photos/src/main/java/com/vayunmathur/photos/MainActivity.kt+++ b/photos/src/main/java/com/vayunmathur/photos/MainActivity.kt@@ -22,6 +22,7 @@ import androidx.compose.foundation.layout.padding import com.vayunmathur.library.util.AppMessages import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.LoadingIndicator+import com.vayunmathur.library.ui.IconAlbum import com.vayunmathur.library.ui.IconGroup import com.vayunmathur.library.ui.IconLock import com.vayunmathur.library.ui.IconMap@@ -72,6 +73,8 @@ import com.vayunmathur.library.widgets.updateWidgetPreviews import com.vayunmathur.photos.data.Photo import com.vayunmathur.photos.data.PhotosRepository import com.vayunmathur.photos.glance.PhotoGlanceWidgetReceiver+import com.vayunmathur.photos.ui.AlbumDetailPage+import com.vayunmathur.photos.ui.AlbumsPage import com.vayunmathur.photos.ui.GalleryPage import com.vayunmathur.photos.ui.MapPage import com.vayunmathur.photos.ui.PeoplePage@@ -232,6 +235,12 @@ sealed interface Route: NavKey {     @Serializable     data object People: Route +    @Serializable+    data object Albums: Route++    @Serializable+    data class AlbumDetail(val albumName: String): Route+     @Serializable     data object Trash: Route @@ -317,6 +326,14 @@ fun Navigation(             PeoplePage(backStack, galleryViewModel)         } +        entry<Route.Albums>(metadata = SiblingPage()) {+            AlbumsPage(backStack, galleryViewModel)+        }++        entry<Route.AlbumDetail> {+            AlbumDetailPage(backStack, galleryViewModel, it.albumName)+        }+         entry<Route.PhotoPage>(metadata = ListDetailPage() + MorphPage()) {             PhotoPage(galleryViewModel, photoMapViewModel, it.id, it.overridePhotosList, it.pendingUri, backStack)         }@@ -368,6 +385,7 @@ private enum class MainRoute(val route: Route, @StringRes val titleRes: Int, val     Gallery(Route.Gallery, R.string.label_gallery, { IconPhotoLibrary() }),     Map(Route.Map, R.string.label_map, { IconMap() }),     People(Route.People, R.string.label_people, { IconGroup() }),+    Albums(Route.Albums, R.string.label_albums, { IconAlbum() }),     Trash(Route.Trash, R.string.label_trash, { IconDelete() }),     SecureFolder(Route.SecureFolder, R.string.label_secure_folder, { IconLock() }) }
photos/src/main/java/com/vayunmathur/photos/data/Photo.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/data/Photo.kt b/photos/src/main/java/com/vayunmathur/photos/data/Photo.ktindex fc0fa7c882..58712b4f09 100644--- a/photos/src/main/java/com/vayunmathur/photos/data/Photo.kt+++ b/photos/src/main/java/com/vayunmathur/photos/data/Photo.kt@@ -78,6 +78,10 @@ data class Photo(     // text layer over the image. Null for videos, for photos with no text, and     // for rows OCR'd before this column existed (the viewer backfills those).     val ocrBoxes: String? = null,+    // MediaStore bucket (BUCKET_DISPLAY_NAME): the album/folder the item lives+    // in. Null only on rows written before the column existed, which the next+    // sync backfills; the Albums view shows those as Unknown meanwhile.+    val album: String? = null, ) : DatabaseItem {     /** True for an animated image, which plays rather than showing a single frame. */     val isGif: Boolean get() = mimeType.equals("image/gif", ignoreCase = true)
photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt b/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.ktindex 7ca50b2bbf..bbcd1136be 100644--- a/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt+++ b/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt@@ -25,7 +25,7 @@ interface PhotoDao {     // trash, people) groups/sorts by date descending anyway, so the composition     // pass now groups pre-ordered rows instead of sorting the whole library on     // the main thread — cutting first-load jank without changing what's shown.-    @Query("SELECT id, name, uri, date, width, height, dateModified, exifSet, lat, `long`, duration, fullWidth, fullHeight, croppedWidth, croppedHeight, croppedLeft, croppedTop, projectionType, isTrashed, faceScanned, ocrScanned, clipScanned, mimeType FROM Photo ORDER BY date DESC")+    @Query("SELECT id, name, uri, date, width, height, dateModified, exifSet, lat, `long`, duration, fullWidth, fullHeight, croppedWidth, croppedHeight, croppedLeft, croppedTop, projectionType, isTrashed, faceScanned, ocrScanned, clipScanned, mimeType, album FROM Photo ORDER BY date DESC")     fun getAllFlow(): Flow<List<Photo>>      @Query("SELECT * FROM Photo WHERE id = :id")@@ -252,13 +252,13 @@ data class ExifResult(     val pano: PanoData?, ) -@Database(entities = [Photo::class, Person::class, PhotoFace::class], version = 17, exportSchema = false)+@Database(entities = [Photo::class, Person::class, PhotoFace::class], version = 18, exportSchema = false) abstract class PhotoDatabase : RoomDatabase() {     abstract fun photoDao(): PhotoDao     abstract fun faceDao(): FaceDao      companion object : com.vayunmathur.library.util.DatabaseMigrations {-        override val migrations: List<Migration> = listOf(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9, MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13, MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17)+        override val migrations: List<Migration> = listOf(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7, MIGRATION_7_8, MIGRATION_8_9, MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13, MIGRATION_13_14, MIGRATION_14_15, MIGRATION_15_16, MIGRATION_16_17, MIGRATION_17_18)     } } @@ -319,6 +319,14 @@ val MIGRATION_16_17 = Migration(16, 17) {     it.execSQL("CREATE INDEX IF NOT EXISTS `index_Photo_isTrashed_duration` ON `Photo` (`isTrashed`, `duration`)") } +val MIGRATION_17_18 = Migration(17, 18) {+    // Add the MediaStore bucket (BUCKET_DISPLAY_NAME) so the Albums view can+    // group photos. Existing rows stay NULL until the next sync backfills+    // them; the UI shows those as Unknown meanwhile. SQL mirrors Room's+    // generated schema exactly so schema validation passes.+    it.execSQL("ALTER TABLE Photo ADD COLUMN album TEXT")+}+ val MIGRATION_8_9 = Migration(8, 9) {     // Move OCR text off the FTS side-table and onto the Photo row so search is a     // plain case-insensitive LIKE (no external inference service). ocrScanned
photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.ktnew file mode 100644index 0000000000..ffbfc93c9a--- /dev/null+++ b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailPage.kt@@ -0,0 +1,27 @@+package com.vayunmathur.photos.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.derivedStateOf+import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.photos.Route+import com.vayunmathur.photos.util.GalleryViewModel++/** Binds [GalleryViewModel] to the stateless [AlbumDetailScreen] for one album. */+@Composable+fun AlbumDetailPage(+    backStack: NavBackStack<Route>,+    galleryViewModel: GalleryViewModel,+    albumName: String,+) {+    val albums by galleryViewModel.albums.collectAsState()+    val album by remember { derivedStateOf { albums.firstOrNull { it.name == albumName } } }++    AlbumDetailScreen(+        backStack = backStack,+        albumName = albumName,+        album = album,+    )+}
photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.kt b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.ktnew file mode 100644index 0000000000..a070de6eb2--- /dev/null+++ b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumDetailScreen.kt@@ -0,0 +1,77 @@+package com.vayunmathur.photos.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.grid.GridCells+import androidx.compose.foundation.lazy.grid.LazyVerticalGrid+import androidx.compose.foundation.lazy.grid.items+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.AppScaffold+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.photos.R+import com.vayunmathur.photos.Route+import com.vayunmathur.photos.data.Photo+import com.vayunmathur.photos.pushPhoto+import com.vayunmathur.photos.util.Album+import com.vayunmathur.photos.util.ImageLoader++/**+ * The photo grid for one album, with no dependency on the ViewModel so it can+ * be rendered from a `@Preview`.+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun AlbumDetailScreen(+    backStack: NavBackStack<Route>,+    albumName: String,+    album: Album?,+    /**+     * How a grid tile paints its photo. Previews pass a placeholder, because+     * Layoutlib has neither MediaStore nor the [ImageLoader] singleton+     * MainActivity initialises.+     */+    thumbnail: @Composable (Photo, Modifier) -> Unit = { photo, modifier -> ImageLoader.PhotoItem(photo, modifier) },+) {+    val title = if (albumName == Album.UNKNOWN_NAME) stringResource(R.string.albums_unknown) else albumName+    AppScaffold(+        title = title,+        onNavigateBack = { backStack.pop() },+        scrollBehavior = appBarScrollBehavior(),+    ) { padding ->+        val photos = album?.photos.orEmpty()+        if (photos.isEmpty()) {+            EmptyState(+                title = stringResource(R.string.albums_empty),+                modifier = Modifier.fillMaxSize().padding(padding),+            )+        } else {+            LazyVerticalGrid(+                columns = GridCells.Fixed(3),+                horizontalArrangement = Arrangement.spacedBy(4.dp),+                verticalArrangement = Arrangement.spacedBy(4.dp),+                modifier = Modifier.fillMaxSize().padding(padding).padding(4.dp),+            ) {+                items(photos, key = { it.id }, contentType = { "photo_thumbnail" }) { photo ->+                    ImageLoader.SelectablePhotoItem(+                        photo = photo,+                        isSelected = false,+                        isSelectionMode = false,+                        onToggleSelection = {},+                        onClick = {+                            backStack.pushPhoto(Route.PhotoPage(photo.id, photos))+                        },+                        thumbnail = thumbnail,+                        sharedKey = photo.id,+                    )+                }+            }+        }+    }+}
photos/src/main/java/com/vayunmathur/photos/ui/AlbumsPage.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumsPage.kt b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumsPage.ktnew file mode 100644index 0000000000..ad61ea50da--- /dev/null+++ b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumsPage.kt@@ -0,0 +1,23 @@+package com.vayunmathur.photos.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.photos.Route+import com.vayunmathur.photos.util.AlbumsUiState+import com.vayunmathur.photos.util.GalleryViewModel++/** Binds [GalleryViewModel] to the stateless [AlbumsScreen]. */+@Composable+fun AlbumsPage(+    backStack: NavBackStack<Route>,+    galleryViewModel: GalleryViewModel,+) {+    val albums by galleryViewModel.albums.collectAsState()++    AlbumsScreen(+        backStack = backStack,+        state = AlbumsUiState(albums = albums),+    )+}
photos/src/main/java/com/vayunmathur/photos/ui/AlbumsScreen.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/AlbumsScreen.kt b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumsScreen.ktnew file mode 100644index 0000000000..a7157a1f2d--- /dev/null+++ b/photos/src/main/java/com/vayunmathur/photos/ui/AlbumsScreen.kt@@ -0,0 +1,129 @@+package com.vayunmathur.photos.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.aspectRatio+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.grid.GridCells+import androidx.compose.foundation.lazy.grid.LazyVerticalGrid+import androidx.compose.foundation.lazy.grid.items+import androidx.compose.ui.res.pluralStringResource+import com.vayunmathur.library.ui.EmptyState+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import androidx.core.net.toUri+import com.vayunmathur.library.image.ImageRequest+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.invisibleClickable+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.photos.NavigationBar+import com.vayunmathur.photos.R+import com.vayunmathur.photos.Route+import com.vayunmathur.photos.data.Photo+import com.vayunmathur.photos.util.Album+import com.vayunmathur.photos.util.AlbumsUiState++/**+ * The albums grid, with no dependency on the ViewModel so it can be rendered from a+ * `@Preview` — see `src/screenshotTest`, which is where the store listing images come from.+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun AlbumsScreen(+    backStack: NavBackStack<Route>,+    state: AlbumsUiState,+    /**+     * How an album tile paints its cover photo. Previews pass a placeholder,+     * because Layoutlib has neither MediaStore nor the ImageLoader singleton+     * MainActivity initialises.+     */+    thumbnail: @Composable (Photo, Modifier) -> Unit = { photo, modifier -> AlbumCover(photo, modifier) },+) {+    AppScaffold(+        title = stringResource(R.string.label_albums),+        bottomBar = { NavigationBar(Route.Albums, backStack) },+        scrollBehavior = appBarScrollBehavior(),+    ) { padding ->+        if (state.albums.isEmpty()) {+            EmptyState(+                title = stringResource(R.string.albums_empty),+                modifier = Modifier.fillMaxSize().padding(padding),+            )+        } else {+            LazyVerticalGrid(+                columns = GridCells.Fixed(2),+                horizontalArrangement = Arrangement.spacedBy(8.dp),+                verticalArrangement = Arrangement.spacedBy(12.dp),+                modifier = Modifier.fillMaxSize().padding(padding).padding(8.dp),+            ) {+                // Stable key = album name so Compose reuses tiles across re-emissions+                // instead of recreating (and re-loading) them during syncs.+                items(state.albums, key = { it.name }) { album ->+                    Column(horizontalAlignment = Alignment.CenterHorizontally) {+                        Box(+                            Modifier+                                .fillMaxWidth()+                                .aspectRatio(1f)+                                .invisibleClickable { backStack.add(Route.AlbumDetail(album.name)) },+                        ) {+                            thumbnail(album.coverPhoto, Modifier.fillMaxSize())+                        }+                        Text(+                            text = albumDisplayName(album),+                            style = MaterialTheme.typography.bodyMedium,+                            color = MaterialTheme.colorScheme.onSurface,+                            maxLines = 1,+                            overflow = TextOverflow.Ellipsis,+                            textAlign = TextAlign.Center,+                            modifier = Modifier.padding(top = 4.dp),+                        )+                        Text(+                            text = pluralStringResource(R.plurals.album_photo_count, album.count, album.count),+                            style = MaterialTheme.typography.bodySmall,+                            color = MaterialTheme.colorScheme.onSurfaceVariant,+                        )+                    }+                }+            }+        }+    }+}++/** The user-visible album name; the unknown-bucket sentinel shows R.string.albums_unknown. */+@Composable+private fun albumDisplayName(album: Album): String =+    if (album.name == Album.UNKNOWN_NAME) stringResource(R.string.albums_unknown) else album.name++/** An album's cover: the newest photo in the bucket, cropped square. */+@Composable+private fun AlbumCover(photo: Photo, modifier: Modifier) {+    val context = LocalContext.current+    AsyncImage(+        model = ImageRequest.Builder(context)+            .data(photo.uri.toUri())+            .videoFrameMillis(1000)+            .diskCacheKey("thumb_${photo.id}_${photo.dateModified}")+            .memoryCacheKey("thumb_${photo.id}_${photo.dateModified}")+            .crossfade(false)+            .size(512)+            .build(),+        contentDescription = null,+        contentScale = ContentScale.Crop,+        modifier = modifier,+    )+}
photos/src/main/java/com/vayunmathur/photos/util/GalleryUiContract.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/util/GalleryUiContract.kt b/photos/src/main/java/com/vayunmathur/photos/util/GalleryUiContract.ktindex f6fbc7c42e..82e65a3964 100644--- a/photos/src/main/java/com/vayunmathur/photos/util/GalleryUiContract.kt+++ b/photos/src/main/java/com/vayunmathur/photos/util/GalleryUiContract.kt@@ -40,6 +40,11 @@ data class PeopleUiState(     val faceTargetCount: Int = 0, ) +/** Everything the albums grid draws. */+data class AlbumsUiState(+    val albums: List<Album> = emptyList(),+)+ /**  * Gallery callbacks. Every method has a no-op default so a preview can render the screen  * without supplying behaviour — [Noop] is the whole implementation a preview needs.
photos/src/main/java/com/vayunmathur/photos/util/GalleryViewModel.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/util/GalleryViewModel.kt b/photos/src/main/java/com/vayunmathur/photos/util/GalleryViewModel.ktindex 7b218f0197..c06b554e73 100644--- a/photos/src/main/java/com/vayunmathur/photos/util/GalleryViewModel.kt+++ b/photos/src/main/java/com/vayunmathur/photos/util/GalleryViewModel.kt@@ -169,6 +169,38 @@ class GalleryViewModel(             .flowOn(Dispatchers.Default)             .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyMap()) +    /**+     * Photos grouped by MediaStore bucket (album), for the Albums view.+     *+     * Derived from the photos flow rather than a DAO distinct query, mirroring+     * the [people] style: the cover photo (newest in the album) travels with+     * the group so the tile needs no second lookup. Trashed photos are+     * excluded, like the gallery grid. Null/blank buckets (rows written before+     * the album column existed, or MediaStore rows with no bucket) fall back to+     * [Album.UNKNOWN_NAME]; the screen resolves that to+     * R.string.albums_unknown.+     */+    val albums: StateFlow<List<Album>> =+        photoDao.getAllFlow()+            .conflate()+            .map { allPhotos ->+                allPhotos.filter { !it.isTrashed }+                    .groupBy { it.album?.takeIf { name -> name.isNotBlank() } ?: Album.UNKNOWN_NAME }+                    .map { (name, albumPhotos) ->+                        Album(+                            name = name,+                            // getAllFlow is ORDER BY date DESC, so the first row+                            // is the album's newest photo — the cover.+                            coverPhoto = albumPhotos.first(),+                            photos = albumPhotos,+                        )+                    }+                    .sortedBy { it.name.lowercase() }+            }+            .distinctUntilChanged()+            .flowOn(Dispatchers.Default)+            .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())+     /**      * Face geometry per photo, for the viewer's face overlay. Combined with the      * clusters because the label text lives on [com.vayunmathur.photos.data.Person],@@ -410,6 +442,26 @@ data class PersonCluster(     val photos: List<Photo>, ) +/**+ * A MediaStore bucket (album) and the library photos in it, newest first.+ *+ * [name] is the BUCKET_DISPLAY_NAME, or [UNKNOWN_NAME] when the row has no+ * bucket (see [GalleryViewModel.albums]); the screen resolves that sentinel+ * to R.string.albums_unknown.+ */+data class Album(+    val name: String,+    val coverPhoto: Photo,+    val photos: List<Photo>,+) {+    /** Photo count shown under the album tile. */+    val count: Int get() = photos.size++    companion object {+        const val UNKNOWN_NAME = "__unknown__"+    }+}+ /**  * The faces detected in one photo, plus the dimensions their boxes are  * normalised against — the display-orientation dimensions of the detection
photos/src/main/java/com/vayunmathur/photos/util/SyncWorker.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/util/SyncWorker.kt b/photos/src/main/java/com/vayunmathur/photos/util/SyncWorker.ktindex 2d53b0bb1e..95030787de 100644--- a/photos/src/main/java/com/vayunmathur/photos/util/SyncWorker.kt+++ b/photos/src/main/java/com/vayunmathur/photos/util/SyncWorker.kt@@ -233,6 +233,7 @@ suspend fun syncPhotos(context: Context, repository: PhotosRepository, uris: Lis         val heightColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.HEIGHT)         val isTrashedColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.IS_TRASHED)         val mimeTypeColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.MIME_TYPE)+        val albumColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.BUCKET_DISPLAY_NAME)         val durationColumn = if (isVideo) cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION) else -1          val baseUri = if (isVideo) MediaStore.Video.Media.EXTERNAL_CONTENT_URI else MediaStore.Images.Media.EXTERNAL_CONTENT_URI@@ -248,12 +249,13 @@ suspend fun syncPhotos(context: Context, repository: PhotosRepository, uris: Lis                 val height = cursor.getInt(heightColumn)                 val isTrashed = cursor.getInt(isTrashedColumn) == 1                 val mimeType = cursor.getString(mimeTypeColumn)+                val album = cursor.getString(albumColumn)                 val contentUri = ContentUris.withAppendedId(baseUri, id).toString()                 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 || existing.width != width || existing.height != height || existing.dateModified != dateModified || existing.isTrashed != isTrashed || existing.mimeType != mimeType) {-                    newOrUpdatedPhotos += Photo(id, name, contentUri, date, width, height, dateModified, existing?.exifSet ?: false, existing?.lat, existing?.long, videoData, existing?.panoData, isTrashed, faceScanned = existing?.faceScanned ?: false, ocrText = existing?.ocrText, ocrScanned = existing?.ocrScanned ?: false, mimeType = mimeType)+                if (existing == null || existing.date != date || existing.uri != contentUri || existing.videoData != videoData || existing.width != width || existing.height != height || existing.dateModified != dateModified || existing.isTrashed != isTrashed || existing.mimeType != mimeType || existing.album != album) {+                    newOrUpdatedPhotos += Photo(id, name, contentUri, date, width, height, dateModified, existing?.exifSet ?: false, existing?.lat, existing?.long, videoData, existing?.panoData, isTrashed, faceScanned = existing?.faceScanned ?: false, ocrText = existing?.ocrText, ocrScanned = existing?.ocrScanned ?: false, mimeType = mimeType, album = album)                 }             } catch (e: Exception) {                 Log.e("SyncWorker", "Error processing photo/video from cursor", e)@@ -268,7 +270,7 @@ suspend fun syncPhotos(context: Context, repository: PhotosRepository, uris: Lis         }         context.contentResolver.query(             MediaStore.Images.Media.EXTERNAL_CONTENT_URI,-            arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.DATE_ADDED, MediaStore.Images.Media.WIDTH, MediaStore.Images.Media.HEIGHT, MediaStore.Images.Media.DATE_MODIFIED, MediaStore.Images.Media.IS_TRASHED, MediaStore.Images.Media.MIME_TYPE),+            arrayOf(MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.DATE_ADDED, MediaStore.Images.Media.WIDTH, MediaStore.Images.Media.HEIGHT, MediaStore.Images.Media.DATE_MODIFIED, MediaStore.Images.Media.IS_TRASHED, MediaStore.Images.Media.MIME_TYPE, MediaStore.Images.Media.BUCKET_DISPLAY_NAME),             bundle, null         )?.use { processCursor(it, false) }     } catch (e: Exception) {@@ -282,7 +284,7 @@ suspend fun syncPhotos(context: Context, repository: PhotosRepository, uris: Lis         }         context.contentResolver.query(             MediaStore.Video.Media.EXTERNAL_CONTENT_URI,-            arrayOf(MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.DATE_TAKEN, MediaStore.Video.Media.DATE_ADDED, MediaStore.Video.Media.WIDTH, MediaStore.Video.Media.HEIGHT, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.DATE_MODIFIED, MediaStore.Video.Media.IS_TRASHED, MediaStore.Video.Media.MIME_TYPE),+            arrayOf(MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.DATE_TAKEN, MediaStore.Video.Media.DATE_ADDED, MediaStore.Video.Media.WIDTH, MediaStore.Video.Media.HEIGHT, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.DATE_MODIFIED, MediaStore.Video.Media.IS_TRASHED, MediaStore.Video.Media.MIME_TYPE, MediaStore.Video.Media.BUCKET_DISPLAY_NAME),             bundle, null         )?.use { processCursor(it, true) }     } catch (e: Exception) {