|
1 | 1 | package com.flipcash.app.lab.internal |
2 | 2 |
|
3 | | -import androidx.compose.foundation.layout.Arrangement |
4 | 3 | import androidx.compose.foundation.layout.Box |
5 | 4 | import androidx.compose.foundation.layout.Column |
| 5 | +import androidx.compose.foundation.layout.PaddingValues |
6 | 6 | import androidx.compose.foundation.layout.fillMaxSize |
7 | 7 | import androidx.compose.foundation.layout.fillMaxWidth |
8 | | -import androidx.compose.foundation.layout.navigationBarsPadding |
9 | 8 | import androidx.compose.foundation.layout.padding |
10 | 9 | import androidx.compose.foundation.lazy.LazyColumn |
11 | 10 | import androidx.compose.foundation.lazy.items |
12 | | -import androidx.compose.material.Text |
| 11 | +import androidx.compose.foundation.lazy.rememberLazyListState |
| 12 | +import androidx.compose.material.icons.Icons |
| 13 | +import androidx.compose.material.icons.filled.MarkEmailUnread |
| 14 | +import androidx.compose.material.icons.filled.PhonelinkErase |
| 15 | +import androidx.compose.material.icons.filled.Token |
| 16 | +import androidx.compose.material3.HorizontalDivider |
| 17 | +import androidx.compose.material3.Text |
13 | 18 | import androidx.compose.runtime.Composable |
14 | 19 | import androidx.compose.runtime.getValue |
15 | 20 | import androidx.compose.ui.Alignment |
16 | 21 | import androidx.compose.ui.Modifier |
| 22 | +import androidx.compose.ui.graphics.vector.rememberVectorPainter |
17 | 23 | import androidx.compose.ui.res.stringResource |
| 24 | +import androidx.compose.ui.unit.dp |
18 | 25 | import androidx.lifecycle.compose.collectAsStateWithLifecycle |
| 26 | +import com.flipcash.app.core.AppRoute |
| 27 | +import com.flipcash.app.core.extensions.navigateTo |
19 | 28 | import com.flipcash.app.featureflags.LocalFeatureFlags |
20 | 29 | import com.flipcash.app.featureflags.message |
21 | 30 | import com.flipcash.app.featureflags.title |
22 | 31 | import com.flipcash.features.lab.R |
| 32 | +import com.getcode.navigation.core.LocalCodeNavigator |
23 | 33 | import com.getcode.theme.CodeTheme |
| 34 | +import com.getcode.ui.components.ListItem |
24 | 35 | import com.getcode.ui.components.SettingsSwitchRow |
25 | | -import com.getcode.ui.theme.ButtonState |
26 | | -import com.getcode.ui.theme.CodeButton |
27 | | -import com.getcode.ui.theme.CodeScaffold |
| 36 | +import com.getcode.ui.components.text.SectionHeader |
| 37 | +import com.getcode.ui.core.verticalScrollStateGradient |
| 38 | +import com.getcode.ui.utils.sheetResignmentBehavior |
28 | 39 |
|
29 | 40 | @Composable |
30 | 41 | internal fun LabsScreenContent(viewModel: LabsScreenViewModel) { |
31 | 42 | val betaFlagsController = LocalFeatureFlags.current |
32 | 43 | val betaFlags by betaFlagsController.observe().collectAsStateWithLifecycle() |
33 | | - |
| 44 | + val navigator = LocalCodeNavigator.current |
34 | 45 | val isLoggedIn by viewModel.isLoggedIn.collectAsStateWithLifecycle() |
| 46 | + val isStaff by viewModel.isStaff.collectAsStateWithLifecycle() |
35 | 47 |
|
36 | | - CodeScaffold( |
37 | | - bottomBar = { |
38 | | - Column( |
39 | | - modifier = Modifier.fillMaxWidth().navigationBarsPadding(), |
40 | | - verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x2) |
| 48 | + val state = rememberLazyListState() |
| 49 | + LazyColumn( |
| 50 | + modifier = Modifier |
| 51 | + .fillMaxSize() |
| 52 | + .verticalScrollStateGradient( |
| 53 | + scrollState = state, |
| 54 | + isLongGradient = true, |
| 55 | + ).sheetResignmentBehavior(state), |
| 56 | + contentPadding = PaddingValues(bottom = CodeTheme.dimens.grid.x3), |
| 57 | + ) { |
| 58 | + item { |
| 59 | + SectionHeader(stringResource(R.string.title_settingsSectionFeatures)) |
| 60 | + } |
| 61 | + items(betaFlags, key = { it.flag.key }) { feature -> |
| 62 | + SettingsSwitchRow( |
| 63 | + title = feature.flag.title, |
| 64 | + subtitle = feature.flag.message, |
| 65 | + checked = feature.enabled |
41 | 66 | ) { |
42 | | - if (isLoggedIn) { |
43 | | - CodeButton( |
44 | | - modifier = Modifier |
45 | | - .fillMaxWidth() |
46 | | - .padding(horizontal = CodeTheme.dimens.inset), |
47 | | - text = stringResource(R.string.action_unlinkPhone), |
48 | | - buttonState = ButtonState.Subtle, |
49 | | - onClick = viewModel::unlinkPhone |
50 | | - ) |
| 67 | + betaFlagsController.set(feature.flag, !feature.enabled) |
| 68 | + } |
| 69 | + |
| 70 | + HorizontalDivider( |
| 71 | + modifier = Modifier.padding(horizontal = CodeTheme.dimens.inset), |
| 72 | + color = CodeTheme.colors.divider, |
| 73 | + thickness = 0.5.dp |
| 74 | + ) |
| 75 | + } |
51 | 76 |
|
52 | | - CodeButton( |
53 | | - modifier = Modifier |
54 | | - .fillMaxWidth() |
55 | | - .padding(horizontal = CodeTheme.dimens.inset), |
56 | | - text = stringResource(R.string.action_unlinkEmail), |
57 | | - buttonState = ButtonState.Subtle, |
58 | | - onClick = viewModel::unlinkEmail |
59 | | - ) |
| 77 | + if (betaFlags.isEmpty()) { |
| 78 | + item { |
| 79 | + Box { |
| 80 | + Column( |
| 81 | + modifier = Modifier.align(Alignment.Center), |
| 82 | + horizontalAlignment = Alignment.CenterHorizontally |
| 83 | + ) { |
| 84 | + Text( |
| 85 | + text = "\uD83D\uDE2D", |
| 86 | + style = CodeTheme.typography.displayMedium |
| 87 | + ) |
| 88 | + Text( |
| 89 | + text = stringResource(R.string.title_labsAreEmpty), |
| 90 | + style = CodeTheme.typography.textLarge, |
| 91 | + color = CodeTheme.colors.textMain |
| 92 | + ) |
| 93 | + |
| 94 | + Text( |
| 95 | + text = stringResource(R.string.subtitle_labsAreEmpty), |
| 96 | + style = CodeTheme.typography.textSmall, |
| 97 | + color = CodeTheme.colors.textSecondary, |
| 98 | + ) |
| 99 | + } |
60 | 100 | } |
61 | 101 | } |
62 | | - }, |
63 | | - ) { innerPadding -> |
64 | | - LazyColumn( |
65 | | - modifier = Modifier.fillMaxSize().padding(innerPadding), |
66 | | - ) { |
67 | | - items(betaFlags, key = { it.flag.key }) { feature -> |
68 | | - SettingsSwitchRow( |
69 | | - title = feature.flag.title, |
70 | | - subtitle = feature.flag.message, |
71 | | - checked = feature.enabled |
| 102 | + } |
| 103 | + |
| 104 | + if (isStaff) { |
| 105 | + item { SectionHeader(stringResource(R.string.title_settingsSectionDeveloper)) } |
| 106 | + item { |
| 107 | + ListItem( |
| 108 | + headline = stringResource(R.string.subtitle_settingsUserFlags), |
| 109 | + icon = rememberVectorPainter(Icons.Default.Token), |
72 | 110 | ) { |
73 | | - betaFlagsController.set(feature.flag, !feature.enabled) |
| 111 | + navigator.navigateTo(AppRoute.UserFlags) |
74 | 112 | } |
75 | 113 | } |
76 | | - if (betaFlags.isEmpty()) { |
77 | | - item { |
78 | | - Box( |
79 | | - modifier = Modifier.fillParentMaxSize() |
80 | | - ) { |
81 | | - Column( |
82 | | - modifier = Modifier.align(Alignment.Center), |
83 | | - horizontalAlignment = Alignment.CenterHorizontally |
84 | | - ) { |
85 | | - Text( |
86 | | - text = "\uD83D\uDE2D", |
87 | | - style = CodeTheme.typography.displayMedium |
88 | | - ) |
89 | | - Text( |
90 | | - text = stringResource(R.string.title_labsAreEmpty), |
91 | | - style = CodeTheme.typography.textLarge, |
92 | | - color = CodeTheme.colors.textMain |
93 | | - ) |
| 114 | + } |
94 | 115 |
|
95 | | - Text( |
96 | | - text = stringResource(R.string.subtitle_labsAreEmpty), |
97 | | - style = CodeTheme.typography.textSmall, |
98 | | - color = CodeTheme.colors.textSecondary |
99 | | - ) |
100 | | - } |
101 | | - } |
| 116 | + if (isLoggedIn) { |
| 117 | + item { SectionHeader(stringResource(R.string.title_settingsSectionAccount)) } |
| 118 | + item { |
| 119 | + ListItem( |
| 120 | + headline = stringResource(R.string.action_unlinkPhone), |
| 121 | + icon = rememberVectorPainter(Icons.Default.PhonelinkErase), |
| 122 | + ) { |
| 123 | + viewModel.unlinkPhone() |
| 124 | + } |
| 125 | + } |
| 126 | + item { |
| 127 | + ListItem( |
| 128 | + headline = stringResource(R.string.action_unlinkEmail), |
| 129 | + icon = rememberVectorPainter(Icons.Default.MarkEmailUnread), |
| 130 | + ) { |
| 131 | + viewModel.unlinkEmail() |
102 | 132 | } |
103 | 133 | } |
104 | 134 | } |
|
0 commit comments