Skip to content

Commit b8c3f2b

Browse files
committed
set fixed avatar sizes for requests
necessary because of nextcloud/server#31010 known issue: avatars in chat messages are too big atm Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
1 parent 98a2a62 commit b8c3f2b

15 files changed

+65
-74
lines changed

app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,13 +2188,13 @@ private void setupVideoStreamForLayout(@Nullable MediaStream mediaStream,
21882188

21892189
String urlForAvatar;
21902190
if (!TextUtils.isEmpty(userId)) {
2191-
urlForAvatar = ApiUtils.getUrlForAvatarWithName(baseUrl,
2192-
userId,
2193-
R.dimen.avatar_size_big);
2191+
urlForAvatar = ApiUtils.getUrlForAvatar(baseUrl,
2192+
userId,
2193+
true);
21942194
} else {
2195-
urlForAvatar = ApiUtils.getUrlForAvatarWithNameForGuests(baseUrl,
2196-
nick,
2197-
R.dimen.avatar_size_big);
2195+
urlForAvatar = ApiUtils.getUrlForGuestAvatar(baseUrl,
2196+
nick,
2197+
true);
21982198
}
21992199

22002200
ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(userId,

app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ private void setUpAfterConversationIsKnown() {
330330
private void setAvatarForOneToOneCall() {
331331
ImageRequest imageRequest =
332332
DisplayUtils.getImageRequestForUrl(
333-
ApiUtils.getUrlForAvatarWithName(userBeingCalled.getBaseUrl(),
334-
currentConversation.getName(),
335-
R.dimen.avatar_size_big), null);
333+
ApiUtils.getUrlForAvatar(userBeingCalled.getBaseUrl(),
334+
currentConversation.getName(),
335+
true), null);
336336

337337
ImagePipeline imagePipeline = Fresco.getImagePipeline();
338338
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, null);

app/src/main/java/com/nextcloud/talk/adapters/items/AdvancedUserItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ public void bindViewHolder(FlexibleAdapter adapter, UserItemViewHolder holder, i
138138
.setAutoPlayAnimations(true)
139139
.setImageRequest(
140140
DisplayUtils.getImageRequestForUrl(
141-
ApiUtils.getUrlForAvatarWithName(
141+
ApiUtils.getUrlForAvatar(
142142
userEntity.getBaseUrl(),
143143
participant.getActorId(),
144-
R.dimen.small_item_height),
144+
true),
145145
null))
146146
.build();
147147
holder.binding.userIcon.setController(draweeController);

app/src/main/java/com/nextcloud/talk/adapters/items/ContactItem.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ public void bindViewHolder(FlexibleAdapter adapter, ContactItemViewHolder holder
179179
.setOldController(holder.binding.avatarDraweeView.getController())
180180
.setAutoPlayAnimations(true)
181181
.setImageRequest(DisplayUtils.getImageRequestForUrl(
182-
ApiUtils.getUrlForAvatarWithNameForGuests(userEntity.getBaseUrl(),
183-
displayName,
184-
R.dimen.avatar_size),
182+
ApiUtils.getUrlForGuestAvatar(userEntity.getBaseUrl(),
183+
displayName,
184+
false),
185185
null))
186186
.build();
187187
holder.binding.avatarDraweeView.setController(draweeController);
@@ -192,9 +192,9 @@ public void bindViewHolder(FlexibleAdapter adapter, ContactItemViewHolder holder
192192
.setOldController(holder.binding.avatarDraweeView.getController())
193193
.setAutoPlayAnimations(true)
194194
.setImageRequest(DisplayUtils.getImageRequestForUrl(
195-
ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
196-
participant.getActorId(),
197-
R.dimen.avatar_size),
195+
ApiUtils.getUrlForAvatar(userEntity.getBaseUrl(),
196+
participant.getActorId(),
197+
false),
198198
null))
199199
.build();
200200
holder.binding.avatarDraweeView.setController(draweeController);

app/src/main/java/com/nextcloud/talk/adapters/items/ConversationItem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ public void bindViewHolder(FlexibleAdapter<IFlexible> adapter,
297297
.setOldController(holder.binding.dialogAvatar.getController())
298298
.setAutoPlayAnimations(true)
299299
.setImageRequest(DisplayUtils.getImageRequestForUrl(
300-
ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
301-
conversation.getName(),
302-
R.dimen.avatar_size),
300+
ApiUtils.getUrlForAvatar(userEntity.getBaseUrl(),
301+
conversation.getName(),
302+
false),
303303
userEntity))
304304
.build();
305305
holder.binding.dialogAvatar.setController(draweeController);

app/src/main/java/com/nextcloud/talk/adapters/items/MentionAutocompleteItem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ public void bindViewHolder(FlexibleAdapter<IFlexible> adapter,
157157
}
158158
} else {
159159
String avatarId = objectId;
160-
String avatarUrl = ApiUtils.getUrlForAvatarWithName(currentUser.getBaseUrl(),
161-
avatarId, R.dimen.avatar_size_big);
160+
String avatarUrl = ApiUtils.getUrlForAvatar(currentUser.getBaseUrl(),
161+
avatarId, true);
162162

163163
if (SOURCE_GUESTS.equals(source)) {
164164
avatarId = displayName;
165-
avatarUrl = ApiUtils.getUrlForAvatarWithNameForGuests(
165+
avatarUrl = ApiUtils.getUrlForGuestAvatar(
166166
currentUser.getBaseUrl(),
167167
avatarId,
168-
R.dimen.avatar_size_big);
168+
false);
169169
}
170170

171171
if (holder.binding.avatarDraweeView != null) {

app/src/main/java/com/nextcloud/talk/adapters/items/ParticipantItem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ public void bindViewHolder(FlexibleAdapter adapter, ParticipantItemViewHolder ho
168168
.setOldController(holder.binding.avatarDraweeView.getController())
169169
.setAutoPlayAnimations(true)
170170
.setImageRequest(DisplayUtils.getImageRequestForUrl(
171-
ApiUtils.getUrlForAvatarWithNameForGuests(userEntity.getBaseUrl(),
172-
displayName, R.dimen.avatar_size), null))
171+
ApiUtils.getUrlForGuestAvatar(userEntity.getBaseUrl(),
172+
displayName, false), null))
173173
.build();
174174
holder.binding.avatarDraweeView.setController(draweeController);
175175

@@ -179,8 +179,8 @@ public void bindViewHolder(FlexibleAdapter adapter, ParticipantItemViewHolder ho
179179
.setOldController(holder.binding.avatarDraweeView.getController())
180180
.setAutoPlayAnimations(true)
181181
.setImageRequest(DisplayUtils.getImageRequestForUrl(
182-
ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
183-
participant.getActorId(), R.dimen.avatar_size), null))
182+
ApiUtils.getUrlForAvatar(userEntity.getBaseUrl(),
183+
participant.getActorId(), false), null))
184184
.build();
185185
holder.binding.avatarDraweeView.setController(draweeController);
186186
}

app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ import java.util.HashMap
192192
import java.util.Objects
193193
import java.util.concurrent.ExecutionException
194194
import javax.inject.Inject
195+
import kotlin.math.roundToInt
195196

196197
@AutoInjector(NextcloudTalkApplication::class)
197198
class ChatController(args: Bundle) :
@@ -405,16 +406,11 @@ class ChatController(args: Bundle) :
405406

406407
private fun loadAvatarForStatusBar() {
407408
if (inOneToOneCall() && activity != null && conversationVoiceCallMenuItem != null) {
408-
val avatarSize = DisplayUtils.convertDpToPixel(
409-
conversationVoiceCallMenuItem?.icon!!
410-
.intrinsicWidth.toFloat(),
411-
activity
412-
).toInt()
413409

414410
val imageRequest = DisplayUtils.getImageRequestForUrl(
415-
ApiUtils.getUrlForAvatarWithNameAndPixels(
411+
ApiUtils.getUrlForAvatar(
416412
conversationUser?.baseUrl,
417-
currentConversation?.name, avatarSize / 2
413+
currentConversation?.name, true
418414
),
419415
conversationUser!!
420416
)
@@ -426,7 +422,11 @@ class ChatController(args: Bundle) :
426422
object : BaseBitmapDataSubscriber() {
427423
override fun onNewResultImpl(bitmap: Bitmap?) {
428424
if (actionBar != null && bitmap != null && resources != null) {
429-
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources!!, bitmap)
425+
426+
val avatarSize = (actionBar?.height!! / 1.5).roundToInt()
427+
val bitmapResized = Bitmap.createScaledBitmap(bitmap, avatarSize, avatarSize, false)
428+
429+
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources!!, bitmapResized)
430430
roundedBitmapDrawable.isCircular = true
431431
roundedBitmapDrawable.setAntiAlias(true)
432432
actionBar?.setIcon(roundedBitmapDrawable)

app/src/main/java/com/nextcloud/talk/controllers/ConversationInfoController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,9 @@ class ConversationInfoController(args: Bundle) :
722722
.setAutoPlayAnimations(true)
723723
.setImageRequest(
724724
DisplayUtils.getImageRequestForUrl(
725-
ApiUtils.getUrlForAvatarWithName(
725+
ApiUtils.getUrlForAvatar(
726726
conversationUser!!.baseUrl,
727-
conversation!!.name, R.dimen.avatar_size_big
727+
conversation!!.name, true
728728
),
729729
conversationUser
730730
)

app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,16 +256,12 @@ protected void onViewBound(@NonNull View view) {
256256

257257
private void loadUserAvatar(MaterialButton button) {
258258
if (getActivity() != null) {
259-
int avatarSize;
260-
261-
if (getResources() != null) {
262-
avatarSize = getResources().getDimensionPixelSize(R.dimen.avatar_size_app_bar);
263-
} else {
264-
avatarSize = (int) DisplayUtils.convertDpToPixel(30.0f, context);
265-
}
266-
267-
ImageRequest imageRequest = DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithNameAndPixels(currentUser.getBaseUrl(),
268-
currentUser.getUserId(), avatarSize), currentUser);
259+
ImageRequest imageRequest = DisplayUtils.getImageRequestForUrl(
260+
ApiUtils.getUrlForAvatar(
261+
currentUser.getBaseUrl(),
262+
currentUser.getUserId(),
263+
false),
264+
currentUser);
269265

270266
ImagePipeline imagePipeline = Fresco.getImagePipeline();
271267
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, null);

0 commit comments

Comments
 (0)