Skip to content

Commit 78aeb7c

Browse files
committed
fix: polish contact add flow
1 parent 733dec3 commit 78aeb7c

11 files changed

Lines changed: 57 additions & 33 deletions

File tree

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ fun ContentView(
385385
val hasSeenProfileIntro by settingsViewModel.hasSeenProfileIntro.collectAsStateWithLifecycle()
386386
val hasSeenContactsIntro by settingsViewModel.hasSeenContactsIntro.collectAsStateWithLifecycle()
387387
val isProfileAuthenticated by settingsViewModel.isPubkyAuthenticated.collectAsStateWithLifecycle()
388+
val hasPubkyContacts by settingsViewModel.hasPubkyContacts.collectAsStateWithLifecycle()
388389
val currentSheet by appViewModel.currentSheet.collectAsStateWithLifecycle()
389390

390391
Box(
@@ -526,6 +527,7 @@ fun ContentView(
526527
},
527528
hasSeenProfileIntro = hasSeenProfileIntro,
528529
hasSeenContactsIntro = hasSeenContactsIntro,
530+
hasContacts = hasPubkyContacts,
529531
isProfileAuthenticated = isProfileAuthenticated,
530532
modifier = Modifier.align(Alignment.TopEnd)
531533
)
@@ -933,7 +935,8 @@ private fun NavGraphBuilder.contacts(
933935
settingsViewModel: SettingsViewModel,
934936
appViewModel: AppViewModel,
935937
) {
936-
composableWithDefaultTransitions<Routes.Contacts> {
938+
composableWithDefaultTransitions<Routes.Contacts> { backStackEntry ->
939+
val route = backStackEntry.toRoute<Routes.Contacts>()
937940
val viewModel: ContactsViewModel = hiltViewModel()
938941
ContactsScreen(
939942
viewModel = viewModel,
@@ -946,6 +949,7 @@ private fun NavGraphBuilder.contacts(
946949
navController.navigateTo(Routes.AddContact(scannedData))
947950
}
948951
},
952+
openAddContactSheet = route.showAddContactSheet,
949953
)
950954
}
951955
composableWithDefaultTransitions<Routes.ContactsIntro> {
@@ -954,12 +958,14 @@ private fun NavGraphBuilder.contacts(
954958
ContactsIntroScreen(
955959
onContinue = {
956960
settingsViewModel.setHasSeenContactsIntro(true)
957-
val destination = when {
958-
isAuthenticated -> Routes.Contacts
959-
hasSeenProfileIntro -> Routes.PubkyChoice
960-
else -> Routes.ProfileIntro
961+
when {
962+
isAuthenticated -> navController.navigateTo(
963+
Routes.Contacts(showAddContactSheet = true)
964+
) { popUpTo(Routes.Home) }
965+
966+
hasSeenProfileIntro -> navController.navigateTo(Routes.PubkyChoice) { popUpTo(Routes.Home) }
967+
else -> navController.navigateTo(Routes.ProfileIntro) { popUpTo(Routes.Home) }
961968
}
962-
navController.navigateTo(destination) { popUpTo(Routes.Home) }
963969
},
964970
onBackClick = { navController.popBackStack() },
965971
)
@@ -986,7 +992,7 @@ private fun NavGraphBuilder.contacts(
986992
viewModel = viewModel,
987993
onBackClick = { navController.popBackStack() },
988994
onContactDeleted = {
989-
navController.navigateTo(Routes.Contacts) { popUpTo(Routes.Home) }
995+
navController.navigateTo(Routes.Contacts()) { popUpTo(Routes.Home) }
990996
},
991997
)
992998
}
@@ -1894,7 +1900,7 @@ sealed interface Routes {
18941900
data object LanguageSettings : Routes
18951901

18961902
@Serializable
1897-
data object Contacts : Routes
1903+
data class Contacts(val showAddContactSheet: Boolean = false) : Routes
18981904

18991905
@Serializable
19001906
data object ContactsIntro : Routes

app/src/main/java/to/bitkit/ui/components/CenteredProfileHeader.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import androidx.compose.ui.draw.clip
1313
import androidx.compose.ui.platform.testTag
1414
import androidx.compose.ui.res.painterResource
1515
import androidx.compose.ui.text.style.TextAlign
16+
import androidx.compose.ui.text.style.TextOverflow
1617
import androidx.compose.ui.tooling.preview.Preview
1718
import androidx.compose.ui.unit.dp
1819
import to.bitkit.R
@@ -67,6 +68,9 @@ fun CenteredProfileHeader(
6768

6869
Display(
6970
text = name,
71+
maxLines = 2,
72+
overflow = TextOverflow.Ellipsis,
73+
textAlign = TextAlign.Center,
7074
modifier = if (nameTestTag != null) Modifier.testTag(nameTestTag) else Modifier,
7175
)
7276

app/src/main/java/to/bitkit/ui/components/DrawerMenu.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ fun DrawerMenu(
7373
modifier: Modifier = Modifier,
7474
hasSeenProfileIntro: Boolean = false,
7575
hasSeenContactsIntro: Boolean = false,
76+
hasContacts: Boolean = false,
7677
isProfileAuthenticated: Boolean = false,
7778
) {
7879
val scope = rememberCoroutineScope()
@@ -127,14 +128,14 @@ fun DrawerMenu(
127128
},
128129
onClickContacts = {
129130
when {
130-
!hasSeenContactsIntro -> {
131+
!hasSeenContactsIntro && !hasContacts -> {
131132
onBeforeNavigate(Routes.ContactsIntro)
132133
rootNavController.navigateIfNotCurrent(Routes.ContactsIntro)
133134
}
134135

135136
isProfileAuthenticated -> {
136-
onBeforeNavigate(Routes.Contacts)
137-
rootNavController.navigateIfNotCurrent(Routes.Contacts)
137+
onBeforeNavigate(Routes.Contacts())
138+
rootNavController.navigateIfNotCurrent(Routes.Contacts())
138139
}
139140

140141
hasSeenProfileIntro -> {

app/src/main/java/to/bitkit/ui/components/ProfileEditForm.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fun ProfileEditForm(
9696
colors = AppTextFieldDefaults.transparent,
9797
modifier = Modifier
9898
.fillMaxWidth()
99-
.testTag("ProfileEditName"),
99+
.testTag("ProfileEditName")
100100
)
101101
HorizontalDivider()
102102
VerticalSpacer(12.dp)
@@ -128,7 +128,7 @@ fun ProfileEditForm(
128128
maxLines = 4,
129129
modifier = Modifier
130130
.fillMaxWidth()
131-
.testTag("ProfileEditBio"),
131+
.testTag("ProfileEditBio")
132132
)
133133

134134
VerticalSpacer(16.dp)
@@ -177,7 +177,7 @@ fun ProfileEditForm(
177177
color = Colors.White10,
178178
shape = AppShapes.small,
179179
)
180-
.testTag("ProfileEditLink_$index"),
180+
.testTag("ProfileEditLink_$index")
181181
)
182182
VerticalSpacer(8.dp)
183183
}
@@ -296,15 +296,15 @@ fun ProfileEditForm(
296296
onClick = onCancel,
297297
modifier = Modifier
298298
.weight(1f)
299-
.testTag("ProfileEditCancel"),
299+
.testTag("ProfileEditCancel")
300300
)
301301
PrimaryButton(
302302
text = stringResource(R.string.common__save),
303303
onClick = onSave,
304304
enabled = isSaveEnabled,
305305
modifier = Modifier
306306
.weight(1f)
307-
.testTag("ProfileEditSave"),
307+
.testTag("ProfileEditSave")
308308
)
309309
}
310310
VerticalSpacer(16.dp)

app/src/main/java/to/bitkit/ui/components/Text.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ fun Display(
2424
fontWeight: FontWeight = FontWeight.Black,
2525
fontSize: TextUnit = 44.sp,
2626
color: Color = MaterialTheme.colorScheme.primary,
27+
maxLines: Int = Int.MAX_VALUE,
28+
overflow: TextOverflow = if (maxLines == 1) TextOverflow.Ellipsis else TextOverflow.Clip,
2729
textAlign: TextAlign? = null,
2830
) {
2931
Text(
@@ -33,6 +35,8 @@ fun Display(
3335
fontSize = fontSize,
3436
color = color,
3537
),
38+
maxLines = maxLines,
39+
overflow = overflow,
3640
textAlign = textAlign,
3741
modifier = modifier,
3842
)

app/src/main/java/to/bitkit/ui/screens/contacts/AddContactScreen.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private fun LoadingContent(publicKey: String) {
271271
horizontalAlignment = Alignment.CenterHorizontally,
272272
modifier = Modifier
273273
.fillMaxSize()
274-
.padding(horizontal = 32.dp),
274+
.padding(horizontal = 32.dp)
275275
) {
276276
VerticalSpacer(24.dp)
277277

@@ -287,7 +287,7 @@ private fun LoadingContent(publicKey: String) {
287287
modifier = Modifier
288288
.size(80.dp)
289289
.clip(CircleShape)
290-
.background(Colors.Gray5),
290+
.background(Colors.Gray5)
291291
) {
292292
Display(
293293
text = publicKey.take(1).uppercase(),
@@ -306,7 +306,7 @@ private fun LoadingContent(publicKey: String) {
306306
contentAlignment = Alignment.Center,
307307
modifier = Modifier
308308
.weight(1f)
309-
.fillMaxWidth(),
309+
.fillMaxWidth()
310310
) {
311311
RotatingEllipses(modifier = Modifier.size(256.dp))
312312
}
@@ -391,7 +391,7 @@ private fun RotatingEllipses(modifier: Modifier = Modifier) {
391391
style = dashedStroke,
392392
)
393393
}
394-
},
394+
}
395395
) {
396396
Image(
397397
painter = painterResource(R.drawable.card),
@@ -411,7 +411,7 @@ private fun ErrorContent(
411411
verticalArrangement = Arrangement.Center,
412412
modifier = Modifier
413413
.fillMaxSize()
414-
.padding(horizontal = 32.dp),
414+
.padding(horizontal = 32.dp)
415415
) {
416416
BodyM(text = error, color = Colors.White64, textAlign = TextAlign.Center)
417417
VerticalSpacer(16.dp)
@@ -434,7 +434,7 @@ private fun LoadedContent(
434434
horizontalAlignment = Alignment.CenterHorizontally,
435435
modifier = Modifier
436436
.fillMaxSize()
437-
.padding(horizontal = 32.dp),
437+
.padding(horizontal = 32.dp)
438438
) {
439439
VerticalSpacer(24.dp)
440440

app/src/main/java/to/bitkit/ui/screens/contacts/ContactsScreen.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import androidx.compose.runtime.Composable
1717
import androidx.compose.runtime.LaunchedEffect
1818
import androidx.compose.runtime.getValue
1919
import androidx.compose.runtime.mutableStateOf
20-
import androidx.compose.runtime.remember
20+
import androidx.compose.runtime.saveable.rememberSaveable
2121
import androidx.compose.runtime.setValue
2222
import androidx.compose.ui.Alignment
2323
import androidx.compose.ui.Modifier
@@ -59,6 +59,7 @@ fun ContactsScreen(
5959
onClickContact: (String) -> Unit,
6060
onAddContact: (String) -> Unit = {},
6161
onScanQr: () -> Unit = {},
62+
openAddContactSheet: Boolean = false,
6263
) {
6364
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
6465

@@ -72,6 +73,7 @@ fun ContactsScreen(
7273
onSearchTextChange = { viewModel.onSearchTextChange(it) },
7374
onAddContact = onAddContact,
7475
onScanQr = onScanQr,
76+
openAddContactSheet = openAddContactSheet,
7577
)
7678
}
7779

@@ -84,8 +86,9 @@ private fun Content(
8486
onSearchTextChange: (String) -> Unit,
8587
onAddContact: (String) -> Unit,
8688
onScanQr: () -> Unit,
89+
openAddContactSheet: Boolean,
8790
) {
88-
var showAddContactSheet by remember { mutableStateOf(false) }
91+
var showAddContactSheet by rememberSaveable { mutableStateOf(openAddContactSheet) }
8992

9093
ScreenColumn {
9194
AppTopBar(
@@ -329,6 +332,7 @@ private fun Preview() {
329332
onSearchTextChange = {},
330333
onAddContact = {},
331334
onScanQr = {},
335+
openAddContactSheet = false,
332336
)
333337
}
334338
}

app/src/main/java/to/bitkit/ui/screens/profile/EditProfileScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private fun AvatarSection(
224224
.clip(CircleShape)
225225
.background(Colors.Gray5)
226226
.testTag("EditProfileAvatar")
227-
.clickable(onClick = onClick),
227+
.clickable(onClick = onClick)
228228
) {
229229
when {
230230
newAvatarUri != null -> AsyncImage(

app/src/main/java/to/bitkit/ui/screens/profile/ProfileScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private fun ProfileBody(
217217
color = Colors.White64,
218218
modifier = Modifier
219219
.fillMaxWidth()
220-
.testTag("ProfileViewTagsHeader"),
220+
.testTag("ProfileViewTagsHeader")
221221
)
222222
VerticalSpacer(8.dp)
223223
@OptIn(ExperimentalLayoutApi::class)

app/src/main/java/to/bitkit/viewmodels/SettingsViewModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class SettingsViewModel @Inject constructor(
110110
}
111111

112112
val isPubkyAuthenticated = pubkyRepo.isAuthenticated
113+
val hasPubkyContacts = pubkyRepo.contacts.map { it.isNotEmpty() }
114+
.asStateFlow(initialValue = false)
113115

114116
val quickPayIntroSeen = settingsStore.data.map { it.quickPayIntroSeen }
115117
.asStateFlow(initialValue = false)

0 commit comments

Comments
 (0)