Skip to content

Commit 7c03008

Browse files
style(avatar): respect avatar border for TextDrawable
...since they can't resize automatically, so the border must be calculated into the radius Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent c91ac0a commit 7c03008

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

app/src/main/java/com/owncloud/android/ui/AvatarGroupLayout.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ class AvatarGroupLayout @JvmOverloads constructor(
111111
avatarRadius,
112112
resources,
113113
avatar,
114-
context
114+
context,
115+
avatarBorderSize
115116
)
116117
}
117118
}

app/src/main/java/com/owncloud/android/utils/DisplayUtils.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ public static void setAvatar(@NonNull User user, @NonNull String userId, AvatarG
460460
* @param avatarRadius the avatar radius
461461
* @param resources reference for density information
462462
* @param callContext which context is called to set the generated avatar
463+
* @param context general context
463464
*/
464465
public static void setAvatar(@NonNull User user,
465466
@NonNull String userId,
@@ -469,6 +470,30 @@ public static void setAvatar(@NonNull User user,
469470
Resources resources,
470471
Object callContext,
471472
Context context) {
473+
setAvatar(user, userId, displayName, listener, avatarRadius, resources, callContext, context, 0);
474+
}
475+
476+
/**
477+
* fetches and sets the avatar of the given account in the passed callContext
478+
*
479+
* @param user the account to be used to connect to server
480+
* @param userId the userId which avatar should be set
481+
* @param displayName displayName used to generate avatar with first char, only used as fallback
482+
* @param avatarRadius the avatar radius
483+
* @param resources reference for density information
484+
* @param callContext which context is called to set the generated avatar
485+
* @param context general context
486+
* @param avatarBorder value in case the avatar has a border, like in the case of the AvatarGroupLayout
487+
*/
488+
public static void setAvatar(@NonNull User user,
489+
@NonNull String userId,
490+
String displayName,
491+
AvatarGenerationListener listener,
492+
float avatarRadius,
493+
Resources resources,
494+
Object callContext,
495+
Context context,
496+
int avatarBorder) {
472497
if (callContext instanceof View v) {
473498
v.setContentDescription(String.valueOf(user.toPlatformAccount().hashCode()));
474499
}
@@ -495,7 +520,8 @@ public static void setAvatar(@NonNull User user,
495520
// if no one exists, show colored icon with initial char
496521
if (avatar == null) {
497522
try {
498-
avatar = TextDrawable.createAvatarByUserId(displayName, avatarRadius);
523+
avatar = TextDrawable.createAvatarByUserId(displayName,
524+
(avatarRadius - avatarBorder));
499525
} catch (Exception e) {
500526
Log_OC.e(TAG, "Error calculating RGB value for active account icon.", e);
501527
avatar = ResourcesCompat.getDrawable(resources,

0 commit comments

Comments
 (0)