set fixed avatar sizes for requests

necessary because of https://github.com/nextcloud/server/pull/31010

known issue: avatars in chat messages are too big atm

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-03-02 09:26:15 +01:00
parent 9dd8dc451a
commit 508f519468
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
15 changed files with 65 additions and 74 deletions

View file

@ -2188,13 +2188,13 @@ public class CallActivity extends CallBaseActivity {
String urlForAvatar;
if (!TextUtils.isEmpty(userId)) {
urlForAvatar = ApiUtils.getUrlForAvatarWithName(baseUrl,
userId,
R.dimen.avatar_size_big);
urlForAvatar = ApiUtils.getUrlForAvatar(baseUrl,
userId,
true);
} else {
urlForAvatar = ApiUtils.getUrlForAvatarWithNameForGuests(baseUrl,
nick,
R.dimen.avatar_size_big);
urlForAvatar = ApiUtils.getUrlForGuestAvatar(baseUrl,
nick,
true);
}
ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(userId,

View file

@ -330,9 +330,9 @@ public class CallNotificationActivity extends CallBaseActivity {
private void setAvatarForOneToOneCall() {
ImageRequest imageRequest =
DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(userBeingCalled.getBaseUrl(),
currentConversation.getName(),
R.dimen.avatar_size_big), null);
ApiUtils.getUrlForAvatar(userBeingCalled.getBaseUrl(),
currentConversation.getName(),
true), null);
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, null);

View file

@ -138,10 +138,10 @@ public class AdvancedUserItem extends AbstractFlexibleItem<AdvancedUserItem.User
.setAutoPlayAnimations(true)
.setImageRequest(
DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(
ApiUtils.getUrlForAvatar(
userEntity.getBaseUrl(),
participant.getActorId(),
R.dimen.small_item_height),
true),
null))
.build();
holder.binding.userIcon.setController(draweeController);

View file

@ -179,9 +179,9 @@ public class ContactItem extends AbstractFlexibleItem<ContactItem.ContactItemVie
.setOldController(holder.binding.avatarDraweeView.getController())
.setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithNameForGuests(userEntity.getBaseUrl(),
displayName,
R.dimen.avatar_size),
ApiUtils.getUrlForGuestAvatar(userEntity.getBaseUrl(),
displayName,
false),
null))
.build();
holder.binding.avatarDraweeView.setController(draweeController);
@ -192,9 +192,9 @@ public class ContactItem extends AbstractFlexibleItem<ContactItem.ContactItemVie
.setOldController(holder.binding.avatarDraweeView.getController())
.setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
participant.getActorId(),
R.dimen.avatar_size),
ApiUtils.getUrlForAvatar(userEntity.getBaseUrl(),
participant.getActorId(),
false),
null))
.build();
holder.binding.avatarDraweeView.setController(draweeController);

View file

@ -297,9 +297,9 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
.setOldController(holder.binding.dialogAvatar.getController())
.setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
conversation.getName(),
R.dimen.avatar_size),
ApiUtils.getUrlForAvatar(userEntity.getBaseUrl(),
conversation.getName(),
false),
userEntity))
.build();
holder.binding.dialogAvatar.setController(draweeController);

View file

@ -157,15 +157,15 @@ public class MentionAutocompleteItem extends AbstractFlexibleItem<ParticipantIte
}
} else {
String avatarId = objectId;
String avatarUrl = ApiUtils.getUrlForAvatarWithName(currentUser.getBaseUrl(),
avatarId, R.dimen.avatar_size_big);
String avatarUrl = ApiUtils.getUrlForAvatar(currentUser.getBaseUrl(),
avatarId, true);
if (SOURCE_GUESTS.equals(source)) {
avatarId = displayName;
avatarUrl = ApiUtils.getUrlForAvatarWithNameForGuests(
avatarUrl = ApiUtils.getUrlForGuestAvatar(
currentUser.getBaseUrl(),
avatarId,
R.dimen.avatar_size_big);
false);
}
if (holder.binding.avatarDraweeView != null) {

View file

@ -168,8 +168,8 @@ public class ParticipantItem extends AbstractFlexibleItem<ParticipantItem.Partic
.setOldController(holder.binding.avatarDraweeView.getController())
.setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithNameForGuests(userEntity.getBaseUrl(),
displayName, R.dimen.avatar_size), null))
ApiUtils.getUrlForGuestAvatar(userEntity.getBaseUrl(),
displayName, false), null))
.build();
holder.binding.avatarDraweeView.setController(draweeController);
@ -179,8 +179,8 @@ public class ParticipantItem extends AbstractFlexibleItem<ParticipantItem.Partic
.setOldController(holder.binding.avatarDraweeView.getController())
.setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
participant.getActorId(), R.dimen.avatar_size), null))
ApiUtils.getUrlForAvatar(userEntity.getBaseUrl(),
participant.getActorId(), false), null))
.build();
holder.binding.avatarDraweeView.setController(draweeController);
}

