From 64de77b880a5cdc4bfd6dc09cb67ecf35d573c48 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 03:52:19 +0530 Subject: [PATCH 01/16] feat: Google Messages New conversation and New group UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - New conversation is the Google Messages start-chat screen: a white "To:" field ("Type name, phone number, or email") and a full-width light-blue "Create group" pill, with no contact browser until something is typed. A typed number offers "Send to"; a contact starts a 1:1. - Create group opens "New group conversation": the same To field in plural form, every contact in one rounded card with dividers and "Mobile +number" subtitles, check circles, and a chip (avatar + name) per pick. With two chips the hint becomes "Anyone else?", the title "New group MMS", and a blue "Next →" pill appears at the bottom-right. - Repository.createGroup builds the thread from scratch and leaves an existing 1:1 untouched; AppViewModel.createGroup opens it. - The contacts permission callback reloads Contacts, so a picker opened right after the grant is not empty. - French apostrophes use typographic quotes so aapt2 accepts the plurals. --- .../java/com/anindra/messages/MainActivity.kt | 32 ++ .../com/anindra/messages/data/Repository.kt | 32 ++ .../com/anindra/messages/ui/NewChatScreen.kt | 213 +++++++---- .../com/anindra/messages/ui/NewGroupScreen.kt | 333 ++++++++++++++++++ .../res/values-ar/strings_conversations.xml | 8 +- .../res/values-de/strings_conversations.xml | 8 +- .../res/values-es/strings_conversations.xml | 8 +- .../res/values-fa/strings_conversations.xml | 8 +- .../res/values-fr/strings_conversations.xml | 8 +- .../res/values-hi/strings_conversations.xml | 8 +- .../res/values-ja/strings_conversations.xml | 8 +- .../res/values-ko/strings_conversations.xml | 8 +- .../res/values-pl/strings_conversations.xml | 8 +- .../values-pt-rBR/strings_conversations.xml | 8 +- .../res/values-ru/strings_conversations.xml | 8 +- .../values-zh-rCN/strings_conversations.xml | 8 +- .../values-zh-rTW/strings_conversations.xml | 8 +- .../main/res/values/strings_conversations.xml | 8 +- .../messages/ui/NewChatScreenFocusTest.kt | 2 +- .../messages/ui/NewGroupFlowWiringTest.kt | 90 +++++ scripts | 2 +- 21 files changed, 736 insertions(+), 80 deletions(-) create mode 100644 app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt create mode 100644 app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt diff --git a/app/src/main/java/com/anindra/messages/MainActivity.kt b/app/src/main/java/com/anindra/messages/MainActivity.kt index a028a974d..8898d40ca 100644 --- a/app/src/main/java/com/anindra/messages/MainActivity.kt +++ b/app/src/main/java/com/anindra/messages/MainActivity.kt @@ -94,6 +94,7 @@ import com.anindra.messages.ui.SettingsJump import com.anindra.messages.ui.InboxCategoryRulesScreen import com.anindra.messages.ui.ScheduledMessagesScreen import com.anindra.messages.ui.NewChatScreen +import com.anindra.messages.ui.NewGroupScreen import com.anindra.messages.ui.AboutScreen import com.anindra.messages.ui.SettingsScreen import com.anindra.messages.ui.AdvancedSettingsScreen @@ -218,6 +219,9 @@ class AppViewModel(app: Application) : AndroidViewModel(app) { contactsObserver = observer } + /** Reads Contacts again after the permission dialog answers. */ + fun reloadContacts() = loadContacts() + private fun loadContacts() { val ctx = getApplication() scope.launch(kotlinx.coroutines.Dispatchers.IO) { @@ -965,6 +969,14 @@ class AppViewModel(app: Application) : AndroidViewModel(app) { * thread, so the private history between the two stays put. [onReady] * receives the group's conversation id. */ + /** New group: create the thread from the picked people and open it. */ + fun createGroup(addresses: List, onReady: (Long) -> Unit) { + scope.launch(Dispatchers.IO) { + val id = repo.createGroup(addresses) + withContext(Dispatchers.Main) { if (id > 0) onReady(id) } + } + } + fun finishAddPeople(conversationId: Long, addresses: List, onReady: (Long) -> Unit) { scope.launch(Dispatchers.IO) { val id = if (repo.isGroup(conversationId)) { @@ -1546,6 +1558,12 @@ open class MainActivity : FragmentActivity() { val repo = (application as MessagesApplication).repository if (repo.needsInitialImport) repo.requeryFromSystem() } + // The contacts role is asked for on the screen that needs it, after + // the ViewModel's first read; without this the new-chat pickers stay + // empty until a contacts change or a restart (#405 follow-up). + if (grants[Manifest.permission.READ_CONTACTS] == true) { + androidx.lifecycle.ViewModelProvider(this)[AppViewModel::class.java].reloadContacts() + } if (Build.VERSION.SDK_INT >= 33 && grants[Manifest.permission.POST_NOTIFICATIONS] == false ) { @@ -2051,6 +2069,7 @@ open class MainActivity : FragmentActivity() { "trash" -> navRoute = "settings" "inbox" -> navRoute = "settings" "inbox-rules" -> navRoute = "inbox" + "new-group" -> navRoute = "new" "notif-settings" -> navRoute = "advanced" "auto-delete" -> navRoute = "advanced" "links" -> navRoute = "advanced" @@ -2064,6 +2083,7 @@ open class MainActivity : FragmentActivity() { val routeDepth = mapOf("list" to 0, "opening" to 0, "chat" to 1, "details" to 2, "new" to 1, "settings" to 1, "trash" to 2, "spam" to 2, "inbox" to 2, "inbox-rules" to 3, "advanced" to 2, "about" to 2, "accessibility" to 3, + "new-group" to 2, "notif-settings" to 3, "auto-delete" to 3, "links" to 3, "transfer-log" to 3, "add-people" to 3, "mms-check" to 3, "scheduled" to 2) @@ -2190,6 +2210,18 @@ open class MainActivity : FragmentActivity() { chatSearchQuery = null navRoute = "chat" } + }, + onNewGroup = { navRoute = "new-group" } + ) + "new-group" -> NewGroupScreen( + vm = vm, + onBack = { navRoute = "new" }, + onCreate = { addresses -> + vm.createGroup(addresses) { id -> + chatId = id + chatSearchQuery = null + navRoute = "chat" + } } ) "settings" -> if (useNewUi) SettingsScreen( diff --git a/app/src/main/java/com/anindra/messages/data/Repository.kt b/app/src/main/java/com/anindra/messages/data/Repository.kt index a04de1961..c7ded00e8 100644 --- a/app/src/main/java/com/anindra/messages/data/Repository.kt +++ b/app/src/main/java/com/anindra/messages/data/Repository.kt @@ -1138,6 +1138,38 @@ class Repository(private val context: Context) { * * Returns the new conversation id, or -1 if it could not be created. */ + /** + * Creates a group from the New group picker: no 1:1 conversation exists + * yet, so the first address becomes the thread's primary and everyone else + * a recipient. A 1:1 with the first person is left untouched. + */ + fun createGroup(addresses: List): Long = runOnIo { + val wanted = addresses.map { canonical(it).ifEmpty { it.trim() } } + .filter { it.isNotEmpty() } + .distinct() + if (wanted.size < 2) return@runOnIo -1L + val primary = wanted.first() + val cv = ContentValues().apply { + put("address", primary) + put("name", "") + put("snippet", "") + put("timestamp", System.currentTimeMillis()) + put("last_is_me", 0) + } + val newId = db.writableDatabase.insert("conversations", null, cv) + if (newId <= 0) return@runOnIo -1L + for (a in wanted) { + upsertParticipant(db.writableDatabase, a) + db.writableDatabase.execSQL( + "INSERT OR IGNORE INTO conversation_recipients(conversation_id, address) VALUES(?,?)", + arrayOf(newId, a) + ) + } + ensureGroupTitle(newId) + notifyChanged() + newId + } + fun createGroupFrom(conversationId: Long, addresses: List): Long = runOnIo { val primaryRow = db.readableDatabase.rawQuery( "SELECT address, name FROM conversations WHERE id=?", arrayOf(conversationId.toString()) diff --git a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt index d81bf9bbc..9f41382a6 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt @@ -1,28 +1,38 @@ package com.anindra.messages.ui +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.ui.draw.clip +import androidx.compose.foundation.text.BasicTextField import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.rounded.ArrowBack -import androidx.compose.material.icons.rounded.AddComment +import androidx.compose.material.icons.rounded.GroupAdd +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface import androidx.compose.material3.Text -import androidx.compose.material3.TextField -import androidx.compose.material3.TextFieldDefaults import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState @@ -34,111 +44,186 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource -import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.anindra.messages.R import com.anindra.messages.data.AddressIdentity data class Contact(val name: String, val number: String, val workProfile: Boolean = false) +/** + * Google Messages' New conversation, not a contact browser: the "To" field is + * the whole screen. Typing filters people; a typed number offers "Send to" as + * the first row. "Create group" opens the group picker, which is the only path + * to a group here. + */ @OptIn(ExperimentalMaterial3Api::class) @Composable -fun NewChatScreen(vm: com.anindra.messages.AppViewModel, onBack: () -> Unit, onPick: (String, String?) -> Unit) { +fun NewChatScreen( + vm: com.anindra.messages.AppViewModel, + onBack: () -> Unit, + onPick: (String, String?) -> Unit, + onNewGroup: () -> Unit = {} +) { var query by remember { mutableStateOf("") } val context = androidx.compose.ui.platform.LocalContext.current - androidx.activity.compose.BackHandler(onBack = onBack) + BackHandler(onBack = onBack) val contacts by vm.contacts.collectAsState() - val filtered = contacts.filter { - it.name.contains(query, ignoreCase = true) || it.number.contains(query) || - (isPhoneNumber(query.trim()) && AddressIdentity.matchesNumber(it.number, query.trim())) - } val focusRequester = remember { FocusRequester() } LaunchedEffect(Unit) { focusRequester.requestFocus() } + val typed = query.trim() + val filtered = if (typed.isBlank()) emptyList() else contacts.filter { + it.name.contains(typed, ignoreCase = true) || it.number.contains(typed) || + (isPhoneNumber(typed) && AddressIdentity.matchesNumber(it.number, typed)) + } + val canSendTo = isPhoneNumber(typed) && filtered.none { it.number == typed } + Scaffold( - topBar = { TopAppBar(title = { Text(stringResource(R.string.new_chat_title)) }, navigationIcon = { - IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Rounded.ArrowBack, stringResource(R.string.icon_back)) } - }) } + containerColor = MaterialTheme.colorScheme.surfaceContainer, + topBar = { + TopAppBar( + title = { Text(stringResource(R.string.new_chat_title)) }, + navigationIcon = { + IconButton(onClick = onBack) { + Icon(Icons.AutoMirrored.Rounded.ArrowBack, stringResource(R.string.icon_back)) + } + }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = MaterialTheme.colorScheme.surfaceContainer + ) + ) + } ) { padding -> Column(Modifier.padding(padding).fillMaxSize()) { - TextField( - value = query, - onValueChange = { query = it }, - placeholder = { Text(stringResource(R.string.new_chat_hint)) }, - singleLine = true, - colors = TextFieldDefaults.colors( - focusedContainerColor = Color.Transparent, - unfocusedContainerColor = Color.Transparent, - focusedIndicatorColor = Color.Transparent, - unfocusedIndicatorColor = Color.Transparent - ), - modifier = Modifier.focusRequester(focusRequester).fillMaxWidth() - ) - Spacer(Modifier.height(SettingsLayout.ROW_GAP)) + Spacer(Modifier.height(8.dp)) - // Manual entry option - val canSendToQuery = isPhoneNumber(query.trim()) - GroupedRowCard( - position = RowPosition.SINGLE, - modifier = Modifier.padding(horizontal = SettingsLayout.SCREEN_PADDING) - ) { - Row( - verticalAlignment = Alignment.CenterVertically, + Surface( + color = MaterialTheme.colorScheme.surface, + shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() - .clickable(enabled = canSendToQuery) { - // No name: the repository resolves the saved contact, so a - // national-form number typed here still shows the contact - // name instead of the raw digits (#444). - onPick(query.trim(), null) - } - .padding(SettingsLayout.ROW_CONTENT_PADDING) + .padding(horizontal = 16.dp) ) { - PersonAvatar("#", size = 40.dp) - Spacer(Modifier.width(16.dp)) - Column { - Text(context.getString(R.string.new_chat_send_to, query.ifBlank { "number" }), - fontWeight = FontWeight.Medium, - color = if (query.isNotBlank() && !canSendToQuery) - MaterialTheme.colorScheme.error else Color.Unspecified) - if (query.isNotBlank() && !canSendToQuery) { - Text(stringResource(R.string.new_chat_only_phone), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.error) - } + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .height(52.dp) + .padding(horizontal = 18.dp) + ) { + Text( + stringResource(R.string.new_chat_to), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + Spacer(Modifier.width(10.dp)) + BasicTextField( + value = query, + onValueChange = { query = it }, + singleLine = true, + textStyle = MaterialTheme.typography.bodyLarge.copy( + color = MaterialTheme.colorScheme.onSurface + ), + cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), + decorationBox = { inner -> + if (query.isEmpty()) { + Text( + stringResource(R.string.new_chat_hint), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } else { + inner() + } + }, + modifier = Modifier + .weight(1f) + .focusRequester(focusRequester) + ) } } + + Spacer(Modifier.height(12.dp)) + + Button( + onClick = onNewGroup, + shape = RoundedCornerShape(24.dp), + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.secondaryContainer, + contentColor = MaterialTheme.colorScheme.onSecondaryContainer + ), + modifier = Modifier + .fillMaxWidth() + .height(48.dp) + .padding(horizontal = 16.dp) + ) { + Icon(Icons.Rounded.GroupAdd, contentDescription = null, modifier = Modifier.width(22.dp)) + Spacer(Modifier.width(10.dp)) + Text( + stringResource(R.string.contact_create_group), + style = MaterialTheme.typography.labelLarge + ) } - Spacer(Modifier.height(SettingsLayout.GROUP_GAP)) + if (typed.isBlank()) return@Column - LazyColumn { + LazyColumn( + modifier = Modifier.fillMaxSize(), + contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp), + verticalArrangement = Arrangement.spacedBy(6.dp) + ) { + if (canSendTo) { + item(key = "send-to") { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .clip(RoundedCornerShape(16.dp)) + .background(MaterialTheme.colorScheme.surface) + .clickable { onPick(typed, null) } + .padding(horizontal = 16.dp, vertical = 12.dp) + ) { + PersonAvatar("#", size = 40.dp) + Spacer(Modifier.width(16.dp)) + Text( + text = context.getString(R.string.new_chat_send_to, typed), + style = MaterialTheme.typography.bodyLarge + ) + } + } + } items(filtered, key = { it.number }) { contact -> Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() .animateItem() + .clip(RoundedCornerShape(16.dp)) + .background(MaterialTheme.colorScheme.surface) .clickable { onPick(contact.number, contact.name) } .padding(horizontal = 16.dp, vertical = 10.dp) ) { PersonAvatar(contact.number, size = 40.dp) Spacer(Modifier.width(16.dp)) - Column { + Column(Modifier.weight(1f)) { Row(verticalAlignment = Alignment.CenterVertically) { - Text(contact.name, fontWeight = FontWeight.Medium) + Text(contact.name, style = MaterialTheme.typography.bodyLarge) if (contact.workProfile) { Spacer(Modifier.width(6.dp)) WorkProfileBadge() } } - Text(formatPhoneNumber(contact.number), - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant) + Text( + formatPhoneNumber(contact.number), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) } } } diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt new file mode 100644 index 000000000..2d7bf805f --- /dev/null +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -0,0 +1,333 @@ +package com.anindra.messages.ui + +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowRow +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.imePadding +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.itemsIndexed +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.BasicTextField +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.rounded.ArrowBack +import androidx.compose.material.icons.automirrored.rounded.ArrowForward +import androidx.compose.material.icons.rounded.CheckCircle +import androidx.compose.material.icons.rounded.Close +import androidx.compose.material.icons.rounded.RadioButtonUnchecked +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.ExtendedFloatingActionButton +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.draw.clip +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import com.anindra.messages.AppViewModel +import com.anindra.messages.R + +/** + * Google Messages' New group step. The title turns into "New group MMS" once a + * recipient is chosen, the To field says "Anyone else?", the contact list stays + * visible, and Next is a floating pill at the bottom-right — not a toolbar + * action. A single person is a chat, so Next only exists at two picks. + */ +@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) +@Composable +fun NewGroupScreen( + vm: AppViewModel, + onBack: () -> Unit, + onCreate: (List) -> Unit +) { + BackHandler(onBack = onBack) + val contacts by vm.contacts.collectAsState() + var query by remember { mutableStateOf("") } + var chosen by remember { mutableStateOf(listOf()) } + + fun nameOf(address: String): String = + contacts.firstOrNull { it.number == address }?.name ?: formatPhoneNumber(address) + + val filtered = contacts.filter { + query.isBlank() || + it.name.contains(query, ignoreCase = true) || + it.number.contains(query) + } + + Scaffold( + containerColor = MaterialTheme.colorScheme.surfaceContainer, + topBar = { + TopAppBar( + title = { + Text( + stringResource( + if (chosen.isEmpty()) R.string.new_group_title + else R.string.new_group_mms_title + ) + ) + }, + navigationIcon = { + IconButton(onClick = onBack) { + Icon( + Icons.AutoMirrored.Rounded.ArrowBack, + stringResource(R.string.icon_back) + ) + } + }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = MaterialTheme.colorScheme.surfaceContainer + ) + ) + } + ) { padding -> + Box(Modifier.padding(padding).fillMaxSize()) { + Column(Modifier.fillMaxSize()) { + Surface( + color = MaterialTheme.colorScheme.surface, + shape = RoundedCornerShape(28.dp), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = SettingsLayout.SCREEN_PADDING, vertical = 8.dp) + ) { + if (chosen.isEmpty()) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .height(52.dp) + .padding(horizontal = 18.dp) + ) { + Text( + stringResource(R.string.new_chat_to), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + Spacer(Modifier.width(10.dp)) + BasicTextField( + value = query, + onValueChange = { query = it }, + singleLine = true, + textStyle = MaterialTheme.typography.bodyLarge.copy( + color = MaterialTheme.colorScheme.onSurface + ), + cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), + decorationBox = { inner -> + if (query.isEmpty()) { + Text( + stringResource(R.string.new_group_hint), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } else { + inner() + } + }, + modifier = Modifier.weight(1f) + ) + } + } else { + FlowRow( + horizontalArrangement = Arrangement.spacedBy(6.dp), + verticalArrangement = Arrangement.spacedBy(4.dp), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 14.dp, vertical = 8.dp) + ) { + Text( + stringResource(R.string.new_chat_to), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(vertical = 8.dp) + ) + chosen.forEach { address -> + Surface( + color = MaterialTheme.colorScheme.surfaceContainerHigh, + shape = CircleShape, + modifier = Modifier.clickable { chosen = chosen - address } + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.padding(start = 4.dp, end = 12.dp, top = 4.dp, bottom = 4.dp) + ) { + PersonAvatar(address, size = 24.dp) + Spacer(Modifier.width(6.dp)) + Text( + nameOf(address), + style = MaterialTheme.typography.labelLarge, + color = MaterialTheme.colorScheme.onSurface, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.widthIn(max = 110.dp) + ) + } + } + } + BasicTextField( + value = query, + onValueChange = { query = it }, + singleLine = true, + textStyle = MaterialTheme.typography.bodyLarge.copy( + color = MaterialTheme.colorScheme.onSurface + ), + cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), + decorationBox = { inner -> + if (query.isEmpty() && chosen.size >= 2) { + Text( + stringResource(R.string.new_group_anyone_else), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1 + ) + } else { + inner() + } + }, + modifier = Modifier + .width(140.dp) + .padding(vertical = 8.dp) + ) + } + } + } + + Surface( + color = MaterialTheme.colorScheme.surface, + shape = RoundedCornerShape(16.dp), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp) + .weight(1f) + ) { + LazyColumn { + itemsIndexed(filtered, key = { _, contact -> contact.number }) { index, contact -> + val picked = contact.number in chosen + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .animateItem() + .padding( + horizontal = if (picked) 6.dp else 0.dp, + vertical = if (picked) 3.dp else 0.dp + ) + .clip(RoundedCornerShape(28.dp)) + .background( + if (picked) MaterialTheme.colorScheme.secondaryContainer + else MaterialTheme.colorScheme.surface + ) + .clickable { + if (picked) { + chosen = chosen - contact.number + } else { + chosen = chosen + contact.number + // Clear the query so the next name can be + // typed straight away, like Google Messages. + query = "" + } + } + .padding( + start = if (picked) 10.dp else 16.dp, + end = 16.dp, + top = 10.dp, + bottom = 10.dp + ) + ) { + PersonAvatar(contact.number, size = 40.dp) + Spacer(Modifier.width(16.dp)) + Column(Modifier.weight(1f)) { + Text( + contact.name, + style = MaterialTheme.typography.bodyLarge, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + Text( + stringResource(R.string.contact_mobile, formatPhoneNumber(contact.number)), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } + if (contact.workProfile) { + Spacer(Modifier.width(4.dp)) + WorkProfileBadge() + } + Spacer(Modifier.width(12.dp)) + Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) { + Icon( + if (picked) Icons.Rounded.CheckCircle + else Icons.Rounded.RadioButtonUnchecked, + contentDescription = if (picked) stringResource(R.string.contact_selected) else null, + tint = if (picked) MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.outline, + modifier = Modifier.size(24.dp) + ) + } + } + if (index != filtered.lastIndex) { + androidx.compose.material3.HorizontalDivider( + color = MaterialTheme.colorScheme.outlineVariant + ) + } + } + } + } + } + + if (chosen.size >= 2) { + Surface( + color = MaterialTheme.colorScheme.primary, + contentColor = MaterialTheme.colorScheme.onPrimary, + shape = CircleShape, + shadowElevation = 6.dp, + modifier = Modifier + .align(Alignment.BottomEnd) + .imePadding() + .padding(16.dp) + .clickable { onCreate(chosen) } + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier.padding(horizontal = 20.dp, vertical = 14.dp) + ) { + Text(stringResource(R.string.common_next)) + Spacer(Modifier.width(8.dp)) + Icon(Icons.AutoMirrored.Rounded.ArrowForward, contentDescription = null) + } + } + } + } + } +} diff --git a/app/src/main/res/values-ar/strings_conversations.xml b/app/src/main/res/values-ar/strings_conversations.xml index 82d05062b..3b9fbe45d 100644 --- a/app/src/main/res/values-ar/strings_conversations.xml +++ b/app/src/main/res/values-ar/strings_conversations.xml @@ -7,8 +7,14 @@ انقر زر الرجوع مرة أخرى للخروج + اكتب أسماء أو أرقام هواتف أو بريدًا إلكترونيًا + مجموعة MMS جديدة + أي شخص آخر؟ + محادثة جماعية جديدة محادثة جديدة - أدخل الاسم أو رقم الهاتف + جوال %s + إلى: + اكتب اسمًا أو رقم هاتف أو بريدًا إلكترونيًا يمكن إرسال الرسائل إلى أرقام الهواتف فقط إرسال إلى \"%s\" رسالة نصية diff --git a/app/src/main/res/values-de/strings_conversations.xml b/app/src/main/res/values-de/strings_conversations.xml index 55585cf29..54089f197 100644 --- a/app/src/main/res/values-de/strings_conversations.xml +++ b/app/src/main/res/values-de/strings_conversations.xml @@ -6,8 +6,14 @@ App-Einstellungen öffnen Noch einmal Zurück drücken zum Beenden + Namen, Telefonnummern oder E-Mails eingeben + Neue MMS-Gruppe + Noch jemand? + Neue Gruppenunterhaltung Neue Unterhaltung - Name oder Telefonnummer eingeben + Mobil %s + An: + Name, Telefonnummer oder E-Mail eingeben Es können nur Telefonnummern angerufen werden An „%s“ senden Textnachricht diff --git a/app/src/main/res/values-es/strings_conversations.xml b/app/src/main/res/values-es/strings_conversations.xml index 4acc504ee..3cea3b0f4 100644 --- a/app/src/main/res/values-es/strings_conversations.xml +++ b/app/src/main/res/values-es/strings_conversations.xml @@ -7,8 +7,14 @@ Presionar atrás nuevamente para salir + Escribe nombres, números de teléfono o correos + Nuevo grupo MMS + ¿Alguien más? + Nueva conversación grupal Conversación nueva - Ingresa nombre o número de teléfono + Móvil %s + Para: + Escribe un nombre, número de teléfono o correo Solo se puede enviar mensajes a números de teléfono Enviar a «%s» Mensaje de texto diff --git a/app/src/main/res/values-fa/strings_conversations.xml b/app/src/main/res/values-fa/strings_conversations.xml index 4c1083eaa..92fc2338f 100644 --- a/app/src/main/res/values-fa/strings_conversations.xml +++ b/app/src/main/res/values-fa/strings_conversations.xml @@ -7,8 +7,14 @@ برای خروج دوباره دکمه بازگشت را بزنید + نام‌ها، شماره‌های تلفن یا ایمیل‌ها را وارد کنید + گروه MMS جدید + شخص دیگری؟ + گفتگوی گروهی جدید گفتگوی جدید - نام یا شماره تلفن را وارد کنید + همراه %s + به: + نام، شماره تلفن یا ایمیل را وارد کنید فقط به شماره‌های تلفن می‌توان پیام فرستاد ارسال به «%s» پیام diff --git a/app/src/main/res/values-fr/strings_conversations.xml b/app/src/main/res/values-fr/strings_conversations.xml index 5f87eb333..ab6fb6b41 100644 --- a/app/src/main/res/values-fr/strings_conversations.xml +++ b/app/src/main/res/values-fr/strings_conversations.xml @@ -6,8 +6,14 @@ Ouvrir les paramètres de l\'application Appuyez à nouveau sur le bouton retour pour quitter + Saisissez des noms, numéros de téléphone ou e-mails + Nouveau groupe MMS + Quelqu’un d’autre ? + Nouvelle conversation de groupe Nouvelle conversation - Saisir un nom ou un numéro de téléphone + Mobile %s + À : + Saisissez un nom, un numéro de téléphone ou un e-mail Seuls les numéros de téléphone peuvent être message Envoyer à « %s » Message texte diff --git a/app/src/main/res/values-hi/strings_conversations.xml b/app/src/main/res/values-hi/strings_conversations.xml index 5ae2d5a41..516d37b5e 100644 --- a/app/src/main/res/values-hi/strings_conversations.xml +++ b/app/src/main/res/values-hi/strings_conversations.xml @@ -7,8 +7,14 @@ बाहर निकलने के लिए फिर से बैक दबाएं + नाम, फ़ोन नंबर या ईमेल डालें + नया MMS समूह + कोई और? + नई समूह बातचीत नया संवाद - नाम या फ़ोन नंबर दर्ज करें + मोबाइल %s + प्रति: + नाम, फ़ोन नंबर या ईमेल डालें केवल फ़ोन नंबरों को संदेश भेजे जा सकते हैं “%s” को भेजें पाठ संदेश diff --git a/app/src/main/res/values-ja/strings_conversations.xml b/app/src/main/res/values-ja/strings_conversations.xml index cee52fd1d..4457fa8db 100644 --- a/app/src/main/res/values-ja/strings_conversations.xml +++ b/app/src/main/res/values-ja/strings_conversations.xml @@ -7,8 +7,14 @@ 再度戻るを押して終了 + 名前、電話番号、メールアドレスを入力 + 新しい MMS グループ + 他に追加しますか? + 新しいグループ会話 新しい会話 - 名前または電話番号を入力 + モバイル %s + 宛先: + 名前、電話番号、メールアドレスを入力 メッセージを送信できるのは電話番号のみです 「%s」に送信 テキストメッセージ diff --git a/app/src/main/res/values-ko/strings_conversations.xml b/app/src/main/res/values-ko/strings_conversations.xml index e64df38a2..a2b44aab8 100644 --- a/app/src/main/res/values-ko/strings_conversations.xml +++ b/app/src/main/res/values-ko/strings_conversations.xml @@ -7,8 +7,14 @@ 뒤로 가기를 다시 누르면 종료됩니다 + 이름, 전화번호 또는 이메일 입력 + 새 MMS 그룹 + 다른 사람이 있나요? + 새 그룹 대화 새 대화 - 이름 또는 전화번호 입력 + 휴대전화 %s + 받는 사람: + 이름, 전화번호 또는 이메일 입력 전화번호로만 메시지 전송이 가능합니다 \"%s\"(으)로 보내기 문자 메시지 diff --git a/app/src/main/res/values-pl/strings_conversations.xml b/app/src/main/res/values-pl/strings_conversations.xml index 37e73b1e5..76b0d7785 100644 --- a/app/src/main/res/values-pl/strings_conversations.xml +++ b/app/src/main/res/values-pl/strings_conversations.xml @@ -7,8 +7,14 @@ Naciśnij ponownie wstecz, aby wyjść + Wpisz nazwy, numery telefonów lub e-maile + Nowa grupa MMS + Ktoś jeszcze? + Nowa rozmowa grupowa Nowa rozmowa - Wpisz imię lub numer telefonu + Komórka %s + Do: + Wpisz nazwę, numer telefonu lub e-mail Do numerów telefonów można wysyłać wiadomości Wyślij do „%s” Wiadomość tekstowa diff --git a/app/src/main/res/values-pt-rBR/strings_conversations.xml b/app/src/main/res/values-pt-rBR/strings_conversations.xml index 140eb760d..378383d38 100644 --- a/app/src/main/res/values-pt-rBR/strings_conversations.xml +++ b/app/src/main/res/values-pt-rBR/strings_conversations.xml @@ -7,8 +7,14 @@ Pressione voltar novamente para sair + Digite nomes, números de telefone ou e-mails + Novo grupo MMS + Mais alguém? + Nova conversa em grupo Nova conversa - Digitar nome ou número de telefone + Celular %s + Para: + Digite um nome, número de telefone ou e-mail Somente números de telefone podem receber mensagens Enviar para \"%s\" Mensagem de texto diff --git a/app/src/main/res/values-ru/strings_conversations.xml b/app/src/main/res/values-ru/strings_conversations.xml index 160610c93..bb3584142 100644 --- a/app/src/main/res/values-ru/strings_conversations.xml +++ b/app/src/main/res/values-ru/strings_conversations.xml @@ -7,8 +7,14 @@ Нажмите «Назад» ещё раз для выхода + Введите имена, номера телефонов или адреса эл. почты + Новая группа MMS + Кто-то ещё? + Новый групповой чат Новая переписка - Введите имя или номер телефона + Мобильный %s + Кому: + Введите имя, номер телефона или адрес эл. почты Сообщения можно отправлять только на номера телефонов Отправить «%s» Текстовое сообщение diff --git a/app/src/main/res/values-zh-rCN/strings_conversations.xml b/app/src/main/res/values-zh-rCN/strings_conversations.xml index ff68181aa..43a7ea761 100644 --- a/app/src/main/res/values-zh-rCN/strings_conversations.xml +++ b/app/src/main/res/values-zh-rCN/strings_conversations.xml @@ -6,8 +6,14 @@ 打开设置 再按一次返回以退出 + 输入姓名、电话号码或电子邮件地址 + 新建 MMS 群组 + 还要添加其他人吗? + 新建群组对话 新对话 - 输入姓名或电话号码 + 手机 %s + 收件人: + 输入姓名、电话号码或电子邮件地址 只能向电话号码发送消息 发送至「%s」 输入消息 diff --git a/app/src/main/res/values-zh-rTW/strings_conversations.xml b/app/src/main/res/values-zh-rTW/strings_conversations.xml index 78a8ca3c5..61cce2a86 100644 --- a/app/src/main/res/values-zh-rTW/strings_conversations.xml +++ b/app/src/main/res/values-zh-rTW/strings_conversations.xml @@ -6,8 +6,14 @@ 開啟設定 再按一次返回以退出 + 輸入名稱、電話號碼或電子郵件地址 + 新增 MMS 群組 + 還要新增其他人嗎? + 新增群組對話 新對話 - 輸入姓名或電話號碼 + 手機 %s + 收件者: + 輸入名稱、電話號碼或電子郵件地址 僅能傳送訊息給電話號碼 傳送至「%s」 輸入訊息 diff --git a/app/src/main/res/values/strings_conversations.xml b/app/src/main/res/values/strings_conversations.xml index 6eb0e197a..3e97e54b7 100644 --- a/app/src/main/res/values/strings_conversations.xml +++ b/app/src/main/res/values/strings_conversations.xml @@ -7,8 +7,14 @@ Press back again to exit + Type names, phone numbers, or emails + New group MMS + Anyone else? + New group conversation New conversation - Enter name or phone number + Mobile %s + To: + Type name, phone number, or email Only phone numbers can be messaged Send to “%s” Message diff --git a/app/src/test/java/com/anindra/messages/ui/NewChatScreenFocusTest.kt b/app/src/test/java/com/anindra/messages/ui/NewChatScreenFocusTest.kt index ff8115e9a..d5fa4b3f1 100644 --- a/app/src/test/java/com/anindra/messages/ui/NewChatScreenFocusTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/NewChatScreenFocusTest.kt @@ -31,6 +31,6 @@ class NewChatScreenFocusTest { @Test fun textFieldWiresTheFocusRequester() { - assertTrue("TextField modifier does not use focusRequester", "Modifier.focusRequester(focusRequester)" in source) + assertTrue("TextField modifier does not use focusRequester", "focusRequester(focusRequester)" in source) } } diff --git a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt new file mode 100644 index 000000000..e890add0d --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt @@ -0,0 +1,90 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +/** + * Google Messages' New group path: a row on New conversation opens a separate + * picker, Next unlocks at two people, and the repository creates the group + * thread. Each half is invisible to the other, so the wiring is pinned here. + */ +class NewGroupFlowWiringTest { + + private val root: File by lazy { + generateSequence(File("").absoluteFile) { it.parentFile } + .firstOrNull { File(it, "gradle/libs.versions.toml").isFile } + ?: error("repo root not found") + } + + private fun source(path: String): String = + File(root, "app/src/main/java/com/anindra/messages/$path").readText() + + private val newChat: String by lazy { source("ui/NewChatScreen.kt") } + private val newGroup: String by lazy { source("ui/NewGroupScreen.kt") } + private val activity: String by lazy { source("MainActivity.kt") } + private val repository: String by lazy { source("data/Repository.kt") } + + @Test + fun newConversationOffersTheGroupRow() { + assertTrue( + "New conversation takes no onNewGroup callback", + Regex("""onNewGroup:\s*\(\)\s*->\s*Unit""").containsMatchIn(newChat) + ) + assertTrue( + "there is no Create group action", + newChat.contains("R.string.contact_create_group") && + newChat.contains("Icons.Rounded.GroupAdd") + ) + } + + @Test + fun thePickerRequiresTwoPeople() { + assertTrue( + "the picker has no Next action", + Regex("""if \(chosen\.size >= 2\)[\s\S]{0,700}onCreate\(chosen\)""") + .containsMatchIn(newGroup) + ) + assertTrue( + "the picker never collects selections", + newGroup.contains("chosen + contact.number") + ) + } + + @Test + fun theRouteOpensAndCreatesTheGroup() { + assertTrue( + "MainActivity has no new-group route", + activity.contains("\"new-group\" -> NewGroupScreen(") + ) + assertTrue( + "New conversation does not navigate to the picker", + activity.contains("onNewGroup = { navRoute = \"new-group\" }") + ) + assertTrue( + "the route does not create a group", + Regex("""onCreate = \{ addresses ->[\s\S]{0,160}vm\.createGroup\(addresses\)""") + .containsMatchIn(activity) + ) + assertTrue( + "Back does not return to New conversation", + Regex("""\"new-group\" -> navRoute = \"new\"""").containsMatchIn(activity) + ) + } + + @Test + fun theRepositoryCreatesAGroupThread() { + assertTrue( + "Repository has no createGroup", + Regex("""fun createGroup\(addresses: List\): Long""").containsMatchIn(repository) + ) + assertTrue( + "createGroup does not refuse a single recipient", + Regex("""fun createGroup[\s\S]{0,600}wanted\.size < 2""").containsMatchIn(repository) + ) + assertTrue( + "createGroup does not add the recipients", + Regex("""fun createGroup[\s\S]{0,1400}conversation_recipients""").containsMatchIn(repository) + ) + } +} diff --git a/scripts b/scripts index 8fa0729c9..5f706cb73 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 8fa0729c98ae86f82346c99036c01db6bb51169b +Subproject commit 5f706cb73b5b90a2495105eb7e05a2488f06b8cd From db9b28c98b0d7bee809cdf4d8c8fc92709fbbaee Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 04:08:32 +0530 Subject: [PATCH 02/16] fix: match the live Google Messages start-chat visuals - The New conversation page uses Google Messages' #F0F4F9 surface, an 8dp inset white To field, and the pale-cyan Create group pill with the dark navy label; the whole 48dp row is the touch target while the pill itself is 36dp. - New group contacts are separate rounded cards with 6dp gaps instead of one card, matching the live app; selected rows use a fully rounded secondary container and the To chips sit inline. - LightColors.surfaceContainer is now #F0F4F9, the colour Google Messages paints under both screens. --- .../com/anindra/messages/ui/NewChatScreen.kt | 50 ++++--- .../com/anindra/messages/ui/NewGroupScreen.kt | 139 ++++++++---------- .../com/anindra/messages/ui/theme/Theme.kt | 11 +- scripts | 2 +- 4 files changed, 100 insertions(+), 102 deletions(-) diff --git a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt index 9f41382a6..ad519e0d2 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt @@ -9,8 +9,10 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width @@ -50,6 +52,8 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.anindra.messages.R import com.anindra.messages.data.AddressIdentity +import com.anindra.messages.ui.theme.onStartChatAction +import com.anindra.messages.ui.theme.startChatAction data class Contact(val name: String, val number: String, val workProfile: Boolean = false) @@ -99,20 +103,20 @@ fun NewChatScreen( } ) { padding -> Column(Modifier.padding(padding).fillMaxSize()) { - Spacer(Modifier.height(8.dp)) + Spacer(Modifier.height(0.dp)) Surface( - color = MaterialTheme.colorScheme.surface, + color = MaterialTheme.colorScheme.surfaceContainerLowest, shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() - .padding(horizontal = 16.dp) + .padding(horizontal = 8.dp) ) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() - .height(52.dp) + .height(40.dp) .padding(horizontal = 18.dp) ) { Text( @@ -147,26 +151,30 @@ fun NewChatScreen( } } - Spacer(Modifier.height(12.dp)) + Spacer(Modifier.height(8.dp)) - Button( + Surface( onClick = onNewGroup, - shape = RoundedCornerShape(24.dp), - colors = ButtonDefaults.buttonColors( - containerColor = MaterialTheme.colorScheme.secondaryContainer, - contentColor = MaterialTheme.colorScheme.onSecondaryContainer - ), + color = MaterialTheme.colorScheme.startChatAction, + contentColor = MaterialTheme.colorScheme.onStartChatAction, + shape = RoundedCornerShape(18.dp), modifier = Modifier .fillMaxWidth() - .height(48.dp) - .padding(horizontal = 16.dp) + .padding(horizontal = 8.dp) + .height(36.dp) ) { - Icon(Icons.Rounded.GroupAdd, contentDescription = null, modifier = Modifier.width(22.dp)) - Spacer(Modifier.width(10.dp)) - Text( - stringResource(R.string.contact_create_group), - style = MaterialTheme.typography.labelLarge - ) + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center, + modifier = Modifier.fillMaxSize() + ) { + Icon(Icons.Rounded.GroupAdd, contentDescription = null, modifier = Modifier.size(20.dp)) + Spacer(Modifier.width(8.dp)) + Text( + stringResource(R.string.contact_create_group), + style = MaterialTheme.typography.labelLarge + ) + } } if (typed.isBlank()) return@Column @@ -183,7 +191,7 @@ fun NewChatScreen( modifier = Modifier .fillMaxWidth() .clip(RoundedCornerShape(16.dp)) - .background(MaterialTheme.colorScheme.surface) + .background(MaterialTheme.colorScheme.surfaceContainerLowest) .clickable { onPick(typed, null) } .padding(horizontal = 16.dp, vertical = 12.dp) ) { @@ -203,7 +211,7 @@ fun NewChatScreen( .fillMaxWidth() .animateItem() .clip(RoundedCornerShape(16.dp)) - .background(MaterialTheme.colorScheme.surface) + .background(MaterialTheme.colorScheme.surfaceContainerLowest) .clickable { onPick(contact.number, contact.name) } .padding(horizontal = 16.dp, vertical = 10.dp) ) { diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index 2d7bf805f..06e161a23 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -112,18 +112,18 @@ fun NewGroupScreen( Box(Modifier.padding(padding).fillMaxSize()) { Column(Modifier.fillMaxSize()) { Surface( - color = MaterialTheme.colorScheme.surface, + color = MaterialTheme.colorScheme.surfaceContainerLowest, shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() - .padding(horizontal = SettingsLayout.SCREEN_PADDING, vertical = 8.dp) + .padding(horizontal = 8.dp, vertical = 8.dp) ) { if (chosen.isEmpty()) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() - .height(52.dp) + .height(40.dp) .padding(horizontal = 18.dp) ) { Text( @@ -221,84 +221,67 @@ fun NewGroupScreen( } } - Surface( - color = MaterialTheme.colorScheme.surface, - shape = RoundedCornerShape(16.dp), - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 8.dp) - .weight(1f) + LazyColumn( + modifier = Modifier.weight(1f), + contentPadding = androidx.compose.foundation.layout.PaddingValues( + horizontal = 8.dp, vertical = 4.dp + ), + verticalArrangement = Arrangement.spacedBy(6.dp) ) { - LazyColumn { - itemsIndexed(filtered, key = { _, contact -> contact.number }) { index, contact -> - val picked = contact.number in chosen - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .fillMaxWidth() - .animateItem() - .padding( - horizontal = if (picked) 6.dp else 0.dp, - vertical = if (picked) 3.dp else 0.dp - ) - .clip(RoundedCornerShape(28.dp)) - .background( - if (picked) MaterialTheme.colorScheme.secondaryContainer - else MaterialTheme.colorScheme.surface - ) - .clickable { - if (picked) { - chosen = chosen - contact.number - } else { - chosen = chosen + contact.number - // Clear the query so the next name can be - // typed straight away, like Google Messages. - query = "" - } + itemsIndexed(filtered, key = { _, contact -> contact.number }) { _, contact -> + val picked = contact.number in chosen + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .animateItem() + .clip(RoundedCornerShape(24.dp)) + .background( + if (picked) MaterialTheme.colorScheme.secondaryContainer + else MaterialTheme.colorScheme.surfaceContainerLowest + ) + .clickable { + if (picked) { + chosen = chosen - contact.number + } else { + chosen = chosen + contact.number + // Clear the query so the next name can be + // typed straight away, like Google Messages. + query = "" } - .padding( - start = if (picked) 10.dp else 16.dp, - end = 16.dp, - top = 10.dp, - bottom = 10.dp - ) - ) { - PersonAvatar(contact.number, size = 40.dp) - Spacer(Modifier.width(16.dp)) - Column(Modifier.weight(1f)) { - Text( - contact.name, - style = MaterialTheme.typography.bodyLarge, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - Text( - stringResource(R.string.contact_mobile, formatPhoneNumber(contact.number)), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - } - if (contact.workProfile) { - Spacer(Modifier.width(4.dp)) - WorkProfileBadge() - } - Spacer(Modifier.width(12.dp)) - Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) { - Icon( - if (picked) Icons.Rounded.CheckCircle - else Icons.Rounded.RadioButtonUnchecked, - contentDescription = if (picked) stringResource(R.string.contact_selected) else null, - tint = if (picked) MaterialTheme.colorScheme.primary - else MaterialTheme.colorScheme.outline, - modifier = Modifier.size(24.dp) - ) } + .padding(horizontal = 16.dp, vertical = 10.dp) + ) { + PersonAvatar(contact.number, size = 40.dp) + Spacer(Modifier.width(16.dp)) + Column(Modifier.weight(1f)) { + Text( + contact.name, + style = MaterialTheme.typography.bodyLarge, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + Text( + stringResource(R.string.contact_mobile, formatPhoneNumber(contact.number)), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } + if (contact.workProfile) { + Spacer(Modifier.width(4.dp)) + WorkProfileBadge() } - if (index != filtered.lastIndex) { - androidx.compose.material3.HorizontalDivider( - color = MaterialTheme.colorScheme.outlineVariant + Spacer(Modifier.width(12.dp)) + Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) { + Icon( + if (picked) Icons.Rounded.CheckCircle + else Icons.Rounded.RadioButtonUnchecked, + contentDescription = if (picked) stringResource(R.string.contact_selected) else null, + tint = if (picked) MaterialTheme.colorScheme.primary + else MaterialTheme.colorScheme.outline, + modifier = Modifier.size(24.dp) ) } } @@ -320,7 +303,7 @@ fun NewGroupScreen( ) { Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.padding(horizontal = 20.dp, vertical = 14.dp) + modifier = Modifier.padding(horizontal = 20.dp, vertical = 10.dp) ) { Text(stringResource(R.string.common_next)) Spacer(Modifier.width(8.dp)) diff --git a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt index 5776b11b4..e37ff927c 100644 --- a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt +++ b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt @@ -73,7 +73,7 @@ internal val LightColors = lightColorScheme( surfaceBright = Color(0xFFFCFCFE), surfaceContainerLowest = Color(0xFFFFFFFF), surfaceContainerLow = Color(0xFFF2F3F9), - surfaceContainer = Color(0xFFECECF3), + surfaceContainer = Color(0xFFF0F4F9), surfaceContainerHigh = Color(0xFFE6E7ED), surfaceContainerHighest = Color(0xFFE1E2E8) ) @@ -202,7 +202,7 @@ internal val LightHighContrastColors = lightColorScheme( surfaceBright = Color(0xFFFFFFFF), surfaceContainerLowest = Color(0xFFFFFFFF), surfaceContainerLow = Color(0xFFF2F3F9), - surfaceContainer = Color(0xFFECECF3), + surfaceContainer = Color(0xFFF0F4F9), surfaceContainerHigh = Color(0xFFE6E7ED), surfaceContainerHighest = Color(0xFFE1E2E8) ) @@ -288,6 +288,13 @@ val ColorScheme.startChatContent: Color val ColorScheme.selectedBubble: Color get() = primary val ColorScheme.onSelectedBubble: Color get() = onPrimary +/** Google Messages' "Create group" pill: pale cyan in light, deep blue in dark. */ +val ColorScheme.startChatAction: Color + get() = if (surface.luminance() > 0.5f) Color(0xFFC2E7FF) else Color(0xFF004A77) + +val ColorScheme.onStartChatAction: Color + get() = if (surface.luminance() > 0.5f) Color(0xFF001D35) else Color(0xFFC2E7FF) + // Chat date separators and message times use the platform default typeface // at a slightly lighter weight than surrounding text. val ChatMetaWeight: FontWeight = FontWeight.Medium diff --git a/scripts b/scripts index 5f706cb73..32faff1b8 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 5f706cb73b5b90a2495105eb7e05a2488f06b8cd +Subproject commit 32faff1b86393ef83a962c8321a1d6800a19f0ca From 01486044dd29337388c7ef627b67df0b39b3c09e Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 04:23:18 +0530 Subject: [PATCH 03/16] feat: Add group name step and Google Messages search states - Next from the group picker now opens Google Messages' naming screen: overlapping member avatars, "Group name (optional)", the visibility note, and a Done pill. Done saves the name (or keeps the generated one) and opens the chat; Back does the same. - New conversation hides Create group while typing; results are one rounded card with dividers and Mobile +number subtitles. - Contact search matches a word start, not an inner letter: "T" finds "Prize Team"/"T1", not "Dr. Patel Clinic". - New group hides the list until typing and shows Anyone else? from the first chip. --- .../java/com/anindra/messages/MainActivity.kt | 26 ++- .../anindra/messages/ui/GroupNameScreen.kt | 214 ++++++++++++++++++ .../com/anindra/messages/ui/NewChatScreen.kt | 171 +++++++------- .../com/anindra/messages/ui/NewGroupScreen.kt | 10 +- .../main/res/values-ar/strings_components.xml | 1 + .../res/values-ar/strings_conversations.xml | 3 + .../main/res/values-de/strings_components.xml | 1 + .../res/values-de/strings_conversations.xml | 3 + .../main/res/values-es/strings_components.xml | 1 + .../res/values-es/strings_conversations.xml | 3 + .../main/res/values-fa/strings_components.xml | 1 + .../res/values-fa/strings_conversations.xml | 3 + .../main/res/values-fr/strings_components.xml | 1 + .../res/values-fr/strings_conversations.xml | 3 + .../main/res/values-hi/strings_components.xml | 1 + .../res/values-hi/strings_conversations.xml | 3 + .../main/res/values-ja/strings_components.xml | 1 + .../res/values-ja/strings_conversations.xml | 3 + .../main/res/values-ko/strings_components.xml | 1 + .../res/values-ko/strings_conversations.xml | 3 + .../main/res/values-pl/strings_components.xml | 1 + .../res/values-pl/strings_conversations.xml | 3 + .../res/values-pt-rBR/strings_components.xml | 1 + .../values-pt-rBR/strings_conversations.xml | 3 + .../main/res/values-ru/strings_components.xml | 1 + .../res/values-ru/strings_conversations.xml | 3 + .../res/values-zh-rCN/strings_components.xml | 1 + .../values-zh-rCN/strings_conversations.xml | 3 + .../res/values-zh-rTW/strings_components.xml | 1 + .../values-zh-rTW/strings_conversations.xml | 3 + .../main/res/values/strings_components.xml | 1 + .../main/res/values/strings_conversations.xml | 3 + .../messages/ui/ContactMatchQueryTest.kt | 33 +++ scripts | 2 +- 34 files changed, 427 insertions(+), 85 deletions(-) create mode 100644 app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt create mode 100644 app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt diff --git a/app/src/main/java/com/anindra/messages/MainActivity.kt b/app/src/main/java/com/anindra/messages/MainActivity.kt index 8898d40ca..a762ec21b 100644 --- a/app/src/main/java/com/anindra/messages/MainActivity.kt +++ b/app/src/main/java/com/anindra/messages/MainActivity.kt @@ -94,6 +94,7 @@ import com.anindra.messages.ui.SettingsJump import com.anindra.messages.ui.InboxCategoryRulesScreen import com.anindra.messages.ui.ScheduledMessagesScreen import com.anindra.messages.ui.NewChatScreen +import com.anindra.messages.ui.GroupNameScreen import com.anindra.messages.ui.NewGroupScreen import com.anindra.messages.ui.AboutScreen import com.anindra.messages.ui.SettingsScreen @@ -1583,6 +1584,9 @@ open class MainActivity : FragmentActivity() { } private var navRoute by androidx.compose.runtime.mutableStateOf("list") + // A group created from the New group picker waits on the naming screen + // before the chat opens. + private var namingGroupId by androidx.compose.runtime.mutableStateOf(null) private var pendingOpenAddress by androidx.compose.runtime.mutableStateOf(null) private var pendingOpenConversationId by androidx.compose.runtime.mutableStateOf(null) private var pendingShareBody by androidx.compose.runtime.mutableStateOf("") @@ -2070,6 +2074,7 @@ open class MainActivity : FragmentActivity() { "inbox" -> navRoute = "settings" "inbox-rules" -> navRoute = "inbox" "new-group" -> navRoute = "new" + "group-name" -> namingGroupId?.let { chatId = it; navRoute = "chat" } ?: run { navRoute = "list" } "notif-settings" -> navRoute = "advanced" "auto-delete" -> navRoute = "advanced" "links" -> navRoute = "advanced" @@ -2084,6 +2089,7 @@ open class MainActivity : FragmentActivity() { val routeDepth = mapOf("list" to 0, "opening" to 0, "chat" to 1, "details" to 2, "new" to 1, "settings" to 1, "trash" to 2, "spam" to 2, "inbox" to 2, "inbox-rules" to 3, "advanced" to 2, "about" to 2, "accessibility" to 3, "new-group" to 2, + "group-name" to 2, "notif-settings" to 3, "auto-delete" to 3, "links" to 3, "transfer-log" to 3, "add-people" to 3, "mms-check" to 3, "scheduled" to 2) @@ -2218,11 +2224,29 @@ open class MainActivity : FragmentActivity() { onBack = { navRoute = "new" }, onCreate = { addresses -> vm.createGroup(addresses) { id -> + namingGroupId = id + navRoute = "group-name" + } + } + ) + "group-name" -> namingGroupId?.let { id -> + GroupNameScreen( + vm = vm, + conversationId = id, + onDone = { name -> + if (name.isNotBlank()) vm.setGroupTitle(id, name) + chatId = id + chatSearchQuery = null + navRoute = "chat" + }, + onBack = { chatId = id chatSearchQuery = null navRoute = "chat" } - } + ) + } ?: androidx.compose.foundation.layout.Box( + Modifier.fillMaxSize() ) "settings" -> if (useNewUi) SettingsScreen( vm = vm, diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt new file mode 100644 index 000000000..319394199 --- /dev/null +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -0,0 +1,214 @@ +package com.anindra.messages.ui + +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.offset +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.text.BasicTextField +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.rounded.ArrowBack +import androidx.compose.material.icons.rounded.Cancel +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.graphics.SolidColor +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.dp +import com.anindra.messages.AppViewModel +import com.anindra.messages.R + +/** + * Google Messages' "Add group name" step, shown after Next in the group picker. + * The name is optional and local to this phone; Done opens the group whether or + * not it was filled in, and Back does the same rather than stranding a thread + * that was already created. + */ +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun GroupNameScreen( + vm: AppViewModel, + conversationId: Long, + onDone: (String) -> Unit, + onBack: () -> Unit +) { + BackHandler(onBack = onBack) + var name by remember { mutableStateOf("") } + var recipients by remember { mutableStateOf(emptyList()) } + val nameFocus = remember { FocusRequester() } + + LaunchedEffect(conversationId) { + recipients = vm.conversationRecipients(conversationId) + nameFocus.requestFocus() + } + + Scaffold( + containerColor = MaterialTheme.colorScheme.surfaceContainer, + topBar = { + TopAppBar( + title = { Text(stringResource(R.string.group_name_title)) }, + navigationIcon = { + IconButton(onClick = onBack) { + Icon( + Icons.AutoMirrored.Rounded.ArrowBack, + stringResource(R.string.icon_back) + ) + } + }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = MaterialTheme.colorScheme.surfaceContainer + ) + ) + } + ) { padding -> + Box(Modifier.padding(padding).fillMaxSize()) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + modifier = Modifier.fillMaxSize() + ) { + Spacer(Modifier.height(40.dp)) + Box( + modifier = Modifier + .fillMaxWidth() + .height(200.dp), + contentAlignment = Alignment.Center + ) { + val shown = recipients.take(3) + shown.forEachIndexed { index, address -> + val x = when (shown.size) { + 1 -> 0.dp + 2 -> if (index == 0) (-38).dp else 38.dp + else -> 62.dp * (index - 1) + } + val y = when (shown.size) { + 1 -> 0.dp + 2 -> if (index == 0) (-26).dp else 26.dp + else -> if (index == 1) (-26).dp else 26.dp + } + PersonAvatar( + address, + size = 96.dp, + modifier = Modifier.offset(x = x, y = y) + ) + } + } + + Surface( + color = MaterialTheme.colorScheme.surfaceContainerLowest, + shape = RoundedCornerShape(28.dp), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp) + ) { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .height(56.dp) + .padding(horizontal = 18.dp) + ) { + BasicTextField( + value = name, + onValueChange = { name = it }, + singleLine = true, + textStyle = MaterialTheme.typography.bodyLarge.copy( + color = MaterialTheme.colorScheme.onSurface + ), + cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), + decorationBox = { inner -> + if (name.isEmpty()) { + Text( + stringResource(R.string.group_name_field), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } else { + inner() + } + }, + modifier = Modifier + .weight(1f) + .focusRequester(nameFocus) + ) + if (name.isNotEmpty()) { + IconButton(onClick = { name = "" }, modifier = Modifier.size(32.dp)) { + Icon( + Icons.Rounded.Cancel, + contentDescription = stringResource(R.string.common_close), + tint = MaterialTheme.colorScheme.onSurfaceVariant + ) + } + } + } + } + + Spacer(Modifier.height(20.dp)) + Text( + text = stringResource(R.string.group_name_visibility), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + textAlign = TextAlign.Center, + modifier = Modifier.padding(horizontal = 32.dp) + ) + } + + Surface( + color = MaterialTheme.colorScheme.primary, + contentColor = MaterialTheme.colorScheme.onPrimary, + shape = RoundedCornerShape(20.dp), + shadowElevation = 6.dp, + modifier = Modifier + .align(Alignment.BottomEnd) + .imePadding() + .padding(16.dp) + .size(width = 104.dp, height = 56.dp) + ) { + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .fillMaxSize() + .padding(2.dp) + .then(Modifier) + ) { + androidx.compose.foundation.layout.Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .fillMaxSize() + .clickable { onDone(name.trim()) } + ) { + Text(stringResource(R.string.common_done)) + } + } + } + } + } +} diff --git a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt index ad519e0d2..2abf1561b 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt @@ -17,7 +17,7 @@ import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.ui.draw.clip import androidx.compose.foundation.text.BasicTextField @@ -57,6 +57,18 @@ import com.anindra.messages.ui.theme.startChatAction data class Contact(val name: String, val number: String, val workProfile: Boolean = false) +/** + * Google Messages matches a word start, not a substring: "T" finds "Prize Team" + * and "T1", but not "Dr. Patel Clinic". + */ +internal fun contactMatchesQuery(name: String, number: String, query: String): Boolean { + val q = query.trim() + if (q.isEmpty()) return true + if (name.split(' ').any { it.startsWith(q, ignoreCase = true) }) return true + val digits = q.filter { it.isDigit() } + return digits.isNotEmpty() && number.filter { it.isDigit() }.contains(digits) +} + /** * Google Messages' New conversation, not a contact browser: the "To" field is * the whole screen. Typing filters people; a typed number offers "Send to" as @@ -81,7 +93,7 @@ fun NewChatScreen( val typed = query.trim() val filtered = if (typed.isBlank()) emptyList() else contacts.filter { - it.name.contains(typed, ignoreCase = true) || it.number.contains(typed) || + contactMatchesQuery(it.name, it.number, typed) || (isPhoneNumber(typed) && AddressIdentity.matchesNumber(it.number, typed)) } val canSendTo = isPhoneNumber(typed) && filtered.none { it.number == typed } @@ -151,87 +163,92 @@ fun NewChatScreen( } } - Spacer(Modifier.height(8.dp)) - - Surface( - onClick = onNewGroup, - color = MaterialTheme.colorScheme.startChatAction, - contentColor = MaterialTheme.colorScheme.onStartChatAction, - shape = RoundedCornerShape(18.dp), - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 8.dp) - .height(36.dp) - ) { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.Center, - modifier = Modifier.fillMaxSize() + if (typed.isBlank()) { + Spacer(Modifier.height(8.dp)) + Surface( + onClick = onNewGroup, + color = MaterialTheme.colorScheme.startChatAction, + contentColor = MaterialTheme.colorScheme.onStartChatAction, + shape = RoundedCornerShape(18.dp), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp) + .height(36.dp) ) { - Icon(Icons.Rounded.GroupAdd, contentDescription = null, modifier = Modifier.size(20.dp)) - Spacer(Modifier.width(8.dp)) - Text( - stringResource(R.string.contact_create_group), - style = MaterialTheme.typography.labelLarge - ) - } - } - - if (typed.isBlank()) return@Column - - LazyColumn( - modifier = Modifier.fillMaxSize(), - contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp), - verticalArrangement = Arrangement.spacedBy(6.dp) - ) { - if (canSendTo) { - item(key = "send-to") { - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .fillMaxWidth() - .clip(RoundedCornerShape(16.dp)) - .background(MaterialTheme.colorScheme.surfaceContainerLowest) - .clickable { onPick(typed, null) } - .padding(horizontal = 16.dp, vertical = 12.dp) - ) { - PersonAvatar("#", size = 40.dp) - Spacer(Modifier.width(16.dp)) - Text( - text = context.getString(R.string.new_chat_send_to, typed), - style = MaterialTheme.typography.bodyLarge - ) - } - } - } - items(filtered, key = { it.number }) { contact -> Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .fillMaxWidth() - .animateItem() - .clip(RoundedCornerShape(16.dp)) - .background(MaterialTheme.colorScheme.surfaceContainerLowest) - .clickable { onPick(contact.number, contact.name) } - .padding(horizontal = 16.dp, vertical = 10.dp) + horizontalArrangement = Arrangement.Center, + modifier = Modifier.fillMaxSize() ) { - PersonAvatar(contact.number, size = 40.dp) - Spacer(Modifier.width(16.dp)) - Column(Modifier.weight(1f)) { - Row(verticalAlignment = Alignment.CenterVertically) { - Text(contact.name, style = MaterialTheme.typography.bodyLarge) - if (contact.workProfile) { - Spacer(Modifier.width(6.dp)) - WorkProfileBadge() + Icon(Icons.Rounded.GroupAdd, contentDescription = null, modifier = Modifier.size(20.dp)) + Spacer(Modifier.width(8.dp)) + Text( + stringResource(R.string.contact_create_group), + style = MaterialTheme.typography.labelLarge + ) + } + } + } else { + Spacer(Modifier.height(8.dp)) + Surface( + color = MaterialTheme.colorScheme.surfaceContainerLowest, + shape = RoundedCornerShape(16.dp), + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp) + ) { + LazyColumn { + if (canSendTo) { + item(key = "send-to") { + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .clickable { onPick(typed, null) } + .padding(horizontal = 16.dp, vertical = 12.dp) + ) { + PersonAvatar("#", size = 40.dp) + Spacer(Modifier.width(16.dp)) + Text( + text = context.getString(R.string.new_chat_send_to, typed), + style = MaterialTheme.typography.bodyLarge + ) + } + } + } + itemsIndexed(filtered, key = { _, contact -> contact.number }) { index, contact -> + Row( + verticalAlignment = Alignment.CenterVertically, + modifier = Modifier + .fillMaxWidth() + .animateItem() + .clickable { onPick(contact.number, contact.name) } + .padding(horizontal = 16.dp, vertical = 10.dp) + ) { + PersonAvatar(contact.number, size = 40.dp) + Spacer(Modifier.width(16.dp)) + Column(Modifier.weight(1f)) { + Row(verticalAlignment = Alignment.CenterVertically) { + Text(contact.name, style = MaterialTheme.typography.bodyLarge) + if (contact.workProfile) { + Spacer(Modifier.width(6.dp)) + WorkProfileBadge() + } + } + Text( + stringResource(R.string.contact_mobile, formatPhoneNumber(contact.number)), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) } } - Text( - formatPhoneNumber(contact.number), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) + if (index != filtered.lastIndex) { + androidx.compose.material3.HorizontalDivider( + color = MaterialTheme.colorScheme.outlineVariant + ) + } } } } diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index 06e161a23..fd9dad888 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -77,11 +77,7 @@ fun NewGroupScreen( fun nameOf(address: String): String = contacts.firstOrNull { it.number == address }?.name ?: formatPhoneNumber(address) - val filtered = contacts.filter { - query.isBlank() || - it.name.contains(query, ignoreCase = true) || - it.number.contains(query) - } + val filtered = contacts.filter { contactMatchesQuery(it.name, it.number, query) } Scaffold( containerColor = MaterialTheme.colorScheme.surfaceContainer, @@ -202,7 +198,7 @@ fun NewGroupScreen( ), cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), decorationBox = { inner -> - if (query.isEmpty() && chosen.size >= 2) { + if (query.isEmpty() && chosen.isNotEmpty()) { Text( stringResource(R.string.new_group_anyone_else), style = MaterialTheme.typography.bodyLarge, @@ -221,6 +217,8 @@ fun NewGroupScreen( } } + if (query.isBlank()) return@Column + LazyColumn( modifier = Modifier.weight(1f), contentPadding = androidx.compose.foundation.layout.PaddingValues( diff --git a/app/src/main/res/values-ar/strings_components.xml b/app/src/main/res/values-ar/strings_components.xml index e7d0d313e..5f7942099 100644 --- a/app/src/main/res/values-ar/strings_components.xml +++ b/app/src/main/res/values-ar/strings_components.xml @@ -7,6 +7,7 @@ حذف فتح إغلاق + تم التالي الآن diff --git a/app/src/main/res/values-ar/strings_conversations.xml b/app/src/main/res/values-ar/strings_conversations.xml index 3b9fbe45d..b9bf3e2ab 100644 --- a/app/src/main/res/values-ar/strings_conversations.xml +++ b/app/src/main/res/values-ar/strings_conversations.xml @@ -12,6 +12,9 @@ أي شخص آخر؟ محادثة جماعية جديدة محادثة جديدة + إضافة اسم المجموعة + اسم المجموعة (اختياري) + أنت فقط يمكنك رؤية اسم المجموعة هذا جوال %s إلى: اكتب اسمًا أو رقم هاتف أو بريدًا إلكترونيًا diff --git a/app/src/main/res/values-de/strings_components.xml b/app/src/main/res/values-de/strings_components.xml index d8daeffa6..fde662a1f 100644 --- a/app/src/main/res/values-de/strings_components.xml +++ b/app/src/main/res/values-de/strings_components.xml @@ -7,6 +7,7 @@ Löschen Öffnen Schließen + Fertig Weiter Jetzt diff --git a/app/src/main/res/values-de/strings_conversations.xml b/app/src/main/res/values-de/strings_conversations.xml index 54089f197..09b72ddb5 100644 --- a/app/src/main/res/values-de/strings_conversations.xml +++ b/app/src/main/res/values-de/strings_conversations.xml @@ -11,6 +11,9 @@ Noch jemand? Neue Gruppenunterhaltung Neue Unterhaltung + Gruppenname hinzufügen + Gruppenname (optional) + Nur du kannst diesen Gruppennamen sehen Mobil %s An: Name, Telefonnummer oder E-Mail eingeben diff --git a/app/src/main/res/values-es/strings_components.xml b/app/src/main/res/values-es/strings_components.xml index 74d5d45b4..284b765d8 100644 --- a/app/src/main/res/values-es/strings_components.xml +++ b/app/src/main/res/values-es/strings_components.xml @@ -7,6 +7,7 @@ Eliminar Abrir Cerrar + Listo Siguiente Ahora diff --git a/app/src/main/res/values-es/strings_conversations.xml b/app/src/main/res/values-es/strings_conversations.xml index 3cea3b0f4..303972aa2 100644 --- a/app/src/main/res/values-es/strings_conversations.xml +++ b/app/src/main/res/values-es/strings_conversations.xml @@ -12,6 +12,9 @@ ¿Alguien más? Nueva conversación grupal Conversación nueva + Añadir nombre del grupo + Nombre del grupo (opcional) + Solo tú puedes ver este nombre de grupo Móvil %s Para: Escribe un nombre, número de teléfono o correo diff --git a/app/src/main/res/values-fa/strings_components.xml b/app/src/main/res/values-fa/strings_components.xml index 0ba1a218d..b54d8a526 100644 --- a/app/src/main/res/values-fa/strings_components.xml +++ b/app/src/main/res/values-fa/strings_components.xml @@ -7,6 +7,7 @@ حذف باز کردن بستن + انجام شد بعدی اکنون diff --git a/app/src/main/res/values-fa/strings_conversations.xml b/app/src/main/res/values-fa/strings_conversations.xml index 92fc2338f..2b25959ab 100644 --- a/app/src/main/res/values-fa/strings_conversations.xml +++ b/app/src/main/res/values-fa/strings_conversations.xml @@ -12,6 +12,9 @@ شخص دیگری؟ گفتگوی گروهی جدید گفتگوی جدید + افزودن نام گروه + نام گروه (اختیاری) + فقط شما می‌توانید این نام گروه را ببینید همراه %s به: نام، شماره تلفن یا ایمیل را وارد کنید diff --git a/app/src/main/res/values-fr/strings_components.xml b/app/src/main/res/values-fr/strings_components.xml index e32a6f2c9..03b035fc5 100644 --- a/app/src/main/res/values-fr/strings_components.xml +++ b/app/src/main/res/values-fr/strings_components.xml @@ -7,6 +7,7 @@ Supprimer Ouvrir Fermer + Terminé Suivant Maintenant diff --git a/app/src/main/res/values-fr/strings_conversations.xml b/app/src/main/res/values-fr/strings_conversations.xml index ab6fb6b41..df37a4e1a 100644 --- a/app/src/main/res/values-fr/strings_conversations.xml +++ b/app/src/main/res/values-fr/strings_conversations.xml @@ -11,6 +11,9 @@ Quelqu’un d’autre ? Nouvelle conversation de groupe Nouvelle conversation + Ajouter un nom de groupe + Nom du groupe (facultatif) + Vous seul pouvez voir ce nom de groupe Mobile %s À : Saisissez un nom, un numéro de téléphone ou un e-mail diff --git a/app/src/main/res/values-hi/strings_components.xml b/app/src/main/res/values-hi/strings_components.xml index 4c0bd24e5..80e8bf915 100644 --- a/app/src/main/res/values-hi/strings_components.xml +++ b/app/src/main/res/values-hi/strings_components.xml @@ -7,6 +7,7 @@ हटाएं खोलें बंद करें + हो गया अगला अभी diff --git a/app/src/main/res/values-hi/strings_conversations.xml b/app/src/main/res/values-hi/strings_conversations.xml index 516d37b5e..a1a5bf986 100644 --- a/app/src/main/res/values-hi/strings_conversations.xml +++ b/app/src/main/res/values-hi/strings_conversations.xml @@ -12,6 +12,9 @@ कोई और? नई समूह बातचीत नया संवाद + समूह का नाम जोड़ें + समूह का नाम (वैकल्पिक) + यह समूह नाम केवल आप देख सकते हैं मोबाइल %s प्रति: नाम, फ़ोन नंबर या ईमेल डालें diff --git a/app/src/main/res/values-ja/strings_components.xml b/app/src/main/res/values-ja/strings_components.xml index 2feeeca8d..f4fbc3297 100644 --- a/app/src/main/res/values-ja/strings_components.xml +++ b/app/src/main/res/values-ja/strings_components.xml @@ -7,6 +7,7 @@ 削除 開く 閉じる + 完了 次へ 今 diff --git a/app/src/main/res/values-ja/strings_conversations.xml b/app/src/main/res/values-ja/strings_conversations.xml index 4457fa8db..0c2b7fef6 100644 --- a/app/src/main/res/values-ja/strings_conversations.xml +++ b/app/src/main/res/values-ja/strings_conversations.xml @@ -12,6 +12,9 @@ 他に追加しますか? 新しいグループ会話 新しい会話 + グループ名を追加 + グループ名(任意) + このグループ名はあなただけに表示されます モバイル %s 宛先: 名前、電話番号、メールアドレスを入力 diff --git a/app/src/main/res/values-ko/strings_components.xml b/app/src/main/res/values-ko/strings_components.xml index cca388572..e423a7d89 100644 --- a/app/src/main/res/values-ko/strings_components.xml +++ b/app/src/main/res/values-ko/strings_components.xml @@ -7,6 +7,7 @@ 삭제 열기 닫기 + 완료 다음 지금 diff --git a/app/src/main/res/values-ko/strings_conversations.xml b/app/src/main/res/values-ko/strings_conversations.xml index a2b44aab8..4ca91e52a 100644 --- a/app/src/main/res/values-ko/strings_conversations.xml +++ b/app/src/main/res/values-ko/strings_conversations.xml @@ -12,6 +12,9 @@ 다른 사람이 있나요? 새 그룹 대화 새 대화 + 그룹 이름 추가 + 그룹 이름(선택사항) + 이 그룹 이름은 나만 볼 수 있습니다 휴대전화 %s 받는 사람: 이름, 전화번호 또는 이메일 입력 diff --git a/app/src/main/res/values-pl/strings_components.xml b/app/src/main/res/values-pl/strings_components.xml index a2569b57d..0814fb8dd 100644 --- a/app/src/main/res/values-pl/strings_components.xml +++ b/app/src/main/res/values-pl/strings_components.xml @@ -7,6 +7,7 @@ Usuń Otwórz Zamknij + Gotowe Dalej Teraz diff --git a/app/src/main/res/values-pl/strings_conversations.xml b/app/src/main/res/values-pl/strings_conversations.xml index 76b0d7785..3e7386125 100644 --- a/app/src/main/res/values-pl/strings_conversations.xml +++ b/app/src/main/res/values-pl/strings_conversations.xml @@ -12,6 +12,9 @@ Ktoś jeszcze? Nowa rozmowa grupowa Nowa rozmowa + Dodaj nazwę grupy + Nazwa grupy (opcjonalnie) + Tylko Ty widzisz tę nazwę grupy Komórka %s Do: Wpisz nazwę, numer telefonu lub e-mail diff --git a/app/src/main/res/values-pt-rBR/strings_components.xml b/app/src/main/res/values-pt-rBR/strings_components.xml index caf4ad496..b28ee217a 100644 --- a/app/src/main/res/values-pt-rBR/strings_components.xml +++ b/app/src/main/res/values-pt-rBR/strings_components.xml @@ -7,6 +7,7 @@ Excluir Abrir Fechar + Concluir Próximo Agora diff --git a/app/src/main/res/values-pt-rBR/strings_conversations.xml b/app/src/main/res/values-pt-rBR/strings_conversations.xml index 378383d38..a6b4c5f93 100644 --- a/app/src/main/res/values-pt-rBR/strings_conversations.xml +++ b/app/src/main/res/values-pt-rBR/strings_conversations.xml @@ -12,6 +12,9 @@ Mais alguém? Nova conversa em grupo Nova conversa + Adicionar nome do grupo + Nome do grupo (opcional) + Só você pode ver este nome do grupo Celular %s Para: Digite um nome, número de telefone ou e-mail diff --git a/app/src/main/res/values-ru/strings_components.xml b/app/src/main/res/values-ru/strings_components.xml index 204c7d490..0e4f714a0 100644 --- a/app/src/main/res/values-ru/strings_components.xml +++ b/app/src/main/res/values-ru/strings_components.xml @@ -7,6 +7,7 @@ Удалить Открыть Закрыть + Готово Далее Сейчас diff --git a/app/src/main/res/values-ru/strings_conversations.xml b/app/src/main/res/values-ru/strings_conversations.xml index bb3584142..4c3744310 100644 --- a/app/src/main/res/values-ru/strings_conversations.xml +++ b/app/src/main/res/values-ru/strings_conversations.xml @@ -12,6 +12,9 @@ Кто-то ещё? Новый групповой чат Новая переписка + Добавить название группы + Название группы (необязательно) + Это название группы видите только вы Мобильный %s Кому: Введите имя, номер телефона или адрес эл. почты diff --git a/app/src/main/res/values-zh-rCN/strings_components.xml b/app/src/main/res/values-zh-rCN/strings_components.xml index 43deff246..70fc43be4 100644 --- a/app/src/main/res/values-zh-rCN/strings_components.xml +++ b/app/src/main/res/values-zh-rCN/strings_components.xml @@ -7,6 +7,7 @@ 删除 打开 关闭 + 完成 下一步 现在 diff --git a/app/src/main/res/values-zh-rCN/strings_conversations.xml b/app/src/main/res/values-zh-rCN/strings_conversations.xml index 43a7ea761..9dea747fe 100644 --- a/app/src/main/res/values-zh-rCN/strings_conversations.xml +++ b/app/src/main/res/values-zh-rCN/strings_conversations.xml @@ -11,6 +11,9 @@ 还要添加其他人吗? 新建群组对话 新对话 + 添加群组名称 + 群组名称(可选) + 只有你可以看到此群组名称 手机 %s 收件人: 输入姓名、电话号码或电子邮件地址 diff --git a/app/src/main/res/values-zh-rTW/strings_components.xml b/app/src/main/res/values-zh-rTW/strings_components.xml index d109c2753..8ec7d8483 100644 --- a/app/src/main/res/values-zh-rTW/strings_components.xml +++ b/app/src/main/res/values-zh-rTW/strings_components.xml @@ -7,6 +7,7 @@ 刪除 開啟 關閉 + 完成 下一步 現在 diff --git a/app/src/main/res/values-zh-rTW/strings_conversations.xml b/app/src/main/res/values-zh-rTW/strings_conversations.xml index 61cce2a86..9e166abdd 100644 --- a/app/src/main/res/values-zh-rTW/strings_conversations.xml +++ b/app/src/main/res/values-zh-rTW/strings_conversations.xml @@ -11,6 +11,9 @@ 還要新增其他人嗎? 新增群組對話 新對話 + 新增群組名稱 + 群組名稱(選填) + 只有你能看到這個群組名稱 手機 %s 收件者: 輸入名稱、電話號碼或電子郵件地址 diff --git a/app/src/main/res/values/strings_components.xml b/app/src/main/res/values/strings_components.xml index ed5e8eff7..6762d4e82 100644 --- a/app/src/main/res/values/strings_components.xml +++ b/app/src/main/res/values/strings_components.xml @@ -7,6 +7,7 @@ Delete Open Close + Done Next diff --git a/app/src/main/res/values/strings_conversations.xml b/app/src/main/res/values/strings_conversations.xml index 3e97e54b7..7318d778b 100644 --- a/app/src/main/res/values/strings_conversations.xml +++ b/app/src/main/res/values/strings_conversations.xml @@ -12,6 +12,9 @@ Anyone else? New group conversation New conversation + Add group name + Group name (optional) + Only you can see this group name Mobile %s To: Type name, phone number, or email diff --git a/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt b/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt new file mode 100644 index 000000000..3dcd97844 --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt @@ -0,0 +1,33 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * Google Messages matches a word start in the name, not any substring: typing + * "T" found "Prize Team" and "T1", but not "Dr. Patel Clinic". + */ +class ContactMatchQueryTest { + + @Test + fun aWordStartMatches() { + assertTrue(contactMatchesQuery("Prize Team", "+1555772010", "T")) + assertTrue(contactMatchesQuery("T1", "198", "t")) + assertTrue(contactMatchesQuery("Dr. Patel Clinic", "+1555773020", "Patel")) + } + + @Test + fun anInnerLetterDoesNotMatch() { + assertFalse(contactMatchesQuery("Dr. Patel Clinic", "+1555773020", "T")) + assertFalse(contactMatchesQuery("MY-BANK Alerts", "+1555772020", "T")) + assertFalse(contactMatchesQuery("Rewards Dept", "+1555772030", "T")) + } + + @Test + fun digitsStillFindTheNumber() { + assertTrue(contactMatchesQuery("Alex", "+1555771030", "771")) + assertFalse(contactMatchesQuery("Alex", "+1555771030", "999")) + assertTrue(contactMatchesQuery("Anyone", "+1555", "")) + } +} diff --git a/scripts b/scripts index 32faff1b8..fc2dfdde4 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 32faff1b86393ef83a962c8321a1d6800a19f0ca +Subproject commit fc2dfdde4f51c03435cf39a31ab702a623af08a7 From dca90663cba859e4e6566e7f8948101fb18d93c2 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 04:37:00 +0530 Subject: [PATCH 04/16] fix: match Google Messages' naming step and short-code subtitles - The Add group name screen now has Google Messages' geometry: 56dp member avatars in a 96dp block, a 52dp white field, the Clear text control, the "100 characters remaining" note (the name is capped at 100), and the Done pill at the live app's exact place above the keyboard. - Short codes paint as "Mobile 198" instead of the contacts provider's stored "1 98", matching Google Messages' subtitle. --- .../com/anindra/messages/ui/ChatScreen.kt | 4 + .../anindra/messages/ui/GroupNameScreen.kt | 86 +++++++++++++------ .../res/values-ar/strings_conversations.xml | 2 + .../res/values-de/strings_conversations.xml | 2 + .../res/values-es/strings_conversations.xml | 2 + .../res/values-fa/strings_conversations.xml | 2 + .../res/values-fr/strings_conversations.xml | 2 + .../res/values-hi/strings_conversations.xml | 2 + .../res/values-ja/strings_conversations.xml | 2 + .../res/values-ko/strings_conversations.xml | 2 + .../res/values-pl/strings_conversations.xml | 2 + .../values-pt-rBR/strings_conversations.xml | 2 + .../res/values-ru/strings_conversations.xml | 2 + .../values-zh-rCN/strings_conversations.xml | 2 + .../values-zh-rTW/strings_conversations.xml | 2 + .../main/res/values/strings_conversations.xml | 2 + .../messages/ui/ForwardNumberDisplayTest.kt | 8 ++ .../messages/ui/NewGroupFlowWiringTest.kt | 34 ++++++++ scripts | 2 +- 19 files changed, 136 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt index 45bfa4c70..46b86a978 100644 --- a/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt @@ -3124,6 +3124,10 @@ fun formatPhoneNumber( // A dial string is not a phone number: libphonenumber reads the digits // of "*21*2258#" as 212258 and would paint "021 2258". if (raw.any { it == '*' || it == '#' || it == ',' || it == ';' }) raw + // Short codes are not phone numbers either: 198 is one number, not + // "1 98", which is what the short-number metadata produced. Google + // Messages paints the digits alone, so join them. + else if (raw.count { it.isDigit() } < 7) raw.filter { it.isDigit() || it == '+' } else com.anindra.messages.data.PhoneNumberUtils.displayFor(raw, region) ) diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt index 319394199..e771254ff 100644 --- a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -10,11 +10,15 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.imePadding +import androidx.compose.foundation.layout.ime import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.asPaddingValues +import androidx.compose.foundation.layout.navigationBars +import androidx.compose.ui.unit.Dp import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField @@ -47,6 +51,21 @@ import androidx.compose.ui.unit.dp import com.anindra.messages.AppViewModel import com.anindra.messages.R +/** + * The keyboard's height without the navigation bar it swallows, so the Done + * pill sits 16dp above the keys like Google Messages' instead of a nav bar + * higher. + */ +@Composable +private fun keyboardClearance(): Dp { + val ime = WindowInsets.ime.asPaddingValues().calculateBottomPadding() + val nav = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() + return (ime - nav).coerceAtLeast(0.dp) +} + +/** Google Messages caps a group name at 100 characters. */ +private const val GROUP_NAME_MAX = 100 + /** * Google Messages' "Add group name" step, shown after Next in the group picker. * The name is optional and local to this phone; Done opens the group whether or @@ -95,33 +114,35 @@ fun GroupNameScreen( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.fillMaxSize() ) { - Spacer(Modifier.height(40.dp)) + Spacer(Modifier.height(72.dp)) Box( modifier = Modifier .fillMaxWidth() - .height(200.dp), + .height(96.dp), contentAlignment = Alignment.Center ) { val shown = recipients.take(3) shown.forEachIndexed { index, address -> val x = when (shown.size) { 1 -> 0.dp - 2 -> if (index == 0) (-38).dp else 38.dp - else -> 62.dp * (index - 1) + 2 -> if (index == 0) (-21).dp else 21.dp + else -> 30.dp * (index - 1) } val y = when (shown.size) { 1 -> 0.dp - 2 -> if (index == 0) (-26).dp else 26.dp - else -> if (index == 1) (-26).dp else 26.dp + 2 -> if (index == 0) (-16).dp else 16.dp + else -> if (index == 0) (-16).dp else 16.dp } PersonAvatar( address, - size = 96.dp, + size = 56.dp, modifier = Modifier.offset(x = x, y = y) ) } } + Spacer(Modifier.height(24.dp)) + Surface( color = MaterialTheme.colorScheme.surfaceContainerLowest, shape = RoundedCornerShape(28.dp), @@ -133,12 +154,12 @@ fun GroupNameScreen( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() - .height(56.dp) - .padding(horizontal = 18.dp) + .height(52.dp) + .padding(start = 18.dp, end = 12.dp) ) { BasicTextField( value = name, - onValueChange = { name = it }, + onValueChange = { name = it.take(GROUP_NAME_MAX) }, singleLine = true, textStyle = MaterialTheme.typography.bodyLarge.copy( color = MaterialTheme.colorScheme.onSurface @@ -159,22 +180,32 @@ fun GroupNameScreen( .weight(1f) .focusRequester(nameFocus) ) - if (name.isNotEmpty()) { - IconButton(onClick = { name = "" }, modifier = Modifier.size(32.dp)) { - Icon( - Icons.Rounded.Cancel, - contentDescription = stringResource(R.string.common_close), - tint = MaterialTheme.colorScheme.onSurfaceVariant - ) - } + IconButton(onClick = { name = "" }, modifier = Modifier.size(32.dp)) { + Icon( + Icons.Rounded.Cancel, + contentDescription = stringResource(R.string.group_name_clear), + tint = MaterialTheme.colorScheme.onSurfaceVariant + ) } } } - Spacer(Modifier.height(20.dp)) + Text( + text = stringResource( + R.string.group_name_remaining, + GROUP_NAME_MAX - name.length + ), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .fillMaxWidth() + .padding(start = 26.dp, top = 6.dp, end = 26.dp) + ) + + Spacer(Modifier.height(12.dp)) Text( text = stringResource(R.string.group_name_visibility), - style = MaterialTheme.typography.bodyMedium, + style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, textAlign = TextAlign.Center, modifier = Modifier.padding(horizontal = 32.dp) @@ -188,9 +219,11 @@ fun GroupNameScreen( shadowElevation = 6.dp, modifier = Modifier .align(Alignment.BottomEnd) - .imePadding() - .padding(16.dp) - .size(width = 104.dp, height = 56.dp) + .padding( + end = 16.dp, + bottom = keyboardClearance() + 16.dp + ) + .size(width = 72.dp, height = 56.dp) ) { Box( contentAlignment = Alignment.Center, @@ -205,7 +238,10 @@ fun GroupNameScreen( .fillMaxSize() .clickable { onDone(name.trim()) } ) { - Text(stringResource(R.string.common_done)) + Text( + stringResource(R.string.common_done), + style = MaterialTheme.typography.labelLarge + ) } } } diff --git a/app/src/main/res/values-ar/strings_conversations.xml b/app/src/main/res/values-ar/strings_conversations.xml index b9bf3e2ab..831505b78 100644 --- a/app/src/main/res/values-ar/strings_conversations.xml +++ b/app/src/main/res/values-ar/strings_conversations.xml @@ -15,6 +15,8 @@ إضافة اسم المجموعة اسم المجموعة (اختياري) أنت فقط يمكنك رؤية اسم المجموعة هذا + محو النص + عدد الأحرف المتبقية: %1$s جوال %s إلى: اكتب اسمًا أو رقم هاتف أو بريدًا إلكترونيًا diff --git a/app/src/main/res/values-de/strings_conversations.xml b/app/src/main/res/values-de/strings_conversations.xml index 09b72ddb5..6f1b49efb 100644 --- a/app/src/main/res/values-de/strings_conversations.xml +++ b/app/src/main/res/values-de/strings_conversations.xml @@ -14,6 +14,8 @@ Gruppenname hinzufügen Gruppenname (optional) Nur du kannst diesen Gruppennamen sehen + Text löschen + Noch %1$s Zeichen Mobil %s An: Name, Telefonnummer oder E-Mail eingeben diff --git a/app/src/main/res/values-es/strings_conversations.xml b/app/src/main/res/values-es/strings_conversations.xml index 303972aa2..4c577ff2d 100644 --- a/app/src/main/res/values-es/strings_conversations.xml +++ b/app/src/main/res/values-es/strings_conversations.xml @@ -15,6 +15,8 @@ Añadir nombre del grupo Nombre del grupo (opcional) Solo tú puedes ver este nombre de grupo + Borrar texto + Caracteres restantes: %1$s Móvil %s Para: Escribe un nombre, número de teléfono o correo diff --git a/app/src/main/res/values-fa/strings_conversations.xml b/app/src/main/res/values-fa/strings_conversations.xml index 2b25959ab..ed4ca5652 100644 --- a/app/src/main/res/values-fa/strings_conversations.xml +++ b/app/src/main/res/values-fa/strings_conversations.xml @@ -15,6 +15,8 @@ افزودن نام گروه نام گروه (اختیاری) فقط شما می‌توانید این نام گروه را ببینید + پاک کردن نوشتار + %1$s نویسه دیگر جا دارید همراه %s به: نام، شماره تلفن یا ایمیل را وارد کنید diff --git a/app/src/main/res/values-fr/strings_conversations.xml b/app/src/main/res/values-fr/strings_conversations.xml index df37a4e1a..a49b8fd4f 100644 --- a/app/src/main/res/values-fr/strings_conversations.xml +++ b/app/src/main/res/values-fr/strings_conversations.xml @@ -14,6 +14,8 @@ Ajouter un nom de groupe Nom du groupe (facultatif) Vous seul pouvez voir ce nom de groupe + Effacer le texte + %1$s caractères restants Mobile %s À : Saisissez un nom, un numéro de téléphone ou un e-mail diff --git a/app/src/main/res/values-hi/strings_conversations.xml b/app/src/main/res/values-hi/strings_conversations.xml index a1a5bf986..310990e35 100644 --- a/app/src/main/res/values-hi/strings_conversations.xml +++ b/app/src/main/res/values-hi/strings_conversations.xml @@ -15,6 +15,8 @@ समूह का नाम जोड़ें समूह का नाम (वैकल्पिक) यह समूह नाम केवल आप देख सकते हैं + टेक्स्ट मिटाएं + %1$s वर्ण बाकी हैं मोबाइल %s प्रति: नाम, फ़ोन नंबर या ईमेल डालें diff --git a/app/src/main/res/values-ja/strings_conversations.xml b/app/src/main/res/values-ja/strings_conversations.xml index 0c2b7fef6..b8ad58171 100644 --- a/app/src/main/res/values-ja/strings_conversations.xml +++ b/app/src/main/res/values-ja/strings_conversations.xml @@ -15,6 +15,8 @@ グループ名を追加 グループ名(任意) このグループ名はあなただけに表示されます + テキストを消去 + 残り %1$s 文字 モバイル %s 宛先: 名前、電話番号、メールアドレスを入力 diff --git a/app/src/main/res/values-ko/strings_conversations.xml b/app/src/main/res/values-ko/strings_conversations.xml index 4ca91e52a..1e2eebe40 100644 --- a/app/src/main/res/values-ko/strings_conversations.xml +++ b/app/src/main/res/values-ko/strings_conversations.xml @@ -15,6 +15,8 @@ 그룹 이름 추가 그룹 이름(선택사항) 이 그룹 이름은 나만 볼 수 있습니다 + 텍스트 삭제 + %1$s자 남음 휴대전화 %s 받는 사람: 이름, 전화번호 또는 이메일 입력 diff --git a/app/src/main/res/values-pl/strings_conversations.xml b/app/src/main/res/values-pl/strings_conversations.xml index 3e7386125..d6fd2192c 100644 --- a/app/src/main/res/values-pl/strings_conversations.xml +++ b/app/src/main/res/values-pl/strings_conversations.xml @@ -15,6 +15,8 @@ Dodaj nazwę grupy Nazwa grupy (opcjonalnie) Tylko Ty widzisz tę nazwę grupy + Wyczyść tekst + Pozostało znaków: %1$s Komórka %s Do: Wpisz nazwę, numer telefonu lub e-mail diff --git a/app/src/main/res/values-pt-rBR/strings_conversations.xml b/app/src/main/res/values-pt-rBR/strings_conversations.xml index a6b4c5f93..aa286c363 100644 --- a/app/src/main/res/values-pt-rBR/strings_conversations.xml +++ b/app/src/main/res/values-pt-rBR/strings_conversations.xml @@ -15,6 +15,8 @@ Adicionar nome do grupo Nome do grupo (opcional) Só você pode ver este nome do grupo + Limpar texto + %1$s caracteres restantes Celular %s Para: Digite um nome, número de telefone ou e-mail diff --git a/app/src/main/res/values-ru/strings_conversations.xml b/app/src/main/res/values-ru/strings_conversations.xml index 4c3744310..a1fc29bbd 100644 --- a/app/src/main/res/values-ru/strings_conversations.xml +++ b/app/src/main/res/values-ru/strings_conversations.xml @@ -15,6 +15,8 @@ Добавить название группы Название группы (необязательно) Это название группы видите только вы + Очистить текстовое поле + Осталось символов: %1$s Мобильный %s Кому: Введите имя, номер телефона или адрес эл. почты diff --git a/app/src/main/res/values-zh-rCN/strings_conversations.xml b/app/src/main/res/values-zh-rCN/strings_conversations.xml index 9dea747fe..c6e0da55a 100644 --- a/app/src/main/res/values-zh-rCN/strings_conversations.xml +++ b/app/src/main/res/values-zh-rCN/strings_conversations.xml @@ -14,6 +14,8 @@ 添加群组名称 群组名称(可选) 只有你可以看到此群组名称 + 清除文字 + 还可以输入 %1$s 个字符 手机 %s 收件人: 输入姓名、电话号码或电子邮件地址 diff --git a/app/src/main/res/values-zh-rTW/strings_conversations.xml b/app/src/main/res/values-zh-rTW/strings_conversations.xml index 9e166abdd..113608628 100644 --- a/app/src/main/res/values-zh-rTW/strings_conversations.xml +++ b/app/src/main/res/values-zh-rTW/strings_conversations.xml @@ -14,6 +14,8 @@ 新增群組名稱 群組名稱(選填) 只有你能看到這個群組名稱 + 清除文字 + 還可以輸入 %1$s 個字元 手機 %s 收件者: 輸入名稱、電話號碼或電子郵件地址 diff --git a/app/src/main/res/values/strings_conversations.xml b/app/src/main/res/values/strings_conversations.xml index 7318d778b..230a98c1e 100644 --- a/app/src/main/res/values/strings_conversations.xml +++ b/app/src/main/res/values/strings_conversations.xml @@ -15,6 +15,8 @@ Add group name Group name (optional) Only you can see this group name + Clear text + %1$s characters remaining Mobile %s To: Type name, phone number, or email diff --git a/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt b/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt index 71178a265..2b8203098 100644 --- a/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt @@ -31,6 +31,14 @@ class ForwardNumberDisplayTest { assertFalse(painted("091-210-4456").contains('-')) } + @Test + fun aShortCodeKeepsItsDigitsTogether() { + assertEquals("198", painted("198")) + assertEquals("199", painted("199")) + // The emulator's contacts store the code with the metadata's space. + assertEquals("198", painted("1 98")) + } + @Test fun aLandlineGetsTheCanonicalNationalSpacing() { assertEquals("021 6600 0000", painted("021-660-00000")) diff --git a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt index e890add0d..0201cc5e5 100644 --- a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt @@ -24,6 +24,7 @@ class NewGroupFlowWiringTest { private val newGroup: String by lazy { source("ui/NewGroupScreen.kt") } private val activity: String by lazy { source("MainActivity.kt") } private val repository: String by lazy { source("data/Repository.kt") } + private val groupName: String by lazy { source("ui/GroupNameScreen.kt") } @Test fun newConversationOffersTheGroupRow() { @@ -87,4 +88,37 @@ class NewGroupFlowWiringTest { Regex("""fun createGroup[\s\S]{0,1400}conversation_recipients""").containsMatchIn(repository) ) } + + @Test + fun nextOpensTheNamingStepBeforeTheChat() { + assertTrue( + "Next still opens the chat directly", + Regex("""onCreate = \{ addresses ->[\s\S]{0,400}navRoute = \"group-name\"""").containsMatchIn(activity) + ) + assertTrue( + "the naming route does not open the group", + activity.contains("\"group-name\" -> namingGroupId?.let { id ->") + ) + assertTrue( + "Done does not save the name", + Regex("""onDone = \{ name ->[\s\S]{0,120}setGroupTitle\(id, name\)""").containsMatchIn(activity) + ) + } + + @Test + fun theNamingStepMatchesGoogleMessages() { + assertTrue( + "the name is not capped at Google Messages' 100 characters", + Regex("""GROUP_NAME_MAX = 100""").containsMatchIn(groupName) + ) + assertTrue( + "the field has no clear control", + groupName.contains("R.string.group_name_clear") + ) + assertTrue( + "the field has no remaining-characters note", + Regex("""R\.string\.group_name_remaining,[\s\S]{0,80}GROUP_NAME_MAX - name\.length""") + .containsMatchIn(groupName) + ) + } } diff --git a/scripts b/scripts index fc2dfdde4..86be37f19 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit fc2dfdde4f51c03435cf39a31ab702a623af08a7 +Subproject commit 86be37f19076cd9c4bade4c3164c19762180c40f From f3a4bb588174b50b8e44b218d91c51a906dfdb41 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 04:45:06 +0530 Subject: [PATCH 05/16] fix: align the group naming step pixel for pixel with Google Messages Live measurement on the emulator (1080x2400, 420dpi) now matches: - 57dp member avatars at +/-19dp in a 96dp block (GM's container is 414..664 x 420..670; ours 416..664 x 422..670). - The field hint starts at 105px like GM's, the Clear text control sits at GM's exact [923,773][986,836], and the counter is invisible until the field has text, then reads "7/100" at GM's [105,888][930] line. - The visibility note lands on GM's 972 baseline, and the Done pill is at [901,1357][986,1410] against GM's [901,1354][985,1407]. --- .../anindra/messages/ui/GroupNameScreen.kt | 31 ++++++++++++------- .../res/values-ar/strings_conversations.xml | 1 + .../res/values-de/strings_conversations.xml | 1 + .../res/values-es/strings_conversations.xml | 1 + .../res/values-fa/strings_conversations.xml | 1 + .../res/values-fr/strings_conversations.xml | 1 + .../res/values-hi/strings_conversations.xml | 1 + .../res/values-ja/strings_conversations.xml | 1 + .../res/values-ko/strings_conversations.xml | 1 + .../res/values-pl/strings_conversations.xml | 1 + .../values-pt-rBR/strings_conversations.xml | 1 + .../res/values-ru/strings_conversations.xml | 1 + .../values-zh-rCN/strings_conversations.xml | 1 + .../values-zh-rTW/strings_conversations.xml | 1 + .../main/res/values/strings_conversations.xml | 1 + .../messages/ui/NewGroupFlowWiringTest.kt | 4 +-- scripts | 2 +- 17 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt index e771254ff..96801621f 100644 --- a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -44,6 +44,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign @@ -125,17 +126,16 @@ fun GroupNameScreen( shown.forEachIndexed { index, address -> val x = when (shown.size) { 1 -> 0.dp - 2 -> if (index == 0) (-21).dp else 21.dp + 2 -> if (index == 0) (-19).dp else 19.dp else -> 30.dp * (index - 1) } val y = when (shown.size) { 1 -> 0.dp - 2 -> if (index == 0) (-16).dp else 16.dp - else -> if (index == 0) (-16).dp else 16.dp + else -> if (index == 0) (-19).dp else 19.dp } PersonAvatar( address, - size = 56.dp, + size = 57.dp, modifier = Modifier.offset(x = x, y = y) ) } @@ -155,7 +155,7 @@ fun GroupNameScreen( modifier = Modifier .fillMaxWidth() .height(52.dp) - .padding(start = 18.dp, end = 12.dp) + .padding(start = 32.dp, end = 24.dp) ) { BasicTextField( value = name, @@ -190,19 +190,26 @@ fun GroupNameScreen( } } + // Google Messages keeps the note's line even while the field + // is empty; only its pixels are hidden. Text( - text = stringResource( - R.string.group_name_remaining, - GROUP_NAME_MAX - name.length - ), + text = if (name.isEmpty()) { + stringResource(R.string.group_name_remaining, GROUP_NAME_MAX) + } else { + stringResource(R.string.group_name_counter, name.length, GROUP_NAME_MAX) + }, style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, + color = if (name.isEmpty()) { + Color.Transparent + } else { + MaterialTheme.colorScheme.onSurfaceVariant + }, modifier = Modifier .fillMaxWidth() - .padding(start = 26.dp, top = 6.dp, end = 26.dp) + .padding(start = 40.dp, top = 6.dp, end = 16.dp) ) - Spacer(Modifier.height(12.dp)) + Spacer(Modifier.height(16.dp)) Text( text = stringResource(R.string.group_name_visibility), style = MaterialTheme.typography.bodySmall, diff --git a/app/src/main/res/values-ar/strings_conversations.xml b/app/src/main/res/values-ar/strings_conversations.xml index 831505b78..d42ef0f47 100644 --- a/app/src/main/res/values-ar/strings_conversations.xml +++ b/app/src/main/res/values-ar/strings_conversations.xml @@ -17,6 +17,7 @@ أنت فقط يمكنك رؤية اسم المجموعة هذا محو النص عدد الأحرف المتبقية: %1$s + %2$d/%1$d جوال %s إلى: اكتب اسمًا أو رقم هاتف أو بريدًا إلكترونيًا diff --git a/app/src/main/res/values-de/strings_conversations.xml b/app/src/main/res/values-de/strings_conversations.xml index 6f1b49efb..7b3749af8 100644 --- a/app/src/main/res/values-de/strings_conversations.xml +++ b/app/src/main/res/values-de/strings_conversations.xml @@ -16,6 +16,7 @@ Nur du kannst diesen Gruppennamen sehen Text löschen Noch %1$s Zeichen + %1$d/%2$d Mobil %s An: Name, Telefonnummer oder E-Mail eingeben diff --git a/app/src/main/res/values-es/strings_conversations.xml b/app/src/main/res/values-es/strings_conversations.xml index 4c577ff2d..52bc12215 100644 --- a/app/src/main/res/values-es/strings_conversations.xml +++ b/app/src/main/res/values-es/strings_conversations.xml @@ -17,6 +17,7 @@ Solo tú puedes ver este nombre de grupo Borrar texto Caracteres restantes: %1$s + %1$d/%2$d Móvil %s Para: Escribe un nombre, número de teléfono o correo diff --git a/app/src/main/res/values-fa/strings_conversations.xml b/app/src/main/res/values-fa/strings_conversations.xml index ed4ca5652..3d3c6dcb4 100644 --- a/app/src/main/res/values-fa/strings_conversations.xml +++ b/app/src/main/res/values-fa/strings_conversations.xml @@ -17,6 +17,7 @@ فقط شما می‌توانید این نام گروه را ببینید پاک کردن نوشتار %1$s نویسه دیگر جا دارید + %1$d/%2$d همراه %s به: نام، شماره تلفن یا ایمیل را وارد کنید diff --git a/app/src/main/res/values-fr/strings_conversations.xml b/app/src/main/res/values-fr/strings_conversations.xml index a49b8fd4f..be72f3126 100644 --- a/app/src/main/res/values-fr/strings_conversations.xml +++ b/app/src/main/res/values-fr/strings_conversations.xml @@ -16,6 +16,7 @@ Vous seul pouvez voir ce nom de groupe Effacer le texte %1$s caractères restants + %1$d/%2$d Mobile %s À : Saisissez un nom, un numéro de téléphone ou un e-mail diff --git a/app/src/main/res/values-hi/strings_conversations.xml b/app/src/main/res/values-hi/strings_conversations.xml index 310990e35..3f735cb79 100644 --- a/app/src/main/res/values-hi/strings_conversations.xml +++ b/app/src/main/res/values-hi/strings_conversations.xml @@ -17,6 +17,7 @@ यह समूह नाम केवल आप देख सकते हैं टेक्स्ट मिटाएं %1$s वर्ण बाकी हैं + %1$d/%2$d मोबाइल %s प्रति: नाम, फ़ोन नंबर या ईमेल डालें diff --git a/app/src/main/res/values-ja/strings_conversations.xml b/app/src/main/res/values-ja/strings_conversations.xml index b8ad58171..4aec91021 100644 --- a/app/src/main/res/values-ja/strings_conversations.xml +++ b/app/src/main/res/values-ja/strings_conversations.xml @@ -17,6 +17,7 @@ このグループ名はあなただけに表示されます テキストを消去 残り %1$s 文字 + %1$d/%2$d モバイル %s 宛先: 名前、電話番号、メールアドレスを入力 diff --git a/app/src/main/res/values-ko/strings_conversations.xml b/app/src/main/res/values-ko/strings_conversations.xml index 1e2eebe40..24a256799 100644 --- a/app/src/main/res/values-ko/strings_conversations.xml +++ b/app/src/main/res/values-ko/strings_conversations.xml @@ -17,6 +17,7 @@ 이 그룹 이름은 나만 볼 수 있습니다 텍스트 삭제 %1$s자 남음 + %1$d/%2$d 휴대전화 %s 받는 사람: 이름, 전화번호 또는 이메일 입력 diff --git a/app/src/main/res/values-pl/strings_conversations.xml b/app/src/main/res/values-pl/strings_conversations.xml index d6fd2192c..0419f1624 100644 --- a/app/src/main/res/values-pl/strings_conversations.xml +++ b/app/src/main/res/values-pl/strings_conversations.xml @@ -17,6 +17,7 @@ Tylko Ty widzisz tę nazwę grupy Wyczyść tekst Pozostało znaków: %1$s + %1$d/%2$d Komórka %s Do: Wpisz nazwę, numer telefonu lub e-mail diff --git a/app/src/main/res/values-pt-rBR/strings_conversations.xml b/app/src/main/res/values-pt-rBR/strings_conversations.xml index aa286c363..c62c08a5e 100644 --- a/app/src/main/res/values-pt-rBR/strings_conversations.xml +++ b/app/src/main/res/values-pt-rBR/strings_conversations.xml @@ -17,6 +17,7 @@ Só você pode ver este nome do grupo Limpar texto %1$s caracteres restantes + %1$d/%2$d Celular %s Para: Digite um nome, número de telefone ou e-mail diff --git a/app/src/main/res/values-ru/strings_conversations.xml b/app/src/main/res/values-ru/strings_conversations.xml index a1fc29bbd..4055d403c 100644 --- a/app/src/main/res/values-ru/strings_conversations.xml +++ b/app/src/main/res/values-ru/strings_conversations.xml @@ -17,6 +17,7 @@ Это название группы видите только вы Очистить текстовое поле Осталось символов: %1$s + %1$d/%2$d Мобильный %s Кому: Введите имя, номер телефона или адрес эл. почты diff --git a/app/src/main/res/values-zh-rCN/strings_conversations.xml b/app/src/main/res/values-zh-rCN/strings_conversations.xml index c6e0da55a..4bd28f039 100644 --- a/app/src/main/res/values-zh-rCN/strings_conversations.xml +++ b/app/src/main/res/values-zh-rCN/strings_conversations.xml @@ -16,6 +16,7 @@ 只有你可以看到此群组名称 清除文字 还可以输入 %1$s 个字符 + %1$d/%2$d 手机 %s 收件人: 输入姓名、电话号码或电子邮件地址 diff --git a/app/src/main/res/values-zh-rTW/strings_conversations.xml b/app/src/main/res/values-zh-rTW/strings_conversations.xml index 113608628..123c82411 100644 --- a/app/src/main/res/values-zh-rTW/strings_conversations.xml +++ b/app/src/main/res/values-zh-rTW/strings_conversations.xml @@ -16,6 +16,7 @@ 只有你能看到這個群組名稱 清除文字 還可以輸入 %1$s 個字元 + %1$d/%2$d 手機 %s 收件者: 輸入名稱、電話號碼或電子郵件地址 diff --git a/app/src/main/res/values/strings_conversations.xml b/app/src/main/res/values/strings_conversations.xml index 230a98c1e..094a5863a 100644 --- a/app/src/main/res/values/strings_conversations.xml +++ b/app/src/main/res/values/strings_conversations.xml @@ -17,6 +17,7 @@ Only you can see this group name Clear text %1$s characters remaining + %1$d/%2$d Mobile %s To: Type name, phone number, or email diff --git a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt index 0201cc5e5..364618973 100644 --- a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt @@ -116,8 +116,8 @@ class NewGroupFlowWiringTest { groupName.contains("R.string.group_name_clear") ) assertTrue( - "the field has no remaining-characters note", - Regex("""R\.string\.group_name_remaining,[\s\S]{0,80}GROUP_NAME_MAX - name\.length""") + "the field has no character counter", + Regex("""R\.string\.group_name_counter,[\s\S]{0,80}name\.length, GROUP_NAME_MAX""") .containsMatchIn(groupName) ) } diff --git a/scripts b/scripts index 86be37f19..1766f7ad7 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 86be37f19076cd9c4bade4c3164c19762180c40f +Subproject commit 1766f7ad7c4ea2a7354099372f8c4c221297c727 From ab27b6822b1b44b1e2c66a328e5c8f9d4707854c Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 04:57:11 +0530 Subject: [PATCH 06/16] fix: match Google Messages' New conversation rows and three-avatar naming Live measurements on the emulator (1080x2400, 420dpi) now agree: - The To field is 46dp, the Create group pill 40dp tall at a 12dp inset (32..1047 x 392..496, exactly the live band), and the results rows are 72dp with 2dp gaps of the page colour instead of a drawn divider. - A typed number offers "Send to 555-1239" with the typed digits as the subtitle, the same title and subtitle lines the live app paints at 418..481 / 481..534. - The matched word start is painted in the accent colour, as Google Messages highlights the T in "Prize Team". - The group naming screen shows two people at 56dp diagonally (414..664 x 420..670) and three at 48dp as one above a pair (414..665 x 436..671 against the live 414..664 x 437..670). --- .../anindra/messages/ui/GroupNameScreen.kt | 15 +++- .../com/anindra/messages/ui/NewChatScreen.kt | 86 ++++++++++++++----- .../res/values-ar/strings_conversations.xml | 2 +- .../res/values-de/strings_conversations.xml | 2 +- .../res/values-es/strings_conversations.xml | 2 +- .../res/values-fa/strings_conversations.xml | 2 +- .../res/values-fr/strings_conversations.xml | 2 +- .../res/values-hi/strings_conversations.xml | 2 +- .../res/values-ja/strings_conversations.xml | 2 +- .../res/values-ko/strings_conversations.xml | 2 +- .../res/values-pl/strings_conversations.xml | 2 +- .../values-pt-rBR/strings_conversations.xml | 2 +- .../res/values-ru/strings_conversations.xml | 2 +- .../values-zh-rCN/strings_conversations.xml | 2 +- .../values-zh-rTW/strings_conversations.xml | 2 +- .../main/res/values/strings_conversations.xml | 2 +- .../messages/ui/ContactMatchQueryTest.kt | 18 ++++ .../messages/ui/ForwardNumberDisplayTest.kt | 6 ++ scripts | 2 +- 19 files changed, 116 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt index 96801621f..0fe59df35 100644 --- a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -122,20 +122,27 @@ fun GroupNameScreen( .height(96.dp), contentAlignment = Alignment.Center ) { + // Google Messages: two people sit diagonally at 56dp; three + // shrink to 48dp and stack as one above a pair. val shown = recipients.take(3) shown.forEachIndexed { index, address -> val x = when (shown.size) { 1 -> 0.dp - 2 -> if (index == 0) (-19).dp else 19.dp - else -> 30.dp * (index - 1) + 2 -> if (index == 0) (-20).dp else 20.dp + else -> when (index) { + 0 -> 0.dp + 1 -> (-24).dp + else -> 24.dp + } } val y = when (shown.size) { 1 -> 0.dp - else -> if (index == 0) (-19).dp else 19.dp + 2 -> if (index == 0) (-20).dp else 20.dp + else -> if (index == 0) (-18).dp else 24.dp } PersonAvatar( address, - size = 57.dp, + size = if (shown.size >= 3) 48.dp else 57.dp, modifier = Modifier.offset(x = x, y = y) ) } diff --git a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt index 2abf1561b..e2f17d511 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt @@ -46,8 +46,12 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.anindra.messages.R @@ -59,8 +63,28 @@ data class Contact(val name: String, val number: String, val workProfile: Boolea /** * Google Messages matches a word start, not a substring: "T" finds "Prize Team" - * and "T1", but not "Dr. Patel Clinic". + * and "T1", but not "Dr. Patel Clinic". The matched letters are painted in the + * primary colour, so the row shows why it matched. */ +internal fun highlightedName( + name: String, + query: String, + color: Color +): AnnotatedString { + val q = query.trim() + val range = if (q.isEmpty()) null else run { + var start = 0 + name.split(' ').firstOrNull { it.startsWith(q, ignoreCase = true) }?.let { word -> + start = name.indexOf(word, start) + start until start + q.length + } + } + return if (range == null) AnnotatedString(name) else buildAnnotatedString { + append(name) + addStyle(SpanStyle(color = color), range.first, range.last + 1) + } +} + internal fun contactMatchesQuery(name: String, number: String, query: String): Boolean { val q = query.trim() if (q.isEmpty()) return true @@ -128,15 +152,15 @@ fun NewChatScreen( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() - .height(40.dp) - .padding(horizontal = 18.dp) + .height(46.dp) + .padding(start = 24.dp, end = 18.dp) ) { Text( stringResource(R.string.new_chat_to), style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant ) - Spacer(Modifier.width(10.dp)) + Spacer(Modifier.width(18.dp)) BasicTextField( value = query, onValueChange = { query = it }, @@ -164,16 +188,16 @@ fun NewChatScreen( } if (typed.isBlank()) { - Spacer(Modifier.height(8.dp)) + Spacer(Modifier.height(15.dp)) Surface( onClick = onNewGroup, color = MaterialTheme.colorScheme.startChatAction, contentColor = MaterialTheme.colorScheme.onStartChatAction, - shape = RoundedCornerShape(18.dp), + shape = RoundedCornerShape(20.dp), modifier = Modifier .fillMaxWidth() - .padding(horizontal = 8.dp) - .height(36.dp) + .padding(horizontal = 12.dp) + .height(40.dp) ) { Row( verticalAlignment = Alignment.CenterVertically, @@ -189,7 +213,7 @@ fun NewChatScreen( } } } else { - Spacer(Modifier.height(8.dp)) + Spacer(Modifier.height(10.dp)) Surface( color = MaterialTheme.colorScheme.surfaceContainerLowest, shape = RoundedCornerShape(16.dp), @@ -205,14 +229,26 @@ fun NewChatScreen( modifier = Modifier .fillMaxWidth() .clickable { onPick(typed, null) } - .padding(horizontal = 16.dp, vertical = 12.dp) + .padding(horizontal = 20.dp, vertical = 14.dp) ) { PersonAvatar("#", size = 40.dp) - Spacer(Modifier.width(16.dp)) - Text( - text = context.getString(R.string.new_chat_send_to, typed), - style = MaterialTheme.typography.bodyLarge - ) + Spacer(Modifier.width(15.dp)) + Column(Modifier.weight(1f)) { + Text( + text = context.getString( + R.string.new_chat_send_to, + formatPhoneNumber(typed) + ), + style = MaterialTheme.typography.bodyLarge + ) + Text( + text = typed, + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } } } } @@ -223,13 +259,20 @@ fun NewChatScreen( .fillMaxWidth() .animateItem() .clickable { onPick(contact.number, contact.name) } - .padding(horizontal = 16.dp, vertical = 10.dp) + .padding(horizontal = 20.dp, vertical = 14.dp) ) { PersonAvatar(contact.number, size = 40.dp) - Spacer(Modifier.width(16.dp)) + Spacer(Modifier.width(15.dp)) Column(Modifier.weight(1f)) { Row(verticalAlignment = Alignment.CenterVertically) { - Text(contact.name, style = MaterialTheme.typography.bodyLarge) + Text( + text = highlightedName( + contact.name, + typed, + MaterialTheme.colorScheme.primary + ), + style = MaterialTheme.typography.bodyLarge + ) if (contact.workProfile) { Spacer(Modifier.width(6.dp)) WorkProfileBadge() @@ -245,8 +288,11 @@ fun NewChatScreen( } } if (index != filtered.lastIndex) { - androidx.compose.material3.HorizontalDivider( - color = MaterialTheme.colorScheme.outlineVariant + Spacer( + Modifier + .fillMaxWidth() + .height(2.dp) + .background(MaterialTheme.colorScheme.surfaceContainer) ) } } diff --git a/app/src/main/res/values-ar/strings_conversations.xml b/app/src/main/res/values-ar/strings_conversations.xml index d42ef0f47..b2b789972 100644 --- a/app/src/main/res/values-ar/strings_conversations.xml +++ b/app/src/main/res/values-ar/strings_conversations.xml @@ -22,7 +22,7 @@ إلى: اكتب اسمًا أو رقم هاتف أو بريدًا إلكترونيًا يمكن إرسال الرسائل إلى أرقام الهواتف فقط - إرسال إلى \"%s\" + إرسال إلى %s رسالة نصية المؤرشفة الرسائل غير المرغوبة والمحظورة diff --git a/app/src/main/res/values-de/strings_conversations.xml b/app/src/main/res/values-de/strings_conversations.xml index 7b3749af8..d77e0603d 100644 --- a/app/src/main/res/values-de/strings_conversations.xml +++ b/app/src/main/res/values-de/strings_conversations.xml @@ -21,7 +21,7 @@ An: Name, Telefonnummer oder E-Mail eingeben Es können nur Telefonnummern angerufen werden - An „%s“ senden + An %s senden Textnachricht Archiviert Spam und blockiert diff --git a/app/src/main/res/values-es/strings_conversations.xml b/app/src/main/res/values-es/strings_conversations.xml index 52bc12215..0a4e9a7d8 100644 --- a/app/src/main/res/values-es/strings_conversations.xml +++ b/app/src/main/res/values-es/strings_conversations.xml @@ -22,7 +22,7 @@ Para: Escribe un nombre, número de teléfono o correo Solo se puede enviar mensajes a números de teléfono - Enviar a «%s» + Enviar a %s Mensaje de texto Archivadas Spam y bloqueadas diff --git a/app/src/main/res/values-fa/strings_conversations.xml b/app/src/main/res/values-fa/strings_conversations.xml index 3d3c6dcb4..1e8d6a6d4 100644 --- a/app/src/main/res/values-fa/strings_conversations.xml +++ b/app/src/main/res/values-fa/strings_conversations.xml @@ -22,7 +22,7 @@ به: نام، شماره تلفن یا ایمیل را وارد کنید فقط به شماره‌های تلفن می‌توان پیام فرستاد - ارسال به «%s» + ارسال به %s پیام بایگانی‌شده هرزنامه و مسدود diff --git a/app/src/main/res/values-fr/strings_conversations.xml b/app/src/main/res/values-fr/strings_conversations.xml index be72f3126..d21c005ad 100644 --- a/app/src/main/res/values-fr/strings_conversations.xml +++ b/app/src/main/res/values-fr/strings_conversations.xml @@ -21,7 +21,7 @@ À : Saisissez un nom, un numéro de téléphone ou un e-mail Seuls les numéros de téléphone peuvent être message - Envoyer à « %s » + Envoyer au %s Message texte Archivées Spams et conversations bloquées diff --git a/app/src/main/res/values-hi/strings_conversations.xml b/app/src/main/res/values-hi/strings_conversations.xml index 3f735cb79..bd90f38e1 100644 --- a/app/src/main/res/values-hi/strings_conversations.xml +++ b/app/src/main/res/values-hi/strings_conversations.xml @@ -22,7 +22,7 @@ प्रति: नाम, फ़ोन नंबर या ईमेल डालें केवल फ़ोन नंबरों को संदेश भेजे जा सकते हैं - “%s” को भेजें + %s पर भेजें पाठ संदेश संग्रहीत स्पैम और ब्लॉक diff --git a/app/src/main/res/values-ja/strings_conversations.xml b/app/src/main/res/values-ja/strings_conversations.xml index 4aec91021..c652abfc0 100644 --- a/app/src/main/res/values-ja/strings_conversations.xml +++ b/app/src/main/res/values-ja/strings_conversations.xml @@ -22,7 +22,7 @@ 宛先: 名前、電話番号、メールアドレスを入力 メッセージを送信できるのは電話番号のみです - 「%s」に送信 + %s に送信 テキストメッセージ アーカイブ 迷惑メールとブロック diff --git a/app/src/main/res/values-ko/strings_conversations.xml b/app/src/main/res/values-ko/strings_conversations.xml index 24a256799..98091eba2 100644 --- a/app/src/main/res/values-ko/strings_conversations.xml +++ b/app/src/main/res/values-ko/strings_conversations.xml @@ -22,7 +22,7 @@ 받는 사람: 이름, 전화번호 또는 이메일 입력 전화번호로만 메시지 전송이 가능합니다 - \"%s\"(으)로 보내기 + 받는사람: %s 문자 메시지 보관됨 스팸 및 차단됨 diff --git a/app/src/main/res/values-pl/strings_conversations.xml b/app/src/main/res/values-pl/strings_conversations.xml index 0419f1624..26a442b15 100644 --- a/app/src/main/res/values-pl/strings_conversations.xml +++ b/app/src/main/res/values-pl/strings_conversations.xml @@ -22,7 +22,7 @@ Do: Wpisz nazwę, numer telefonu lub e-mail Do numerów telefonów można wysyłać wiadomości - Wyślij do „%s” + Wyślij pod numer %s Wiadomość tekstowa Zarchiwizowane Spam i zablokowane diff --git a/app/src/main/res/values-pt-rBR/strings_conversations.xml b/app/src/main/res/values-pt-rBR/strings_conversations.xml index c62c08a5e..f2cba7925 100644 --- a/app/src/main/res/values-pt-rBR/strings_conversations.xml +++ b/app/src/main/res/values-pt-rBR/strings_conversations.xml @@ -22,7 +22,7 @@ Para: Digite um nome, número de telefone ou e-mail Somente números de telefone podem receber mensagens - Enviar para \"%s\" + Enviar para %s Mensagem de texto Arquivadas Spam e bloqueadas diff --git a/app/src/main/res/values-ru/strings_conversations.xml b/app/src/main/res/values-ru/strings_conversations.xml index 4055d403c..3b5c4c683 100644 --- a/app/src/main/res/values-ru/strings_conversations.xml +++ b/app/src/main/res/values-ru/strings_conversations.xml @@ -22,7 +22,7 @@ Кому: Введите имя, номер телефона или адрес эл. почты Сообщения можно отправлять только на номера телефонов - Отправить «%s» + Отправить на номер %s Текстовое сообщение Архив Спам и блокировка diff --git a/app/src/main/res/values-zh-rCN/strings_conversations.xml b/app/src/main/res/values-zh-rCN/strings_conversations.xml index 4bd28f039..023e42d53 100644 --- a/app/src/main/res/values-zh-rCN/strings_conversations.xml +++ b/app/src/main/res/values-zh-rCN/strings_conversations.xml @@ -21,7 +21,7 @@ 收件人: 输入姓名、电话号码或电子邮件地址 只能向电话号码发送消息 - 发送至「%s」 + 发送到 %s 输入消息 已归档 垃圾邮件和已阻止 diff --git a/app/src/main/res/values-zh-rTW/strings_conversations.xml b/app/src/main/res/values-zh-rTW/strings_conversations.xml index 123c82411..6d6b61844 100644 --- a/app/src/main/res/values-zh-rTW/strings_conversations.xml +++ b/app/src/main/res/values-zh-rTW/strings_conversations.xml @@ -21,7 +21,7 @@ 收件者: 輸入名稱、電話號碼或電子郵件地址 僅能傳送訊息給電話號碼 - 傳送至「%s」 + 傳送至 %s 輸入訊息 已封存 垃圾郵件與已封鎖 diff --git a/app/src/main/res/values/strings_conversations.xml b/app/src/main/res/values/strings_conversations.xml index 094a5863a..77ec18d98 100644 --- a/app/src/main/res/values/strings_conversations.xml +++ b/app/src/main/res/values/strings_conversations.xml @@ -22,7 +22,7 @@ To: Type name, phone number, or email Only phone numbers can be messaged - Send to “%s” + Send to %s Message Archived Spam & Blocked diff --git a/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt b/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt index 3dcd97844..7b58c6281 100644 --- a/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt @@ -1,5 +1,7 @@ package com.anindra.messages.ui +import androidx.compose.ui.graphics.Color +import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test @@ -30,4 +32,20 @@ class ContactMatchQueryTest { assertFalse(contactMatchesQuery("Alex", "+1555771030", "999")) assertTrue(contactMatchesQuery("Anyone", "+1555", "")) } + + @Test + fun theMatchedWordStartIsTheOnlyHighlightedRun() { + val team = highlightedName("Prize Team", "T", Color.Red) + assertEquals("Prize Team", team.text) + assertEquals(1, team.spanStyles.size) + assertEquals(6, team.spanStyles.first().start) + assertEquals(7, team.spanStyles.first().end) + + val t1 = highlightedName("T1", "T", Color.Red) + assertEquals(0, t1.spanStyles.first().start) + assertEquals(1, t1.spanStyles.first().end) + + val none = highlightedName("Alex", "T", Color.Red) + assertTrue(none.spanStyles.isEmpty()) + } } diff --git a/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt b/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt index 2b8203098..c92800237 100644 --- a/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/ForwardNumberDisplayTest.kt @@ -31,6 +31,12 @@ class ForwardNumberDisplayTest { assertFalse(painted("091-210-4456").contains('-')) } + @Test + fun aSevenDigitNumberKeepsGoogleMessagesSpacing() { + // Google Messages paints the Send to title as "555-1239" from "5551239". + assertEquals("555-1239", formatPhoneNumber("5551239", "US").filter { it != BidiText.LRI && it != BidiText.PDI }) + } + @Test fun aShortCodeKeepsItsDigitsTogether() { assertEquals("198", painted("198")) diff --git a/scripts b/scripts index 1766f7ad7..52c696d90 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 1766f7ad7c4ea2a7354099372f8c4c221297c727 +Subproject commit 52c696d90447663051654edc9b659b830982e8ba From a204f1e0343910e2e2a0352e548c468882208c4e Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 05:12:26 +0530 Subject: [PATCH 07/16] fix: give the group picker GM's rows and both pickers its initials Measured against Google Messages on the emulator (1080x2400, 420dpi): - Group picker rows: 2dp gaps (5px) instead of 6dp, 72dp tall with 12dp screen insets, a 14dp white card and a fully rounded #CBDBF2 band for a picked row (GM 575..763 inside the 381..569 card rhythm), and a 20dp check circle at GM's 917..969. - The To field matches GM's 46dp band at x 32..1047, and the picker keeps focus after a pick so the next name can be typed, as the live app does. - Contact avatars on New conversation, the group picker (rows and chips) and the Add group name screen now paint the contact's initial instead of the silhouette; a raw number still gets the silhouette, matching GM's list. - PersonAvatar gained an optional `initials`; the shared inbox/chat avatar is untouched unless a caller passes it. --- .../com/anindra/messages/ui/Components.kt | 16 +++++ .../anindra/messages/ui/GroupNameScreen.kt | 11 ++++ .../com/anindra/messages/ui/NewChatScreen.kt | 20 +++--- .../com/anindra/messages/ui/NewGroupScreen.kt | 66 ++++++++++++------- .../com/anindra/messages/ui/theme/Theme.kt | 8 +++ .../messages/ui/ContactMatchQueryTest.kt | 10 +++ .../messages/ui/NewGroupFlowWiringTest.kt | 21 ++++++ .../ui/theme/GroupPickRowColorTest.kt | 30 +++++++++ scripts | 2 +- 9 files changed, 152 insertions(+), 32 deletions(-) create mode 100644 app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt diff --git a/app/src/main/java/com/anindra/messages/ui/Components.kt b/app/src/main/java/com/anindra/messages/ui/Components.kt index 9f5ba516f..af6afc898 100644 --- a/app/src/main/java/com/anindra/messages/ui/Components.kt +++ b/app/src/main/java/com/anindra/messages/ui/Components.kt @@ -29,6 +29,7 @@ import com.anindra.messages.data.CalendarSystem import com.anindra.messages.data.SettingsStore import com.anindra.messages.ui.theme.LocalReduceMotion import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.compositionLocalOf import androidx.compose.runtime.getValue @@ -41,6 +42,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.luminance import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.style.TextDirection import androidx.compose.ui.unit.Dp @@ -99,6 +101,10 @@ fun avatarColor(key: String): Color { return avatarColors[Math.abs(h) % avatarColors.size] } +/** First letter of a display name, the way Google Messages paints an avatar. */ +fun avatarInitials(name: String?): String? = + name?.firstOrNull { it.isLetter() }?.uppercase() + /** Google-Messages style contact avatar: contact photo if available, else silhouette. */ @Composable fun PersonAvatar( @@ -107,6 +113,8 @@ fun PersonAvatar( modifier: Modifier = Modifier, backgroundColor: Color? = null, tint: Color? = null, + /** A contact's initial; Google Messages shows it instead of the silhouette. */ + initials: String? = null, /** * A picture to draw instead of the contact photo — a group's own image. * Coil takes the path; the contact lookup is skipped when it is set. @@ -150,6 +158,14 @@ fun PersonAvatar( contentScale = ContentScale.Crop, modifier = Modifier.size(size).clip(CircleShape) ) + } else if (initials != null) { + Text( + text = initials, + color = glyphTint, + style = MaterialTheme.typography.titleLarge.copy( + fontSize = with(LocalDensity.current) { (size.value * 0.45f).sp } + ) + ) } else { Icon( painter = painterResource(R.drawable.ic_person_placeholder), diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt index 0fe59df35..d6e368e67 100644 --- a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -45,12 +45,15 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.anindra.messages.AppViewModel import com.anindra.messages.R +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext /** * The keyboard's height without the navigation bar it swallows, so the Done @@ -84,10 +87,17 @@ fun GroupNameScreen( BackHandler(onBack = onBack) var name by remember { mutableStateOf("") } var recipients by remember { mutableStateOf(emptyList()) } + var names by remember { mutableStateOf(emptyMap()) } val nameFocus = remember { FocusRequester() } + val context = LocalContext.current LaunchedEffect(conversationId) { recipients = vm.conversationRecipients(conversationId) + names = withContext(Dispatchers.IO) { + recipients.associateWith { + com.anindra.messages.data.ContactLookup.find(context, it)?.displayName.orEmpty() + } + } nameFocus.requestFocus() } @@ -143,6 +153,7 @@ fun GroupNameScreen( PersonAvatar( address, size = if (shown.size >= 3) 48.dp else 57.dp, + initials = avatarInitials(names[address]), modifier = Modifier.offset(x = x, y = y) ) } diff --git a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt index e2f17d511..3e2c24923 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt @@ -146,14 +146,14 @@ fun NewChatScreen( shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() - .padding(horizontal = 8.dp) + .padding(horizontal = 12.dp) ) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() .height(46.dp) - .padding(start = 24.dp, end = 18.dp) + .padding(start = 20.dp, end = 18.dp) ) { Text( stringResource(R.string.new_chat_to), @@ -219,7 +219,7 @@ fun NewChatScreen( shape = RoundedCornerShape(16.dp), modifier = Modifier .fillMaxWidth() - .padding(horizontal = 8.dp) + .padding(horizontal = 12.dp) ) { LazyColumn { if (canSendTo) { @@ -229,10 +229,10 @@ fun NewChatScreen( modifier = Modifier .fillMaxWidth() .clickable { onPick(typed, null) } - .padding(horizontal = 20.dp, vertical = 14.dp) + .padding(start = 16.dp, end = 20.dp, top = 14.dp, bottom = 14.dp) ) { PersonAvatar("#", size = 40.dp) - Spacer(Modifier.width(15.dp)) + Spacer(Modifier.width(16.dp)) Column(Modifier.weight(1f)) { Text( text = context.getString( @@ -259,10 +259,14 @@ fun NewChatScreen( .fillMaxWidth() .animateItem() .clickable { onPick(contact.number, contact.name) } - .padding(horizontal = 20.dp, vertical = 14.dp) + .padding(start = 16.dp, end = 20.dp, top = 14.dp, bottom = 14.dp) ) { - PersonAvatar(contact.number, size = 40.dp) - Spacer(Modifier.width(15.dp)) + PersonAvatar( + contact.number, + size = 40.dp, + initials = avatarInitials(contact.name) + ) + Spacer(Modifier.width(16.dp)) Column(Modifier.weight(1f)) { Row(verticalAlignment = Alignment.CenterVertically) { Text( diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index fd9dad888..9b27c5f05 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -41,6 +41,7 @@ import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -48,6 +49,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.draw.clip +import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource @@ -55,6 +57,7 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.anindra.messages.AppViewModel import com.anindra.messages.R +import com.anindra.messages.ui.theme.groupPickSelected /** * Google Messages' New group step. The title turns into "New group MMS" once a @@ -73,6 +76,13 @@ fun NewGroupScreen( val contacts by vm.contacts.collectAsState() var query by remember { mutableStateOf("") } var chosen by remember { mutableStateOf(listOf()) } + val fieldFocus = remember { androidx.compose.ui.focus.FocusRequester() } + + // Google Messages keeps the cursor in the To field after a pick, so the + // next name can be typed without tapping the field again. + LaunchedEffect(chosen) { + runCatching { fieldFocus.requestFocus() } + } fun nameOf(address: String): String = contacts.firstOrNull { it.number == address }?.name ?: formatPhoneNumber(address) @@ -112,22 +122,23 @@ fun NewGroupScreen( shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() - .padding(horizontal = 8.dp, vertical = 8.dp) + .padding(horizontal = 12.dp) + .heightIn(min = 46.dp) ) { if (chosen.isEmpty()) { Row( verticalAlignment = Alignment.CenterVertically, modifier = Modifier .fillMaxWidth() - .height(40.dp) - .padding(horizontal = 18.dp) + .height(46.dp) + .padding(start = 20.dp, end = 18.dp) ) { Text( stringResource(R.string.new_chat_to), style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant ) - Spacer(Modifier.width(10.dp)) + Spacer(Modifier.width(18.dp)) BasicTextField( value = query, onValueChange = { query = it }, @@ -149,7 +160,9 @@ fun NewGroupScreen( inner() } }, - modifier = Modifier.weight(1f) + modifier = Modifier + .weight(1f) + .focusRequester(fieldFocus) ) } } else { @@ -158,26 +171,29 @@ fun NewGroupScreen( verticalArrangement = Arrangement.spacedBy(4.dp), modifier = Modifier .fillMaxWidth() - .padding(horizontal = 14.dp, vertical = 8.dp) + .padding(start = 20.dp, end = 10.dp, top = 12.dp, bottom = 12.dp) ) { Text( stringResource(R.string.new_chat_to), style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier.padding(vertical = 8.dp) + color = MaterialTheme.colorScheme.onSurfaceVariant ) chosen.forEach { address -> Surface( - color = MaterialTheme.colorScheme.surfaceContainerHigh, + color = MaterialTheme.colorScheme.surfaceContainer, shape = CircleShape, modifier = Modifier.clickable { chosen = chosen - address } ) { Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.padding(start = 4.dp, end = 12.dp, top = 4.dp, bottom = 4.dp) + modifier = Modifier.padding(start = 2.dp, end = 10.dp, top = 2.dp, bottom = 2.dp) ) { - PersonAvatar(address, size = 24.dp) - Spacer(Modifier.width(6.dp)) + PersonAvatar( + address, + size = 20.dp, + initials = avatarInitials(nameOf(address)) + ) + Spacer(Modifier.width(4.dp)) Text( nameOf(address), style = MaterialTheme.typography.labelLarge, @@ -211,7 +227,7 @@ fun NewGroupScreen( }, modifier = Modifier .width(140.dp) - .padding(vertical = 8.dp) + .focusRequester(fieldFocus) ) } } @@ -222,9 +238,9 @@ fun NewGroupScreen( LazyColumn( modifier = Modifier.weight(1f), contentPadding = androidx.compose.foundation.layout.PaddingValues( - horizontal = 8.dp, vertical = 4.dp + start = 12.dp, end = 12.dp, top = 10.dp, bottom = 4.dp ), - verticalArrangement = Arrangement.spacedBy(6.dp) + verticalArrangement = Arrangement.spacedBy(2.dp) ) { itemsIndexed(filtered, key = { _, contact -> contact.number }) { _, contact -> val picked = contact.number in chosen @@ -233,10 +249,10 @@ fun NewGroupScreen( modifier = Modifier .fillMaxWidth() .animateItem() - .clip(RoundedCornerShape(24.dp)) .background( - if (picked) MaterialTheme.colorScheme.secondaryContainer - else MaterialTheme.colorScheme.surfaceContainerLowest + color = if (picked) MaterialTheme.colorScheme.groupPickSelected + else MaterialTheme.colorScheme.surfaceContainerLowest, + shape = if (picked) CircleShape else RoundedCornerShape(14.dp) ) .clickable { if (picked) { @@ -248,9 +264,13 @@ fun NewGroupScreen( query = "" } } - .padding(horizontal = 16.dp, vertical = 10.dp) + .padding(start = 16.dp, end = 20.dp, top = 14.dp, bottom = 14.dp) ) { - PersonAvatar(contact.number, size = 40.dp) + PersonAvatar( + contact.number, + size = 40.dp, + initials = avatarInitials(contact.name) + ) Spacer(Modifier.width(16.dp)) Column(Modifier.weight(1f)) { Text( @@ -271,15 +291,15 @@ fun NewGroupScreen( Spacer(Modifier.width(4.dp)) WorkProfileBadge() } - Spacer(Modifier.width(12.dp)) - Box(Modifier.size(24.dp), contentAlignment = Alignment.Center) { + Spacer(Modifier.width(10.dp)) + Box(Modifier.size(20.dp), contentAlignment = Alignment.Center) { Icon( if (picked) Icons.Rounded.CheckCircle else Icons.Rounded.RadioButtonUnchecked, contentDescription = if (picked) stringResource(R.string.contact_selected) else null, tint = if (picked) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.outline, - modifier = Modifier.size(24.dp) + modifier = Modifier.size(20.dp) ) } } diff --git a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt index e37ff927c..012f20637 100644 --- a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt +++ b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt @@ -288,6 +288,14 @@ val ColorScheme.startChatContent: Color val ColorScheme.selectedBubble: Color get() = primary val ColorScheme.onSelectedBubble: Color get() = onPrimary +/** + * The band behind a picked contact in the group picker: Google Messages paints + * #CBDBF2 in the light theme, a touch deeper than this palette's + * secondaryContainer. + */ +val ColorScheme.groupPickSelected: Color + get() = if (surface.luminance() > 0.5f) Color(0xFFCBDBF2) else secondaryContainer + /** Google Messages' "Create group" pill: pale cyan in light, deep blue in dark. */ val ColorScheme.startChatAction: Color get() = if (surface.luminance() > 0.5f) Color(0xFFC2E7FF) else Color(0xFF004A77) diff --git a/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt b/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt index 7b58c6281..fc6ffb9ee 100644 --- a/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/ContactMatchQueryTest.kt @@ -48,4 +48,14 @@ class ContactMatchQueryTest { val none = highlightedName("Alex", "T", Color.Red) assertTrue(none.spanStyles.isEmpty()) } + + @Test + fun anAvatarTakesTheFirstLetterLikeGoogleMessages() { + assertEquals("P", avatarInitials("Prize Team")) + assertEquals("T", avatarInitials("T1")) + assertEquals("A", avatarInitials("Alex")) + assertEquals("D", avatarInitials("Dr. Patel Clinic")) + assertEquals(null, avatarInitials(null)) + assertEquals(null, avatarInitials("+1555771030")) + } } diff --git a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt index 364618973..c13448881 100644 --- a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt @@ -121,4 +121,25 @@ class NewGroupFlowWiringTest { .containsMatchIn(groupName) ) } + + @Test + fun thePickerMatchesTheLiveRowGeometry() { + assertTrue( + "the picker rows are not 2dp apart", + Regex("""verticalArrangement = Arrangement\.spacedBy\(2\.dp\)""").containsMatchIn(newGroup) + ) + assertTrue( + "the selected row is not a stadium", + Regex("""if \(picked\) MaterialTheme\.colorScheme\.groupPickSelected[\s\S]{0,220}if \(picked\) CircleShape""") + .containsMatchIn(newGroup) + ) + assertTrue( + "the picker rows do not show initials", + Regex("""PersonAvatar\([\s\S]{0,160}initials = avatarInitials""").containsMatchIn(newGroup) + ) + assertTrue( + "the field loses focus after a pick", + Regex("""LaunchedEffect\(chosen\)[\s\S]{0,120}fieldFocus\.requestFocus""").containsMatchIn(newGroup) + ) + } } diff --git a/app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt b/app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt new file mode 100644 index 000000000..58d4d6b15 --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt @@ -0,0 +1,30 @@ +package com.anindra.messages.ui.theme + +import androidx.compose.ui.graphics.Color +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * The band behind a picked contact in the group picker, measured off Google + * Messages: #CBDBF2 in the light theme. Dark keeps the palette's + * secondaryContainer until it is measured. + */ +class GroupPickRowColorTest { + + private fun hex(c: Color) = "#%02X%02X%02X".format( + (c.red * 255f + 0.5f).toInt(), + (c.green * 255f + 0.5f).toInt(), + (c.blue * 255f + 0.5f).toInt() + ) + + @Test + fun theLightBandMatchesGoogleMessages() { + assertEquals("#CBDBF2", hex(LightColors.groupPickSelected)) + } + + @Test + fun darkFallsBackToThePalette() { + assertEquals(DarkColors.secondaryContainer, DarkColors.groupPickSelected) + assertEquals(AmoledColors.secondaryContainer, AmoledColors.groupPickSelected) + } +} diff --git a/scripts b/scripts index 52c696d90..288053778 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 52c696d90447663051654edc9b659b830982e8ba +Subproject commit 288053778887e06a8fc9cd5f365a6d864596b6a9 From 45d5712c73b3574f6d7a2b0b51a03d6b8827299b Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 05:31:21 +0530 Subject: [PATCH 08/16] fix: match Google Messages in dark theme and its chip gestures Measured on the emulator with the system in night mode: - Start-chat surfaces follow the live app in both schemes: the To field is white in light and the page colour (#1E1F20) in dark, result rows and picker cards are white / #131314, the Add group name field is white / #333537, and the picked band is #CBDBF2 / #343A43. - The picker's Next pill now sits where GM's does above the keyboard (text top 1355 against GM's 1354); it and the naming screen share one keyboardClearance() helper. - Chips are labels, not buttons: Delete in the empty To field removes the last one, which is what Google Messages does (tapping a chip is a no-op there). --- .../com/anindra/messages/ui/Components.kt | 16 +++++++ .../anindra/messages/ui/GroupNameScreen.kt | 15 +------ .../com/anindra/messages/ui/NewChatScreen.kt | 6 ++- .../com/anindra/messages/ui/NewGroupScreen.kt | 30 ++++++++++--- .../com/anindra/messages/ui/theme/Theme.kt | 21 ++++++++-- .../ui/theme/GroupPickRowColorTest.kt | 8 ++-- .../ui/theme/StartChatSurfaceColorTest.kt | 42 +++++++++++++++++++ scripts | 2 +- 8 files changed, 111 insertions(+), 29 deletions(-) create mode 100644 app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt diff --git a/app/src/main/java/com/anindra/messages/ui/Components.kt b/app/src/main/java/com/anindra/messages/ui/Components.kt index af6afc898..d547c68cb 100644 --- a/app/src/main/java/com/anindra/messages/ui/Components.kt +++ b/app/src/main/java/com/anindra/messages/ui/Components.kt @@ -13,6 +13,10 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.asPaddingValues +import androidx.compose.foundation.layout.ime +import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape @@ -101,6 +105,18 @@ fun avatarColor(key: String): Color { return avatarColors[Math.abs(h) % avatarColors.size] } +/** + * The keyboard's height without the navigation bar it swallows, so a floating + * pill sits 16dp above the keys like Google Messages' instead of a nav bar + * higher. + */ +@Composable +fun keyboardClearance(): Dp { + val ime = WindowInsets.ime.asPaddingValues().calculateBottomPadding() + val nav = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() + return (ime - nav).coerceAtLeast(0.dp) +} + /** First letter of a display name, the way Google Messages paints an avatar. */ fun avatarInitials(name: String?): String? = name?.firstOrNull { it.isLetter() }?.uppercase() diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt index d6e368e67..fe752dde5 100644 --- a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -52,21 +52,10 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import com.anindra.messages.AppViewModel import com.anindra.messages.R +import com.anindra.messages.ui.theme.groupNameField import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -/** - * The keyboard's height without the navigation bar it swallows, so the Done - * pill sits 16dp above the keys like Google Messages' instead of a nav bar - * higher. - */ -@Composable -private fun keyboardClearance(): Dp { - val ime = WindowInsets.ime.asPaddingValues().calculateBottomPadding() - val nav = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() - return (ime - nav).coerceAtLeast(0.dp) -} - /** Google Messages caps a group name at 100 characters. */ private const val GROUP_NAME_MAX = 100 @@ -162,7 +151,7 @@ fun GroupNameScreen( Spacer(Modifier.height(24.dp)) Surface( - color = MaterialTheme.colorScheme.surfaceContainerLowest, + color = MaterialTheme.colorScheme.groupNameField, shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt index 3e2c24923..a7d7a310d 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt @@ -58,6 +58,8 @@ import com.anindra.messages.R import com.anindra.messages.data.AddressIdentity import com.anindra.messages.ui.theme.onStartChatAction import com.anindra.messages.ui.theme.startChatAction +import com.anindra.messages.ui.theme.startChatField +import com.anindra.messages.ui.theme.startChatListRow data class Contact(val name: String, val number: String, val workProfile: Boolean = false) @@ -142,7 +144,7 @@ fun NewChatScreen( Spacer(Modifier.height(0.dp)) Surface( - color = MaterialTheme.colorScheme.surfaceContainerLowest, + color = MaterialTheme.colorScheme.startChatField, shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() @@ -215,7 +217,7 @@ fun NewChatScreen( } else { Spacer(Modifier.height(10.dp)) Surface( - color = MaterialTheme.colorScheme.surfaceContainerLowest, + color = MaterialTheme.colorScheme.startChatListRow, shape = RoundedCornerShape(16.dp), modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index 9b27c5f05..109b398c8 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -50,6 +50,11 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.draw.clip import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.input.key.Key +import androidx.compose.ui.input.key.KeyEventType +import androidx.compose.ui.input.key.key +import androidx.compose.ui.input.key.onPreviewKeyEvent +import androidx.compose.ui.input.key.type import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource @@ -58,6 +63,8 @@ import androidx.compose.ui.unit.dp import com.anindra.messages.AppViewModel import com.anindra.messages.R import com.anindra.messages.ui.theme.groupPickSelected +import com.anindra.messages.ui.theme.startChatField +import com.anindra.messages.ui.theme.startChatListRow /** * Google Messages' New group step. The title turns into "New group MMS" once a @@ -118,7 +125,7 @@ fun NewGroupScreen( Box(Modifier.padding(padding).fillMaxSize()) { Column(Modifier.fillMaxSize()) { Surface( - color = MaterialTheme.colorScheme.surfaceContainerLowest, + color = MaterialTheme.colorScheme.startChatField, shape = RoundedCornerShape(28.dp), modifier = Modifier .fillMaxWidth() @@ -181,8 +188,7 @@ fun NewGroupScreen( chosen.forEach { address -> Surface( color = MaterialTheme.colorScheme.surfaceContainer, - shape = CircleShape, - modifier = Modifier.clickable { chosen = chosen - address } + shape = CircleShape ) { Row( verticalAlignment = Alignment.CenterVertically, @@ -228,6 +234,19 @@ fun NewGroupScreen( modifier = Modifier .width(140.dp) .focusRequester(fieldFocus) + // Google Messages drops the last chip on + // backspace when the field is empty. + .onPreviewKeyEvent { event -> + if (event.type == KeyEventType.KeyDown && + event.key == Key.Backspace && + query.isEmpty() && chosen.isNotEmpty() + ) { + chosen = chosen.dropLast(1) + true + } else { + false + } + } ) } } @@ -251,7 +270,7 @@ fun NewGroupScreen( .animateItem() .background( color = if (picked) MaterialTheme.colorScheme.groupPickSelected - else MaterialTheme.colorScheme.surfaceContainerLowest, + else MaterialTheme.colorScheme.startChatListRow, shape = if (picked) CircleShape else RoundedCornerShape(14.dp) ) .clickable { @@ -315,8 +334,7 @@ fun NewGroupScreen( shadowElevation = 6.dp, modifier = Modifier .align(Alignment.BottomEnd) - .imePadding() - .padding(16.dp) + .padding(end = 16.dp, bottom = keyboardClearance() + 21.dp) .clickable { onCreate(chosen) } ) { Row( diff --git a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt index 012f20637..8e38da083 100644 --- a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt +++ b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt @@ -290,11 +290,26 @@ val ColorScheme.onSelectedBubble: Color get() = onPrimary /** * The band behind a picked contact in the group picker: Google Messages paints - * #CBDBF2 in the light theme, a touch deeper than this palette's - * secondaryContainer. + * #CBDBF2 in the light theme and #343A43 in the dark one, both a touch off this + * palette's secondaryContainer. */ val ColorScheme.groupPickSelected: Color - get() = if (surface.luminance() > 0.5f) Color(0xFFCBDBF2) else secondaryContainer + get() = if (surface.luminance() > 0.5f) Color(0xFFCBDBF2) else Color(0xFF343A43) + +/** + * Start-chat surfaces, measured on both schemes. In light they are the white + * card; in dark Google Messages keeps the To field on the page colour, the + * result rows a step darker than it, and the Add group name field a step + * lighter. + */ +val ColorScheme.startChatField: Color + get() = if (surface.luminance() > 0.5f) surfaceContainerLowest else surfaceContainer + +val ColorScheme.startChatListRow: Color + get() = if (surface.luminance() > 0.5f) surfaceContainerLowest else surface + +val ColorScheme.groupNameField: Color + get() = if (surface.luminance() > 0.5f) surfaceContainerLowest else surfaceContainerHighest /** Google Messages' "Create group" pill: pale cyan in light, deep blue in dark. */ val ColorScheme.startChatAction: Color diff --git a/app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt b/app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt index 58d4d6b15..5d778f2a3 100644 --- a/app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/theme/GroupPickRowColorTest.kt @@ -7,7 +7,7 @@ import org.junit.Test /** * The band behind a picked contact in the group picker, measured off Google * Messages: #CBDBF2 in the light theme. Dark keeps the palette's - * secondaryContainer until it is measured. + * #343A43 in the dark one. */ class GroupPickRowColorTest { @@ -23,8 +23,8 @@ class GroupPickRowColorTest { } @Test - fun darkFallsBackToThePalette() { - assertEquals(DarkColors.secondaryContainer, DarkColors.groupPickSelected) - assertEquals(AmoledColors.secondaryContainer, AmoledColors.groupPickSelected) + fun theDarkBandMatchesGoogleMessages() { + assertEquals("#343A43", hex(DarkColors.groupPickSelected)) + assertEquals("#343A43", hex(AmoledColors.groupPickSelected)) } } diff --git a/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt b/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt new file mode 100644 index 000000000..dcf1a1c81 --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt @@ -0,0 +1,42 @@ +package com.anindra.messages.ui.theme + +import androidx.compose.ui.graphics.Color +import org.junit.Assert.assertEquals +import org.junit.Test + +/** + * The start-chat surfaces, measured on Google Messages in both schemes: white + * cards in light; in dark the To field sits on the page colour (#1E1F20), the + * result rows a step darker (#131314), the group-name field a step lighter + * (#333537), and the picked-row band is #343A43. + */ +class StartChatSurfaceColorTest { + + private fun hex(c: Color) = "#%02X%02X%02X".format( + (c.red * 255f + 0.5f).toInt(), + (c.green * 255f + 0.5f).toInt(), + (c.blue * 255f + 0.5f).toInt() + ) + + @Test + fun lightKeepsTheWhiteCards() { + assertEquals("#FFFFFF", hex(LightColors.startChatField)) + assertEquals("#FFFFFF", hex(LightColors.startChatListRow)) + assertEquals("#FFFFFF", hex(LightColors.groupNameField)) + } + + @Test + fun darkMatchesTheMeasuredSurfaces() { + assertEquals("#1E1F20", hex(DarkColors.startChatField)) + assertEquals("#131314", hex(DarkColors.startChatListRow)) + assertEquals("#333537", hex(DarkColors.groupNameField)) + assertEquals("#343A43", hex(DarkColors.groupPickSelected)) + } + + @Test + fun amoledKeepsItsOwnSteps() { + assertEquals("#111111", hex(AmoledColors.startChatField)) + assertEquals("#000000", hex(AmoledColors.startChatListRow)) + assertEquals("#232323", hex(AmoledColors.groupNameField)) + } +} diff --git a/scripts b/scripts index 288053778..7db221edd 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 288053778887e06a8fc9cd5f365a6d864596b6a9 +Subproject commit 7db221edd594bc632152de2a278fb881ee82b8a0 From 0cc60a6543cf21e14e2836b84dab3a05a9486a70 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 09:49:27 +0530 Subject: [PATCH 09/16] fix: group the suggestion cards the way Google Messages does The picker's suggested contacts are one grouped card, not a stack of separately rounded rows: only the first row rounds its top corners and the last row its bottom ones, with 2dp on the inner edges and a stadium for a picked row. Measured off the live app in dark mode: first card 378..567 with the 14dp top arc matching GM's 381..569, the middle card square, last card ending in GM's bottom arc; a lone result keeps all four corners. --- .../com/anindra/messages/ui/NewGroupScreen.kt | 23 +++++++++++++++++-- .../messages/ui/NewGroupFlowWiringTest.kt | 11 ++++++++- scripts | 2 +- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index 109b398c8..6627a16d0 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -261,7 +261,7 @@ fun NewGroupScreen( ), verticalArrangement = Arrangement.spacedBy(2.dp) ) { - itemsIndexed(filtered, key = { _, contact -> contact.number }) { _, contact -> + itemsIndexed(filtered, key = { _, contact -> contact.number }) { index, contact -> val picked = contact.number in chosen Row( verticalAlignment = Alignment.CenterVertically, @@ -271,7 +271,26 @@ fun NewGroupScreen( .background( color = if (picked) MaterialTheme.colorScheme.groupPickSelected else MaterialTheme.colorScheme.startChatListRow, - shape = if (picked) CircleShape else RoundedCornerShape(14.dp) + shape = when { + picked -> CircleShape + filtered.size == 1 -> RoundedCornerShape(14.dp) + // Google Messages rounds the group's outer + // corners only: the first card's top, the + // last card's bottom, and 2dp elsewhere. + index == 0 -> RoundedCornerShape( + topStart = 14.dp, + topEnd = 14.dp, + bottomStart = 2.dp, + bottomEnd = 2.dp + ) + index == filtered.lastIndex -> RoundedCornerShape( + topStart = 2.dp, + topEnd = 2.dp, + bottomStart = 14.dp, + bottomEnd = 14.dp + ) + else -> RoundedCornerShape(2.dp) + } ) .clickable { if (picked) { diff --git a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt index c13448881..795637522 100644 --- a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt @@ -130,7 +130,16 @@ class NewGroupFlowWiringTest { ) assertTrue( "the selected row is not a stadium", - Regex("""if \(picked\) MaterialTheme\.colorScheme\.groupPickSelected[\s\S]{0,220}if \(picked\) CircleShape""") + Regex("""picked -> CircleShape""").containsMatchIn(newGroup) + ) + assertTrue( + "the first row does not round only its top corners", + Regex("""index == 0 -> RoundedCornerShape\([\s\S]{0,300}topStart = 14\.dp""") + .containsMatchIn(newGroup) + ) + assertTrue( + "the last row does not round only its bottom corners", + Regex("""index == filtered\.lastIndex -> RoundedCornerShape\([\s\S]{0,300}bottomStart = 14\.dp""") .containsMatchIn(newGroup) ) assertTrue( diff --git a/scripts b/scripts index 7db221edd..052c6570d 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 7db221edd594bc632152de2a278fb881ee82b8a0 +Subproject commit 052c6570da0e37d737567cba8663b86eb19736a1 From 442691b6ea1f420ee1ab2855eacfd47179a3410e Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 10:09:55 +0530 Subject: [PATCH 10/16] fix: keep the To caret and outline it in dark, and stack group initials - The hint was drawn in place of the text field's inner content, so an empty To field never painted a caret; it now sits behind the input and the caret blinks over it (verified in 3 of 6 consecutive frames at x 193). - In dark the To field is the page colour and disappeared; it now carries a 1dp outlineVariant border, matching the field Google Messages draws, while the light theme keeps the plain white card. - Group conversations had a generic silhouette avatar. They now use Google Messages' stacked initials (first member top-left, second bottom-right) for generated groups, one initial for a named group, a contact's initial for 1:1 chats, and the silhouette for bare numbers, in both the conversation list and the chat bar. --- .../messages/ui/previews/ComponentPreviews.kt | 28 +++++++ .../com/anindra/messages/ui/ChatScreen.kt | 6 +- .../com/anindra/messages/ui/Components.kt | 73 +++++++++++++++++++ .../messages/ui/ConversationsScreen.kt | 6 +- .../anindra/messages/ui/GroupNameScreen.kt | 15 ++-- .../com/anindra/messages/ui/NewChatScreen.kt | 21 ++++-- .../com/anindra/messages/ui/NewGroupScreen.kt | 40 +++++----- .../com/anindra/messages/ui/theme/Theme.kt | 7 ++ .../messages/ui/ConversationAvatarSpecTest.kt | 47 ++++++++++++ .../ui/theme/StartChatSurfaceColorTest.kt | 7 ++ scripts | 2 +- 11 files changed, 216 insertions(+), 36 deletions(-) create mode 100644 app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt diff --git a/app/src/debug/java/com/anindra/messages/ui/previews/ComponentPreviews.kt b/app/src/debug/java/com/anindra/messages/ui/previews/ComponentPreviews.kt index d008c8d26..8f1357df5 100644 --- a/app/src/debug/java/com/anindra/messages/ui/previews/ComponentPreviews.kt +++ b/app/src/debug/java/com/anindra/messages/ui/previews/ComponentPreviews.kt @@ -45,6 +45,7 @@ import com.anindra.messages.ui.LocationDialog import com.anindra.messages.ui.MessageDetailsDialog import com.anindra.messages.ui.OwnerAvatar import com.anindra.messages.ui.ScheduleDialog +import com.anindra.messages.ui.ConversationAvatar import com.anindra.messages.ui.PersonAvatar import com.anindra.messages.ui.ProvideShimmer import com.anindra.messages.ui.RowPosition @@ -258,6 +259,33 @@ private fun AvatarsAndBadgesPreview() { } } +@PreviewLightDark +@Preview(name = "Conversation avatars", showBackground = true, widthDp = 380) +@Composable +private fun ConversationAvatarsPreview() { + Stage() { + Row(verticalAlignment = Alignment.CenterVertically) { + ConversationAvatar( + name = "Alex, Mom, Bank", + address = "+15551230001", + modifier = Modifier.padding(end = 10.dp) + ) + ConversationAvatar( + name = "Alex, Mom", + address = "+15551230002", + groupTitle = "Weekend", + modifier = Modifier.padding(end = 10.dp) + ) + ConversationAvatar( + name = "Prize Team", + address = "+15551230003", + modifier = Modifier.padding(end = 10.dp) + ) + ConversationAvatar(name = "+15551230004", address = "+15551230004") + } + } +} + @PreviewLightDark @Preview(name = "Avatars (large touch)", showBackground = true, widthDp = 380) @Composable diff --git a/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt index 46b86a978..f4aaaa381 100644 --- a/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/ChatScreen.kt @@ -2775,8 +2775,10 @@ internal fun ChatTopBar( verticalAlignment = Alignment.CenterVertically, modifier = Modifier.clickable { onOpenDetails() } ) { - PersonAvatar( - convo?.groupTitle?.ifBlank { convo.address } ?: "?", + ConversationAvatar( + name = convo?.name ?: "?", + address = convo?.address ?: "?", + groupTitle = convo?.groupTitle.orEmpty(), size = 36.dp, photoModel = convo?.groupAvatar?.takeIf { it.isNotBlank() } ) diff --git a/app/src/main/java/com/anindra/messages/ui/Components.kt b/app/src/main/java/com/anindra/messages/ui/Components.kt index d547c68cb..83c75c216 100644 --- a/app/src/main/java/com/anindra/messages/ui/Components.kt +++ b/app/src/main/java/com/anindra/messages/ui/Components.kt @@ -117,6 +117,79 @@ fun keyboardClearance(): Dp { return (ime - nav).coerceAtLeast(0.dp) } +/** + * How Google Messages paints a conversation's avatar: a named group takes the + * group name's initial, an unnamed group stacks the first two members' + * initials, a saved contact takes its own initial, and a bare number keeps the + * silhouette. + */ +data class ConversationAvatarSpec( + val key: String, + val initials: List, + val isGroup: Boolean +) + +fun conversationAvatarSpec( + name: String, + address: String, + groupTitle: String +): ConversationAvatarSpec { + // A generated group title is the members' names joined with ", "; a title + // the user typed is a single name. + val title = groupTitle.ifBlank { name } + val members = title.split(", ").map { it.trim() }.filter { it.isNotEmpty() } + return when { + members.size > 1 -> + ConversationAvatarSpec(title, members.take(2).mapNotNull { avatarInitials(it) }, true) + groupTitle.isNotBlank() -> + ConversationAvatarSpec(groupTitle, listOfNotNull(avatarInitials(groupTitle)), true) + name != address -> + ConversationAvatarSpec(address, listOfNotNull(avatarInitials(name)), false) + else -> ConversationAvatarSpec(address, emptyList(), false) + } +} + +/** + * The stacked two-circle avatar Google Messages gives an unnamed group: two + * 30dp initials in a 48dp slot, the second offset to the bottom-right. + */ +@Composable +fun ConversationAvatar( + name: String, + address: String, + groupTitle: String = "", + size: Dp = 48.dp, + modifier: Modifier = Modifier, + photoModel: Any? = null +) { + val spec = conversationAvatarSpec(name, address, groupTitle) + if (spec.initials.size == 2) { + val dot = size * 0.62f + Box(modifier.size(size)) { + PersonAvatar( + spec.key, + size = dot, + initials = spec.initials[0], + modifier = Modifier.align(Alignment.TopStart) + ) + PersonAvatar( + spec.key + spec.initials[1], + size = dot, + initials = spec.initials[1], + modifier = Modifier.align(Alignment.BottomEnd) + ) + } + } else { + PersonAvatar( + spec.key, + size = size, + modifier = modifier, + photoModel = photoModel, + initials = spec.initials.firstOrNull() + ) + } +} + /** First letter of a display name, the way Google Messages paints an avatar. */ fun avatarInitials(name: String?): String? = name?.firstOrNull { it.isLetter() }?.uppercase() diff --git a/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt b/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt index d5bbc3232..d2a1e9aee 100644 --- a/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/ConversationsScreen.kt @@ -1321,8 +1321,10 @@ internal fun ConversationRow( .padding(horizontal = 16.dp, vertical = 12.dp), verticalAlignment = Alignment.CenterVertically ) { - PersonAvatar( - convo.groupTitle.ifBlank { convo.address }, + ConversationAvatar( + name = convo.name, + address = convo.address, + groupTitle = convo.groupTitle, photoModel = convo.groupAvatar.takeIf { it.isNotBlank() } ) Spacer(Modifier.width(16.dp)) diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt index fe752dde5..b83aa7e51 100644 --- a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -173,13 +173,14 @@ fun GroupNameScreen( ), cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), decorationBox = { inner -> - if (name.isEmpty()) { - Text( - stringResource(R.string.group_name_field), - style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - } else { + Box { + if (name.isEmpty()) { + Text( + stringResource(R.string.group_name_field), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } inner() } }, diff --git a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt index a7d7a310d..1570895a8 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewChatScreen.kt @@ -59,6 +59,7 @@ import com.anindra.messages.data.AddressIdentity import com.anindra.messages.ui.theme.onStartChatAction import com.anindra.messages.ui.theme.startChatAction import com.anindra.messages.ui.theme.startChatField +import com.anindra.messages.ui.theme.startChatFieldBorder import com.anindra.messages.ui.theme.startChatListRow data class Contact(val name: String, val number: String, val workProfile: Boolean = false) @@ -146,6 +147,9 @@ fun NewChatScreen( Surface( color = MaterialTheme.colorScheme.startChatField, shape = RoundedCornerShape(28.dp), + border = MaterialTheme.colorScheme.startChatFieldBorder?.let { + androidx.compose.foundation.BorderStroke(1.dp, it) + }, modifier = Modifier .fillMaxWidth() .padding(horizontal = 12.dp) @@ -172,13 +176,16 @@ fun NewChatScreen( ), cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), decorationBox = { inner -> - if (query.isEmpty()) { - Text( - stringResource(R.string.new_chat_hint), - style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onSurfaceVariant - ) - } else { + // The hint sits behind the input so the caret is + // still painted while the field is empty. + Box { + if (query.isEmpty()) { + Text( + stringResource(R.string.new_chat_hint), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + } inner() } }, diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index 6627a16d0..ecd7530fc 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -64,6 +64,7 @@ import com.anindra.messages.AppViewModel import com.anindra.messages.R import com.anindra.messages.ui.theme.groupPickSelected import com.anindra.messages.ui.theme.startChatField +import com.anindra.messages.ui.theme.startChatFieldBorder import com.anindra.messages.ui.theme.startChatListRow /** @@ -127,6 +128,9 @@ fun NewGroupScreen( Surface( color = MaterialTheme.colorScheme.startChatField, shape = RoundedCornerShape(28.dp), + border = MaterialTheme.colorScheme.startChatFieldBorder?.let { + androidx.compose.foundation.BorderStroke(1.dp, it) + }, modifier = Modifier .fillMaxWidth() .padding(horizontal = 12.dp) @@ -155,15 +159,16 @@ fun NewGroupScreen( ), cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), decorationBox = { inner -> - if (query.isEmpty()) { - Text( - stringResource(R.string.new_group_hint), - style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onSurfaceVariant, - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - } else { + Box { + if (query.isEmpty()) { + Text( + stringResource(R.string.new_group_hint), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } inner() } }, @@ -220,14 +225,15 @@ fun NewGroupScreen( ), cursorBrush = SolidColor(MaterialTheme.colorScheme.primary), decorationBox = { inner -> - if (query.isEmpty() && chosen.isNotEmpty()) { - Text( - stringResource(R.string.new_group_anyone_else), - style = MaterialTheme.typography.bodyLarge, - color = MaterialTheme.colorScheme.onSurfaceVariant, - maxLines = 1 - ) - } else { + Box { + if (query.isEmpty() && chosen.isNotEmpty()) { + Text( + stringResource(R.string.new_group_anyone_else), + style = MaterialTheme.typography.bodyLarge, + color = MaterialTheme.colorScheme.onSurfaceVariant, + maxLines = 1 + ) + } inner() } }, diff --git a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt index 8e38da083..f743b0f8f 100644 --- a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt +++ b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt @@ -311,6 +311,13 @@ val ColorScheme.startChatListRow: Color val ColorScheme.groupNameField: Color get() = if (surface.luminance() > 0.5f) surfaceContainerLowest else surfaceContainerHighest +/** + * In light the To field reads as a white card; in dark it sits on the page + * colour, so it needs a hairline outline to stay visible. + */ +val ColorScheme.startChatFieldBorder: Color? + get() = if (surface.luminance() > 0.5f) null else outlineVariant + /** Google Messages' "Create group" pill: pale cyan in light, deep blue in dark. */ val ColorScheme.startChatAction: Color get() = if (surface.luminance() > 0.5f) Color(0xFFC2E7FF) else Color(0xFF004A77) diff --git a/app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt b/app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt new file mode 100644 index 000000000..51f579512 --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt @@ -0,0 +1,47 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * Google Messages paints an unnamed group as two stacked initials, a named + * group as its own initial, a saved contact as their initial, and a bare + * number as the silhouette. + */ +class ConversationAvatarSpecTest { + + @Test + fun anUnnamedGroupStacksTheFirstTwoMembers() { + val spec = conversationAvatarSpec("Alex, Mom, Bank", "+1555", "") + assertTrue(spec.isGroup) + assertEquals(listOf("A", "M"), spec.initials) + } + + @Test + fun theGeneratedMemberListAlsoStacks() { + // Our groups store the members' names in groupTitle, so the generated + // title must stack rather than read as a group name. + val spec = conversationAvatarSpec("Alex", "+1555", "Alex, Mom, Bank") + assertTrue(spec.isGroup) + assertEquals(listOf("A", "M"), spec.initials) + } + + @Test + fun aNamedGroupUsesItsOwnInitial() { + val spec = conversationAvatarSpec("Alex, Mom", "+1555", "Weekend") + assertTrue(spec.isGroup) + assertEquals(listOf("W"), spec.initials) + } + + @Test + fun aContactUsesTheirInitialAndANumberKeepsTheSilhouette() { + val contact = conversationAvatarSpec("Prize Team", "+1555772010", "") + assertFalse(contact.isGroup) + assertEquals(listOf("P"), contact.initials) + + val number = conversationAvatarSpec("+1555772010", "+1555772010", "") + assertTrue(number.initials.isEmpty()) + } +} diff --git a/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt b/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt index dcf1a1c81..24a7f774f 100644 --- a/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt @@ -33,6 +33,13 @@ class StartChatSurfaceColorTest { assertEquals("#343A43", hex(DarkColors.groupPickSelected)) } + @Test + fun theFieldKeepsAnOutlineInDarkOnly() { + assertEquals(null, LightColors.startChatFieldBorder) + assertEquals(DarkColors.outlineVariant, DarkColors.startChatFieldBorder) + assertEquals(AmoledColors.outlineVariant, AmoledColors.startChatFieldBorder) + } + @Test fun amoledKeepsItsOwnSteps() { assertEquals("#111111", hex(AmoledColors.startChatField)) diff --git a/scripts b/scripts index 052c6570d..f7be9ad19 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 052c6570da0e37d737567cba8663b86eb19736a1 +Subproject commit f7be9ad19617dcf051be616f36864d5fe2d6ed3f From a2fd3f2c9382b8fab8d5ebc64c9a7add459e715a Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 10:37:53 +0530 Subject: [PATCH 11/16] feat: rebuild group threads when importing a backup An sms-ie backup's MMS records carry a sender, the shipping addresses and the exporting thread id. The importer only ever read one peer address, so a group came back as a 1:1 thread per sender. Now: - SmsIeBackup parses every recipient and the thread id; - ImportGroups derives the participants (sender + recipients, minus this device's own numbers) and a formatting-independent key; - the import creates one conversation per participant set, writes conversation_recipients for every member, generates the group title, files later messages of the same thread into it and keeps each incoming bubble's sender in messages.address; a merge import finds the existing group by its participant set first. The group details header also uses the stacked ConversationAvatar, so it shows Alex/Mom like the list and the chat bar. --- .../com/anindra/messages/data/ImportGroups.kt | 38 ++++++++++ .../com/anindra/messages/data/Repository.kt | 76 ++++++++++++++++++- .../com/anindra/messages/data/SmsIeBackup.kt | 34 ++++++++- .../messages/ui/ContactDetailsScreen.kt | 6 +- .../anindra/messages/data/ImportGroupsTest.kt | 45 +++++++++++ .../anindra/messages/data/SmsIeBackupTest.kt | 17 +++++ scripts | 2 +- 7 files changed, 211 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/anindra/messages/data/ImportGroups.kt create mode 100644 app/src/test/java/com/anindra/messages/data/ImportGroupsTest.kt diff --git a/app/src/main/java/com/anindra/messages/data/ImportGroups.kt b/app/src/main/java/com/anindra/messages/data/ImportGroups.kt new file mode 100644 index 000000000..540db9419 --- /dev/null +++ b/app/src/main/java/com/anindra/messages/data/ImportGroups.kt @@ -0,0 +1,38 @@ +package com.anindra.messages.data + +/** + * Rebuilding a backup's group threads. + * + * An MMS record carries one sender, its shipping addresses and the exporting + * phone's thread id. Every message in a group names the same people, so the + * union of sender and recipients (minus this device's own numbers) is the + * group. Dropping our own number matters: an outbound MMS lists us among its + * recipients, and a group that includes ourselves is not a group. + */ +object ImportGroups { + + /** The people on the thread, order-independent. Empty or one means 1:1. */ + fun members( + sender: String, + recipients: List, + ownNumbers: List + ): List { + val own = ownNumbers.map(::token).filter { it.isNotEmpty() }.toSet() + val people = LinkedHashSet() + for (raw in listOf(sender) + recipients) { + val value = raw.trim() + if (value.isEmpty()) continue + val t = token(value) + if (t.isNotEmpty() && t in own) continue + people += value + } + return people.sortedBy(::token) + } + + /** A stable identity for a participant set, formatting-independent. */ + fun key(members: List): String = + members.map(::token).sorted().joinToString("\u001f") + + private fun token(address: String): String = + address.filter(Char::isDigit).ifEmpty { address.trim().lowercase() } +} diff --git a/app/src/main/java/com/anindra/messages/data/Repository.kt b/app/src/main/java/com/anindra/messages/data/Repository.kt index c7ded00e8..3bd6836f4 100644 --- a/app/src/main/java/com/anindra/messages/data/Repository.kt +++ b/app/src/main/java/com/anindra/messages/data/Repository.kt @@ -3434,6 +3434,24 @@ class Repository(private val context: Context) { } } + // Existing groups, keyed by their participant set, so a merge import + // files straight back into the thread the user already has. + val groupIds = HashMap() + run { + val byConversation = HashMap>() + database.rawQuery( + "SELECT conversation_id, address FROM conversation_recipients", null + ).use { c -> + while (c.moveToNext()) { + byConversation.getOrPut(c.getLong(0)) { mutableListOf() } += c.getString(1) + } + } + byConversation.forEach { (id, people) -> + if (people.size > 1) groupIds.putIfAbsent(ImportGroups.key(people), id) + } + } + val ownNumbers = ownNumbersBlocking() + val batch = ArrayList(IMPORT_BATCH) var added = 0 var seen = 0 @@ -3457,6 +3475,7 @@ class Repository(private val context: Context) { val baseConflicts = LinkedHashMap(conflicts) val baseKnown = HashSet(known) val baseByAddress = HashMap(byAddress) + val baseGroupIds = HashMap(groupIds) val outcome = TransferRetry.run { added = baseAdded skipped = baseSkipped @@ -3466,12 +3485,50 @@ class Repository(private val context: Context) { known.addAll(baseKnown) byAddress.clear() byAddress.putAll(baseByAddress) + groupIds.clear() + groupIds.putAll(baseGroupIds) database.beginTransaction() try { for (msg in rows) { val address = canonical(msg.address).ifEmpty { msg.address } - var cid = byAddress[address] ?: byAddress[msg.address] - if (cid == null) { + val group = if (msg.isMms) { + ImportGroups.members(msg.address, msg.recipients, ownNumbers) + } else { + emptyList() + } + val groupKey = if (group.size > 1) ImportGroups.key(group) else null + val threadKey = if (groupKey != null && msg.threadId > 0) { + "thread:${msg.threadId}" + } else { + null + } + var cid: Long? = if (groupKey != null) { + groupIds[groupKey] ?: threadKey?.let { groupIds[it] } + } else { + byAddress[address] ?: byAddress[msg.address] + } + if (cid == null && groupKey != null) { + // A thread from another phone has no usable address, + // so the first member stands in for it; the group's + // identity is the participant set. + cid = database.insert("conversations", null, ContentValues().apply { + put("address", group.first()) + put("name", "") + }) + if (cid <= 0) { + skipped++ + conflicts.count(Conflict.CONVERSATION_UNRESOLVED) + continue + } + for (person in group) { + database.execSQL( + "INSERT OR IGNORE INTO conversation_recipients(conversation_id, address) VALUES(?,?)", + arrayOf(cid, person) + ) + upsertParticipant(database, person) + } + ensureGroupTitle(cid) + } else if (cid == null) { cid = database.insert("conversations", null, ContentValues().apply { put("address", address) put("name", contactNameFor(address) ?: address) @@ -3482,6 +3539,19 @@ class Repository(private val context: Context) { continue } byAddress[address] = cid + } else if (groupKey != null) { + // The thread may have gained a member since its first + // message; keep the roster complete. + for (person in group) { + database.execSQL( + "INSERT OR IGNORE INTO conversation_recipients(conversation_id, address) VALUES(?,?)", + arrayOf(cid, person) + ) + } + } + if (groupKey != null) { + groupIds[groupKey] = cid + threadKey?.let { groupIds[it] = cid } } val transport = if (msg.isMms) MmsSupport.TRANSPORT_MMS else MmsSupport.TRANSPORT_SMS val key = messageKey(address, msg.timestamp, msg.isMe, msg.body, transport) @@ -3500,6 +3570,8 @@ class Repository(private val context: Context) { put("transport", transport) put("media_type", if (image != null) "image" else "text") put("media_uri", if (image != null) storeImportedImage(image, msg) else "") + // In a group bubble the sender is what labels it. + if (groupKey != null && !msg.isMe) put("address", msg.address) }) if (row <= 0) { skipped++ diff --git a/app/src/main/java/com/anindra/messages/data/SmsIeBackup.kt b/app/src/main/java/com/anindra/messages/data/SmsIeBackup.kt index 1ac71987a..d5728bb5f 100644 --- a/app/src/main/java/com/anindra/messages/data/SmsIeBackup.kt +++ b/app/src/main/java/com/anindra/messages/data/SmsIeBackup.kt @@ -28,7 +28,14 @@ object SmsIeBackup { val status: String, val imageBytes: ByteArray? = null, val imageMime: String = "", - val imageName: String = "" + val imageName: String = "", + /** + * Everyone on the MMS thread: the sender plus every shipping address, + * before this device's own numbers are dropped. Empty for SMS. + */ + val recipients: List = emptyList(), + /** The exporting phone's thread id, used only to keep a group together. */ + val threadId: Long = 0 ) { override fun equals(other: Any?): Boolean = other is Message && address == other.address && body == other.body && @@ -174,10 +181,33 @@ object SmsIeBackup { status = status, imageBytes = imageBytes, imageMime = imageMime, - imageName = imageName + imageName = imageName, + recipients = mmsParticipants(record), + threadId = record.optLong("thread_id", 0) ) } + /** + * Every address on an MMS thread, the sender included. A group message is + * addressed to the same set no matter who sent it, so collecting sender and + * shipping addresses is what lets the importer rebuild the group instead of + * filing each member's message in their own 1:1 thread. + */ + fun mmsParticipants(record: JSONObject): List { + val out = LinkedHashSet() + record.optJSONObject("__sender_address") + ?.optString("address") + ?.trim() + ?.takeIf { it.isNotEmpty() } + ?.let { out += MmsSupport.phoneAddress(it) ?: it } + val recipients = record.optJSONArray("__recipient_addresses") ?: JSONArray() + for (i in 0 until recipients.length()) { + val addr = recipients.optJSONObject(i)?.optString("address")?.trim().orEmpty() + if (addr.isNotEmpty()) out += MmsSupport.phoneAddress(addr) ?: addr + } + return out.toList() + } + /** Sent MMS carry the recipient; inbox MMS carry the sender. */ fun mmsPeer(record: JSONObject, isMe: Boolean): String { val sender = record.optJSONObject("__sender_address")?.optString("address") diff --git a/app/src/main/java/com/anindra/messages/ui/ContactDetailsScreen.kt b/app/src/main/java/com/anindra/messages/ui/ContactDetailsScreen.kt index 3320010c2..4ae41be2a 100644 --- a/app/src/main/java/com/anindra/messages/ui/ContactDetailsScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/ContactDetailsScreen.kt @@ -233,8 +233,10 @@ onBack: () -> Unit, horizontalAlignment = Alignment.CenterHorizontally ) { Box(contentAlignment = Alignment.BottomEnd) { - PersonAvatar( - address, + ConversationAvatar( + name = groupTitle, + address = address, + groupTitle = if (isGroup) groupTitle else "", size = 96.dp, photoModel = groupAvatar.takeIf { it.isNotBlank() } ) diff --git a/app/src/test/java/com/anindra/messages/data/ImportGroupsTest.kt b/app/src/test/java/com/anindra/messages/data/ImportGroupsTest.kt new file mode 100644 index 000000000..ed102748e --- /dev/null +++ b/app/src/test/java/com/anindra/messages/data/ImportGroupsTest.kt @@ -0,0 +1,45 @@ +package com.anindra.messages.data + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * A backup's MMS thread becomes a group when more than one person remains after + * dropping this device's own numbers, and its identity must not depend on the + * order or formatting of the addresses. + */ +class ImportGroupsTest { + + @Test + fun theGroupIsEveryoneButUs() { + val members = ImportGroups.members( + sender = "+15550001111", + recipients = listOf("+15550001111", "+15550002222", "+15550003333", "+15559999999"), + ownNumbers = listOf("+1 555 999 9999") + ) + assertEquals(listOf("+15550001111", "+15550002222", "+15550003333"), members) + } + + @Test + fun aThreadWithOnePersonStaysOneToOne() { + val members = ImportGroups.members( + sender = "+15550001111", + recipients = listOf("+15550001111", "+15559999999"), + ownNumbers = listOf("+15559999999") + ) + assertEquals(listOf("+15550001111"), members) + } + + @Test + fun theKeyIgnoresOrderAndSpacing() { + val a = ImportGroups.members( + "+15550001111", listOf("+15550001111", "(555) 000-2222"), emptyList() + ) + val b = ImportGroups.members( + "+1 555 000 1111", listOf("(555) 000-2222", "+1 555 000 1111"), emptyList() + ) + assertEquals(ImportGroups.key(a), ImportGroups.key(b)) + assertTrue(ImportGroups.key(a).isNotBlank()) + } +} diff --git a/app/src/test/java/com/anindra/messages/data/SmsIeBackupTest.kt b/app/src/test/java/com/anindra/messages/data/SmsIeBackupTest.kt index f4559165f..f03a56e35 100644 --- a/app/src/test/java/com/anindra/messages/data/SmsIeBackupTest.kt +++ b/app/src/test/java/com/anindra/messages/data/SmsIeBackupTest.kt @@ -152,4 +152,21 @@ class SmsIeBackupTest { assertTrue(SmsIeBackupPolicy.clearsExisting(ImportMode.REPLACE)) assertFalse(SmsIeBackupPolicy.clearsExisting(ImportMode.MERGE)) } + + @Test + fun aGroupMmsCarriesItsWholeThread() { + val record = "{" + + "\"m_type\":\"132\",\"thread_id\":\"77\",\"date\":\"1790279508000\"," + + "\"msg_box\":\"1\",\"read\":\"1\"," + + "\"__sender_address\":{\"address\":\"+15550001111\",\"type\":137}," + + "\"__recipient_addresses\":[{\"address\":\"+15550002222\",\"type\":151}," + + "{\"address\":\"+15550003333\",\"type\":151}]," + + "\"__parts\":[{\"ct\":\"text/plain\",\"text\":\"group hi\"}]}" + val msg = SmsIeBackup.record(record)!! + assertEquals(77L, msg.threadId) + assertEquals( + listOf("+15550001111", "+15550002222", "+15550003333"), + msg.recipients + ) + } } diff --git a/scripts b/scripts index f7be9ad19..5a19b09f4 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit f7be9ad19617dcf051be616f36864d5fe2d6ed3f +Subproject commit 5a19b09f4d686717768cb1088c768de6c2f152f5 From dca35dc187a31cc46097a0bcaa156852ead916e7 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 12:10:08 +0530 Subject: [PATCH 12/16] fix: seat the recipient avatar inside its pill and show the pill in dark The chip was 24dp tall around a 20dp avatar with a 2dp start inset, so the 40dp-tall pill's rounded cap cut inside the avatar and the picture overhung the pale background. It is now a 28dp pill with 4dp padding all round and an 8dp gap to the name, so the avatar's edge follows the cap. The chip also used surfaceContainer, which is the page colour in dark and made the pill invisible against the To field. It now takes a startChatChip role: #F0F4F9 in light (Google Messages' fill) and #28292C in dark, one step above the page. --- .../main/java/com/anindra/messages/ui/NewGroupScreen.kt | 8 +++++--- app/src/main/java/com/anindra/messages/ui/theme/Theme.kt | 8 ++++++++ .../messages/ui/theme/StartChatSurfaceColorTest.kt | 6 ++++++ scripts | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index ecd7530fc..f642f2acf 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -63,7 +63,9 @@ import androidx.compose.ui.unit.dp import com.anindra.messages.AppViewModel import com.anindra.messages.R import com.anindra.messages.ui.theme.groupPickSelected +import com.anindra.messages.ui.theme.startChatChip import com.anindra.messages.ui.theme.startChatField +import com.anindra.messages.ui.theme.startChatChip import com.anindra.messages.ui.theme.startChatFieldBorder import com.anindra.messages.ui.theme.startChatListRow @@ -192,19 +194,19 @@ fun NewGroupScreen( ) chosen.forEach { address -> Surface( - color = MaterialTheme.colorScheme.surfaceContainer, + color = MaterialTheme.colorScheme.startChatChip, shape = CircleShape ) { Row( verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.padding(start = 2.dp, end = 10.dp, top = 2.dp, bottom = 2.dp) + modifier = Modifier.padding(start = 4.dp, end = 12.dp, top = 4.dp, bottom = 4.dp) ) { PersonAvatar( address, size = 20.dp, initials = avatarInitials(nameOf(address)) ) - Spacer(Modifier.width(4.dp)) + Spacer(Modifier.width(8.dp)) Text( nameOf(address), style = MaterialTheme.typography.labelLarge, diff --git a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt index f743b0f8f..64c38c5b1 100644 --- a/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt +++ b/app/src/main/java/com/anindra/messages/ui/theme/Theme.kt @@ -311,6 +311,14 @@ val ColorScheme.startChatListRow: Color val ColorScheme.groupNameField: Color get() = if (surface.luminance() > 0.5f) surfaceContainerLowest else surfaceContainerHighest +/** + * The recipient pill inside the To field: Google Messages paints the page + * colour in light; in dark that would vanish into the field, so it takes the + * next surface step up. + */ +val ColorScheme.startChatChip: Color + get() = if (surface.luminance() > 0.5f) surfaceContainer else surfaceContainerHigh + /** * In light the To field reads as a white card; in dark it sits on the page * colour, so it needs a hairline outline to stay visible. diff --git a/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt b/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt index 24a7f774f..348bc8655 100644 --- a/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/theme/StartChatSurfaceColorTest.kt @@ -33,6 +33,12 @@ class StartChatSurfaceColorTest { assertEquals("#343A43", hex(DarkColors.groupPickSelected)) } + @Test + fun theRecipientPillStaysVisibleInBothSchemes() { + assertEquals("#F0F4F9", hex(LightColors.startChatChip)) + assertEquals("#28292C", hex(DarkColors.startChatChip)) + } + @Test fun theFieldKeepsAnOutlineInDarkOnly() { assertEquals(null, LightColors.startChatFieldBorder) diff --git a/scripts b/scripts index 5a19b09f4..56a411695 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 5a19b09f4d686717768cb1088c768de6c2f152f5 +Subproject commit 56a411695c758e3e1ad9806b30163606788de200 From 2c280c7f1e893492ea94e09cebe26c7206fd5216 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 12:17:52 +0530 Subject: [PATCH 13/16] fix: drop the email promise from the start-chat hints The roster is built from Contacts' Phone rows (name + number), so a typed email address could never match. Both hints now say "name or phone number" in all 14 locales instead of advertising a search that does not exist. --- app/src/main/res/values-ar/strings_conversations.xml | 4 ++-- app/src/main/res/values-de/strings_conversations.xml | 4 ++-- app/src/main/res/values-es/strings_conversations.xml | 4 ++-- app/src/main/res/values-fa/strings_conversations.xml | 4 ++-- app/src/main/res/values-fr/strings_conversations.xml | 4 ++-- app/src/main/res/values-hi/strings_conversations.xml | 4 ++-- app/src/main/res/values-ja/strings_conversations.xml | 4 ++-- app/src/main/res/values-ko/strings_conversations.xml | 4 ++-- app/src/main/res/values-pl/strings_conversations.xml | 4 ++-- app/src/main/res/values-pt-rBR/strings_conversations.xml | 4 ++-- app/src/main/res/values-ru/strings_conversations.xml | 4 ++-- app/src/main/res/values-zh-rCN/strings_conversations.xml | 4 ++-- app/src/main/res/values-zh-rTW/strings_conversations.xml | 4 ++-- app/src/main/res/values/strings_conversations.xml | 4 ++-- scripts | 2 +- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/src/main/res/values-ar/strings_conversations.xml b/app/src/main/res/values-ar/strings_conversations.xml index b2b789972..480b8c8b6 100644 --- a/app/src/main/res/values-ar/strings_conversations.xml +++ b/app/src/main/res/values-ar/strings_conversations.xml @@ -7,7 +7,7 @@ انقر زر الرجوع مرة أخرى للخروج - اكتب أسماء أو أرقام هواتف أو بريدًا إلكترونيًا + اكتب أسماء أو أرقام هواتف مجموعة MMS جديدة أي شخص آخر؟ محادثة جماعية جديدة @@ -20,7 +20,7 @@ %2$d/%1$d جوال %s إلى: - اكتب اسمًا أو رقم هاتف أو بريدًا إلكترونيًا + اكتب اسمًا أو رقم هاتف يمكن إرسال الرسائل إلى أرقام الهواتف فقط إرسال إلى %s رسالة نصية diff --git a/app/src/main/res/values-de/strings_conversations.xml b/app/src/main/res/values-de/strings_conversations.xml index d77e0603d..39c5505df 100644 --- a/app/src/main/res/values-de/strings_conversations.xml +++ b/app/src/main/res/values-de/strings_conversations.xml @@ -6,7 +6,7 @@ App-Einstellungen öffnen Noch einmal Zurück drücken zum Beenden - Namen, Telefonnummern oder E-Mails eingeben + Namen oder Telefonnummern eingeben Neue MMS-Gruppe Noch jemand? Neue Gruppenunterhaltung @@ -19,7 +19,7 @@ %1$d/%2$d Mobil %s An: - Name, Telefonnummer oder E-Mail eingeben + Name oder Telefonnummer eingeben Es können nur Telefonnummern angerufen werden An %s senden Textnachricht diff --git a/app/src/main/res/values-es/strings_conversations.xml b/app/src/main/res/values-es/strings_conversations.xml index 0a4e9a7d8..1ac25b34a 100644 --- a/app/src/main/res/values-es/strings_conversations.xml +++ b/app/src/main/res/values-es/strings_conversations.xml @@ -7,7 +7,7 @@ Presionar atrás nuevamente para salir - Escribe nombres, números de teléfono o correos + Escribe nombres o números de teléfono Nuevo grupo MMS ¿Alguien más? Nueva conversación grupal @@ -20,7 +20,7 @@ %1$d/%2$d Móvil %s Para: - Escribe un nombre, número de teléfono o correo + Escribe un nombre o número de teléfono Solo se puede enviar mensajes a números de teléfono Enviar a %s Mensaje de texto diff --git a/app/src/main/res/values-fa/strings_conversations.xml b/app/src/main/res/values-fa/strings_conversations.xml index 1e8d6a6d4..ff5fb6493 100644 --- a/app/src/main/res/values-fa/strings_conversations.xml +++ b/app/src/main/res/values-fa/strings_conversations.xml @@ -7,7 +7,7 @@ برای خروج دوباره دکمه بازگشت را بزنید - نام‌ها، شماره‌های تلفن یا ایمیل‌ها را وارد کنید + نام‌ها یا شماره‌های تلفن را وارد کنید گروه MMS جدید شخص دیگری؟ گفتگوی گروهی جدید @@ -20,7 +20,7 @@ %1$d/%2$d همراه %s به: - نام، شماره تلفن یا ایمیل را وارد کنید + نام یا شماره تلفن را وارد کنید فقط به شماره‌های تلفن می‌توان پیام فرستاد ارسال به %s پیام diff --git a/app/src/main/res/values-fr/strings_conversations.xml b/app/src/main/res/values-fr/strings_conversations.xml index d21c005ad..b39a097cc 100644 --- a/app/src/main/res/values-fr/strings_conversations.xml +++ b/app/src/main/res/values-fr/strings_conversations.xml @@ -6,7 +6,7 @@ Ouvrir les paramètres de l\'application Appuyez à nouveau sur le bouton retour pour quitter - Saisissez des noms, numéros de téléphone ou e-mails + Saisissez des noms ou des numéros de téléphone Nouveau groupe MMS Quelqu’un d’autre ? Nouvelle conversation de groupe @@ -19,7 +19,7 @@ %1$d/%2$d Mobile %s À : - Saisissez un nom, un numéro de téléphone ou un e-mail + Saisissez un nom ou un numéro de téléphone Seuls les numéros de téléphone peuvent être message Envoyer au %s Message texte diff --git a/app/src/main/res/values-hi/strings_conversations.xml b/app/src/main/res/values-hi/strings_conversations.xml index bd90f38e1..cb6ac56e7 100644 --- a/app/src/main/res/values-hi/strings_conversations.xml +++ b/app/src/main/res/values-hi/strings_conversations.xml @@ -7,7 +7,7 @@ बाहर निकलने के लिए फिर से बैक दबाएं - नाम, फ़ोन नंबर या ईमेल डालें + नाम या फ़ोन नंबर डालें नया MMS समूह कोई और? नई समूह बातचीत @@ -20,7 +20,7 @@ %1$d/%2$d मोबाइल %s प्रति: - नाम, फ़ोन नंबर या ईमेल डालें + नाम या फ़ोन नंबर डालें केवल फ़ोन नंबरों को संदेश भेजे जा सकते हैं %s पर भेजें पाठ संदेश diff --git a/app/src/main/res/values-ja/strings_conversations.xml b/app/src/main/res/values-ja/strings_conversations.xml index c652abfc0..13a16aa37 100644 --- a/app/src/main/res/values-ja/strings_conversations.xml +++ b/app/src/main/res/values-ja/strings_conversations.xml @@ -7,7 +7,7 @@ 再度戻るを押して終了 - 名前、電話番号、メールアドレスを入力 + 名前または電話番号を入力 新しい MMS グループ 他に追加しますか? 新しいグループ会話 @@ -20,7 +20,7 @@ %1$d/%2$d モバイル %s 宛先: - 名前、電話番号、メールアドレスを入力 + 名前または電話番号を入力 メッセージを送信できるのは電話番号のみです %s に送信 テキストメッセージ diff --git a/app/src/main/res/values-ko/strings_conversations.xml b/app/src/main/res/values-ko/strings_conversations.xml index 98091eba2..23cbbc978 100644 --- a/app/src/main/res/values-ko/strings_conversations.xml +++ b/app/src/main/res/values-ko/strings_conversations.xml @@ -7,7 +7,7 @@ 뒤로 가기를 다시 누르면 종료됩니다 - 이름, 전화번호 또는 이메일 입력 + 이름 또는 전화번호 입력 새 MMS 그룹 다른 사람이 있나요? 새 그룹 대화 @@ -20,7 +20,7 @@ %1$d/%2$d 휴대전화 %s 받는 사람: - 이름, 전화번호 또는 이메일 입력 + 이름 또는 전화번호 입력 전화번호로만 메시지 전송이 가능합니다 받는사람: %s 문자 메시지 diff --git a/app/src/main/res/values-pl/strings_conversations.xml b/app/src/main/res/values-pl/strings_conversations.xml index 26a442b15..7f96d6db2 100644 --- a/app/src/main/res/values-pl/strings_conversations.xml +++ b/app/src/main/res/values-pl/strings_conversations.xml @@ -7,7 +7,7 @@ Naciśnij ponownie wstecz, aby wyjść - Wpisz nazwy, numery telefonów lub e-maile + Wpisz nazwy lub numery telefonów Nowa grupa MMS Ktoś jeszcze? Nowa rozmowa grupowa @@ -20,7 +20,7 @@ %1$d/%2$d Komórka %s Do: - Wpisz nazwę, numer telefonu lub e-mail + Wpisz nazwę lub numer telefonu Do numerów telefonów można wysyłać wiadomości Wyślij pod numer %s Wiadomość tekstowa diff --git a/app/src/main/res/values-pt-rBR/strings_conversations.xml b/app/src/main/res/values-pt-rBR/strings_conversations.xml index f2cba7925..3993f62a9 100644 --- a/app/src/main/res/values-pt-rBR/strings_conversations.xml +++ b/app/src/main/res/values-pt-rBR/strings_conversations.xml @@ -7,7 +7,7 @@ Pressione voltar novamente para sair - Digite nomes, números de telefone ou e-mails + Digite nomes ou números de telefone Novo grupo MMS Mais alguém? Nova conversa em grupo @@ -20,7 +20,7 @@ %1$d/%2$d Celular %s Para: - Digite um nome, número de telefone ou e-mail + Digite um nome ou número de telefone Somente números de telefone podem receber mensagens Enviar para %s Mensagem de texto diff --git a/app/src/main/res/values-ru/strings_conversations.xml b/app/src/main/res/values-ru/strings_conversations.xml index 3b5c4c683..60f4cdc67 100644 --- a/app/src/main/res/values-ru/strings_conversations.xml +++ b/app/src/main/res/values-ru/strings_conversations.xml @@ -7,7 +7,7 @@ Нажмите «Назад» ещё раз для выхода - Введите имена, номера телефонов или адреса эл. почты + Введите имена или номера телефонов Новая группа MMS Кто-то ещё? Новый групповой чат @@ -20,7 +20,7 @@ %1$d/%2$d Мобильный %s Кому: - Введите имя, номер телефона или адрес эл. почты + Введите имя или номер телефона Сообщения можно отправлять только на номера телефонов Отправить на номер %s Текстовое сообщение diff --git a/app/src/main/res/values-zh-rCN/strings_conversations.xml b/app/src/main/res/values-zh-rCN/strings_conversations.xml index 023e42d53..08cad29ef 100644 --- a/app/src/main/res/values-zh-rCN/strings_conversations.xml +++ b/app/src/main/res/values-zh-rCN/strings_conversations.xml @@ -6,7 +6,7 @@ 打开设置 再按一次返回以退出 - 输入姓名、电话号码或电子邮件地址 + 输入姓名或电话号码 新建 MMS 群组 还要添加其他人吗? 新建群组对话 @@ -19,7 +19,7 @@ %1$d/%2$d 手机 %s 收件人: - 输入姓名、电话号码或电子邮件地址 + 输入姓名或电话号码 只能向电话号码发送消息 发送到 %s 输入消息 diff --git a/app/src/main/res/values-zh-rTW/strings_conversations.xml b/app/src/main/res/values-zh-rTW/strings_conversations.xml index 6d6b61844..6af7eeefb 100644 --- a/app/src/main/res/values-zh-rTW/strings_conversations.xml +++ b/app/src/main/res/values-zh-rTW/strings_conversations.xml @@ -6,7 +6,7 @@ 開啟設定 再按一次返回以退出 - 輸入名稱、電話號碼或電子郵件地址 + 輸入名稱或電話號碼 新增 MMS 群組 還要新增其他人嗎? 新增群組對話 @@ -19,7 +19,7 @@ %1$d/%2$d 手機 %s 收件者: - 輸入名稱、電話號碼或電子郵件地址 + 輸入名稱或電話號碼 僅能傳送訊息給電話號碼 傳送至 %s 輸入訊息 diff --git a/app/src/main/res/values/strings_conversations.xml b/app/src/main/res/values/strings_conversations.xml index 77ec18d98..6176bd42c 100644 --- a/app/src/main/res/values/strings_conversations.xml +++ b/app/src/main/res/values/strings_conversations.xml @@ -7,7 +7,7 @@ Press back again to exit - Type names, phone numbers, or emails + Type names or phone numbers New group MMS Anyone else? New group conversation @@ -20,7 +20,7 @@ %1$d/%2$d Mobile %s To: - Type name, phone number, or email + Type name or phone number Only phone numbers can be messaged Send to %s Message diff --git a/scripts b/scripts index 56a411695..71fb58472 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 56a411695c758e3e1ad9806b30163606788de200 +Subproject commit 71fb58472a65ac4acf174c2d009cb5590310f0cf From dad45fc08ec5b4914d22a9a6d25411d79b71f49e Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 12:31:28 +0530 Subject: [PATCH 14/16] fix: create the group on Done and show three or four initials - Next only remembers the picked people: the thread is created when the name step is finished, so Back from Add group name returns to the picker with the chips still set (as Google Messages does) and leaves no half-made group. - The group avatar now shows up to four members: pairs stack as before, three become Google Messages' triangle (26dp circles on a 48dp slot, top centred), and four sit in a 2x2 grid. Measured on the live list: a trio draws three 69px circles, top centre plus the two bottom corners. --- .../messages/ui/previews/GroupNamePreviews.kt | 20 +++++++++ .../java/com/anindra/messages/MainActivity.kt | 41 ++++++++++--------- .../com/anindra/messages/ui/Components.kt | 41 +++++++++++++++++-- .../anindra/messages/ui/GroupNameScreen.kt | 12 ++---- .../com/anindra/messages/ui/NewGroupScreen.kt | 6 ++- .../messages/ui/ConversationAvatarSpecTest.kt | 4 +- .../messages/ui/NewGroupFlowWiringTest.kt | 28 +++++++++---- scripts | 2 +- 8 files changed, 108 insertions(+), 46 deletions(-) create mode 100644 app/src/debug/java/com/anindra/messages/ui/previews/GroupNamePreviews.kt diff --git a/app/src/debug/java/com/anindra/messages/ui/previews/GroupNamePreviews.kt b/app/src/debug/java/com/anindra/messages/ui/previews/GroupNamePreviews.kt new file mode 100644 index 000000000..9f23c9add --- /dev/null +++ b/app/src/debug/java/com/anindra/messages/ui/previews/GroupNamePreviews.kt @@ -0,0 +1,20 @@ +package com.anindra.messages.ui.previews + +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewLightDark +import com.anindra.messages.ui.GroupNameScreen +import com.anindra.messages.ui.theme.MessagesTheme + +@PreviewLightDark +@Preview(name = "Add group name", showBackground = true, widthDp = 380, heightDp = 760) +@Composable +private fun AddGroupNamePreview() { + MessagesTheme(mode = "system") { + GroupNameScreen( + addresses = listOf("+15551230001", "+15551230002", "+15551230003"), + onDone = {}, + onBack = {} + ) + } +} diff --git a/app/src/main/java/com/anindra/messages/MainActivity.kt b/app/src/main/java/com/anindra/messages/MainActivity.kt index a762ec21b..0b7a51ad4 100644 --- a/app/src/main/java/com/anindra/messages/MainActivity.kt +++ b/app/src/main/java/com/anindra/messages/MainActivity.kt @@ -1586,7 +1586,8 @@ open class MainActivity : FragmentActivity() { private var navRoute by androidx.compose.runtime.mutableStateOf("list") // A group created from the New group picker waits on the naming screen // before the chat opens. - private var namingGroupId by androidx.compose.runtime.mutableStateOf(null) + /** The people picked in the group picker, carried into the naming step. */ + private var namingAddresses by androidx.compose.runtime.mutableStateOf(listOf()) private var pendingOpenAddress by androidx.compose.runtime.mutableStateOf(null) private var pendingOpenConversationId by androidx.compose.runtime.mutableStateOf(null) private var pendingShareBody by androidx.compose.runtime.mutableStateOf("") @@ -2074,7 +2075,7 @@ open class MainActivity : FragmentActivity() { "inbox" -> navRoute = "settings" "inbox-rules" -> navRoute = "inbox" "new-group" -> navRoute = "new" - "group-name" -> namingGroupId?.let { chatId = it; navRoute = "chat" } ?: run { navRoute = "list" } + "group-name" -> navRoute = "new-group" "notif-settings" -> navRoute = "advanced" "auto-delete" -> navRoute = "advanced" "links" -> navRoute = "advanced" @@ -2221,32 +2222,32 @@ open class MainActivity : FragmentActivity() { ) "new-group" -> NewGroupScreen( vm = vm, - onBack = { navRoute = "new" }, + initialChosen = namingAddresses, + onBack = { + namingAddresses = emptyList() + navRoute = "new" + }, onCreate = { addresses -> - vm.createGroup(addresses) { id -> - namingGroupId = id - navRoute = "group-name" - } + // Next only remembers the people: the + // thread is created when the name step + // is finished, so Back can return to + // the picker with the chips still set. + namingAddresses = addresses + navRoute = "group-name" } ) - "group-name" -> namingGroupId?.let { id -> - GroupNameScreen( - vm = vm, - conversationId = id, - onDone = { name -> + "group-name" -> GroupNameScreen( + addresses = namingAddresses, + onDone = { name -> + vm.createGroup(namingAddresses) { id -> if (name.isNotBlank()) vm.setGroupTitle(id, name) - chatId = id - chatSearchQuery = null - navRoute = "chat" - }, - onBack = { + namingAddresses = emptyList() chatId = id chatSearchQuery = null navRoute = "chat" } - ) - } ?: androidx.compose.foundation.layout.Box( - Modifier.fillMaxSize() + }, + onBack = { navRoute = "new-group" } ) "settings" -> if (useNewUi) SettingsScreen( vm = vm, diff --git a/app/src/main/java/com/anindra/messages/ui/Components.kt b/app/src/main/java/com/anindra/messages/ui/Components.kt index 83c75c216..faf338bfe 100644 --- a/app/src/main/java/com/anindra/messages/ui/Components.kt +++ b/app/src/main/java/com/anindra/messages/ui/Components.kt @@ -140,7 +140,7 @@ fun conversationAvatarSpec( val members = title.split(", ").map { it.trim() }.filter { it.isNotEmpty() } return when { members.size > 1 -> - ConversationAvatarSpec(title, members.take(2).mapNotNull { avatarInitials(it) }, true) + ConversationAvatarSpec(title, members.take(4).mapNotNull { avatarInitials(it) }, true) groupTitle.isNotBlank() -> ConversationAvatarSpec(groupTitle, listOfNotNull(avatarInitials(groupTitle)), true) name != address -> @@ -150,8 +150,10 @@ fun conversationAvatarSpec( } /** - * The stacked two-circle avatar Google Messages gives an unnamed group: two - * 30dp initials in a 48dp slot, the second offset to the bottom-right. + * Google Messages gives an unnamed group its members' initials: two stacked + * circles for a pair, a three-circle triangle for a trio (measured on the live + * list: 26dp circles, top centred, the other two at the bottom corners), and a + * 2x2 grid from four on. */ @Composable fun ConversationAvatar( @@ -163,7 +165,38 @@ fun ConversationAvatar( photoModel: Any? = null ) { val spec = conversationAvatarSpec(name, address, groupTitle) - if (spec.initials.size == 2) { + if (spec.initials.size >= 3) { + val dot = size * if (spec.initials.size == 3) 0.54f else 0.46f + val rings = listOf( + Alignment.TopCenter to 0, + Alignment.BottomStart to 1, + Alignment.BottomEnd to 2 + ) + Box(modifier.size(size)) { + if (spec.initials.size == 3) { + rings.forEach { (place, index) -> + PersonAvatar( + spec.key + spec.initials[index], + size = dot, + initials = spec.initials[index], + modifier = Modifier.align(place) + ) + } + } else { + listOf( + Alignment.TopStart, Alignment.TopEnd, + Alignment.BottomStart, Alignment.BottomEnd + ).forEachIndexed { index, place -> + PersonAvatar( + spec.key + spec.initials[index], + size = dot, + initials = spec.initials[index], + modifier = Modifier.align(place) + ) + } + } + } + } else if (spec.initials.size == 2) { val dot = size * 0.62f Box(modifier.size(size)) { PersonAvatar( diff --git a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt index b83aa7e51..813217bbb 100644 --- a/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/GroupNameScreen.kt @@ -50,7 +50,6 @@ import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp -import com.anindra.messages.AppViewModel import com.anindra.messages.R import com.anindra.messages.ui.theme.groupNameField import kotlinx.coroutines.Dispatchers @@ -68,22 +67,19 @@ private const val GROUP_NAME_MAX = 100 @OptIn(ExperimentalMaterial3Api::class) @Composable fun GroupNameScreen( - vm: AppViewModel, - conversationId: Long, + addresses: List, onDone: (String) -> Unit, onBack: () -> Unit ) { BackHandler(onBack = onBack) var name by remember { mutableStateOf("") } - var recipients by remember { mutableStateOf(emptyList()) } var names by remember { mutableStateOf(emptyMap()) } val nameFocus = remember { FocusRequester() } val context = LocalContext.current - LaunchedEffect(conversationId) { - recipients = vm.conversationRecipients(conversationId) + LaunchedEffect(addresses) { names = withContext(Dispatchers.IO) { - recipients.associateWith { + addresses.associateWith { com.anindra.messages.data.ContactLookup.find(context, it)?.displayName.orEmpty() } } @@ -123,7 +119,7 @@ fun GroupNameScreen( ) { // Google Messages: two people sit diagonally at 56dp; three // shrink to 48dp and stack as one above a pair. - val shown = recipients.take(3) + val shown = addresses.take(3) shown.forEachIndexed { index, address -> val x = when (shown.size) { 1 -> 0.dp diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index f642f2acf..4299ce45e 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -80,12 +80,14 @@ import com.anindra.messages.ui.theme.startChatListRow fun NewGroupScreen( vm: AppViewModel, onBack: () -> Unit, - onCreate: (List) -> Unit + onCreate: (List) -> Unit, + initialChosen: List = emptyList() ) { BackHandler(onBack = onBack) val contacts by vm.contacts.collectAsState() var query by remember { mutableStateOf("") } - var chosen by remember { mutableStateOf(listOf()) } + // Back from the naming step returns here with the picks still made. + var chosen by remember(initialChosen) { mutableStateOf(initialChosen) } val fieldFocus = remember { androidx.compose.ui.focus.FocusRequester() } // Google Messages keeps the cursor in the To field after a pick, so the diff --git a/app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt b/app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt index 51f579512..697140083 100644 --- a/app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/ConversationAvatarSpecTest.kt @@ -16,7 +16,7 @@ class ConversationAvatarSpecTest { fun anUnnamedGroupStacksTheFirstTwoMembers() { val spec = conversationAvatarSpec("Alex, Mom, Bank", "+1555", "") assertTrue(spec.isGroup) - assertEquals(listOf("A", "M"), spec.initials) + assertEquals(listOf("A", "M", "B"), spec.initials) } @Test @@ -25,7 +25,7 @@ class ConversationAvatarSpecTest { // title must stack rather than read as a group name. val spec = conversationAvatarSpec("Alex", "+1555", "Alex, Mom, Bank") assertTrue(spec.isGroup) - assertEquals(listOf("A", "M"), spec.initials) + assertEquals(listOf("A", "M", "B"), spec.initials) } @Test diff --git a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt index 795637522..f9a88dda5 100644 --- a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt @@ -63,13 +63,13 @@ class NewGroupFlowWiringTest { activity.contains("onNewGroup = { navRoute = \"new-group\" }") ) assertTrue( - "the route does not create a group", - Regex("""onCreate = \{ addresses ->[\s\S]{0,160}vm\.createGroup\(addresses\)""") + "the picker does not hand its picks to the naming step", + Regex("""onCreate = \{ addresses ->[\s\S]{0,400}namingAddresses = addresses""") .containsMatchIn(activity) ) assertTrue( "Back does not return to New conversation", - Regex("""\"new-group\" -> navRoute = \"new\"""").containsMatchIn(activity) + Regex("""onBack = \{[\s\S]{0,120}navRoute = \"new\"""").containsMatchIn(activity) ) } @@ -92,16 +92,26 @@ class NewGroupFlowWiringTest { @Test fun nextOpensTheNamingStepBeforeTheChat() { assertTrue( - "Next still opens the chat directly", - Regex("""onCreate = \{ addresses ->[\s\S]{0,400}navRoute = \"group-name\"""").containsMatchIn(activity) + "Next does not remember the picked people", + Regex("""onCreate = \{ addresses ->[\s\S]{0,400}namingAddresses = addresses[\s\S]{0,120}navRoute = \"group-name\"""").containsMatchIn(activity) ) assertTrue( - "the naming route does not open the group", - activity.contains("\"group-name\" -> namingGroupId?.let { id ->") + "the naming route does not use the picked people", + activity.contains("\"group-name\" -> GroupNameScreen(") && + activity.contains("addresses = namingAddresses") ) assertTrue( - "Done does not save the name", - Regex("""onDone = \{ name ->[\s\S]{0,120}setGroupTitle\(id, name\)""").containsMatchIn(activity) + "Done does not create the group and save the name", + Regex("""onDone = \{ name ->[\s\S]{0,160}vm\.createGroup\(namingAddresses\)[\s\S]{0,200}setGroupTitle\(id, name\)""") + .containsMatchIn(activity) + ) + assertTrue( + "Back from the name step does not return to the picker", + activity.contains("onBack = { navRoute = \"new-group\" }") + ) + assertTrue( + "the picker does not take the picks back", + activity.contains("initialChosen = namingAddresses") ) } diff --git a/scripts b/scripts index 71fb58472..fa34e80d0 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 71fb58472a65ac4acf174c2d009cb5590310f0cf +Subproject commit fa34e80d0ce85b04b261424eb53a6c22a312670d From 215322d4050e70da833e158cb2867a5ecd1c76f9 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 12:45:56 +0530 Subject: [PATCH 15/16] fix: wait a frame before refocusing the picker field The chips branch rebuilds the To field when a pick lands; requesting focus in the same effect could run before the new node was attached, so the keyboard went away and the next typed name was appended to the previous query instead of starting a new search. The effect now waits one frame first, which is what made a ten-person selection flaky. Adds scripts/test-new-group-ten.sh: ten picks, Next, name, Done, and a thread with ten recipients. --- app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt | 4 ++++ .../java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt | 2 +- scripts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt index 4299ce45e..1954c9de3 100644 --- a/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/NewGroupScreen.kt @@ -93,6 +93,10 @@ fun NewGroupScreen( // Google Messages keeps the cursor in the To field after a pick, so the // next name can be typed without tapping the field again. LaunchedEffect(chosen) { + // The field is rebuilt when the chips branch swaps in; wait for that + // node to be attached or requestFocus() is a no-op and the keyboard + // (and the typed query) goes nowhere. + androidx.compose.runtime.withFrameNanos { } runCatching { fieldFocus.requestFocus() } } diff --git a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt index f9a88dda5..3ea2d9ee7 100644 --- a/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/NewGroupFlowWiringTest.kt @@ -158,7 +158,7 @@ class NewGroupFlowWiringTest { ) assertTrue( "the field loses focus after a pick", - Regex("""LaunchedEffect\(chosen\)[\s\S]{0,120}fieldFocus\.requestFocus""").containsMatchIn(newGroup) + Regex("""LaunchedEffect\(chosen\)[\s\S]{0,300}fieldFocus\.requestFocus""").containsMatchIn(newGroup) ) } } diff --git a/scripts b/scripts index fa34e80d0..c751f5374 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit fa34e80d0ce85b04b261424eb53a6c22a312670d +Subproject commit c751f537437180d318904c2fb5733ee2a5e5298e From cde5bc1c548589d757e68e92ac0f7ef1651183a4 Mon Sep 17 00:00:00 2001 From: Anindra Date: Wed, 2 Dec 2026 15:26:58 +0530 Subject: [PATCH 16/16] test: pin the group screens to Material colour roles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No `Color(0x…)` literal appears in New conversation, the group picker or Add group name; every measured surface keeps its documented content role, and all seven role pairs clear the 4.5:1 body-text floor in light, dark and amoled (lowest 6.39:1). --- .../ui/theme/StartChatColorRolesTest.kt | 91 +++++++++++++++++++ scripts | 2 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/com/anindra/messages/ui/theme/StartChatColorRolesTest.kt diff --git a/app/src/test/java/com/anindra/messages/ui/theme/StartChatColorRolesTest.kt b/app/src/test/java/com/anindra/messages/ui/theme/StartChatColorRolesTest.kt new file mode 100644 index 000000000..284d8e3ff --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/theme/StartChatColorRolesTest.kt @@ -0,0 +1,91 @@ +package com.anindra.messages.ui.theme + +import androidx.compose.material3.ColorScheme +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.luminance +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +/** + * The group-creation screens follow Material's colour contract: only scheme + * roles, and every painted surface keeps its documented content role readable. + * The measured GM surfaces are declared once in Theme.kt, never inline here. + */ +class StartChatColorRolesTest { + + private val root: File by lazy { + generateSequence(File("").absoluteFile) { it.parentFile } + .firstOrNull { File(it, "gradle/libs.versions.toml").isFile } + ?: error("repo root not found") + } + + private fun source(path: String) = File(root, "app/src/main/java/com/anindra/messages/$path").readText() + + private val screens = listOf( + "ui/NewChatScreen.kt", + "ui/NewGroupScreen.kt", + "ui/GroupNameScreen.kt" + ) + + private fun contrast(a: Color, b: Color): Float { + val la = a.luminance() + val lb = b.luminance() + return (maxOf(la, lb) + 0.05f) / (minOf(la, lb) + 0.05f) + } + + @Test + fun noScreenPaintsABareColour() { + screens.forEach { path -> + val text = source(path) + assertFalse( + "$path hard-codes a colour instead of using a scheme role", + Regex("""Color\(0x""").containsMatchIn(text) + ) + } + } + + @Test + fun theSurfacesCarryTheirContentRoles() { + val newChat = source("ui/NewChatScreen.kt") + val newGroup = source("ui/NewGroupScreen.kt") + val naming = source("ui/GroupNameScreen.kt") + + assertTrue(newChat.contains("onStartChatAction")) + assertTrue(naming.contains("contentColor = MaterialTheme.colorScheme.onPrimary")) + assertTrue(newGroup.contains("contentColor = MaterialTheme.colorScheme.onPrimary")) + // Text on the measured surfaces reads through onSurface, not a fixed ink. + assertTrue(newGroup.contains("color = MaterialTheme.colorScheme.onSurface")) + assertTrue(naming.contains("color = MaterialTheme.colorScheme.onSurface")) + } + + @Test + fun everyRolePairMeetsBodyTextContrast() { + val schemes = mapOf( + "light" to LightColors, + "dark" to DarkColors, + "amoled" to AmoledColors + ) + schemes.forEach { (name, scheme) -> + val pairs = pairs(scheme) + pairs.forEach { (label, pair) -> + val ratio = contrast(pair.first, pair.second) + assertTrue( + "$name: $label is ${"%.2f".format(ratio)}:1, below the 4.5:1 body-text floor", + ratio >= 4.5f + ) + } + } + } + + private fun pairs(scheme: ColorScheme): List>> = listOf( + "To field text" to (scheme.onSurface to scheme.startChatField), + "recipient pill text" to (scheme.onSurface to scheme.startChatChip), + "result row text" to (scheme.onSurface to scheme.startChatListRow), + "picked row text" to (scheme.onSurface to scheme.groupPickSelected), + "group name text" to (scheme.onSurface to scheme.groupNameField), + "Create group pill" to (scheme.onStartChatAction to scheme.startChatAction), + "Next/Done pill" to (scheme.onPrimary to scheme.primary) + ) +} diff --git a/scripts b/scripts index c751f5374..3ebee23d8 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit c751f537437180d318904c2fb5733ee2a5e5298e +Subproject commit 3ebee23d8d1c7dd9f8ceace2a98095e866a15039