Skip to content

Commit 1874f8b

Browse files
QE Top section updates (#664)
* Replace the icon in the View profile button * Limit ProfileCard font scale up to 1.5f * Hide email in QE when auth token provided
1 parent eba4c6f commit 1874f8b

File tree

10 files changed

+127
-71
lines changed

10 files changed

+127
-71
lines changed

gravatar-quickeditor/api/gravatar-quickeditor.api

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ public final class com/gravatar/quickeditor/ui/components/ComposableSingletons$P
233233
public final class com/gravatar/quickeditor/ui/components/ComposableSingletons$ProfileCardKt {
234234
public static final field INSTANCE Lcom/gravatar/quickeditor/ui/components/ComposableSingletons$ProfileCardKt;
235235
public static field lambda-1 Lkotlin/jvm/functions/Function3;
236-
public static field lambda-2 Lkotlin/jvm/functions/Function2;
236+
public static field lambda-2 Lkotlin/jvm/functions/Function3;
237+
public static field lambda-3 Lkotlin/jvm/functions/Function2;
237238
public fun <init> ()V
238239
public final fun getLambda-1$gravatar_quickeditor_release ()Lkotlin/jvm/functions/Function3;
239-
public final fun getLambda-2$gravatar_quickeditor_release ()Lkotlin/jvm/functions/Function2;
240+
public final fun getLambda-2$gravatar_quickeditor_release ()Lkotlin/jvm/functions/Function3;
241+
public final fun getLambda-3$gravatar_quickeditor_release ()Lkotlin/jvm/functions/Function2;
240242
}
241243

242244
public final class com/gravatar/quickeditor/ui/components/ComposableSingletons$QEButtonKt {
69.1 KB
Loading

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/ProfileCard.kt

Lines changed: 78 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.material3.Icon
2323
import androidx.compose.material3.MaterialTheme
2424
import androidx.compose.material3.minimumInteractiveComponentSize
2525
import androidx.compose.runtime.Composable
26+
import androidx.compose.runtime.CompositionLocalProvider
2627
import androidx.compose.runtime.remember
2728
import androidx.compose.ui.Alignment
2829
import androidx.compose.ui.Modifier
@@ -32,6 +33,7 @@ import androidx.compose.ui.platform.LocalDensity
3233
import androidx.compose.ui.res.painterResource
3334
import androidx.compose.ui.res.stringResource
3435
import androidx.compose.ui.tooling.preview.Preview
36+
import androidx.compose.ui.unit.Density
3537
import androidx.compose.ui.unit.dp
3638
import com.gravatar.AvatarQueryOptions
3739
import com.gravatar.DefaultAvatarOption
@@ -57,74 +59,87 @@ internal fun ProfileCard(
5759
onEditAboutClicked: () -> Unit = { },
5860
avatarCacheBuster: String? = null,
5961
) {
60-
GravatarCard(modifier) { backgroundColor ->
61-
profile?.let {
62-
Row(
63-
verticalAlignment = Alignment.Top,
64-
modifier = Modifier
65-
.fillMaxWidth()
66-
.background(backgroundColor)
67-
.padding(horizontal = 16.dp, vertical = 11.dp),
68-
) {
69-
Box(
62+
CompositionLocalProvider(
63+
LocalDensity provides Density(
64+
LocalDensity.current.density,
65+
LocalDensity.current.fontScale.coerceAtMost(1.5f),
66+
),
67+
) {
68+
GravatarCard(modifier) { backgroundColor ->
69+
profile?.let {
70+
Row(
71+
verticalAlignment = Alignment.Top,
7072
modifier = Modifier
71-
.weight(1f, fill = true),
73+
.fillMaxWidth()
74+
.background(backgroundColor)
75+
.padding(horizontal = 16.dp, vertical = 11.dp),
7276
) {
73-
ProfileSummary(
74-
state = it,
77+
Box(
7578
modifier = Modifier
76-
.background(backgroundColor),
77-
avatar = {
78-
val sizePx = with(LocalDensity.current) { 72.dp.roundToPx() }
79-
Box {
80-
Avatar(
81-
email = email,
82-
avatarQueryOptions = AvatarQueryOptions {
83-
preferredSize = sizePx
84-
rating = ImageRating.X
85-
defaultAvatarOption = DefaultAvatarOption.Status404
86-
},
87-
size = 72.dp,
88-
modifier = Modifier.clip(CircleShape),
89-
cacheBuster = avatarCacheBuster,
90-
)
91-
if (editAvatarEnabled) {
92-
EditButton(
93-
onClick = onEditAvatarClicked,
94-
backgroundColor = backgroundColor,
95-
contentAlignment = Alignment.BottomEnd,
96-
contentDescription = stringResource(
97-
R.string.gravatar_qe_edit_avatar_content_description,
98-
),
99-
modifier = Modifier
100-
.offset(12.dp, 12.dp)
101-
.align(Alignment.BottomEnd),
79+
.weight(1f, fill = true),
80+
) {
81+
ProfileSummary(
82+
state = it,
83+
modifier = Modifier
84+
.background(backgroundColor),
85+
avatar = {
86+
val sizePx = with(LocalDensity.current) { 72.dp.roundToPx() }
87+
Box {
88+
Avatar(
89+
email = email,
90+
avatarQueryOptions = AvatarQueryOptions {
91+
preferredSize = sizePx
92+
rating = ImageRating.X
93+
defaultAvatarOption = DefaultAvatarOption.Status404
94+
},
95+
size = 72.dp,
96+
modifier = Modifier.clip(CircleShape),
97+
cacheBuster = avatarCacheBuster,
10298
)
99+
if (editAvatarEnabled) {
100+
EditButton(
101+
onClick = onEditAvatarClicked,
102+
backgroundColor = backgroundColor,
103+
contentAlignment = Alignment.BottomEnd,
104+
contentDescription = stringResource(
105+
R.string.gravatar_qe_edit_avatar_content_description,
106+
),
107+
modifier = Modifier
108+
.offset(12.dp, 12.dp)
109+
.align(Alignment.BottomEnd),
110+
)
111+
}
103112
}
104-
}
105-
},
106-
viewProfile = { state ->
107-
if (state !is ComponentState.Empty) {
108-
ViewProfileButton(
109-
state = state,
110-
modifier = Modifier.height(32.dp),
111-
)
112-
}
113-
},
114-
)
115-
}
116-
if (editAboutEnabled) {
117-
EditButton(
118-
onClick = onEditAboutClicked,
119-
backgroundColor = backgroundColor,
120-
contentAlignment = Alignment.TopEnd,
121-
contentDescription = stringResource(
122-
R.string.gravatar_qe_edit_about_content_description,
123-
),
124-
modifier = Modifier
125-
.offset(x = 12.dp, y = (-12).dp)
126-
.padding(top = 5.dp),
127-
)
113+
},
114+
viewProfile = { state ->
115+
if (state !is ComponentState.Empty) {
116+
ViewProfileButton(
117+
state = state,
118+
modifier = Modifier.height(32.dp),
119+
) {
120+
Icon(
121+
painterResource(R.drawable.ic_external),
122+
tint = MaterialTheme.colorScheme.onBackground,
123+
contentDescription = "",
124+
)
125+
}
126+
}
127+
},
128+
)
129+
}
130+
if (editAboutEnabled) {
131+
EditButton(
132+
onClick = onEditAboutClicked,
133+
backgroundColor = backgroundColor,
134+
contentAlignment = Alignment.TopEnd,
135+
contentDescription = stringResource(
136+
R.string.gravatar_qe_edit_about_content_description,
137+
),
138+
modifier = Modifier
139+
.offset(x = 12.dp, y = (-12).dp)
140+
.padding(top = 5.dp),
141+
)
142+
}
128143
}
129144
}
130145
}

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/GravatarQuickEditorPage.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ internal fun GravatarQuickEditorPage(
8686
}
8787
addEditorGraph(
8888
gravatarQuickEditorParams = gravatarQuickEditorParams,
89+
showEmail = true,
8990
handleExpiredSession = true,
9091
navController = navController,
9192
updateHandler = updateHandler,
@@ -142,6 +143,7 @@ internal fun GravatarQuickEditorPage(
142143
}
143144
addEditorGraph(
144145
gravatarQuickEditorParams = gravatarQuickEditorParams,
146+
showEmail = false,
145147
handleExpiredSession = false,
146148
navController = navController,
147149
updateHandler = updateHandler,
@@ -157,6 +159,7 @@ internal fun GravatarQuickEditorPage(
157159
private fun NavGraphBuilder.addEditorGraph(
158160
navController: NavHostController,
159161
gravatarQuickEditorParams: GravatarQuickEditorParams,
162+
showEmail: Boolean,
160163
handleExpiredSession: Boolean,
161164
updateHandler: UpdateHandler,
162165
confirmDismissal: Boolean,
@@ -178,6 +181,7 @@ private fun NavGraphBuilder.addEditorGraph(
178181
) {
179182
QuickEditor(
180183
gravatarQuickEditorParams = gravatarQuickEditorParams,
184+
showEmail = showEmail,
181185
handleExpiredSession = handleExpiredSession,
182186
updateHandler = updateHandler,
183187
confirmDismissal = confirmDismissal,

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/QuickEditor.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import androidx.compose.animation.fadeOut
77
import androidx.compose.animation.togetherWith
88
import androidx.compose.foundation.layout.Box
99
import androidx.compose.foundation.layout.Column
10+
import androidx.compose.foundation.layout.Spacer
1011
import androidx.compose.foundation.layout.fillMaxWidth
12+
import androidx.compose.foundation.layout.height
1113
import androidx.compose.foundation.layout.padding
1214
import androidx.compose.material3.Surface
1315
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
@@ -38,6 +40,7 @@ import kotlinx.coroutines.withContext
3840
@Composable
3941
internal fun QuickEditor(
4042
gravatarQuickEditorParams: GravatarQuickEditorParams,
43+
showEmail: Boolean,
4144
handleExpiredSession: Boolean,
4245
updateHandler: UpdateHandler,
4346
confirmDismissal: Boolean,
@@ -50,6 +53,7 @@ internal fun QuickEditor(
5053
factory = QuickEditorViewModelFactory(
5154
gravatarQuickEditorParams = gravatarQuickEditorParams,
5255
compactWindowEnabled = windowSizeClass == WindowHeightSizeClass.COMPACT,
56+
showEmail = showEmail,
5357
),
5458
),
5559
) {
@@ -157,12 +161,14 @@ internal fun QuickEditor(
157161
Surface {
158162
Column {
159163
if (!uiState.compactWindow) {
160-
EmailLabel(
161-
email = uiState.email,
162-
modifier = Modifier
163-
.fillMaxWidth()
164-
.padding(bottom = 10.dp),
165-
)
164+
if (uiState.emailVisible) {
165+
EmailLabel(
166+
email = uiState.email,
167+
modifier = Modifier
168+
.fillMaxWidth(),
169+
)
170+
}
171+
Spacer(Modifier.height(10.dp))
166172
ProfileCard(
167173
profile = uiState.profile,
168174
email = uiState.email,

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/QuickEditorUiState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ internal data class QuickEditorUiState(
1313
val compactWindow: Boolean = false,
1414
val aboutEditorUnsavedChangesPresent: Boolean = false,
1515
val discardAboutEditorChangesDialogVisible: Boolean = false,
16+
val emailVisible: Boolean = true,
1617
) {
1718
val editAvatarButtonVisible: Boolean = pageNavigationEnabled && page == QuickEditorPage.AboutEditor
1819
val editAboutButtonVisible: Boolean = pageNavigationEnabled && page == QuickEditorPage.AvatarPicker

gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/editor/QuickEditorViewModel.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ import kotlinx.coroutines.flow.receiveAsFlow
2323
import kotlinx.coroutines.flow.update
2424
import kotlinx.coroutines.launch
2525

26+
@Suppress("LongParameterList")
2627
internal class QuickEditorViewModel(
2728
private val email: Email,
2829
private val profileRepository: ProfileRepository,
2930
private val clock: Clock,
3031
initialPage: QuickEditorPage,
3132
navigationEnabled: Boolean,
3233
compactWindowEnabled: Boolean,
34+
showEmail: Boolean,
3335
) : ViewModel() {
3436
private val _uiState = MutableStateFlow(
3537
QuickEditorUiState(
@@ -38,6 +40,7 @@ internal class QuickEditorViewModel(
3840
pageNavigationEnabled = navigationEnabled,
3941
avatarCacheBuster = clock.getTimeMillis(),
4042
compactWindow = compactWindowEnabled,
43+
emailVisible = showEmail,
4144
),
4245
)
4346
val uiState: StateFlow<QuickEditorUiState> = _uiState.asStateFlow()
@@ -144,6 +147,7 @@ internal class QuickEditorViewModel(
144147
internal class QuickEditorViewModelFactory(
145148
private val gravatarQuickEditorParams: GravatarQuickEditorParams,
146149
private val compactWindowEnabled: Boolean,
150+
private val showEmail: Boolean,
147151
) : ViewModelProvider.Factory {
148152
@Suppress("UNCHECKED_CAST")
149153
override fun <T : ViewModel> create(modelClass: Class<T>, extras: CreationExtras): T {
@@ -155,6 +159,7 @@ internal class QuickEditorViewModelFactory(
155159
initialPage = scopeConfig.initialPage,
156160
clock = SystemClock(),
157161
compactWindowEnabled = compactWindowEnabled,
162+
showEmail = showEmail,
158163
) as T
159164
}
160165
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:autoMirrored="true"
5+
android:viewportWidth="24"
6+
android:viewportHeight="24">
7+
<path
8+
android:fillColor="#101517"
9+
android:pathData="M19.5,4.5H12.5V6H16.94L10.97,11.97L12.03,13.03L18,7.06V11.5H19.5V4.5ZM6.5,5.5C5.97,5.5 5.461,5.711 5.086,6.086C4.711,6.461 4.5,6.97 4.5,7.5V17.5C4.5,18.03 4.711,18.539 5.086,18.914C5.461,19.289 5.97,19.5 6.5,19.5H16.5C17.03,19.5 17.539,19.289 17.914,18.914C18.289,18.539 18.5,18.03 18.5,17.5V14.5H17V17.5C17,17.633 16.947,17.76 16.854,17.854C16.76,17.947 16.633,18 16.5,18H6.5C6.367,18 6.24,17.947 6.146,17.854C6.053,17.76 6,17.633 6,17.5V7.5C6,7.367 6.053,7.24 6.146,7.146C6.24,7.053 6.367,7 6.5,7H9.5V5.5H6.5Z" />
10+
</vector>

gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/editor/QuickEditorTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ class QuickEditorTest : RoborazziTest() {
4242
}
4343
}
4444

45+
@Test
46+
fun quickEditorWithoutEmail() = gravatarScreenshotTest {
47+
QuickEditor(
48+
uiState = uiState.copy(emailVisible = false),
49+
onDoneClicked = { },
50+
onEditAvatarClicked = { },
51+
onEditAboutClicked = { },
52+
) {
53+
AvatarPickerComponent()
54+
}
55+
}
56+
4557
@Test
4658
fun quickEditorWithAvatarPickerWithNavigationEnabled() {
4759
gravatarScreenshotTest {

gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/editor/QuickEditorViewModelTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,6 @@ class QuickEditorViewModelTest {
241241
initialPage = initialPage,
242242
navigationEnabled = navigationEnabled,
243243
compactWindowEnabled = false,
244+
showEmail = true,
244245
)
245246
}

0 commit comments

Comments
 (0)