View file

@ -192,6 +192,7 @@ import java.util.HashMap
import java.util.Objects
import java.util.concurrent.ExecutionException
import javax.inject.Inject
import kotlin.math.roundToInt
@AutoInjector(NextcloudTalkApplication::class)
class ChatController(args: Bundle) :
@ -405,16 +406,11 @@ class ChatController(args: Bundle) :
private fun loadAvatarForStatusBar() {
if (inOneToOneCall() && activity != null && conversationVoiceCallMenuItem != null) {
val avatarSize = DisplayUtils.convertDpToPixel(
conversationVoiceCallMenuItem?.icon!!
.intrinsicWidth.toFloat(),
activity
).toInt()
val imageRequest = DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithNameAndPixels(
ApiUtils.getUrlForAvatar(
conversationUser?.baseUrl,
currentConversation?.name, avatarSize / 2
currentConversation?.name, true
),
conversationUser!!
)
@ -426,7 +422,11 @@ class ChatController(args: Bundle) :
object : BaseBitmapDataSubscriber() {
override fun onNewResultImpl(bitmap: Bitmap?) {
if (actionBar != null && bitmap != null && resources != null) {
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources!!, bitmap)
val avatarSize = (actionBar?.height!! / 1.5).roundToInt()
val bitmapResized = Bitmap.createScaledBitmap(bitmap, avatarSize, avatarSize, false)
val roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(resources!!, bitmapResized)
roundedBitmapDrawable.isCircular = true
roundedBitmapDrawable.setAntiAlias(true)
actionBar?.setIcon(roundedBitmapDrawable)

View file

@ -722,9 +722,9 @@ class ConversationInfoController(args: Bundle) :
.setAutoPlayAnimations(true)
.setImageRequest(
DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(
ApiUtils.getUrlForAvatar(
conversationUser!!.baseUrl,
conversation!!.name, R.dimen.avatar_size_big
conversation!!.name, true
),
conversationUser
)

View file

@ -256,16 +256,12 @@ public class ConversationsListController extends BaseController implements Searc
private void loadUserAvatar(MaterialButton button) {
if (getActivity() != null) {
int avatarSize;
if (getResources() != null) {
avatarSize = getResources().getDimensionPixelSize(R.dimen.avatar_size_app_bar);
} else {
avatarSize = (int) DisplayUtils.convertDpToPixel(30.0f, context);
}
ImageRequest imageRequest = DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithNameAndPixels(currentUser.getBaseUrl(),
currentUser.getUserId(), avatarSize), currentUser);
ImageRequest imageRequest = DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatar(
currentUser.getBaseUrl(),
currentUser.getUserId(),
false),
currentUser);
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, null);

View file

@ -379,11 +379,13 @@ public class NotificationWorker extends Worker {
notificationBuilder.setOnlyAlertOnce(true);
if (decryptedPushMessage.getNotificationUser().getType().equals("user") || decryptedPushMessage.getNotificationUser().getType().equals("guest")) {
String avatarUrl = ApiUtils.getUrlForAvatarWithName(signatureVerification.getUserEntity().getBaseUrl(), decryptedPushMessage.getNotificationUser().getId(), R.dimen.avatar_size);
String avatarUrl = ApiUtils.getUrlForAvatar(signatureVerification.getUserEntity().getBaseUrl(),
decryptedPushMessage.getNotificationUser().getId(), false);
if (decryptedPushMessage.getNotificationUser().getType().equals("guest")) {
avatarUrl = ApiUtils.getUrlForAvatarWithNameForGuests(signatureVerification.getUserEntity().getBaseUrl(),
decryptedPushMessage.getNotificationUser().getName(), R.dimen.avatar_size);
avatarUrl = ApiUtils.getUrlForGuestAvatar(signatureVerification.getUserEntity().getBaseUrl(),
decryptedPushMessage.getNotificationUser().getName(),
false);
}
ImageRequest imageRequest =

View file

@ -290,10 +290,10 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
@Override
public String getAvatar() {
if (getActorType().equals("users")) {
return ApiUtils.getUrlForAvatarWithName(getActiveUser().getBaseUrl(), actorId, R.dimen.avatar_size);
return ApiUtils.getUrlForAvatar(getActiveUser().getBaseUrl(), actorId, true);
} else if (getActorType().equals("bridged")) {
return ApiUtils.getUrlForAvatarWithName(getActiveUser().getBaseUrl(), "bridge-bot",
R.dimen.avatar_size);
return ApiUtils.getUrlForAvatar(getActiveUser().getBaseUrl(), "bridge-bot",
true);
} else {
String apiId =
NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest);
@ -301,7 +301,7 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image
if (!TextUtils.isEmpty(getActorDisplayName())) {
apiId = getActorDisplayName();
}
return ApiUtils.getUrlForAvatarWithNameForGuests(getActiveUser().getBaseUrl(), apiId, R.dimen.avatar_size);
return ApiUtils.getUrlForGuestAvatar(getActiveUser().getBaseUrl(), apiId, true);
}
}
};

View file

@ -129,10 +129,10 @@ public class ChooseAccountDialogFragment extends DialogFragment {
.setOldController(binding.currentAccount.userIcon.getController())
.setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(
ApiUtils.getUrlForAvatar(
user.getBaseUrl(),
user.getUserId(),
R.dimen.small_item_height),
false),
null))
.build();
binding.currentAccount.userIcon.setController(draweeController);

View file

@ -44,6 +44,8 @@ public class ApiUtils {
public static final int APIv2 = 2;
public static final int APIv3 = 3;
public static final int APIv4 = 4;
public static final int AVATAR_SIZE_BIG = 512;
public static final int AVATAR_SIZE_SMALL = 64;
private static final String TAG = "ApiUtils";
private static final String ocsApiVersion = "/ocs/v2.php";
private static final String spreedApiVersion = "/apps/spreed/api/v1";
@ -347,22 +349,13 @@ public class ApiUtils {
return "/status.php";
}
public static String getUrlForAvatarWithNameAndPixels(String baseUrl, String name, int avatarSize) {
public static String getUrlForAvatar(String baseUrl, String name, boolean requestBigSize) {
int avatarSize = requestBigSize ? AVATAR_SIZE_BIG : AVATAR_SIZE_SMALL;
return baseUrl + "/index.php/avatar/" + Uri.encode(name) + "/" + avatarSize;
}
public static String getUrlForAvatarWithName(String baseUrl, String name, @DimenRes int avatarSize) {
avatarSize = Math.round(NextcloudTalkApplication
.Companion.getSharedApplication().getResources().getDimension(avatarSize));
return baseUrl + "/index.php/avatar/" + Uri.encode(name) + "/" + avatarSize;
}
public static String getUrlForAvatarWithNameForGuests(String baseUrl, String name,
@DimenRes int avatarSize) {
avatarSize = Math.round(NextcloudTalkApplication
.Companion.getSharedApplication().getResources().getDimension(avatarSize));
public static String getUrlForGuestAvatar(String baseUrl, String name, boolean requestBigSize) {
int avatarSize = requestBigSize ? AVATAR_SIZE_BIG : AVATAR_SIZE_SMALL;
return baseUrl + "/index.php/avatar/guest/" + Uri.encode(name) + "/" + avatarSize;
}

View file

@ -318,11 +318,11 @@ public class DisplayUtils {
chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
if (!isCall) {
String url = ApiUtils.getUrlForAvatarWithName(conversationUser.getBaseUrl(), id, R.dimen.avatar_size_big);
String url = ApiUtils.getUrlForAvatar(conversationUser.getBaseUrl(), id, true);
if ("guests".equals(type) || "guest".equals(type)) {
url = ApiUtils.getUrlForAvatarWithNameForGuests(
url = ApiUtils.getUrlForGuestAvatar(
conversationUser.getBaseUrl(),
String.valueOf(label), R.dimen.avatar_size_big);
String.valueOf(label), true);
}
ImageRequest imageRequest = getImageRequestForUrl(url, null);
ImagePipeline imagePipeline = Fresco.getImagePipeline();
@ -572,7 +572,7 @@ public class DisplayUtils {
avatarId = user.getUsername();
}
String avatarString = ApiUtils.getUrlForAvatarWithName(user.getBaseUrl(), avatarId, R.dimen.avatar_size_big);
String avatarString = ApiUtils.getUrlForAvatar(user.getBaseUrl(), avatarId, true);
// clear cache
if (deleteCache) {