mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix(contact-import): streamline shared contact handling (#2828)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
a2b89d7a91
commit
9d1f5f48ec
3 changed files with 11 additions and 12 deletions
|
|
@ -630,7 +630,7 @@ constructor(
|
|||
get() = _sharedContactRequested.asStateFlow()
|
||||
|
||||
fun setSharedContactRequested(sharedContact: AdminProtos.SharedContact?) {
|
||||
viewModelScope.launch { _sharedContactRequested.value = sharedContact }
|
||||
_sharedContactRequested.value = sharedContact
|
||||
}
|
||||
|
||||
fun addSharedContact(sharedContact: AdminProtos.SharedContact) =
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ fun AddContactFAB(
|
|||
model: UIViewModel = hiltViewModel(),
|
||||
onSharedContactImport: (AdminProtos.SharedContact) -> Unit = {},
|
||||
) {
|
||||
val contactToImport: AdminProtos.SharedContact? by model.sharedContactRequested.collectAsStateWithLifecycle(null)
|
||||
val scannedContact: AdminProtos.SharedContact? by model.sharedContactRequested.collectAsStateWithLifecycle(null)
|
||||
|
||||
val barcodeLauncher =
|
||||
rememberLauncherForActivityResult(ScanContract()) { result ->
|
||||
|
|
@ -108,8 +108,8 @@ fun AddContactFAB(
|
|||
}
|
||||
}
|
||||
|
||||
if (contactToImport != null) {
|
||||
val nodeNum = contactToImport?.nodeNum
|
||||
scannedContact?.let { contactToImport ->
|
||||
val nodeNum = scannedContact?.nodeNum
|
||||
val nodes by model.unfilteredNodeList.collectAsState()
|
||||
val node = nodes.find { it.num == nodeNum }
|
||||
SimpleAlertDialog(
|
||||
|
|
@ -118,16 +118,16 @@ fun AddContactFAB(
|
|||
Column {
|
||||
if (node != null) {
|
||||
Text(text = stringResource(R.string.import_known_shared_contact_text))
|
||||
if (node.user.publicKey.size() > 0 && node.user.publicKey != contactToImport?.user?.publicKey) {
|
||||
if (node.user.publicKey.size() > 0 && node.user.publicKey != contactToImport.user?.publicKey) {
|
||||
Text(
|
||||
text = stringResource(R.string.public_key_changed),
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
}
|
||||
HorizontalDivider()
|
||||
Text(text = compareUsers(node.user, contactToImport!!.user))
|
||||
Text(text = compareUsers(node.user, contactToImport.user))
|
||||
} else {
|
||||
Text(text = userFieldsToString(contactToImport!!.user))
|
||||
Text(text = userFieldsToString(contactToImport.user))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -135,7 +135,7 @@ fun AddContactFAB(
|
|||
onDismiss = { model.setSharedContactRequested(null) },
|
||||
confirmText = stringResource(R.string.import_label),
|
||||
onConfirm = {
|
||||
onSharedContactImport(contactToImport!!)
|
||||
onSharedContactImport(contactToImport)
|
||||
model.setSharedContactRequested(null)
|
||||
},
|
||||
)
|
||||
|
|
@ -155,9 +155,7 @@ fun AddContactFAB(
|
|||
|
||||
LaunchedEffect(cameraPermissionState.status) {
|
||||
if (cameraPermissionState.status.isGranted) {
|
||||
// If permission was granted as a result of a request, and not initially,
|
||||
// we might want to trigger the scan. However, simple auto-triggering on grant
|
||||
// might not always be desired UX. For now, rely on user re-click if needed.
|
||||
zxingScan()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue