@@ -4,6 +4,7 @@ import androidx.compose.animation.AnimatedContent
44import androidx.compose.animation.animateColorAsState
55import androidx.compose.foundation.background
66import androidx.compose.foundation.border
7+ import androidx.compose.foundation.clickable
78import androidx.compose.foundation.layout.Arrangement
89import androidx.compose.foundation.layout.Column
910import androidx.compose.foundation.layout.Row
@@ -15,14 +16,19 @@ import androidx.compose.foundation.shape.CircleShape
1516import androidx.compose.foundation.text.TextAutoSize
1617import androidx.compose.material3.Icon
1718import androidx.compose.material3.Text
19+ import android.content.Intent
20+ import androidx.activity.compose.rememberLauncherForActivityResult
21+ import androidx.activity.result.contract.ActivityResultContracts
1822import androidx.compose.runtime.Composable
1923import androidx.compose.runtime.getValue
2024import androidx.compose.ui.Alignment
2125import androidx.compose.ui.Modifier
2226import androidx.compose.ui.draw.clip
2327import androidx.compose.ui.res.painterResource
28+ import androidx.compose.ui.res.stringResource
2429import androidx.compose.ui.text.style.TextOverflow
2530import com.flipcash.app.contacts.ui.ContactAvatar
31+ import com.flipcash.app.core.android.IntentUtils
2632import com.flipcash.app.core.contacts.DeviceContact
2733import com.flipcash.features.messenger.R
2834import com.getcode.theme.CodeTheme
@@ -31,6 +37,7 @@ import com.getcode.theme.CodeTheme
3137internal fun ContactInfoContainer (
3238 contact : DeviceContact ? ,
3339 modifier : Modifier = Modifier ,
40+ onRefreshContact : () -> Unit = {},
3441) {
3542 Column (
3643 modifier = modifier
@@ -61,44 +68,67 @@ internal fun ContactInfoContainer(
6168 color = CodeTheme .colors.textMain,
6269 )
6370
71+ if (contact?.isUnknown == false ) {
72+ Text (
73+ modifier = Modifier .padding(top = CodeTheme .dimens.grid.x1),
74+ text = contact.displayNumber,
75+ style = CodeTheme .typography.textSmall,
76+ color = CodeTheme .colors.textSecondary,
77+ )
78+ }
79+
80+ val launcher = rememberLauncherForActivityResult(
81+ contract = ActivityResultContracts .StartActivityForResult ()
82+ ) { onRefreshContact() }
83+
6484 ContactPill (
6585 modifier = Modifier .padding(top = CodeTheme .dimens.inset),
6686 contact = contact
67- )
87+ ) {
88+ contact ? : return @ContactPill
89+ val intent = IntentUtils .openContact(contact).apply {
90+ // Remove NEW_TASK so the result callback fires when the user returns,
91+ // not immediately.
92+ flags = flags and Intent .FLAG_ACTIVITY_NEW_TASK .inv ()
93+ }
94+ launcher.launch(intent)
95+ }
6896 }
6997}
7098
7199@Composable
72100private fun ContactPill (
73101 contact : DeviceContact ? ,
74- modifier : Modifier = Modifier
102+ modifier : Modifier = Modifier ,
103+ onClick : () -> Unit ,
75104) {
76105 AnimatedContent (contact) { c ->
77106 if (c == null ) {
78107 Spacer (modifier = modifier.fillMaxWidth())
79108 return @AnimatedContent
80109 }
81110
82- val isContact = ! c.isUnknown
83111 val backgroundColor by animateColorAsState(
84- if (isContact ) CodeTheme .colors.surfaceVariant else CodeTheme .colors.warning.copy(alpha = 0.10f )
112+ if (! c.isUnknown ) CodeTheme .colors.surfaceVariant else CodeTheme .colors.warning.copy(alpha = 0.10f )
85113 )
86114
87115 val contentColor by animateColorAsState(
88- if (isContact ) CodeTheme .colors.textSecondary else CodeTheme .colors.warning
116+ if (! c.isUnknown ) CodeTheme .colors.textSecondary else CodeTheme .colors.warning
89117 )
90118
91119 Row (
92120 modifier = modifier
93121 .background(color = backgroundColor, shape = CircleShape )
122+ .clip(CircleShape )
123+ .clickable { onClick() }
94124 .padding(horizontal = CodeTheme .dimens.grid.x2, vertical = CodeTheme .dimens.grid.x1),
95125 verticalAlignment = Alignment .CenterVertically ,
96126 horizontalArrangement = Arrangement .spacedBy(CodeTheme .dimens.grid.x1)
97127 ) {
98128 Icon (
99129 modifier = Modifier .size(CodeTheme .dimens.staticGrid.x4),
100130 painter = painterResource(
101- if (isContact ) {
131+ if (! c.isUnknown ) {
102132 R .drawable.ic_existing_contact
103133 } else {
104134 R .drawable.ic_unknown_contact
@@ -109,7 +139,7 @@ private fun ContactPill(
109139 )
110140
111141 Text (
112- text = if (isContact) " From Your Contacts " else " Unknown Contact " ,
142+ text = if (! c.isUnknown) stringResource( R .string.label_fromYourContacts) else stringResource( R .string.label_addContact) ,
113143 color = contentColor,
114144 style = CodeTheme .typography.textSmall,
115145 )
0 commit comments