@@ -3,7 +3,10 @@ package app.fyreplace.fyreplace.ui.screens
3
3
import androidx.compose.foundation.clickable
4
4
import androidx.compose.foundation.layout.Arrangement
5
5
import androidx.compose.foundation.layout.Column
6
+ import androidx.compose.foundation.layout.Row
6
7
import androidx.compose.foundation.layout.fillMaxWidth
8
+ import androidx.compose.foundation.layout.imePadding
9
+ import androidx.compose.foundation.layout.padding
7
10
import androidx.compose.foundation.rememberScrollState
8
11
import androidx.compose.foundation.verticalScroll
9
12
import androidx.compose.material.icons.Icons
@@ -12,22 +15,27 @@ import androidx.compose.material.icons.outlined.Code
12
15
import androidx.compose.material.icons.outlined.Info
13
16
import androidx.compose.material.icons.outlined.Lock
14
17
import androidx.compose.material.icons.outlined.Shield
18
+ import androidx.compose.material3.Button
15
19
import androidx.compose.material3.Icon
16
20
import androidx.compose.material3.ListItem
17
21
import androidx.compose.material3.Text
22
+ import androidx.compose.material3.TextField
18
23
import androidx.compose.runtime.Composable
19
24
import androidx.compose.runtime.getValue
20
25
import androidx.compose.ui.Modifier
21
26
import androidx.compose.ui.res.dimensionResource
27
+ import androidx.compose.ui.res.integerResource
22
28
import androidx.compose.ui.res.stringResource
23
29
import androidx.compose.ui.tooling.preview.Preview
24
30
import androidx.hilt.navigation.compose.hiltViewModel
25
31
import androidx.lifecycle.SavedStateHandle
26
32
import androidx.lifecycle.compose.collectAsStateWithLifecycle
27
33
import app.fyreplace.api.data.User
28
34
import app.fyreplace.fyreplace.R
35
+ import app.fyreplace.fyreplace.extensions.codePointCount
29
36
import app.fyreplace.fyreplace.fakes.FakeApiResolver
30
37
import app.fyreplace.fyreplace.fakes.FakeEventBus
38
+ import app.fyreplace.fyreplace.fakes.FakeResourceResolver
31
39
import app.fyreplace.fyreplace.fakes.FakeStoreResolver
32
40
import app.fyreplace.fyreplace.fakes.placeholder
33
41
import app.fyreplace.fyreplace.ui.theme.AppTheme
@@ -43,8 +51,11 @@ fun SettingsScreen(viewModel: SettingsViewModel = hiltViewModel()) {
43
51
modifier = Modifier
44
52
.fillMaxWidth()
45
53
.verticalScroll(rememberScrollState())
54
+ .imePadding()
46
55
) {
47
56
val currentUser by viewModel.currentUser.collectAsStateWithLifecycle()
57
+ val bio by viewModel.bio.collectAsStateWithLifecycle()
58
+ val canUpdateBio by viewModel.canUpdateBio.collectAsStateWithLifecycle()
48
59
val isLoadingAvatar by viewModel.isLoadingAvatar.collectAsStateWithLifecycle()
49
60
50
61
Section (stringResource(R .string.settings_profile_header)) {
@@ -64,6 +75,41 @@ fun SettingsScreen(viewModel: SettingsViewModel = hiltViewModel()) {
64
75
)
65
76
}
66
77
78
+ Section (stringResource(R .string.settings_bio_header)) {
79
+ TextField (
80
+ value = bio,
81
+ maxLines = 10 ,
82
+ placeholder = { Text (stringResource(R .string.settings_bio_placeholder)) },
83
+ supportingText = {
84
+ Text (
85
+ stringResource(
86
+ R .string.settings_bio_length,
87
+ bio.codePointCount,
88
+ integerResource(R .integer.bio_max_length)
89
+ )
90
+ )
91
+ },
92
+ onValueChange = viewModel::updatePendingBio,
93
+ modifier = Modifier
94
+ .fillMaxWidth()
95
+ .padding(horizontal = dimensionResource(R .dimen.spacing_medium))
96
+ )
97
+
98
+ Row (
99
+ horizontalArrangement = Arrangement .Center ,
100
+ modifier = Modifier
101
+ .fillMaxWidth()
102
+ .padding(top = dimensionResource(R .dimen.spacing_small))
103
+ ) {
104
+ Button (
105
+ enabled = canUpdateBio,
106
+ onClick = viewModel::updateBio
107
+ ) {
108
+ Text (stringResource(R .string.settings_bio_save))
109
+ }
110
+ }
111
+ }
112
+
67
113
Section (stringResource(R .string.settings_about_header)) {
68
114
LinkListItem (
69
115
title = stringResource(R .string.settings_about_website),
@@ -100,8 +146,10 @@ fun SettingsScreenPreview() {
100
146
viewModel = SettingsViewModel (
101
147
SavedStateHandle ().apply {
102
148
this [SettingsViewModel ::currentUser.name] = User .placeholder
149
+ this [SettingsViewModel ::bio.name] = User .placeholder.bio
103
150
},
104
151
FakeEventBus (),
152
+ FakeResourceResolver (mapOf (R .integer.bio_max_length to 100 )),
105
153
FakeStoreResolver (),
106
154
FakeApiResolver ()
107
155
)
0 commit comments