-
-
Notifications
You must be signed in to change notification settings - Fork 310
⚒️🎨 Migrate Profile to Composable #5943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44dc2d7
style(profile): Migrate Profile to Composable
AndyScherzinger 09238c9
fix: cleanup code removing unused variables and parameters
AndyScherzinger 5fd472c
feat: Migrate scope dialog to compose and also migrate ProfileActivit…
AndyScherzinger 1b2372a
style: centge avatar section in landscape mode
AndyScherzinger 15535b5
style: Move profile enablement to list
AndyScherzinger 8a0849e
chore: Migrate to AsyncImage
AndyScherzinger 32d8ddf
feat: Add caching to avatar
AndyScherzinger 6564f27
ci(lint): Update lowered lint score
AndyScherzinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
app/src/main/java/com/nextcloud/talk/profile/AvatarSection.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * Nextcloud Talk - Android Client | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: GPL-3.0-or-later | ||
| */ | ||
| package com.nextcloud.talk.profile | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.shape.CircleShape | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.FilledTonalIconButton | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.layout.ContentScale | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.style.TextOverflow | ||
| import androidx.compose.ui.unit.Dp | ||
| import androidx.compose.ui.unit.dp | ||
| import coil.compose.AsyncImage | ||
| import coil.request.ImageRequest | ||
| import com.nextcloud.talk.R | ||
| import com.nextcloud.talk.utils.ApiUtils | ||
|
|
||
| @Composable | ||
| private fun AvatarImage(state: ProfileUiState, avatarSize: Dp) { | ||
| val user = state.currentUser | ||
| val url = ApiUtils.getUrlForAvatar(user?.baseUrl,state.currentUser?.userId, true) | ||
| val model = ImageRequest.Builder(LocalContext.current) | ||
| .data(url) | ||
| .crossfade(true) | ||
| .build() | ||
|
|
||
| AsyncImage( | ||
| model = model, | ||
| contentDescription = stringResource(R.string.avatar), | ||
| contentScale = ContentScale.Crop, | ||
| placeholder = painterResource(R.drawable.account_circle_96dp), | ||
| error = painterResource(R.drawable.account_circle_96dp), | ||
| modifier = Modifier | ||
| .size(avatarSize) | ||
| .clip(CircleShape) | ||
| ) | ||
| } | ||
|
AndyScherzinger marked this conversation as resolved.
|
||
|
|
||
| @Composable | ||
| fun AvatarSection(state: ProfileUiState, callbacks: ProfileCallbacks, modifier: Modifier) { | ||
| Column(modifier = modifier.padding(top = 16.dp), horizontalAlignment = Alignment.CenterHorizontally) { | ||
| AvatarImage(state, 96.dp) | ||
| if (state.showAvatarButtons) { | ||
| AvatarButtonsRow(callbacks = callbacks, modifier = Modifier.padding(top = 8.dp, bottom = 8.dp)) | ||
| } | ||
| if (state.displayName.isNotEmpty()) { | ||
| Spacer(modifier = Modifier.height(8.dp)) | ||
| Text( | ||
| text = state.displayName, | ||
| style = MaterialTheme.typography.titleLarge, | ||
| maxLines = 1, | ||
| overflow = TextOverflow.Ellipsis, | ||
| modifier = Modifier.padding(horizontal = 16.dp) | ||
| ) | ||
| } | ||
| if (state.baseUrl.isNotEmpty()) { | ||
| Text( | ||
| text = state.baseUrl, | ||
| style = MaterialTheme.typography.bodyMedium, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| maxLines = 2, | ||
| overflow = TextOverflow.Ellipsis, | ||
| modifier = Modifier.padding(horizontal = 16.dp, vertical = 2.dp) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| private fun AvatarButtonsRow(callbacks: ProfileCallbacks, modifier: Modifier = Modifier) { | ||
| val buttonShape = RoundedCornerShape(12.dp) | ||
| Row( | ||
| modifier = modifier, | ||
| horizontalArrangement = Arrangement.spacedBy(8.dp) | ||
| ) { | ||
| FilledTonalIconButton( | ||
| onClick = callbacks.onAvatarUploadClick, | ||
| modifier = Modifier.size(40.dp), | ||
| shape = buttonShape | ||
| ) { | ||
| Icon( | ||
| painter = painterResource(R.drawable.upload), | ||
| contentDescription = stringResource(R.string.upload_new_avatar_from_device) | ||
| ) | ||
| } | ||
| FilledTonalIconButton( | ||
| onClick = callbacks.onAvatarChooseClick, | ||
| modifier = Modifier.size(40.dp), | ||
| shape = buttonShape | ||
| ) { | ||
| Icon( | ||
| painter = painterResource(R.drawable.ic_folder), | ||
| contentDescription = stringResource(R.string.choose_avatar_from_cloud) | ||
| ) | ||
| } | ||
| FilledTonalIconButton( | ||
| onClick = callbacks.onAvatarCameraClick, | ||
| modifier = Modifier.size(40.dp), | ||
| shape = buttonShape | ||
| ) { | ||
| Icon( | ||
| painter = painterResource(R.drawable.ic_baseline_photo_camera_24), | ||
| contentDescription = stringResource(R.string.set_avatar_from_camera) | ||
| ) | ||
| } | ||
| FilledTonalIconButton( | ||
| onClick = callbacks.onAvatarDeleteClick, | ||
| modifier = Modifier.size(40.dp), | ||
| shape = buttonShape | ||
| ) { | ||
| Icon( | ||
| painter = painterResource(R.drawable.trashbin), | ||
| contentDescription = stringResource(R.string.delete_avatar) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.