-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix: Avatar is not visible when the profile is disabled but the Avatar is set to public #568
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -21,20 +21,21 @@ import androidx.compose.ui.platform.LocalDensity | |
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.gravatar.AvatarQueryOptions | ||
import com.gravatar.DefaultAvatarOption | ||
import com.gravatar.ImageRating | ||
import com.gravatar.extensions.avatarUrl | ||
import com.gravatar.extensions.defaultProfile | ||
import com.gravatar.restapi.models.Profile | ||
import com.gravatar.types.Email | ||
import com.gravatar.ui.GravatarTheme | ||
import com.gravatar.ui.components.ComponentState | ||
import com.gravatar.ui.components.ProfileSummary | ||
import com.gravatar.ui.components.atomic.Avatar | ||
import com.gravatar.ui.components.atomic.ViewProfileButton | ||
import com.gravatar.ui.components.transform | ||
|
||
@Composable | ||
internal fun ProfileCard( | ||
profile: ComponentState<Profile>?, | ||
email: Email, | ||
modifier: Modifier = Modifier, | ||
avatarCacheBuster: String? = null, | ||
) { | ||
|
@@ -49,16 +50,15 @@ internal fun ProfileCard( | |
avatar = { | ||
val sizePx = with(LocalDensity.current) { 72.dp.roundToPx() } | ||
Avatar( | ||
state = profile.transform { | ||
avatarUrl( | ||
AvatarQueryOptions { | ||
preferredSize = sizePx | ||
rating = ImageRating.X | ||
}, | ||
).url(avatarCacheBuster).toString() | ||
email = email, | ||
avatarQueryOptions = AvatarQueryOptions { | ||
preferredSize = sizePx | ||
rating = ImageRating.X | ||
defaultAvatarOption = DefaultAvatarOption.Status404 | ||
}, | ||
size = 72.dp, | ||
modifier = Modifier.clip(CircleShape), | ||
cacheBuster = avatarCacheBuster, | ||
) | ||
}, | ||
viewProfile = { state -> | ||
|
@@ -106,6 +106,7 @@ private fun ProfileCardPreview() { | |
profile = ComponentState.Loaded( | ||
defaultProfile(hash = "dfadf", "John Travolta"), | ||
), | ||
email = Email("[email protected]"), | ||
modifier = Modifier.padding(20.dp), | ||
) | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -4,16 +4,23 @@ import android.content.res.Configuration | |
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import coil.compose.AsyncImage | ||
import com.gravatar.AvatarQueryOptions | ||
import com.gravatar.AvatarUrl | ||
import com.gravatar.extensions.avatarUrl | ||
import com.gravatar.extensions.defaultProfile | ||
import com.gravatar.restapi.models.Profile | ||
import com.gravatar.types.Email | ||
import com.gravatar.ui.R | ||
import com.gravatar.ui.components.ComponentState | ||
import com.gravatar.ui.components.LoadingToLoadedProfileStatePreview | ||
|
@@ -144,11 +151,70 @@ private fun EmptyAvatar(size: Dp, modifier: Modifier = Modifier) { | |
private fun Avatar(model: Any?, size: Dp, modifier: Modifier) { | ||
AsyncImage( | ||
model = model, | ||
contentDescription = "User profile image", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was hardcoded in the component, we could probably skip the waiting for the translation for this one, as it will delay the release again. |
||
contentDescription = stringResource(R.string.gravatar_ui_avatar_content_description), | ||
modifier = modifier.size(size), | ||
) | ||
} | ||
|
||
private enum class AvatarState { | ||
None, | ||
Loading, | ||
Loaded, | ||
Placeholder, | ||
} | ||
|
||
/** | ||
* Atomic Avatar composable that displays a user's avatar that is generated from the user's email address. | ||
* A skeleton overlay will be shown while loading the image. | ||
* | ||
* @param email The user's email address | ||
* @param size The size of the avatar | ||
* @param modifier Composable modifier | ||
* @param avatarQueryOptions Options to customize the avatar query | ||
* @param cacheBuster Random string value to force a cache bust | ||
*/ | ||
@Composable | ||
public fun Avatar( | ||
email: Email, | ||
size: Dp, | ||
modifier: Modifier = Modifier, | ||
avatarQueryOptions: AvatarQueryOptions? = null, | ||
cacheBuster: String? = null, | ||
) { | ||
var state by remember { mutableStateOf(AvatarState.None) } | ||
val sizePx = with(LocalDensity.current) { size.roundToPx() } | ||
Box( | ||
modifier = modifier.size(size), | ||
) { | ||
AsyncImage( | ||
model = AvatarUrl( | ||
hash = email.hash(), | ||
avatarQueryOptions = AvatarQueryOptions { | ||
preferredSize = sizePx | ||
rating = avatarQueryOptions?.rating | ||
forceDefaultAvatar = avatarQueryOptions?.forceDefaultAvatar | ||
defaultAvatarOption = avatarQueryOptions?.defaultAvatarOption | ||
}, | ||
).url(cacheBuster).toString(), | ||
contentDescription = stringResource(R.string.gravatar_ui_avatar_content_description), | ||
onLoading = { | ||
state = AvatarState.Loading | ||
}, | ||
onError = { | ||
state = AvatarState.Placeholder | ||
}, | ||
onSuccess = { | ||
state = AvatarState.Loaded | ||
}, | ||
) | ||
when (state) { | ||
AvatarState.Loading -> SkeletonAvatar(size = size) | ||
AvatarState.Placeholder -> EmptyAvatar(size = size) | ||
else -> Unit | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun AvatarPreview() { | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't have to use the cache buster on this page, but: