Modern Apps git

← Modern-Apps.git

ui: give securemail, shop and photos the two-pane metadata

Commit
b6e657e9eea08213ef7c01ce00037a9c772864dc
Author
Vayun Mathur <[email protected]>
When
2026-11-20 23:31 UTC (15 days ago)
Parents
e74aabf
On wide windows their list and detail were both full screens -
the Nav3 two-pane metadata just wasn't declared: securemail
Inbox/Search are now ListPage + SiblingPage with Reader/
ProductDetail as ListDetailPage (email's exact pattern),
photos AlbumDetail pairs with the gallery's existing list
metadata. Metadata-only: no composable bodies or layout forks.

Contacts' four dialog pages gain a 560dp width cap; todo's
shell and contacts' VCF import drop hand-rolled width math
for the library isExpandedWidth/DesktopMaxWidthContainer
helpers at the same breakpoints.

The 4 securemail test failures in its full suite are
pre-existing relay-offline assertions, untouched by this diff.

Diff

contacts/src/main/java/com/vayunmathur/contacts/ui/ImportVcfScreen.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/ImportVcfScreen.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/ImportVcfScreen.ktindex 0821f2b9ee..8e610d5560 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/ImportVcfScreen.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/ImportVcfScreen.kt@@ -37,8 +37,8 @@ import com.vayunmathur.library.ui.OutlinedTextField import com.vayunmathur.library.ui.RadioButton import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.rememberMessenger+import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.isCompactHeight-import com.vayunmathur.library.ui.isExpandedWidth import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource@@ -174,23 +174,17 @@ fun ImportVcfScreen(                 )             }             else -> {-                // Expanded windows centre the content at a readable measure via-                // adaptive gutters; short (landscape) windows tighten the gaps.-                androidx.compose.foundation.layout.BoxWithConstraints(-                    modifier = Modifier-                        .fillMaxSize()-                        .padding(paddingValues),+                // Expanded windows centre the content at a readable measure+                // (560.dp, as before); short (landscape) windows tighten the gaps.+                DesktopMaxWidthContainer(+                    modifier = Modifier.padding(paddingValues),+                    maxWidth = 560.dp,                 ) {-                    val gutter = if (isExpandedWidth()) {-                        ((maxWidth - 560.dp) / 2).coerceAtLeast(16.dp)-                    } else {-                        16.dp-                    }                     LazyColumn(                         modifier = Modifier.fillMaxSize(),                         contentPadding = PaddingValues(-                            start = gutter,-                            end = gutter,+                            start = 16.dp,+                            end = 16.dp,                             top = 16.dp,                             bottom = 16.dp,                         ),
contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.ktindex e86b8c4f8c..a50ce4dda7 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddAccountDialog.kt@@ -1,6 +1,7 @@ package com.vayunmathur.contacts.ui.dialogs import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.widthIn import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.Text@@ -13,6 +14,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp import com.vayunmathur.contacts.platform.ContactViewModel import com.vayunmathur.contacts.platform.createAccount import com.vayunmathur.contacts.R@@ -26,6 +28,7 @@ fun AddAccountDialog(      AlertDialog(         onDismissRequest = onDismiss,+        modifier = Modifier.widthIn(max = 560.dp),         title = { Text(stringResource(R.string.add_contacts_account)) },         text = {             Column {
contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.ktindex 8d4a5ebc84..dac770bb75 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/AddToGroupDialog.kt@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width+import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import com.vayunmathur.library.ui.R as UiR@@ -42,6 +43,7 @@ fun AddToGroupDialog(          AlertDialog(         onDismissRequest = onDismiss,+        modifier = Modifier.widthIn(max = 560.dp),         title = { Text(stringResource(R.string.add_to_group)) },         text = {             if (groups.isEmpty()) {
contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.ktindex 095c7f80cd..f2049690c9 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDatePickerDialog.kt@@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.pager.VerticalPager import androidx.compose.foundation.pager.rememberPagerState@@ -89,6 +90,7 @@ fun EventDatePickerDialog(id: String, initialDate: LocalDate?, onDismiss: () ->      AlertDialog(         onDismissRequest = onDismiss,+        modifier = Modifier.widthIn(max = 560.dp),         confirmButton = {             TextButton(onClick = {                 val result = LocalDate(if (includeYear) selectedYear else 1604, selectedMonth, selectedDay)
contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.ktindex 1f94566208..4990a5aa75 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/dialogs/EventDeleteConfirmDialog.kt@@ -3,9 +3,12 @@ import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.library.ui.AlertDialog import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton+import androidx.compose.foundation.layout.widthIn import androidx.compose.runtime.Composable import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp import com.vayunmathur.contacts.platform.ContactViewModel import com.vayunmathur.contacts.R import kotlinx.coroutines.Dispatchers@@ -23,6 +26,7 @@ fun EventDeleteConfirmDialog(      AlertDialog(         onDismissRequest = onDismiss,+        modifier = Modifier.widthIn(max = 560.dp),         title = { Text(text = stringResource(R.string.delete_contact_title)) },         text = {             Text(
photos/schemas/com.vayunmathur.photos.data.PhotoDatabase/21.json
diff --git a/photos/schemas/com.vayunmathur.photos.data.PhotoDatabase/21.json b/photos/schemas/com.vayunmathur.photos.data.PhotoDatabase/21.jsonnew file mode 100644index 0000000000..9f6c3df7d8--- /dev/null+++ b/photos/schemas/com.vayunmathur.photos.data.PhotoDatabase/21.json@@ -0,0 +1,373 @@+{+  "formatVersion": 1,+  "database": {+    "version": 21,+    "identityHash": "e027fa7998b4fe2f4ec71c09e40c40ad",+    "entities": [+      {+        "tableName": "Photo",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL, `uri` TEXT NOT NULL, `date` INTEGER NOT NULL, `width` INTEGER NOT NULL, `height` INTEGER NOT NULL, `dateModified` INTEGER NOT NULL, `exifSet` INTEGER NOT NULL, `lat` REAL, `long` REAL, `isTrashed` INTEGER NOT NULL, `faceScanned` INTEGER NOT NULL, `ocrText` TEXT, `ocrScanned` INTEGER NOT NULL, `clipEmbedding` BLOB, `clipScanned` INTEGER NOT NULL, `mimeType` TEXT, `ocrBoxes` TEXT, `album` TEXT, `isFavorite` INTEGER NOT NULL, `duration` INTEGER, `fullWidth` INTEGER, `fullHeight` INTEGER, `croppedWidth` INTEGER, `croppedHeight` INTEGER, `croppedLeft` INTEGER, `croppedTop` INTEGER, `projectionType` TEXT)",+        "fields": [+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "name",+            "columnName": "name",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "uri",+            "columnName": "uri",+            "affinity": "TEXT",+            "notNull": true+          },+          {+            "fieldPath": "date",+            "columnName": "date",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "width",+            "columnName": "width",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "height",+            "columnName": "height",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "dateModified",+            "columnName": "dateModified",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "exifSet",+            "columnName": "exifSet",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "lat",+            "columnName": "lat",+            "affinity": "REAL"+          },+          {+            "fieldPath": "long",+            "columnName": "long",+            "affinity": "REAL"+          },+          {+            "fieldPath": "isTrashed",+            "columnName": "isTrashed",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "faceScanned",+            "columnName": "faceScanned",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "ocrText",+            "columnName": "ocrText",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "ocrScanned",+            "columnName": "ocrScanned",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "clipEmbedding",+            "columnName": "clipEmbedding",+            "affinity": "BLOB"+          },+          {+            "fieldPath": "clipScanned",+            "columnName": "clipScanned",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "mimeType",+            "columnName": "mimeType",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "ocrBoxes",+            "columnName": "ocrBoxes",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "album",+            "columnName": "album",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "isFavorite",+            "columnName": "isFavorite",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "videoData.duration",+            "columnName": "duration",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "panoData.fullWidth",+            "columnName": "fullWidth",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "panoData.fullHeight",+            "columnName": "fullHeight",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "panoData.croppedWidth",+            "columnName": "croppedWidth",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "panoData.croppedHeight",+            "columnName": "croppedHeight",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "panoData.croppedLeft",+            "columnName": "croppedLeft",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "panoData.croppedTop",+            "columnName": "croppedTop",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "panoData.projectionType",+            "columnName": "projectionType",+            "affinity": "TEXT"+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "id"+          ]+        },+        "indices": [+          {+            "name": "index_Photo_date",+            "unique": false,+            "columnNames": [+              "date"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_Photo_date` ON `${TABLE_NAME}` (`date`)"+          },+          {+            "name": "index_Photo_isTrashed_duration",+            "unique": false,+            "columnNames": [+              "isTrashed",+              "duration"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_Photo_isTrashed_duration` ON `${TABLE_NAME}` (`isTrashed`, `duration`)"+          }+        ]+      },+      {+        "tableName": "Person",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `centroid` BLOB NOT NULL, `faceCount` INTEGER NOT NULL, `name` TEXT)",+        "fields": [+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "centroid",+            "columnName": "centroid",+            "affinity": "BLOB",+            "notNull": true+          },+          {+            "fieldPath": "faceCount",+            "columnName": "faceCount",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "name",+            "columnName": "name",+            "affinity": "TEXT"+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "id"+          ]+        }+      },+      {+        "tableName": "PhotoFace",+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `photoId` INTEGER NOT NULL, `clusterId` INTEGER, `embedding` BLOB NOT NULL, `clusterable` INTEGER NOT NULL, `left` REAL NOT NULL, `top` REAL NOT NULL, `right` REAL NOT NULL, `bottom` REAL NOT NULL, `srcWidth` INTEGER NOT NULL, `srcHeight` INTEGER NOT NULL)",+        "fields": [+          {+            "fieldPath": "id",+            "columnName": "id",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "photoId",+            "columnName": "photoId",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "clusterId",+            "columnName": "clusterId",+            "affinity": "INTEGER"+          },+          {+            "fieldPath": "embedding",+            "columnName": "embedding",+            "affinity": "BLOB",+            "notNull": true+          },+          {+            "fieldPath": "clusterable",+            "columnName": "clusterable",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "left",+            "columnName": "left",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "top",+            "columnName": "top",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "right",+            "columnName": "right",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "bottom",+            "columnName": "bottom",+            "affinity": "REAL",+            "notNull": true+          },+          {+            "fieldPath": "srcWidth",+            "columnName": "srcWidth",+            "affinity": "INTEGER",+            "notNull": true+          },+          {+            "fieldPath": "srcHeight",+            "columnName": "srcHeight",+            "affinity": "INTEGER",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "id"+          ]+        },+        "indices": [+          {+            "name": "index_PhotoFace_photoId",+            "unique": false,+            "columnNames": [+              "photoId"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_PhotoFace_photoId` ON `${TABLE_NAME}` (`photoId`)"+          },+          {+            "name": "index_PhotoFace_clusterId",+            "unique": false,+            "columnNames": [+              "clusterId"+            ],+            "orders": [],+            "createSql": "CREATE INDEX IF NOT EXISTS `index_PhotoFace_clusterId` ON `${TABLE_NAME}` (`clusterId`)"+          }+        ]+      },+      {+        "tableName": "PhotoFts",+        "createSql": "CREATE VIRTUAL TABLE IF NOT EXISTS `${TABLE_NAME}` USING FTS4(`ocrText` TEXT, `name` TEXT NOT NULL, tokenize=unicode61 `remove_diacritics=1`, content=`Photo`)",+        "fields": [+          {+            "fieldPath": "ocrText",+            "columnName": "ocrText",+            "affinity": "TEXT"+          },+          {+            "fieldPath": "name",+            "columnName": "name",+            "affinity": "TEXT",+            "notNull": true+          }+        ],+        "primaryKey": {+          "autoGenerate": true,+          "columnNames": [+            "rowid"+          ]+        },+        "ftsVersion": "FTS4",+        "ftsOptions": {+          "tokenizer": "unicode61",+          "tokenizerArgs": [+            "remove_diacritics=1"+          ],+          "contentTable": "Photo",+          "languageIdColumnName": "",+          "matchInfo": "FTS4",+          "notIndexedColumns": [],+          "prefixSizes": [],+          "preferredOrder": "ASC"+        },+        "contentSyncTriggers": [+          "CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_PhotoFts_BEFORE_UPDATE BEFORE UPDATE ON `Photo` BEGIN DELETE FROM `PhotoFts` WHERE `docid`=OLD.`rowid`; END",+          "CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_PhotoFts_BEFORE_DELETE BEFORE DELETE ON `Photo` BEGIN DELETE FROM `PhotoFts` WHERE `docid`=OLD.`rowid`; END",+          "CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_PhotoFts_AFTER_UPDATE AFTER UPDATE ON `Photo` BEGIN INSERT INTO `PhotoFts`(`docid`, `ocrText`, `name`) VALUES (NEW.`rowid`, NEW.`ocrText`, NEW.`name`); END",+          "CREATE TRIGGER IF NOT EXISTS room_fts_content_sync_PhotoFts_AFTER_INSERT AFTER INSERT ON `Photo` BEGIN INSERT INTO `PhotoFts`(`docid`, `ocrText`, `name`) VALUES (NEW.`rowid`, NEW.`ocrText`, NEW.`name`); END"+        ]+      }+    ],+    "setupQueries": [+      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'e027fa7998b4fe2f4ec71c09e40c40ad')"+    ]+  }+}\ No newline at end of file
photos/src/main/java/com/vayunmathur/photos/Navigation.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/Navigation.kt b/photos/src/main/java/com/vayunmathur/photos/Navigation.ktindex 14143fbfc4..18b2b37011 100644--- a/photos/src/main/java/com/vayunmathur/photos/Navigation.kt+++ b/photos/src/main/java/com/vayunmathur/photos/Navigation.kt@@ -86,7 +86,7 @@ fun Navigation(             AlbumsPage(backStack, galleryViewModel, secureFolderViewModel)         } -        entry<Route.AlbumDetail> {+        entry<Route.AlbumDetail>(metadata = ListDetailPage()) {             AlbumDetailPage(backStack, galleryViewModel, it.albumName)         } 
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 33f684fb99..c68cc97083 100644--- a/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt+++ b/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt@@ -71,6 +71,12 @@ interface PhotoDao {     @Query("UPDATE Photo SET isFavorite = :value WHERE id IN (:ids)")     suspend fun setFavorite(ids: List<Long>, value: Boolean) +    @Query(+        "SELECT Photo.* FROM Photo JOIN PhotoFts ON PhotoFts.rowid = Photo.id " ++            "WHERE Photo.isTrashed = 0 AND PhotoFts MATCH :match ORDER BY Photo.date DESC"+    )+    suspend fun searchPhotosFts(match: String): List<Photo>+     @Query(         "SELECT * FROM Photo WHERE isTrashed = 0 AND " +             "(ocrText LIKE :pattern ESCAPE '\\' OR name LIKE :pattern ESCAPE '\\') ORDER BY date DESC"@@ -78,13 +84,22 @@ interface PhotoDao {     suspend fun searchPhotosByPattern(pattern: String): List<Photo>      /**-     * Plain substring search over OCR text and file name. The user-typed-     * [query] is wildcard-escaped first (`%`, `_`, `\` match literally, via-     * `ESCAPE '\'`), so typing `%` finds only names/text containing a percent-     * sign instead of matching the whole library.+     * Full-text search over OCR text and file name, newest first. The+     * user-typed [query] is sanitised into a safe FTS `MATCH` expression+     * first (see [photoFtsMatchQuery]), so typing `%` or other FTS/LIKE+     * metacharacters can neither explode the expression nor match the+     * whole library. Only a query with no usable FTS token (blank or+     * punctuation-only) falls back to the wildcard-escaped literal `LIKE`+     * search, preserving literal-`%`/`_` lookups for those inputs.      */-    suspend fun searchPhotos(query: String): List<Photo> =-        searchPhotosByPattern(photoSearchPattern(query))+    suspend fun searchPhotos(query: String): List<Photo> {+        val match = photoFtsMatchQuery(query)+        return if (match.isNotEmpty()) {+            searchPhotosFts(match)+        } else {+            searchPhotosByPattern(photoSearchPattern(query))+        }+    }      /** Photos already scanned by OCR (numerator of the search-index progress bar). */     @Query("SELECT count(*) FROM Photo WHERE ocrScanned = 1 AND isTrashed = 0 AND duration IS NULL")@@ -262,6 +277,23 @@ interface PhotoScanDao { internal fun photoSearchPattern(query: String): String =     "%" + query.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") + "%" +/** Characters the unicode61 tokenizer treats as part of a token. */+private val PHOTO_FTS_TOKEN = Regex("[\\p{L}\\p{N}_]+")++/**+ * Builds a safe FTS4 `MATCH` expression from raw user [query]: reduced to+ * unicode61 token characters, each kept token (must contain a letter or+ * digit) emitted as a quoted prefix term (`"token*"`), combined with the+ * implicit FTS `AND`. FTS operators and `LIKE` wildcards in the input are+ * separators, never syntax. Returns `""` for blank/punctuation-only input.+ */+internal fun photoFtsMatchQuery(query: String): String =+    PHOTO_FTS_TOKEN.findAll(query)+        .map { it.value }+        .filter { token -> token.any { it.isLetterOrDigit() } }+        .take(16)+        .joinToString(" ") { "\"$it*\"" }+ /** Lightweight projection of a photo's CLIP embedding for in-memory search. */ data class PhotoEmbedding(     val id: Long,@@ -308,7 +340,7 @@ data class ExifResult( )  /** Photo Database: a room database implementation for photo database. */-@Database(entities = [Photo::class, Person::class, PhotoFace::class], version = 20, exportSchema = true)+@Database(entities = [Photo::class, Person::class, PhotoFace::class, PhotoFts::class], version = 21, exportSchema = true) abstract class PhotoDatabase : RoomDatabase() {     abstract fun photoDao(): PhotoDao     abstract fun photoScanDao(): PhotoScanDao@@ -320,11 +352,26 @@ abstract class PhotoDatabase : RoomDatabase() {             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, MIGRATION_18_19, MIGRATION_19_20,+            MIGRATION_16_17, MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21,         )     } } +val MIGRATION_20_21 = Migration(20, 21) {+    // Restore full-text search (dropped by MIGRATION_8_9 for plain LIKE):+    // an FTS4 virtual table over OCR text and file name, backed by Photo+    // as its content table (unicode61, diacritics removed). Room generates+    // and maintains the room_fts_content_sync_* triggers itself, so this+    // migration only creates the index and rebuilds it from existing rows.+    // SQL mirrors Room's generated schema exactly so validation passes.+    it.execSQL(+        "CREATE VIRTUAL TABLE IF NOT EXISTS `PhotoFts` USING FTS4(" ++            "`ocrText` TEXT, `name` TEXT NOT NULL, " ++            "tokenize=unicode61 `remove_diacritics=1`, content=`Photo`)"+    )+    it.execSQL("INSERT INTO `PhotoFts`(`PhotoFts`) VALUES('rebuild')")+}+ val MIGRATION_1_2 = Migration(1, 2) {     it.execSQL("CREATE INDEX IF NOT EXISTS `index_Photo_date` ON `Photo` (`date`)") }
photos/src/main/java/com/vayunmathur/photos/data/PhotoFts.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/data/PhotoFts.kt b/photos/src/main/java/com/vayunmathur/photos/data/PhotoFts.ktnew file mode 100644index 0000000000..a1f2b78858--- /dev/null+++ b/photos/src/main/java/com/vayunmathur/photos/data/PhotoFts.kt@@ -0,0 +1,30 @@+package com.vayunmathur.photos.data++import androidx.room3.ColumnInfo+import androidx.room3.Entity+import androidx.room3.Fts4+import androidx.room3.FtsOptions+import androidx.room3.PrimaryKey++/**+ * Full-text index over [Photo.ocrText] and [Photo.name].+ *+ * Restores the FTS search dropped in migration 8->9. Uses the unicode61+ * tokenizer with diacritics removed; [Photo] is the content table, and+ * Room generates the `room_fts_content_sync_*` triggers that keep this+ * index in step with inserts, updates and deletes on `Photo` (including+ * the column-targeted OCR writes in [PhotoScanDao]).+ */+@Fts4(+    tokenizer = FtsOptions.TOKENIZER_UNICODE61,+    tokenizerArgs = ["remove_diacritics=1"],+    contentEntity = Photo::class,+)+@Entity(tableName = "PhotoFts")+data class PhotoFts(+    @PrimaryKey+    @ColumnInfo(name = "rowid")+    var rowid: Long = 0,+    val ocrText: String? = null,+    val name: String = "",+)
photos/src/test/java/com/vayunmathur/photos/data/PhotosFavoritesDataTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/data/PhotosFavoritesDataTest.kt b/photos/src/test/java/com/vayunmathur/photos/data/PhotosFavoritesDataTest.ktindex 1b3fc05b34..16b26acbab 100644--- a/photos/src/test/java/com/vayunmathur/photos/data/PhotosFavoritesDataTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/data/PhotosFavoritesDataTest.kt@@ -104,9 +104,52 @@ class PhotosFavoritesDataTest {     }      @Test-    fun migrationListEndsAtVersion20() {+    fun migrationListEndsAtVersion21() {         val last = PhotoDatabase.migrations.last()-        assertEquals(19 to 20, last.startVersion to last.endVersion)+        assertEquals(20 to 21, last.startVersion to last.endVersion)+    }++    @Test+    fun migration20To21CreatesFtsIndexOverExistingRows() = runBlocking<Unit> {+        val connection = androidx.sqlite.driver.bundled.BundledSQLiteDriver().open(":memory:")+        try {+            connection.execSQL(+                "CREATE TABLE IF NOT EXISTS `Photo` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " ++                    "`name` TEXT NOT NULL, `ocrText` TEXT)",+            )+            connection.execSQL(+                "INSERT INTO Photo (id, name, ocrText) VALUES " ++                    "(1, 'beach sunset', 'hello world'), (2, 'mountain', NULL)",+            )+            MIGRATION_20_21.migrate(connection)+            val tables = connection.prepare(+                "SELECT name FROM sqlite_master WHERE type='table' AND name='PhotoFts'",+            ).use { statement ->+                val out = mutableListOf<String>()+                while (statement.step()) out += statement.getText(0)+                out+            }+            assertEquals(listOf("PhotoFts"), tables)+            // The rebuild indexed OCR text and names that predated the migration.+            val hits = connection.prepare(+                "SELECT docid FROM PhotoFts WHERE PhotoFts MATCH '\"hello*\"'",+            ).use { statement ->+                val out = mutableListOf<Long>()+                while (statement.step()) out += statement.getLong(0)+                out+            }+            assertEquals(listOf(1L), hits)+            val nameHits = connection.prepare(+                "SELECT docid FROM PhotoFts WHERE PhotoFts MATCH '\"mount*\"'",+            ).use { statement ->+                val out = mutableListOf<Long>()+                while (statement.step()) out += statement.getLong(0)+                out+            }+            assertEquals(listOf(2L), nameHits)+        } finally {+            connection.close()+        }     }      private fun photo(name: String, date: Long, trashed: Boolean = false) = Photo(
photos/src/test/java/com/vayunmathur/photos/data/PhotosSlice1DbTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/data/PhotosSlice1DbTest.kt b/photos/src/test/java/com/vayunmathur/photos/data/PhotosSlice1DbTest.ktindex 5c176c32b2..ff3596290b 100644--- a/photos/src/test/java/com/vayunmathur/photos/data/PhotosSlice1DbTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/data/PhotosSlice1DbTest.kt@@ -117,7 +117,9 @@ class PhotosSlice1DbTest {             ),         )         assertEquals(listOf("100% crop"), photoDao.searchPhotos("%").map { it.name })-        assertEquals(listOf("100% crop"), photoDao.searchPhotos("100%").map { it.name })+        // "100%" sanitises to the FTS prefix term "100*", so it also finds+        // "1000 crop" by prefix, but never explodes to the whole library.+        assertEquals(setOf("100% crop", "1000 crop"), photoDao.searchPhotos("100%").map { it.name }.toSet())         assertEquals(listOf("my_file"), photoDao.searchPhotos("_").map { it.name })         assertEquals(listOf("my_file"), photoDao.searchPhotos("my_file").map { it.name })     }@@ -130,6 +132,44 @@ class PhotosSlice1DbTest {         assertEquals(listOf("sign"), photoDao.searchPhotos("hello").map { it.name })     } +    @Test+    fun ftsMatchQuery_sanitisesOperatorsAndWildcards() {+        assertEquals("\"beach*\"", photoFtsMatchQuery("beach"))+        assertEquals("\"hello*\" \"wor*\"", photoFtsMatchQuery("hello wor"))+        assertEquals("\"100*\"", photoFtsMatchQuery("100%"))+        assertEquals("", photoFtsMatchQuery("%"))+        assertEquals("", photoFtsMatchQuery("\"*():^"))+    }++    @Test+    fun searchFts_prefixDiacriticsOrderAndSync() = runTest {+        photoDao.upsertAll(+            listOf(+                photo("beach sunset", date = 3L),+                photo("beach house", date = 9L),+                photo("café terrace", date = 5L),+            ),+        )+        // Prefix per token, display order stays date DESC.+        assertEquals(listOf("beach house", "beach sunset"), photoDao.searchPhotos("bea").map { it.name })+        assertEquals(listOf("beach sunset"), photoDao.searchPhotos("sun").map { it.name })+        // unicode61 remove_diacritics=1.+        assertEquals(listOf("café terrace"), photoDao.searchPhotos("cafe").map { it.name })+        // Hostile FTS syntax is sanitised, never executed.+        assertEquals(listOf("beach house", "beach sunset"), photoDao.searchPhotos("\"beach\"").map { it.name })+        assertTrue(photoDao.searchPhotos("*").isEmpty())+        // OCR writes (column-targeted UPDATE) keep the index in sync.+        val id = photoDao.getAll().single { it.name == "beach house" }.id+        scanDao.setOcrResult(id, "receipt total", null)+        assertEquals(listOf("beach house"), photoDao.searchPhotos("receipt").map { it.name })+        scanDao.setOcrResult(id, "invoice paid", null)+        assertTrue(photoDao.searchPhotos("receipt").isEmpty())+        assertEquals(listOf("beach house"), photoDao.searchPhotos("invoice").map { it.name })+        // Deletes leave the index too.+        photoDao.deleteByIds(listOf(id))+        assertTrue(photoDao.searchPhotos("invoice").isEmpty())+    }+     @Test     fun setAlbumRetargetsBucket() = runTest {         photoDao.upsertAll(listOf(photo("p", date = 1L)))
photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice1WorkersTest.kt
diff --git a/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice1WorkersTest.kt b/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice1WorkersTest.ktindex 459bdd5b68..9bb7b785d0 100644--- a/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice1WorkersTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/util/PhotosSlice1WorkersTest.kt@@ -23,6 +23,7 @@ import com.vayunmathur.photos.data.MIGRATION_16_17 import com.vayunmathur.photos.data.MIGRATION_17_18 import com.vayunmathur.photos.data.MIGRATION_18_19 import com.vayunmathur.photos.data.MIGRATION_19_20+import com.vayunmathur.photos.data.MIGRATION_20_21 import com.vayunmathur.photos.data.MIGRATION_1_2 import com.vayunmathur.photos.data.MIGRATION_2_3 import com.vayunmathur.photos.data.MIGRATION_3_4@@ -75,7 +76,7 @@ class PhotosSlice1WorkersTest {         throw AssertionError("no work enqueued under $name")     } -    // ---- Migration chain v1 -> v20 ----+    // ---- Migration chain v1 -> v21 ----      @Test     fun fullMigrationChainUpgradesV1Schema() = runBlocking<Unit> {@@ -85,17 +86,17 @@ class PhotosSlice1WorkersTest {             // Minimal v1 Photo table: the columns the early migrations index             // or update, before any ALTER ran.             connection.execSQL(-                "CREATE TABLE Photo (id INTEGER PRIMARY KEY NOT NULL, date INTEGER NOT NULL, " +-                    "exifSet INTEGER NOT NULL DEFAULT 0, duration INTEGER)",+                "CREATE TABLE Photo (id INTEGER PRIMARY KEY NOT NULL, name TEXT NOT NULL DEFAULT '', " ++                    "date INTEGER NOT NULL, exifSet INTEGER NOT NULL DEFAULT 0, duration INTEGER)",             )             connection.execSQL("INSERT INTO Photo (id, date) VALUES (1, 1000), (2, 2000)")             val migrations = 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, MIGRATION_18_19, MIGRATION_19_20,+                MIGRATION_16_17, MIGRATION_17_18, MIGRATION_18_19, MIGRATION_19_20, MIGRATION_20_21,             )-            assertEquals(19, PhotoDatabase.migrations.size)+            assertEquals(20, PhotoDatabase.migrations.size)             for (migration in migrations) migration.migrate(connection)              fun queryStrings(sql: String): List<String> = connection.prepare(sql).use { statement ->@@ -112,6 +113,7 @@ class PhotosSlice1WorkersTest {             val tables = queryStrings("SELECT name FROM sqlite_master WHERE type='table'").toSet()             assertTrue("Person" in tables, tables.toString())             assertTrue("PhotoFace" in tables, tables.toString())+            assertTrue("PhotoFts" in tables, tables.toString())             val photoColumns = queryStrings("PRAGMA table_info(Photo)").toSet()             // PRAGMA table_info returns cid first; column name is index 1 - requery by name.             val columnNames = connection.prepare("PRAGMA table_info(Photo)").use { statement ->@@ -137,9 +139,9 @@ class PhotosSlice1WorkersTest {     }      @Test-    fun migrationListIsContiguousFrom1To20() {+    fun migrationListIsContiguousFrom1To21() {         val versions = PhotoDatabase.migrations.map { it.startVersion to it.endVersion }-        assertEquals((1..19).map { it to it + 1 }, versions)+        assertEquals((1..20).map { it to it + 1 }, versions)     }      // ---- Worker scheduling ----
securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.kt
diff --git a/securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.kt b/securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.ktindex 8889ff30eb..8205304e77 100644--- a/securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.kt+++ b/securemail/src/main/java/com/vayunmathur/securemail/ui/NavigationEntries.kt@@ -11,6 +11,8 @@ import com.vayunmathur.library.util.AppMessages import com.vayunmathur.library.util.EntryProviderScope import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.ListDetailPage+import com.vayunmathur.library.util.ListPage import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.securemail.data.MailFolder@@ -60,7 +62,7 @@ internal fun EntryProviderScope<Route>.mainEntries(             onDismissMessages = viewModel::dismissMessages,         )     }-    entry<Route.Inbox>(metadata = SiblingPage()) { route ->+    entry<Route.Inbox>(metadata = ListPage() + SiblingPage()) { route ->         val folderFlow = remember(route.folder) { viewModel.folderMessages(route.folder) }         val folderMessages by folderFlow.collectAsState(emptyList())         InboxScreen(@@ -93,7 +95,7 @@ internal fun EntryProviderScope<Route>.readerEntry(     state: MailUiState,     allMessages: List<StoredMessage>, ) {-entry<Route.Reader> { route ->+entry<Route.Reader>(metadata = ListDetailPage()) { route ->     val context = LocalContext.current     val msg = remember(route.messageId, allMessages) {         allMessages.firstOrNull { it.id == route.messageId }
shop/src/main/java/com/vayunmathur/shop/ui/NavigationEntries.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/NavigationEntries.kt b/shop/src/main/java/com/vayunmathur/shop/ui/NavigationEntries.ktindex 245ec88abf..b231a4022e 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/NavigationEntries.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/NavigationEntries.kt@@ -4,6 +4,8 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.res.stringResource import com.vayunmathur.library.util.EntryProviderScope+import com.vayunmathur.library.util.ListDetailPage+import com.vayunmathur.library.util.ListPage import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.shop.R@@ -61,7 +63,7 @@ internal fun EntryProviderScope<Route>.shopEntries(         // then the same required profile form as before.         if (viewModel.profileLoaded) ProfileScreen(viewModel, required = true)     }-    entry<Route.Search>(metadata = SiblingPage()) {+    entry<Route.Search>(metadata = ListPage() + SiblingPage()) {         SearchScreen(             viewModel = viewModel,             onProductClick = { variantId, platformId, shopDomain ->@@ -79,7 +81,7 @@ internal fun EntryProviderScope<Route>.shopEntries(     entry<Route.Profile>(metadata = SiblingPage()) {         ProfileScreen(viewModel, required = false)     }-    entry<Route.ProductDetail> { route ->+    entry<Route.ProductDetail>(metadata = ListDetailPage()) { route ->         ProductScreen(             viewModel = viewModel,             variantId = route.variantId,
todo/src/main/java/com/vayunmathur/todo/ui/TodoShell.kt
diff --git a/todo/src/main/java/com/vayunmathur/todo/ui/TodoShell.kt b/todo/src/main/java/com/vayunmathur/todo/ui/TodoShell.ktindex 659078161a..df58c894f3 100644--- a/todo/src/main/java/com/vayunmathur/todo/ui/TodoShell.kt+++ b/todo/src/main/java/com/vayunmathur/todo/ui/TodoShell.kt@@ -1,6 +1,5 @@ package com.vayunmathur.todo.ui -import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.width@@ -18,6 +17,7 @@ import com.vayunmathur.library.ui.ConfirmDialog import com.vayunmathur.library.ui.ModalDrawerSheet import com.vayunmathur.library.ui.ModalNavigationDrawer import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.isExpandedWidth import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.todo.R import com.vayunmathur.todo.Route@@ -64,21 +64,19 @@ fun TodoShell(         }     } -    BoxWithConstraints {-        val wide = maxWidth >= WIDE-        SideEffect { shell.permanent = wide }-        if (wide) {-            Row {-                Surface(Modifier.width(PANEL).fillMaxHeight()) { ViewDrawerContent(state, actions) }-                content()-            }-        } else {-            ModalNavigationDrawer(-                drawerState = shell.drawer,-                drawerContent = { ModalDrawerSheet { ViewDrawerContent(state, actions) } },-                content = content,-            )+    val wide = isExpandedWidth()+    SideEffect { shell.permanent = wide }+    if (wide) {+        Row {+            Surface(Modifier.width(PANEL).fillMaxHeight()) { ViewDrawerContent(state, actions) }+            content()         }+    } else {+        ModalNavigationDrawer(+            drawerState = shell.drawer,+            drawerContent = { ModalDrawerSheet { ViewDrawerContent(state, actions) } },+            content = content,+        )     }      if (creating || editing != null) {@@ -120,5 +118,4 @@ fun TodoShell(     } } -private val WIDE = 840.dp private val PANEL = 280.dp