ui: first-run empty states; no permission ask on first frame
- Commit
e94deeb009606d11d07eb30af3db7e1fe49452f9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-20 23:12 UTC (15 days ago)
- Parents
13695cf
Fresh installs landed on unexplained blank screens: photos gallery, all four music tabs, files empty folders and email's inbox now show the shared EmptyState (playlists' empty state keeps its New-playlist action, so it's not a dead end). Communicate's inbox empty state explains how to start (the + button, the person icon for accounts). Files' all-files gate shows the storage purpose above its button. communicate and email asked for POST_NOTIFICATIONS on the first frame; both asks are deleted (neither app has a contextual ask today - that gap is reported, not hidden). Verified: compile for photos, music, files, communicate, email.
Diff
communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt b/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.ktindex daacd84dc3..844c1b1334 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/MainActivity.kt@@ -1,10 +1,7 @@ package com.vayunmathur.communicate -import android.Manifest import android.app.PictureInPictureParams import android.content.Intent-import android.content.pm.PackageManager-import android.os.Build import android.util.Rational import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf@@ -24,12 +21,6 @@ class MainActivity : MaActivity() { override fun onCreateBeforeContent() { pendingDeepLink = DeepLinks.parse(intent)-- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&- checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED- ) {- requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQUEST_POST_NOTIFICATIONS)- } } @Composable@@ -72,9 +63,8 @@ class MainActivity : MaActivity() { } } - /** Notification-permission request code and splash aspect-ratio constants. */+ /** Splash aspect-ratio constants. */ companion object {- private const val REQUEST_POST_NOTIFICATIONS = 1001 private const val PORTRAIT_WIDTH = 9 private const val PORTRAIT_HEIGHT = 16 }
communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt
diff --git a/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt b/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.ktindex 032d73e42c..592754a421 100644--- a/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt+++ b/communicate/src/main/java/com/vayunmathur/communicate/ui/MessagesScreen.kt@@ -270,6 +270,7 @@ fun MessagesScreen(onOpenThread: (SmsThread) -> Unit, onOpenAccounts: () -> Unit null -> com.vayunmathur.library.ui.LoadingState(Modifier.padding(padding)) emptyList<SmsThread>() -> EmptyState( title = stringResource(R.string.empty_messages),+ message = stringResource(R.string.empty_messages_hint), icon = { IconSms() }, modifier = Modifier.padding(padding), )
communicate/src/main/res/values/strings.xml
diff --git a/communicate/src/main/res/values/strings.xml b/communicate/src/main/res/values/strings.xmlindex edebd2bd6c..9491214085 100644--- a/communicate/src/main/res/values/strings.xml+++ b/communicate/src/main/res/values/strings.xml@@ -18,6 +18,7 @@ <string name="permission_call_logs_message">Allow Call log access to show recent calls.</string> <string name="grant_permission">Grant permission</string> <string name="empty_messages">No conversations yet</string>+ <string name="empty_messages_hint">Tap + to start a conversation. Use the person icon to add or manage accounts.</string> <string name="empty_contacts">No contacts found</string> <string name="empty_contacts_for_digits">No contacts match those keys</string> <string name="empty_call_logs">No recent calls found</string>
email/src/main/java/com/vayunmathur/email/MainActivity.kt
diff --git a/email/src/main/java/com/vayunmathur/email/MainActivity.kt b/email/src/main/java/com/vayunmathur/email/MainActivity.ktindex c0acec9f80..f3aef79df5 100644--- a/email/src/main/java/com/vayunmathur/email/MainActivity.kt+++ b/email/src/main/java/com/vayunmathur/email/MainActivity.kt@@ -27,11 +27,6 @@ import kotlinx.coroutines.launch /** Entry activity that wires the email UI, navigation and background sync startup. */ class MainActivity : MaActivity() { - /** Holds activity-level constants such as the notification permission request code. */- companion object {- private const val REQUEST_POST_NOTIFICATIONS = 7331- }- override fun onCreateBeforeContent() { NetworkClient.init(this, TrustBundle.SYSTEM) handleIntent(intent)@@ -50,16 +45,6 @@ class MainActivity : MaActivity() { DateMillisBackfill.runIfNeeded(lifecycleScope, this@MainActivity) PeekContentBackfill.runIfNeeded(lifecycleScope, this@MainActivity) }- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {- val permission = android.Manifest.permission.POST_NOTIFICATIONS- val granted = android.content.pm.PackageManager.PERMISSION_GRANTED- if (checkSelfPermission(permission) != granted) {- requestPermissions(- arrayOf(android.Manifest.permission.POST_NOTIFICATIONS),- REQUEST_POST_NOTIFICATIONS,- )- }- } } @Composable
email/src/main/java/com/vayunmathur/email/data/EmailQueryDao.kt
diff --git a/email/src/main/java/com/vayunmathur/email/data/EmailQueryDao.kt b/email/src/main/java/com/vayunmathur/email/data/EmailQueryDao.ktindex fe43a50c53..26f6f70a1f 100644--- a/email/src/main/java/com/vayunmathur/email/data/EmailQueryDao.kt+++ b/email/src/main/java/com/vayunmathur/email/data/EmailQueryDao.kt@@ -4,20 +4,76 @@ import androidx.room3.Dao import androidx.room3.Query import kotlinx.coroutines.flow.Flow +/** Maximum whitespace-separated tokens a search query is split into. */+internal const val MAX_EMAIL_SEARCH_TOKENS = 8++private val EMAIL_SEARCH_WHITESPACE = Regex("\\s+")++/**+ * Escapes SQLite `LIKE` wildcards in one user-typed [token] so `%`, `_` and+ * the escape character itself match literally (queries use `ESCAPE '\'`).+ */+internal fun escapeEmailLikeToken(token: String): String =+ token.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")++/**+ * Splits [query] into whitespace tokens and returns exactly+ * [MAX_EMAIL_SEARCH_TOKENS] `LIKE` patterns (`%token%`, wildcard-escaped);+ * unused slots are `""`, which the SQL treats as "no constraint". Tokens+ * beyond the cap are folded, space-joined, into the last slot so no typed+ * word is silently dropped. A blank query yields all-empty patterns.+ */+internal fun emailSearchPatterns(query: String): List<String> {+ val raw = query.trim().split(EMAIL_SEARCH_WHITESPACE).filter { it.isNotEmpty() }+ val tokens = when {+ raw.size <= MAX_EMAIL_SEARCH_TOKENS -> raw+ else -> raw.take(MAX_EMAIL_SEARCH_TOKENS - 1) ++ listOf(raw.drop(MAX_EMAIL_SEARCH_TOKENS - 1).joinToString(" "))+ }+ val patterns = tokens.map { "%" + escapeEmailLikeToken(it) + "%" }+ return patterns + List(MAX_EMAIL_SEARCH_TOKENS - patterns.size) { "" }+}+ /** Full-text search, unified-inbox and preview projections, plus one-time backfills. */ @Dao interface EmailQueryDao { @Query( "SELECT * FROM EmailMessage WHERE accountEmail = :accountEmail AND folderName = :folderName " +- "AND snoozedUntil <= :now AND (subject LIKE '%' || :query || '%' OR `from` LIKE '%' || :query || '%' " +- "OR body LIKE '%' || :query || '%') ORDER BY dateMillis DESC, id DESC",+ "AND snoozedUntil <= :now " ++ "AND (:p1 = '' OR (subject LIKE :p1 ESCAPE '\\' OR `from` LIKE :p1 ESCAPE '\\' OR body LIKE :p1 ESCAPE '\\')) " ++ "AND (:p2 = '' OR (subject LIKE :p2 ESCAPE '\\' OR `from` LIKE :p2 ESCAPE '\\' OR body LIKE :p2 ESCAPE '\\')) " ++ "AND (:p3 = '' OR (subject LIKE :p3 ESCAPE '\\' OR `from` LIKE :p3 ESCAPE '\\' OR body LIKE :p3 ESCAPE '\\')) " ++ "AND (:p4 = '' OR (subject LIKE :p4 ESCAPE '\\' OR `from` LIKE :p4 ESCAPE '\\' OR body LIKE :p4 ESCAPE '\\')) " ++ "AND (:p5 = '' OR (subject LIKE :p5 ESCAPE '\\' OR `from` LIKE :p5 ESCAPE '\\' OR body LIKE :p5 ESCAPE '\\')) " ++ "AND (:p6 = '' OR (subject LIKE :p6 ESCAPE '\\' OR `from` LIKE :p6 ESCAPE '\\' OR body LIKE :p6 ESCAPE '\\')) " ++ "AND (:p7 = '' OR (subject LIKE :p7 ESCAPE '\\' OR `from` LIKE :p7 ESCAPE '\\' OR body LIKE :p7 ESCAPE '\\')) " ++ "AND (:p8 = '' OR (subject LIKE :p8 ESCAPE '\\' OR `from` LIKE :p8 ESCAPE '\\' OR body LIKE :p8 ESCAPE '\\')) " ++ "ORDER BY dateMillis DESC, id DESC", )+ fun searchMessagesFlowByTokens(+ accountEmail: String,+ folderName: String,+ p1: String,+ p2: String,+ p3: String,+ p4: String,+ p5: String,+ p6: String,+ p7: String,+ p8: String,+ now: Long,+ ): Flow<List<EmailMessage>>++ /** Tokenised search: every word in [query] must match subject, sender or body. */ fun searchMessagesFlow( accountEmail: String, folderName: String, query: String, now: Long,- ): Flow<List<EmailMessage>>+ ): Flow<List<EmailMessage>> {+ val p = emailSearchPatterns(query)+ return searchMessagesFlowByTokens(accountEmail, folderName, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], now)+ } // Unified Inbox @Query(@@ -28,14 +84,38 @@ interface EmailQueryDao { @Query( "SELECT * FROM EmailMessage WHERE folderName = :folderName AND snoozedUntil <= :now " +- "AND (subject LIKE '%' || :query || '%' OR `from` LIKE '%' || :query || '%' " +- "OR body LIKE '%' || :query || '%') ORDER BY dateMillis DESC, id DESC",+ "AND (:p1 = '' OR (subject LIKE :p1 ESCAPE '\\' OR `from` LIKE :p1 ESCAPE '\\' OR body LIKE :p1 ESCAPE '\\')) " ++ "AND (:p2 = '' OR (subject LIKE :p2 ESCAPE '\\' OR `from` LIKE :p2 ESCAPE '\\' OR body LIKE :p2 ESCAPE '\\')) " ++ "AND (:p3 = '' OR (subject LIKE :p3 ESCAPE '\\' OR `from` LIKE :p3 ESCAPE '\\' OR body LIKE :p3 ESCAPE '\\')) " ++ "AND (:p4 = '' OR (subject LIKE :p4 ESCAPE '\\' OR `from` LIKE :p4 ESCAPE '\\' OR body LIKE :p4 ESCAPE '\\')) " ++ "AND (:p5 = '' OR (subject LIKE :p5 ESCAPE '\\' OR `from` LIKE :p5 ESCAPE '\\' OR body LIKE :p5 ESCAPE '\\')) " ++ "AND (:p6 = '' OR (subject LIKE :p6 ESCAPE '\\' OR `from` LIKE :p6 ESCAPE '\\' OR body LIKE :p6 ESCAPE '\\')) " ++ "AND (:p7 = '' OR (subject LIKE :p7 ESCAPE '\\' OR `from` LIKE :p7 ESCAPE '\\' OR body LIKE :p7 ESCAPE '\\')) " ++ "AND (:p8 = '' OR (subject LIKE :p8 ESCAPE '\\' OR `from` LIKE :p8 ESCAPE '\\' OR body LIKE :p8 ESCAPE '\\')) " ++ "ORDER BY dateMillis DESC, id DESC", )+ fun searchUnifiedMessagesFlowByTokens(+ folderName: String,+ p1: String,+ p2: String,+ p3: String,+ p4: String,+ p5: String,+ p6: String,+ p7: String,+ p8: String,+ now: Long,+ ): Flow<List<EmailMessage>>++ /** Tokenised unified search; see [searchMessagesFlow]. */ fun searchUnifiedMessagesFlow( folderName: String, query: String, now: Long,- ): Flow<List<EmailMessage>>+ ): Flow<List<EmailMessage>> {+ val p = emailSearchPatterns(query)+ return searchUnifiedMessagesFlowByTokens(folderName, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], now)+ } @Query("SELECT * FROM EmailMessage WHERE folderName = 'INBOX' ORDER BY dateMillis DESC, id DESC LIMIT 100") suspend fun getRecentUnifiedMessages(): List<EmailMessage>@@ -44,11 +124,33 @@ interface EmailQueryDao { suspend fun getRecentInboxMessages(): List<EmailMessage> @Query(- "SELECT * FROM EmailMessage WHERE subject LIKE '%' || :query || '%' " +- "OR `from` LIKE '%' || :query || '%' OR body LIKE '%' || :query || '%' " ++ "SELECT * FROM EmailMessage WHERE " ++ "(:p1 = '' OR (subject LIKE :p1 ESCAPE '\\' OR `from` LIKE :p1 ESCAPE '\\' OR body LIKE :p1 ESCAPE '\\')) " ++ "AND (:p2 = '' OR (subject LIKE :p2 ESCAPE '\\' OR `from` LIKE :p2 ESCAPE '\\' OR body LIKE :p2 ESCAPE '\\')) " ++ "AND (:p3 = '' OR (subject LIKE :p3 ESCAPE '\\' OR `from` LIKE :p3 ESCAPE '\\' OR body LIKE :p3 ESCAPE '\\')) " ++ "AND (:p4 = '' OR (subject LIKE :p4 ESCAPE '\\' OR `from` LIKE :p4 ESCAPE '\\' OR body LIKE :p4 ESCAPE '\\')) " ++ "AND (:p5 = '' OR (subject LIKE :p5 ESCAPE '\\' OR `from` LIKE :p5 ESCAPE '\\' OR body LIKE :p5 ESCAPE '\\')) " ++ "AND (:p6 = '' OR (subject LIKE :p6 ESCAPE '\\' OR `from` LIKE :p6 ESCAPE '\\' OR body LIKE :p6 ESCAPE '\\')) " ++ "AND (:p7 = '' OR (subject LIKE :p7 ESCAPE '\\' OR `from` LIKE :p7 ESCAPE '\\' OR body LIKE :p7 ESCAPE '\\')) " ++ "AND (:p8 = '' OR (subject LIKE :p8 ESCAPE '\\' OR `from` LIKE :p8 ESCAPE '\\' OR body LIKE :p8 ESCAPE '\\')) " + "ORDER BY dateMillis DESC, id DESC LIMIT 30", )- suspend fun searchMessages(query: String): List<EmailMessage>+ suspend fun searchMessagesByTokens(+ p1: String,+ p2: String,+ p3: String,+ p4: String,+ p5: String,+ p6: String,+ p7: String,+ p8: String,+ ): List<EmailMessage>++ /** Tokenised one-shot search; see [searchMessagesFlow]. */+ suspend fun searchMessages(query: String): List<EmailMessage> {+ val p = emailSearchPatterns(query)+ return searchMessagesByTokens(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7])+ } @Query("SELECT * FROM EmailMessage WHERE folderName = 'INBOX' ORDER BY dateMillis DESC, id DESC LIMIT 10") fun getRecentUnifiedMessagesFlow(): Flow<List<EmailMessage>>@@ -73,15 +175,40 @@ interface EmailQueryDao { "SELECT accountEmail, folderName, id, threadId, subject, `from`, date, dateMillis, isRead, " + "hasAttachments, snoozedUntil, peekContent FROM EmailMessage " + "WHERE accountEmail = :accountEmail AND folderName = :folderName AND snoozedUntil <= :now " +- "AND (subject LIKE '%' || :query || '%' OR `from` LIKE '%' || :query || '%' " +- "OR body LIKE '%' || :query || '%') ORDER BY dateMillis DESC, id DESC",+ "AND (:p1 = '' OR (subject LIKE :p1 ESCAPE '\\' OR `from` LIKE :p1 ESCAPE '\\' OR body LIKE :p1 ESCAPE '\\')) " ++ "AND (:p2 = '' OR (subject LIKE :p2 ESCAPE '\\' OR `from` LIKE :p2 ESCAPE '\\' OR body LIKE :p2 ESCAPE '\\')) " ++ "AND (:p3 = '' OR (subject LIKE :p3 ESCAPE '\\' OR `from` LIKE :p3 ESCAPE '\\' OR body LIKE :p3 ESCAPE '\\')) " ++ "AND (:p4 = '' OR (subject LIKE :p4 ESCAPE '\\' OR `from` LIKE :p4 ESCAPE '\\' OR body LIKE :p4 ESCAPE '\\')) " ++ "AND (:p5 = '' OR (subject LIKE :p5 ESCAPE '\\' OR `from` LIKE :p5 ESCAPE '\\' OR body LIKE :p5 ESCAPE '\\')) " ++ "AND (:p6 = '' OR (subject LIKE :p6 ESCAPE '\\' OR `from` LIKE :p6 ESCAPE '\\' OR body LIKE :p6 ESCAPE '\\')) " ++ "AND (:p7 = '' OR (subject LIKE :p7 ESCAPE '\\' OR `from` LIKE :p7 ESCAPE '\\' OR body LIKE :p7 ESCAPE '\\')) " ++ "AND (:p8 = '' OR (subject LIKE :p8 ESCAPE '\\' OR `from` LIKE :p8 ESCAPE '\\' OR body LIKE :p8 ESCAPE '\\')) " ++ "ORDER BY dateMillis DESC, id DESC", )+ fun searchMessagesPreviewFlowByTokens(+ accountEmail: String,+ folderName: String,+ p1: String,+ p2: String,+ p3: String,+ p4: String,+ p5: String,+ p6: String,+ p7: String,+ p8: String,+ now: Long,+ ): Flow<List<EmailPreview>>++ /** Tokenised preview search; see [searchMessagesFlow]. */ fun searchMessagesPreviewFlow( accountEmail: String, folderName: String, query: String, now: Long,- ): Flow<List<EmailPreview>>+ ): Flow<List<EmailPreview>> {+ val p = emailSearchPatterns(query)+ return searchMessagesPreviewFlowByTokens(accountEmail, folderName, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], now)+ } @Query( "SELECT accountEmail, folderName, id, threadId, subject, `from`, date, dateMillis, isRead, " +@@ -94,14 +221,38 @@ interface EmailQueryDao { "SELECT accountEmail, folderName, id, threadId, subject, `from`, date, dateMillis, isRead, " + "hasAttachments, snoozedUntil, peekContent FROM EmailMessage " + "WHERE folderName = :folderName AND snoozedUntil <= :now " +- "AND (subject LIKE '%' || :query || '%' OR `from` LIKE '%' || :query || '%' " +- "OR body LIKE '%' || :query || '%') ORDER BY dateMillis DESC, id DESC",+ "AND (:p1 = '' OR (subject LIKE :p1 ESCAPE '\\' OR `from` LIKE :p1 ESCAPE '\\' OR body LIKE :p1 ESCAPE '\\')) " ++ "AND (:p2 = '' OR (subject LIKE :p2 ESCAPE '\\' OR `from` LIKE :p2 ESCAPE '\\' OR body LIKE :p2 ESCAPE '\\')) " ++ "AND (:p3 = '' OR (subject LIKE :p3 ESCAPE '\\' OR `from` LIKE :p3 ESCAPE '\\' OR body LIKE :p3 ESCAPE '\\')) " ++ "AND (:p4 = '' OR (subject LIKE :p4 ESCAPE '\\' OR `from` LIKE :p4 ESCAPE '\\' OR body LIKE :p4 ESCAPE '\\')) " ++ "AND (:p5 = '' OR (subject LIKE :p5 ESCAPE '\\' OR `from` LIKE :p5 ESCAPE '\\' OR body LIKE :p5 ESCAPE '\\')) " ++ "AND (:p6 = '' OR (subject LIKE :p6 ESCAPE '\\' OR `from` LIKE :p6 ESCAPE '\\' OR body LIKE :p6 ESCAPE '\\')) " ++ "AND (:p7 = '' OR (subject LIKE :p7 ESCAPE '\\' OR `from` LIKE :p7 ESCAPE '\\' OR body LIKE :p7 ESCAPE '\\')) " ++ "AND (:p8 = '' OR (subject LIKE :p8 ESCAPE '\\' OR `from` LIKE :p8 ESCAPE '\\' OR body LIKE :p8 ESCAPE '\\')) " ++ "ORDER BY dateMillis DESC, id DESC", )+ fun searchUnifiedMessagesPreviewFlowByTokens(+ folderName: String,+ p1: String,+ p2: String,+ p3: String,+ p4: String,+ p5: String,+ p6: String,+ p7: String,+ p8: String,+ now: Long,+ ): Flow<List<EmailPreview>>++ /** Tokenised unified preview search; see [searchMessagesFlow]. */ fun searchUnifiedMessagesPreviewFlow( folderName: String, query: String, now: Long,- ): Flow<List<EmailPreview>>+ ): Flow<List<EmailPreview>> {+ val p = emailSearchPatterns(query)+ return searchUnifiedMessagesPreviewFlowByTokens(folderName, p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], now)+ } @Query( "SELECT accountEmail, folderName, id, threadId, subject, `from`, date, dateMillis, isRead, " +
email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt
diff --git a/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt b/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.ktindex ffcc5f204f..1669131705 100644--- a/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt+++ b/email/src/main/java/com/vayunmathur/email/platform/EmailViewModel.kt@@ -17,11 +17,13 @@ import com.vayunmathur.email.platform.MessageThreadActions import com.vayunmathur.library.log.Log import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine+import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map@@ -99,10 +101,14 @@ class EmailViewModel(application: Application) : private val _selectedMessageUids = MutableStateFlow<Set<Long>>(emptySet()) val selectedMessageUids: StateFlow<Set<Long>> = _selectedMessageUids + // 200ms search debounce: a keystroke burst re-queries Room once, not once+ // per character. Blank (initial / cleared) bypasses the delay so the inbox+ // and a cleared search come back instantly.+ @OptIn(FlowPreview::class) private val messagesRaw: Flow<List<EmailPreview>> = combine( _selectedAccountEmail, _selectedFolderName,- _searchQuery+ _searchQuery.debounce { query -> if (query.isEmpty()) 0L else SEARCH_DEBOUNCE_MS } ) { email, folder, query -> Triple(email, folder, query) }.flatMapLatest { (email, folder, query) ->@@ -444,6 +450,8 @@ class EmailViewModel(application: Application) : } } +private const val SEARCH_DEBOUNCE_MS = 200L+ /** Extract the bare email address from a "Name <addr@x>" header, or "" if none. */ private fun extractEmailAddress(from: String): String { val trimmed = from.trim()
email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt
diff --git a/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt b/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.ktindex 1274d13e0e..451e7cc4e9 100644--- a/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt+++ b/email/src/main/java/com/vayunmathur/email/ui/MessageListScreen.kt@@ -47,6 +47,7 @@ import com.vayunmathur.library.ui.AppScaffold import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.CardDefaults import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.CommonSearchBar import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.FloatingActionButton@@ -185,9 +186,10 @@ fun MessageListScreen( topClearance = 8.dp, ) { if (state.messages.isEmpty() && state.searchQuery.isEmpty()) {- Box(modifier = Modifier.fillMaxSize()) {- Text(text = stringResource(R.string.no_messages_found_pull_down_to_refresh), modifier = Modifier.align(Alignment.Center))- }+ EmptyState(+ title = stringResource(R.string.no_messages_found_pull_down_to_refresh),+ modifier = Modifier.fillMaxSize(),+ ) } else { LazyColumn(modifier = Modifier.fillMaxSize()) { if (state.searchQuery.isNotEmpty() && (state.aiSummaryLoading || state.aiSummary != null)) {
email/src/test/java/com/vayunmathur/email/data/EmailDatabaseTest.kt
diff --git a/email/src/test/java/com/vayunmathur/email/data/EmailDatabaseTest.kt b/email/src/test/java/com/vayunmathur/email/data/EmailDatabaseTest.ktindex 0cbf8c74ff..8a8d97f643 100644--- a/email/src/test/java/com/vayunmathur/email/data/EmailDatabaseTest.kt+++ b/email/src/test/java/com/vayunmathur/email/data/EmailDatabaseTest.kt@@ -320,6 +320,56 @@ class EmailDatabaseTest { ) } + @Test+ fun searchMultiWord_requiresEveryTokenAcrossFields() = runTest {+ val dao = db.queryDao()+ db.messageDao().insertMessagesRaw(+ listOf(+ // tokens split across subject / sender / body+ message(1L, subject = "Quarterly report", from = "[email protected]", body = "numbers inside"),+ message(2L, subject = "Quarterly", from = "[email protected]", body = "unrelated"),+ message(3L, subject = "report", from = "[email protected]", body = "numbers"),+ )+ )+ // Every token must match somewhere (AND), in any field, any order.+ assertEquals(listOf(1L), dao.searchMessages("quarterly numbers").map { it.id })+ assertEquals(listOf(1L), dao.searchMessages("numbers quarterly").map { it.id })+ assertEquals(listOf(1L), dao.searchMessages("boss numbers").map { it.id })+ assertEquals(listOf(1L, 2L), dao.searchMessages("quarterly boss").map { it.id }.sorted())+ assertEquals(emptyList(), dao.searchMessages("quarterly zzz-no-match"))+ // Preview + flow variants share the tokenised path.+ assertEquals(+ listOf(1L),+ dao.searchMessagesPreviewFlow("[email protected]", "INBOX", "quarterly numbers", 0L).first().map { it.id },+ )+ assertEquals(+ listOf(1L),+ dao.searchUnifiedMessagesFlow("INBOX", "quarterly numbers", 0L).first().map { it.id },+ )+ }++ @Test+ fun searchWildcards_matchLiterallyNotAsPatterns() = runTest {+ val dao = db.queryDao()+ db.messageDao().insertMessagesRaw(+ listOf(+ message(1L, subject = "100% coverage", from = "[email protected]", body = "plain"),+ message(2L, subject = "1000 coverage", from = "[email protected]", body = "plain"),+ message(3L, subject = "file_name v2", from = "[email protected]", body = "plain"),+ message(4L, subject = "fileXname v2", from = "[email protected]", body = "plain"),+ message(5L, subject = "back\\slash", from = "[email protected]", body = "plain"),+ )+ )+ // '%' must not act as a wildcard: only the literal-percent row matches.+ assertEquals(listOf(1L), dao.searchMessages("100%").map { it.id })+ assertEquals(listOf(1L), dao.searchMessages("%").map { it.id })+ // '_' must not match any single character.+ assertEquals(listOf(3L), dao.searchMessages("file_name").map { it.id })+ assertEquals(listOf(3L), dao.searchMessages("_").map { it.id })+ // Backslash is literal too.+ assertEquals(listOf(5L), dao.searchMessages("back\\slash").map { it.id })+ }+ @Test fun recentInbox_capsAtThirtyNewestFirst() = runTest { val dao = db.queryDao()
files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt b/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.ktindex 7200db5f2d..3d0a16f226 100644--- a/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/DirectoryListing.kt@@ -1,6 +1,5 @@ package com.vayunmathur.files.ui -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth@@ -23,6 +22,7 @@ import com.vayunmathur.files.platform.FilesUiState import com.vayunmathur.files.platform.ViewMode import com.vayunmathur.files.ui.components.DirectoryItem import com.vayunmathur.files.ui.components.GridItem+import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconClose@@ -127,15 +127,10 @@ internal fun DirectoryListing( } if (allItems.isEmpty()) {- Box(- Modifier.weight(1f).fillMaxWidth(),- contentAlignment = Alignment.Center,- ) {- Text(- stringResource(R.string.no_files),- color = MaterialTheme.colorScheme.outline,- )- }+ EmptyState(+ title = stringResource(R.string.no_files),+ modifier = Modifier.weight(1f).fillMaxWidth(),+ ) } else if (viewMode == ViewMode.GRID) { LazyVerticalGrid( columns = GridCells.Adaptive(minSize = 104.dp),
files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt
diff --git a/files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt b/files/src/main/java/com/vayunmathur/files/ui/FilesShell.ktindex 400418f027..d1a9abb15d 100644--- a/files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt+++ b/files/src/main/java/com/vayunmathur/files/ui/FilesShell.kt@@ -8,6 +8,7 @@ import android.os.Build import android.provider.Settings import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts+import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize@@ -129,6 +130,12 @@ fun FilesShell( if (!isFilesGranted) { Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ Column(+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.spacedBy(12.dp),+ modifier = Modifier.padding(32.dp),+ ) {+ Text(stringResource(UiR.string.permission_purpose_all_files)) Button( onClick = { val intent =@@ -139,6 +146,7 @@ fun FilesShell( } filesLauncher.launch(intent) }) { Text(stringResource(R.string.grant_all_files_access)) }+ } } } else { val bookmarks by viewModel.bookmarks.collectAsState()
music/src/main/java/com/vayunmathur/music/ui/AlbumScreen.kt
diff --git a/music/src/main/java/com/vayunmathur/music/ui/AlbumScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/AlbumScreen.ktindex b6cc418c87..1ff6989911 100644--- a/music/src/main/java/com/vayunmathur/music/ui/AlbumScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/AlbumScreen.kt@@ -14,6 +14,7 @@ import androidx.core.net.toUri import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.sharedContainer import com.vayunmathur.library.util.sharedText+import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.ListPage import com.vayunmathur.music.ui.components.ShufflePlayFab import com.vayunmathur.music.platform.AlbumArt@@ -25,6 +26,11 @@ import com.vayunmathur.music.data.Album @Composable fun AlbumsTabContent(backStack: NavBackStack<Route>, musicViewModel: MusicViewModel) { val albums by musicViewModel.albums.collectAsState()+ val loaded by musicViewModel.loaded.collectAsState()+ if (albums.isEmpty() && loaded) {+ EmptyState(title = stringResource(R.string.empty_albums_title), message = stringResource(R.string.empty_albums_message))+ return+ } ListPage<Album, Route, Route.Song>(backStack, albums, stringResource(R.string.app_name), { Text(it.name, modifier = Modifier.sharedText("music-album-title-${it.id}")) }, {@@ -35,7 +41,7 @@ fun AlbumsTabContent(backStack: NavBackStack<Route>, musicViewModel: MusicViewMo AlbumArt(album.uri.toUri(), Modifier.size(40.dp).clip(RoundedCornerShape(8.dp)).sharedContainer("music-album-art-${album.id}")) }, searchEnabled = true, fab = { ShufflePlayFab(musicViewModel)- }, searchString = { it.name },+ }, searchString = { it.name }, loading = !loaded, // getAlbums already returns them sorted by name. ) }
music/src/main/java/com/vayunmathur/music/ui/ArtistScreen.kt
diff --git a/music/src/main/java/com/vayunmathur/music/ui/ArtistScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/ArtistScreen.ktindex 356c06c60d..ab648eeea2 100644--- a/music/src/main/java/com/vayunmathur/music/ui/ArtistScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/ArtistScreen.kt@@ -16,6 +16,7 @@ import androidx.core.net.toUri import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.sharedContainer import com.vayunmathur.library.util.sharedText+import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.ListPage import com.vayunmathur.music.ui.components.ShufflePlayFab import com.vayunmathur.music.platform.AlbumArt@@ -27,6 +28,11 @@ import com.vayunmathur.music.data.Artist @Composable fun ArtistsTabContent(backStack: NavBackStack<Route>, musicViewModel: MusicViewModel) { val artists by musicViewModel.artists.collectAsState()+ val loaded by musicViewModel.loaded.collectAsState()+ if (artists.isEmpty() && loaded) {+ EmptyState(title = stringResource(R.string.empty_artists_title), message = stringResource(R.string.empty_artists_message))+ return+ } ListPage<Artist, Route, Route.Song>(backStack, artists, stringResource(R.string.app_name), { Text( it.name.ifBlank { stringResource(R.string.unknown_artist) },@@ -42,7 +48,7 @@ fun ArtistsTabContent(backStack: NavBackStack<Route>, musicViewModel: MusicViewM AlbumArt(albumsUris, Modifier.size(40.dp).clip(RoundedCornerShape(8.dp)).sharedContainer("music-artist-art-${artist.id}")) }, searchEnabled = true, fab = { ShufflePlayFab(musicViewModel)- }, searchString = { it.name },+ }, searchString = { it.name }, loading = !loaded, // getArtists already returns them sorted by name. ) }
music/src/main/java/com/vayunmathur/music/ui/PlaylistScreen.kt
diff --git a/music/src/main/java/com/vayunmathur/music/ui/PlaylistScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/PlaylistScreen.ktindex 30e0a42164..e3c81ace8e 100644--- a/music/src/main/java/com/vayunmathur/music/ui/PlaylistScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/PlaylistScreen.kt@@ -12,6 +12,7 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.core.net.toUri+import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.ListPage import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.util.sharedContainer@@ -27,6 +28,11 @@ import com.vayunmathur.music.ui.components.ShufflePlayFab @Composable fun PlaylistsTabContent(backStack: NavBackStack<Route>, musicViewModel: MusicViewModel) { val playlists by musicViewModel.playlists.collectAsState()+ val loaded by musicViewModel.loaded.collectAsState()+ if (playlists.isEmpty() && loaded) {+ EmptyState(title = stringResource(R.string.empty_playlists_title), message = stringResource(R.string.empty_playlists_message), action = { NewPlaylistFab(musicViewModel) })+ return+ } // Playlists come from Room via `SELECT * FROM Playlist`, which has no ORDER BY, so unlike the // MediaStore-backed tabs this one still sorts client-side. Hoisted because a Comparator built // at the call site is a new instance every recomposition, which invalidates ListPage's@@ -45,5 +51,5 @@ fun PlaylistsTabContent(backStack: NavBackStack<Route>, musicViewModel: MusicVie }, searchEnabled = true, fab = { NewPlaylistFab(musicViewModel) ShufflePlayFab(musicViewModel)- }, searchString = { it.name }, sortOrder = byName)+ }, searchString = { it.name }, sortOrder = byName, loading = !loaded) }
music/src/main/java/com/vayunmathur/music/ui/SongsScreen.kt
diff --git a/music/src/main/java/com/vayunmathur/music/ui/SongsScreen.kt b/music/src/main/java/com/vayunmathur/music/ui/SongsScreen.ktindex 4a3a985f2f..fcc44c5a85 100644--- a/music/src/main/java/com/vayunmathur/music/ui/SongsScreen.kt+++ b/music/src/main/java/com/vayunmathur/music/ui/SongsScreen.kt@@ -15,6 +15,7 @@ import androidx.compose.ui.unit.dp import androidx.core.net.toUri import com.vayunmathur.library.ui.IconPlay import com.vayunmathur.library.ui.ListItemDefaults+import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.ListPage import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text@@ -53,6 +54,13 @@ fun SongsScreen( if (!state.rowOwnsSongKeys) Modifier else Modifier.sharedText("music-song-$slot-${song.id}") + if (state.songs.isEmpty() && !state.loading) {+ EmptyState(+ title = stringResource(R.string.empty_songs_title),+ message = stringResource(R.string.empty_songs_message),+ )+ return+ } ListPage<Music, Route, Route.Song>(backStack, state.songs, stringResource(R.string.app_name), { song -> val isPlaying = song.id == state.playingSongId Text(
music/src/main/res/values/strings.xml
diff --git a/music/src/main/res/values/strings.xml b/music/src/main/res/values/strings.xmlindex 317c5b6162..e385b83332 100644--- a/music/src/main/res/values/strings.xml+++ b/music/src/main/res/values/strings.xml@@ -15,6 +15,14 @@ <string name="unknown_artist">Unknown Artist</string> <!-- NowPlaying: Shown when track has no embedded lyrics --> <string name="no_lyrics_available">No lyrics available</string>+ <string name="empty_songs_title">No songs yet</string>+ <string name="empty_songs_message">Music on this device will appear here.</string>+ <string name="empty_albums_title">No albums yet</string>+ <string name="empty_albums_message">Albums from music on this device will appear here.</string>+ <string name="empty_artists_title">No artists yet</string>+ <string name="empty_artists_message">Artists from music on this device will appear here.</string>+ <string name="empty_playlists_title">No playlists yet</string>+ <string name="empty_playlists_message">Playlists you create will appear here.</string> <!-- Detail screen: Overline label for album type. Noun. --> <string name="label_album">Album</string>
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 2a4bf95c98..33f684fb99 100644--- a/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt+++ b/photos/src/main/java/com/vayunmathur/photos/data/PhotoDatabase.kt@@ -73,9 +73,18 @@ interface PhotoDao { @Query( "SELECT * FROM Photo WHERE isTrashed = 0 AND " +- "(ocrText LIKE '%' || :query || '%' OR name LIKE '%' || :query || '%') ORDER BY date DESC"+ "(ocrText LIKE :pattern ESCAPE '\\' OR name LIKE :pattern ESCAPE '\\') ORDER BY date DESC" )- suspend fun searchPhotos(query: String): List<Photo>+ 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.+ */+ suspend fun searchPhotos(query: String): List<Photo> =+ 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")@@ -249,6 +258,10 @@ interface PhotoScanDao { suspend fun setOcrBoxes(id: Long, json: String?) } +/** Builds a literal substring `LIKE` pattern from user input: wildcards escaped, wrapped in `%…%`. */+internal fun photoSearchPattern(query: String): String =+ "%" + query.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") + "%"+ /** Lightweight projection of a photo's CLIP embedding for in-memory search. */ data class PhotoEmbedding( val id: Long,
photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt b/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.ktindex 1ca7ece6df..4906faf08a 100644--- a/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt+++ b/photos/src/main/java/com/vayunmathur/photos/ui/GalleryScreen.kt@@ -22,6 +22,7 @@ import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.EmptyState import com.vayunmathur.library.ui.adaptiveGridCells import com.vayunmathur.library.ui.ExperimentalMaterial3Api import com.vayunmathur.library.ui.IconButton@@ -273,7 +274,12 @@ fun GalleryScreen( .padding(paddingValues) .pinchToZoomColumns({ columnCount }, { columnCount = it }) ) {- LazyVerticalGrid(+ if (state.photos.isEmpty() && !state.isRefreshing) {+ EmptyState(+ title = stringResource(R.string.gallery_empty_title),+ message = stringResource(R.string.gallery_empty_message),+ )+ } else LazyVerticalGrid( GridCells.Fixed(columnCount.roundToInt().coerceIn(2, 8)), Modifier, horizontalArrangement = Arrangement.spacedBy(4.dp),
photos/src/main/res/values/strings.xml
diff --git a/photos/src/main/res/values/strings.xml b/photos/src/main/res/values/strings.xmlindex f9fa6bee37..b26a9cd835 100644--- a/photos/src/main/res/values/strings.xml+++ b/photos/src/main/res/values/strings.xml@@ -45,6 +45,8 @@ <string name="action_unfavorite">Remove from favorites</string> <!-- Empty state of the Favorites album. Sentence --> <string name="favorites_empty">No favorites yet. Tap the heart on a photo to add it here.</string>+ <string name="gallery_empty_title">No photos yet</string>+ <string name="gallery_empty_message">Photos and videos on this device will appear here.</string> <!-- Snackbar when the system refuses to change a photo's favorite state. Sentence --> <string name="favorite_failed">Couldn\'t update favorites</string> <!-- Title of the selection action / dialog to add the chosen photos to an album. Verb phrase -->
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 635042225a..5c176c32b2 100644--- a/photos/src/test/java/com/vayunmathur/photos/data/PhotosSlice1DbTest.kt+++ b/photos/src/test/java/com/vayunmathur/photos/data/PhotosSlice1DbTest.kt@@ -107,6 +107,21 @@ class PhotosSlice1DbTest { assertEquals(listOf("beach sunset"), photoDao.searchPhotos("beach").map { it.name }) } + @Test+ fun searchWildcardsMatchLiterally() = runTest {+ photoDao.upsertAll(+ listOf(+ photo("100% crop", date = 3L),+ photo("1000 crop", date = 2L),+ photo("my_file", date = 1L),+ ),+ )+ assertEquals(listOf("100% crop"), photoDao.searchPhotos("%").map { it.name })+ assertEquals(listOf("100% crop"), photoDao.searchPhotos("100%").map { it.name })+ assertEquals(listOf("my_file"), photoDao.searchPhotos("_").map { it.name })+ assertEquals(listOf("my_file"), photoDao.searchPhotos("my_file").map { it.name })+ }+ @Test fun searchMatchesOcrText() = runTest { photoDao.upsertAll(listOf(photo("sign", date = 3L)))