Modern Apps git

← Modern-Apps.git

contacts: fix SIM contact editing and slot labels (#499)

Commit
2075c36c5fcf29cb7cf3f445671bb7130966a986
Author
vayun-mathur <[email protected]>
When
2026-09-07 01:17 UTC (3 months ago)
Parents
f71fbc1

Diff

contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt b/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.ktindex 899263cb0a..078f6340e3 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/SimContacts.kt@@ -8,6 +8,7 @@ import android.net.Uri import android.telephony.SubscriptionManager import android.util.Log import androidx.core.content.ContextCompat+import com.vayunmathur.contacts.R  /**  * SIM ADN (Abbreviated Dialling Numbers) data source.@@ -177,6 +178,44 @@ object SimContactsDataSource {         }     } +    /**+     * Edits a row in place. The provider identifies the existing row by `tag`/`number` in the+     * values and replaces it with `newTag`/`newNumber`.+     *+     * Preferred over delete-then-insert, which cannot be made reliable: the ICC provider parses+     * the selection string itself and ignores selectionArgs (see [deleteSingle]).+     */+    fun updateSimContact(+        context: Context,+        old: SimContact,+        name: String,+        number: String,+        email: String? = null,+        subscriptionId: Int? = null+    ): Boolean {+        if (name.isBlank() && number.isBlank()) return false+        return try {+            val targetSubId = subscriptionId ?: old.subscriptionId+            val uri = if (targetSubId != null) Uri.parse("$BASE_URI/subId/$targetSubId") else Uri.parse(BASE_URI)+            val values = ContentValues().apply {+                put("tag", old.name)+                put("number", old.number)+                put("newTag", name)+                put("newNumber", number)+                // Unconditional: an omitted key leaves the old address in place, so clearing an+                // email would report success without changing anything.+                put("newEmails", email.orEmpty())+            }+            context.contentResolver.update(uri, values, null, null) > 0+        } catch (e: SecurityException) {+            Log.e(TAG, "SecurityException updating SIM contact", e)+            false+        } catch (e: Exception) {+            Log.e(TAG, "updateSimContact failed", e)+            false+        }+    }+     fun deleteSimContact(context: Context, simContact: SimContact): Boolean {         return try {             val uri = if (simContact.subscriptionId != null) {@@ -203,17 +242,21 @@ object SimContactsDataSource {     }      private fun deleteSingle(context: Context, uri: Uri, simContact: SimContact): Boolean {-        // ADN provider typically deletes via where tag=? AND number=?-        val variants = listOf(-            "tag=? AND number=?" to arrayOf(simContact.name, simContact.number),-            "name=? AND number=?" to arrayOf(simContact.name, simContact.number),-            "tag=? AND newTag=? AND number=? AND newNumber=?" to arrayOf(simContact.name, simContact.name, simContact.number, simContact.number),-            // Fallback: number only-            "number=?" to arrayOf(simContact.number),+        // The ICC provider parses this selection itself - splitting on "AND" then "=" and stripping+        // surrounding quotes - and never looks at selectionArgs, so a bound "?" is compared+        // literally and matches nothing. The values have to be inlined.+        val tag = simContact.name.asIccLiteral()+        val number = simContact.number.asIccLiteral()+        val variants = listOfNotNull(+            "tag=$tag AND number=$number",+            "name=$tag AND number=$number",+            // Fallback: number only. Skipped for a contact with no number, where it would become+            // number='' and match every other numberless record on the SIM.+            "number=$number".takeIf { simContact.number.isNotBlank() },         )-        for ((where, args) in variants) {+        for (where in variants) {             try {-                val count = context.contentResolver.delete(uri, where, args)+                val count = context.contentResolver.delete(uri, where, null)                 if (count > 0) return true             } catch (_: Exception) { }         }@@ -222,6 +265,13 @@ object SimContactsDataSource {         return false     } +    /**+     * Quotes a value for the ICC provider's own selection parser, which strips one leading and one+     * trailing quote and leaves the rest alone - so an apostrophe inside the value survives and+     * must not be escaped.+     */+    private fun String.asIccLiteral(): String = "'$this'"+     fun hasSim(context: Context): Boolean {         return try {             getActiveSubscriptionIds(context).isNotEmpty()@@ -274,9 +324,11 @@ object SimContactsDataSource {         }     } -    fun getSimAccountDisplayLabel(info: SimSubscriptionInfo): String {-        val slotNum = if (info.slotIndex >= 0) info.slotIndex + 1 else 1-        val base = "SIM $slotNum"+    /** 1-based SIM slot number, for display. */+    fun slotNumberFor(info: SimSubscriptionInfo): Int = if (info.slotIndex >= 0) info.slotIndex + 1 else 1++    fun getSimAccountDisplayLabel(context: Context, info: SimSubscriptionInfo): String {+        val base = context.getString(R.string.sim_slot_label, slotNumberFor(info))         val carrier = info.carrierName?.toString()?.trim()?.takeIf { it.isNotEmpty() }             ?: info.displayName?.trim()?.takeIf { it.isNotEmpty() && !it.equals(base, ignoreCase = true) }         return if (carrier != null) "$base — $carrier" else base
contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.ktindex 22b836d3e9..2f5eff6dfd 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/ContactList.kt@@ -109,6 +109,7 @@ fun ContactList(     val contacts by viewModel.contacts.collectAsStateWithLifecycle()     val groups by viewModel.groups.collectAsStateWithLifecycle()     val showAccountLabels by viewModel.showAccountLabels.collectAsStateWithLifecycle()+    val simSlotLabels by viewModel.simSlotLabels.collectAsStateWithLifecycle()     val searchQuery by viewModel.searchQuery.collectAsStateWithLifecycle()     val hasLoadedContacts by viewModel.hasLoadedContacts.collectAsStateWithLifecycle() @@ -120,6 +121,7 @@ fun ContactList(             groups = groups,             searchQuery = searchQuery,             showAccountLabels = showAccountLabels,+            accountLabels = simSlotLabels,             openContactId = when (last) {                 is Route.ContactDetail -> last.contactId                 is Route.EditContact -> last.contactId@@ -309,6 +311,7 @@ fun ContactListScreen(state: ContactListUiState, actions: ContactsActions) {                         // moment it began morphing into the detail page.                         isSelected = isSelectionMode && contact.id in selectedIds,                         showAccountLabels = state.showAccountLabels,+                        accountLabels = state.accountLabels,                         allGroups = state.groups,                         decodePhoto = actions::decodePhoto,                         embeddedInCard = true,@@ -334,6 +337,7 @@ fun ContactListScreen(state: ContactListUiState, actions: ContactsActions) {                         contact = contact,                         isSelected = isSelectionMode && contact.id in selectedIds,                         showAccountLabels = state.showAccountLabels,+                        accountLabels = state.accountLabels,                         allGroups = state.groups,                         decodePhoto = actions::decodePhoto,                         embeddedInCard = true,@@ -530,6 +534,7 @@ fun ContactItem(     showAccountLabels: Boolean,     onClick: () -> Unit,     modifier: Modifier = Modifier,+    accountLabels: Map<String, String> = emptyMap(),     allGroups: List<ContactGroup> = emptyList(),     decodePhoto: ((String) -> Bitmap?)? = null,     onLongClick: (() -> Unit)? = null,@@ -655,7 +660,8 @@ fun ContactItem(                     Spacer(Modifier.width(16.dp))                     val onDevice = stringResource(R.string.on_device)                     Text(-                        text = contact.accountName ?: onDevice,+                        text = accountLabels["${contact.accountType}|${contact.accountName}"]+                            ?: contact.accountName ?: onDevice,                         style = MaterialTheme.typography.bodySmall,                         color = MaterialTheme.colorScheme.onSurfaceVariant,                         maxLines = 1,
contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.ktindex 53c01c38a1..eb5a746152 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/EditContactPage.kt@@ -198,18 +198,20 @@ fun EditContactPage(backStack: NavBackStack<Route>, viewModel: ContactViewModel,             }              Spacer(Modifier.height(8.dp))-            AddPictureSection(-                photo = currentDraft.photo?.photo,-                viewModel = viewModel,-                onClick = {-                    pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))-                },-                removePhoto = {-                    viewModel.updateEditDraft { it.copy(photo = null) }-                },-                sharedKey = editRoute.contactId,-            )-            Spacer(Modifier.height(24.dp))+            if (!isSimAccount) {+                AddPictureSection(+                    photo = currentDraft.photo?.photo,+                    viewModel = viewModel,+                    onClick = {+                        pickMedia.launch(PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly))+                    },+                    removePhoto = {+                        viewModel.updateEditDraft { it.copy(photo = null) }+                    },+                    sharedKey = editRoute.contactId,+                )+                Spacer(Modifier.height(24.dp))+            }               // Plain Column rather than FormSection: DetailScaffold already insets its content@@ -254,20 +256,22 @@ fun EditContactPage(backStack: NavBackStack<Route>, viewModel: ContactViewModel,                         }                     },                 )-                LabeledTextField(-                    value = currentDraft.nickname,-                    onValueChange = { v -> viewModel.updateEditDraft { it.copy(nickname = v) } },-                    label = stringResource(R.string.nickname),-                    sharedTextKey = id?.let { "contact-nickname-$it" },-                    modifier = Modifier.fillMaxWidth().expandFromLine(),-                )-                LabeledTextField(-                    value = currentDraft.company,-                    onValueChange = { v -> viewModel.updateEditDraft { it.copy(company = v) } },-                    label = stringResource(R.string.company),-                    sharedTextKey = id?.let { "contact-company-$it" },-                    modifier = Modifier.fillMaxWidth().expandFromLine(),-                )+                if (!isSimAccount) {+                    LabeledTextField(+                        value = currentDraft.nickname,+                        onValueChange = { v -> viewModel.updateEditDraft { it.copy(nickname = v) } },+                        label = stringResource(R.string.nickname),+                        sharedTextKey = id?.let { "contact-nickname-$it" },+                        modifier = Modifier.fillMaxWidth().expandFromLine(),+                    )+                    LabeledTextField(+                        value = currentDraft.company,+                        onValueChange = { v -> viewModel.updateEditDraft { it.copy(company = v) } },+                        label = stringResource(R.string.company),+                        sharedTextKey = id?.let { "contact-company-$it" },+                        modifier = Modifier.fillMaxWidth().expandFromLine(),+                    )+                }             }              // A contact always offers a mobile number and a home email, even when blank, so there is@@ -350,81 +354,83 @@ fun EditContactPage(backStack: NavBackStack<Route>, viewModel: ContactViewModel,                 isMandatory = { it == homeEmailIndex },                 expandOnEnter = true,             )-            Spacer(Modifier.height(16.dp))-            val addressCtx = LocalContext.current-            FormDetailGroup(-                items = currentDraft.addresses,-                label = stringResource(R.string.addresses),-                addLabel = stringResource(R.string.add_address),-                typeOptions = listOf(CDKStructuredPostal.TYPE_HOME, CDKStructuredPostal.TYPE_WORK, CDKStructuredPostal.TYPE_OTHER, CDKStructuredPostal.TYPE_CUSTOM),-                value = { it.value },-                onValueChange = { idx, v -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l[idx] = l[idx].withValue(v) }) } },-                typeLabel = { it.typeString(addressCtx) },-                optionLabel = { opt -> ContactDetail.default<Address>().withType(opt).typeString(addressCtx) },-                onTypeChange = { idx, opt -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l[idx] = l[idx].withType(opt) }) } },-                onRemove = { idx -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l.removeAt(idx) }) } },-                onAdd = { viewModel.updateEditDraft { it.copy(addresses = it.addresses + ContactDetail.default<Address>()) } },-                currentType = { it.type },-                isCustom = { it.type == CDKStructuredPostal.TYPE_CUSTOM },-                customLabel = { it.label },-                onLabelChange = { idx, v -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l[idx] = l[idx].withLabel(v) }) } },-                customLabelText = stringResource(R.string.custom_label),-                customPlaceholder = stringResource(R.string.enter_custom_label),-                addIcon = { IconLocationOn() },-                expandOnEnter = true,-            )-            Spacer(Modifier.height(12.dp))-            Birthday(backStack, currentDraft.birthday) { v ->-                viewModel.updateEditDraft { it.copy(birthday = v) }-            }-            DateDetailsSection(-                backStack = backStack,-                details = currentDraft.dates,-                onDetailsChange = { list -> viewModel.updateEditDraft { it.copy(dates = list) } },-                icon = { IconEvent() },-                options = listOf(CDKEvent.TYPE_ANNIVERSARY, CDKEvent.TYPE_OTHER, CDKEvent.TYPE_CUSTOM)-            )-            Spacer(Modifier.height(16.dp))-            Text(-                text = stringResource(R.string.note),-                style = MaterialTheme.typography.labelMedium,-                color = MaterialTheme.colorScheme.onSurfaceVariant,-                modifier = Modifier.fillMaxWidth(),-            )-            Spacer(Modifier.height(4.dp))-            com.vayunmathur.library.ui.OdfMarkdownEditorField(-                controller = noteController,-                modifier = Modifier-                    .fillMaxWidth()-                    .heightIn(min = 96.dp)-                    .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(8.dp))-                    .padding(12.dp),-            )-            Spacer(Modifier.height(16.dp))+            if (!isSimAccount) {+                Spacer(Modifier.height(16.dp))+                val addressCtx = LocalContext.current+                FormDetailGroup(+                    items = currentDraft.addresses,+                    label = stringResource(R.string.addresses),+                    addLabel = stringResource(R.string.add_address),+                    typeOptions = listOf(CDKStructuredPostal.TYPE_HOME, CDKStructuredPostal.TYPE_WORK, CDKStructuredPostal.TYPE_OTHER, CDKStructuredPostal.TYPE_CUSTOM),+                    value = { it.value },+                    onValueChange = { idx, v -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l[idx] = l[idx].withValue(v) }) } },+                    typeLabel = { it.typeString(addressCtx) },+                    optionLabel = { opt -> ContactDetail.default<Address>().withType(opt).typeString(addressCtx) },+                    onTypeChange = { idx, opt -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l[idx] = l[idx].withType(opt) }) } },+                    onRemove = { idx -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l.removeAt(idx) }) } },+                    onAdd = { viewModel.updateEditDraft { it.copy(addresses = it.addresses + ContactDetail.default<Address>()) } },+                    currentType = { it.type },+                    isCustom = { it.type == CDKStructuredPostal.TYPE_CUSTOM },+                    customLabel = { it.label },+                    onLabelChange = { idx, v -> viewModel.updateEditDraft { it.copy(addresses = it.addresses.toMutableList().also { l -> l[idx] = l[idx].withLabel(v) }) } },+                    customLabelText = stringResource(R.string.custom_label),+                    customPlaceholder = stringResource(R.string.enter_custom_label),+                    addIcon = { IconLocationOn() },+                    expandOnEnter = true,+                )+                Spacer(Modifier.height(12.dp))+                Birthday(backStack, currentDraft.birthday) { v ->+                    viewModel.updateEditDraft { it.copy(birthday = v) }+                }+                DateDetailsSection(+                    backStack = backStack,+                    details = currentDraft.dates,+                    onDetailsChange = { list -> viewModel.updateEditDraft { it.copy(dates = list) } },+                    icon = { IconEvent() },+                    options = listOf(CDKEvent.TYPE_ANNIVERSARY, CDKEvent.TYPE_OTHER, CDKEvent.TYPE_CUSTOM)+                )+                Spacer(Modifier.height(16.dp))+                Text(+                    text = stringResource(R.string.note),+                    style = MaterialTheme.typography.labelMedium,+                    color = MaterialTheme.colorScheme.onSurfaceVariant,+                    modifier = Modifier.fillMaxWidth(),+                )+                Spacer(Modifier.height(4.dp))+                com.vayunmathur.library.ui.OdfMarkdownEditorField(+                    controller = noteController,+                    modifier = Modifier+                        .fillMaxWidth()+                        .heightIn(min = 96.dp)+                        .border(1.dp, MaterialTheme.colorScheme.outline, RoundedCornerShape(8.dp))+                        .padding(12.dp),+                )+                Spacer(Modifier.height(16.dp)) -            // Last, to match the detail page. Anything on both pages is in the same order on both, so-            // a value does not have to be hunted for after the morph, and nothing has to travel past-            // the whole form to reach its counterpart.-            val allGroups by viewModel.groups.collectAsStateWithLifecycle()-            val draftGroupIds = currentDraft.groupMemberships.map { it.groupId }.toSet()-            val memberGroups = allGroups.filter { it.id in draftGroupIds && it.name.trim().isNotEmpty() }-            val availableGroups = allGroups.filter { it.id !in draftGroupIds && it.name.trim().isNotEmpty() }-            GroupMembershipSection(-                memberGroups = memberGroups,-                availableGroups = availableGroups,-                onAddGroup = { groupId ->-                    viewModel.updateEditDraft { it.copy(-                        groupMemberships = it.groupMemberships + GroupMembership(0, groupId)-                    )}-                },-                onRemoveGroup = { groupId ->-                    viewModel.updateEditDraft { it.copy(-                        groupMemberships = it.groupMemberships.filter { gm -> gm.groupId != groupId }-                    )}-                },-                sharedId = editRoute.contactId,-            )-            Spacer(Modifier.height(16.dp))+                // Last, to match the detail page. Anything on both pages is in the same order on both, so+                // a value does not have to be hunted for after the morph, and nothing has to travel past+                // the whole form to reach its counterpart.+                val allGroups by viewModel.groups.collectAsStateWithLifecycle()+                val draftGroupIds = currentDraft.groupMemberships.map { it.groupId }.toSet()+                val memberGroups = allGroups.filter { it.id in draftGroupIds && it.name.trim().isNotEmpty() }+                val availableGroups = allGroups.filter { it.id !in draftGroupIds && it.name.trim().isNotEmpty() }+                GroupMembershipSection(+                    memberGroups = memberGroups,+                    availableGroups = availableGroups,+                    onAddGroup = { groupId ->+                        viewModel.updateEditDraft { it.copy(+                            groupMemberships = it.groupMemberships + GroupMembership(0, groupId)+                        )}+                    },+                    onRemoveGroup = { groupId ->+                        viewModel.updateEditDraft { it.copy(+                            groupMemberships = it.groupMemberships.filter { gm -> gm.groupId != groupId }+                        )}+                    },+                    sharedId = editRoute.contactId,+                )+                Spacer(Modifier.height(16.dp))+            }              Spacer(Modifier.height(16.dp))         }
contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModel.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModel.kt b/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModel.ktindex 58f6ecf5f9..9b080ccdf7 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModel.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/util/ContactViewModel.kt@@ -12,6 +12,7 @@ import androidx.collection.LruCache import androidx.core.graphics.scale import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope+import com.vayunmathur.contacts.R import com.vayunmathur.contacts.data.Address import com.vayunmathur.contacts.data.CDKEmail import com.vayunmathur.contacts.data.CDKEvent@@ -115,6 +116,19 @@ class ContactViewModel(application: Application) : AndroidViewModel(application)     fun simDisplayLabel(account: ContactAccount): String? = _simAccountLabels.value["${account.type}|${account.name}"]     fun simDisplayLabelFor(type: String?, name: String?): String? = _simAccountLabels.value["${type ?: ""}|${name ?: ""}"] +    // Short form of the above ("SIM N", no carrier) for the storage badge on a contact row, which+    // has room for a name but not a name plus a carrier.+    private val _simSlotLabels = MutableStateFlow<Map<String, String>>(emptyMap())+    val simSlotLabels: StateFlow<Map<String, String>> = _simSlotLabels.asStateFlow()++    private fun simSlotLabelsFor(infos: List<SimContactsDataSource.SimSubscriptionInfo>): Map<String, String> {+        val app = getApplication<Application>()+        return infos.associate { info ->+            "$SIM_ACCOUNT_TYPE|${SimContactsDataSource.accountNameFor(info)}" to+                app.getString(R.string.sim_slot_label, SimContactsDataSource.slotNumberFor(info))+        }+    }+     val groups: StateFlow<List<ContactGroup>> = callbackFlow {         val resolver = getApplication<Application>().contentResolver         val observer = object : android.database.ContentObserver(null) {@@ -265,9 +279,10 @@ class ContactViewModel(application: Application) : AndroidViewModel(application)             val infos = SimContactsDataSource.getSimSubscriptionInfos(app)             val labels = infos.associate { info ->                 val acc = ContactAccount(SimContactsDataSource.accountNameFor(info), SIM_ACCOUNT_TYPE)-                "${acc.type}|${acc.name}" to SimContactsDataSource.getSimAccountDisplayLabel(info)+                "${acc.type}|${acc.name}" to SimContactsDataSource.getSimAccountDisplayLabel(app, info)             }             _simAccountLabels.value = labels+            _simSlotLabels.value = simSlotLabelsFor(infos)             // Also refresh the accounts list to include current SIM accounts (in case SIM inserted/removed)             // Do it by launching loadAccounts() if needed; but we can update _accounts directly             // to avoid double query. However loadAccounts() also merges DataStore saved accounts,@@ -323,9 +338,10 @@ class ContactViewModel(application: Application) : AndroidViewModel(application)         }         val simLabels = simInfos.associate { info ->             val acc = ContactAccount(SimContactsDataSource.accountNameFor(info), SIM_ACCOUNT_TYPE)-            "${acc.type}|${acc.name}" to SimContactsDataSource.getSimAccountDisplayLabel(info)+            "${acc.type}|${acc.name}" to SimContactsDataSource.getSimAccountDisplayLabel(app, info)         }         _simAccountLabels.value = simLabels+        _simSlotLabels.value = simSlotLabelsFor(simInfos)          // Sort: SIM accounts by display label, others by name         val all = (accountSet + savedAccounts + simAccounts).toList()@@ -728,6 +744,14 @@ class ContactViewModel(application: Application) : AndroidViewModel(application)                     if (oldSc.name == name && oldSc.number == number && oldSc.emails == email && oldSc.subscriptionId == subId) {                         return true                     }+                    // Edit in place where possible. Moving a contact to a different SIM is not an+                    // in-place edit, so that still falls through to delete-then-insert.+                    if (subId == null || subId == oldSc.subscriptionId) {+                        if (SimContactsDataSource.updateSimContact(getApplication(), oldSc, name, number, email, subId)) {+                            syncFromSystem()+                            return true+                        }+                    }                     SimContactsDataSource.deleteSimContact(getApplication(), oldSc)                 }             }@@ -983,7 +1007,7 @@ class ContactViewModel(application: Application) : AndroidViewModel(application)             val nameVal = listOfNotNull(draft.namePrefix.ifEmpty { null }, draft.firstName.ifEmpty { null }, draft.middleName.ifEmpty { null }, draft.lastName.ifEmpty { null }, draft.nameSuffix.ifEmpty { null }).joinToString(" ").trim()             val phoneVal = draft.phoneNumbers.firstOrNull()?.number?.trim() ?: ""             if (nameVal.isEmpty() && phoneVal.isEmpty()) {-                onResult?.invoke(false, "Name or phone required")+                onResult?.invoke(false, getApplication<Application>().getString(R.string.sim_name_or_phone_required))                 return             }         }
contacts/src/main/java/com/vayunmathur/contacts/util/ContactsUiContract.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/util/ContactsUiContract.kt b/contacts/src/main/java/com/vayunmathur/contacts/util/ContactsUiContract.ktindex 96cc45c943..591b9fd5ce 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/util/ContactsUiContract.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/util/ContactsUiContract.kt@@ -16,6 +16,8 @@ data class ContactListUiState(     val groups: List<ContactGroup> = emptyList(),     val searchQuery: String = "",     val showAccountLabels: Boolean = true,+    /** Storage badge text per contact, keyed "accountType|accountName". Absent keys fall back to the raw account name. */+    val accountLabels: Map<String, String> = emptyMap(),     /** Contact open in the detail pane, highlighted in the list on a wide screen. */     val openContactId: Long? = null,     val showAddButton: Boolean = true,
contacts/src/main/res/values/strings.xml
diff --git a/contacts/src/main/res/values/strings.xml b/contacts/src/main/res/values/strings.xmlindex b8a52fd882..17e9b307a4 100644--- a/contacts/src/main/res/values/strings.xml+++ b/contacts/src/main/res/values/strings.xml@@ -245,6 +245,10 @@      <!-- SIM contacts (now virtual accounts) -->     <string name="sim_limited_fields_hint">SIM contacts only store name, phone, and email.</string>+    <!-- Error under the Save button in the contact editor when a SIM contact has neither a name nor a number -->+    <string name="sim_name_or_phone_required">Enter a name or a phone number</string>+    <!-- Storage label on a contact row and in the account picker, naming the SIM slot a contact lives on. %1$d is the 1-based slot number. -->+    <string name="sim_slot_label">SIM %1$d</string>     <string name="save_failed">Save failed</string>     <string name="importing">Importing…</string>