mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 04:55:29 +03:00
Update the way we set images
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
0bcae26e55
commit
68ba88daca
7 changed files with 82 additions and 111 deletions
|
@ -39,6 +39,7 @@ import com.nextcloud.talk.events.MoreMenuClickEvent;
|
|||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.rooms.Conversation;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -159,28 +160,18 @@ public class CallItem extends AbstractFlexibleItem<CallItem.RoomItemViewHolder>
|
|||
holder.moreMenuButton.setContentDescription(String.format(resources.getString(R.string
|
||||
.nc_description_more_menu_group), conversation.getDisplayName()));
|
||||
|
||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_people_group_white_24px)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(holder.avatarImageView.getFrontImageView());
|
||||
holder.avatarImageView.setFrontImageBitmap(DisplayUtils
|
||||
.getRoundedBitmapFromVectorDrawableResource(resources,
|
||||
R.drawable.ic_people_group_white_24px));
|
||||
holder.avatarImageView.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case ROOM_PUBLIC_CALL:
|
||||
holder.moreMenuButton.setContentDescription(String.format(resources.getString(R.string
|
||||
.nc_description_more_menu_public), conversation.getDisplayName()));
|
||||
|
||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_link_white_24px)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(holder.avatarImageView.getFrontImageView());
|
||||
holder.avatarImageView.setFrontImageBitmap(DisplayUtils
|
||||
.getRoundedBitmapFromVectorDrawableResource(resources,
|
||||
R.drawable.ic_link_white_24px));
|
||||
holder.avatarImageView.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -43,6 +43,7 @@ import com.nextcloud.talk.models.database.UserEntity;
|
|||
import com.nextcloud.talk.models.json.chat.ChatMessage;
|
||||
import com.nextcloud.talk.models.json.rooms.Conversation;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -220,25 +221,15 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
|||
switch (objectType) {
|
||||
case "share:password":
|
||||
shouldLoadAvatar = false;
|
||||
GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_file_password_request)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(holder.dialogAvatar);
|
||||
holder.dialogAvatar.setImageBitmap(DisplayUtils
|
||||
.getRoundedBitmapFromVectorDrawableResource(context.getResources(),
|
||||
R.drawable.ic_file_password_request));
|
||||
break;
|
||||
case "file":
|
||||
shouldLoadAvatar = false;
|
||||
GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_file_icon)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(holder.dialogAvatar);
|
||||
holder.dialogAvatar.setImageBitmap(DisplayUtils
|
||||
.getRoundedBitmapFromVectorDrawableResource(context.getResources(),
|
||||
R.drawable.ic_file_icon));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -270,25 +261,14 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
|
|||
}
|
||||
break;
|
||||
case ROOM_GROUP_CALL:
|
||||
|
||||
GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_people_group_white_24px)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(holder.dialogAvatar);
|
||||
holder.dialogAvatar.setImageBitmap(DisplayUtils
|
||||
.getRoundedBitmapFromVectorDrawableResource(context.getResources(),
|
||||
R.drawable.ic_people_group_white_24px));
|
||||
break;
|
||||
case ROOM_PUBLIC_CALL:
|
||||
GlideApp.with(context)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_link_white_24px)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(holder.dialogAvatar);
|
||||
holder.dialogAvatar.setImageBitmap(DisplayUtils
|
||||
.getRoundedBitmapFromVectorDrawableResource(context.getResources(),
|
||||
R.drawable.ic_link_white_24px));
|
||||
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.nextcloud.talk.models.database.UserEntity;
|
|||
import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter;
|
||||
import com.nextcloud.talk.models.json.participants.Participant;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -161,14 +162,9 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
|
|||
}
|
||||
} else if ("groups".equals(participant.getSource())) {
|
||||
|
||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_people_group_white_24px)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(flipView.getFrontImageView());
|
||||
flipView.setFrontImageBitmap(DisplayUtils
|
||||
.getRoundedBitmapFromVectorDrawableResource(NextcloudTalkApplication.getSharedApplication().getResources(),
|
||||
R.drawable.ic_people_group_white_24px));
|
||||
}
|
||||
|
||||
if (!isEnabled()) {
|
||||
|
|
|
@ -28,7 +28,6 @@ import android.content.Intent;
|
|||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.Editable;
|
||||
|
@ -52,9 +51,6 @@ import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
|||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.facebook.imagepipeline.common.RotationOptions;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.activities.MagicCallActivity;
|
||||
import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder;
|
||||
|
@ -322,14 +318,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
|||
adapter = new MessagesListAdapter<>(conversationUser.getUserId(), messageHolders, new ImageLoader() {
|
||||
@Override
|
||||
public void loadImage(SimpleDraweeView imageView, String url) {
|
||||
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
.setRotationOptions(RotationOptions.autoRotate())
|
||||
.disableDiskCache()
|
||||
.build();
|
||||
|
||||
DraweeController draweeController = Fresco.newDraweeControllerBuilder()
|
||||
.setImageRequest(request)
|
||||
.setImageRequest(DisplayUtils.getImageRequestForUrl(url))
|
||||
.setControllerListener(DisplayUtils.getImageControllerListener(imageView))
|
||||
.setOldController(imageView.getController())
|
||||
.setAutoPlayAnimations(true)
|
||||
|
|
|
@ -27,15 +27,12 @@ import android.view.LayoutInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.load.model.GlideUrl;
|
||||
import com.bumptech.glide.load.model.LazyHeaders;
|
||||
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.interfaces.DraweeController;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.adapters.items.UserItem;
|
||||
import com.nextcloud.talk.api.NcApi;
|
||||
|
@ -48,8 +45,8 @@ import com.nextcloud.talk.models.json.participants.ParticipantsOverall;
|
|||
import com.nextcloud.talk.models.json.rooms.Conversation;
|
||||
import com.nextcloud.talk.models.json.rooms.RoomOverall;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.glide.GlideApp;
|
||||
import com.nextcloud.talk.utils.preferencestorage.DatabaseStorageModule;
|
||||
import com.yarolegovich.mp.MaterialChoicePreference;
|
||||
import com.yarolegovich.mp.MaterialPreferenceCategory;
|
||||
|
@ -96,7 +93,7 @@ public class ConversationInfoController extends BaseController {
|
|||
MaterialPreferenceCategory nameCategoryView;
|
||||
|
||||
@BindView(R.id.avatar_image)
|
||||
ImageView conversationAvatarImageView;
|
||||
SimpleDraweeView conversationAvatarImageView;
|
||||
|
||||
@BindView(R.id.display_name_text)
|
||||
TextView conversationDisplayName;
|
||||
|
@ -334,51 +331,31 @@ public class ConversationInfoController extends BaseController {
|
|||
}
|
||||
|
||||
private void loadConversationAvatar() {
|
||||
int avatarSize = getResources().getDimensionPixelSize(R.dimen.avatar_size_big);
|
||||
|
||||
switch (conversation.getType()) {
|
||||
case ROOM_TYPE_ONE_TO_ONE_CALL:
|
||||
if (!TextUtils.isEmpty(conversation.getName())) {
|
||||
GlideUrl glideUrl = new GlideUrl(ApiUtils.getUrlForAvatarWithName(conversationUser.getBaseUrl(),
|
||||
conversation.getName(), R.dimen.avatar_size), new LazyHeaders.Builder()
|
||||
.setHeader("Accept", "image/*")
|
||||
.setHeader("User-Agent", ApiUtils.getUserAgent())
|
||||
.build());
|
||||
|
||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(glideUrl)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(conversationAvatarImageView);
|
||||
|
||||
DraweeController draweeController = Fresco.newDraweeControllerBuilder()
|
||||
.setOldController(conversationAvatarImageView.getController())
|
||||
.setAutoPlayAnimations(true)
|
||||
.setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(conversationUser.getBaseUrl(),
|
||||
conversation.getName(), R.dimen.avatar_size_big)))
|
||||
.build();
|
||||
conversationAvatarImageView.setController(draweeController);
|
||||
}
|
||||
break;
|
||||
case ROOM_GROUP_CALL:
|
||||
|
||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_people_group_white_24px)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(conversationAvatarImageView);
|
||||
conversationAvatarImageView.getHierarchy().setPlaceholderImage(DisplayUtils
|
||||
.getRoundedBitmapDrawableFromVectorDrawableResource(getResources(),
|
||||
R.drawable.ic_people_group_white_24px));
|
||||
break;
|
||||
case ROOM_PUBLIC_CALL:
|
||||
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.load(R.drawable.ic_link_white_24px)
|
||||
.centerInside()
|
||||
.override(avatarSize, avatarSize)
|
||||
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
|
||||
.into(conversationAvatarImageView);
|
||||
conversationAvatarImageView.getHierarchy().setPlaceholderImage(DisplayUtils
|
||||
.getRoundedBitmapDrawableFromVectorDrawableResource(getResources(),
|
||||
R.drawable.ic_link_white_24px));
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,13 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.Spannable;
|
||||
|
@ -48,7 +52,11 @@ import android.widget.TextView;
|
|||
|
||||
import com.facebook.drawee.controller.ControllerListener;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.facebook.imagepipeline.common.RotationOptions;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
|
||||
|
@ -100,6 +108,34 @@ public class DisplayUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static Bitmap getRoundedBitmapFromVectorDrawableResource(Resources resources, int resource) {
|
||||
VectorDrawable vectorDrawable = (VectorDrawable) resources.getDrawable(resource);
|
||||
Bitmap bitmap = getBitmap(vectorDrawable);
|
||||
new RoundAsCirclePostprocessor(true).process(bitmap);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static Drawable getRoundedBitmapDrawableFromVectorDrawableResource(Resources resources, int resource) {
|
||||
return new BitmapDrawable(getRoundedBitmapFromVectorDrawableResource(resources, resource));
|
||||
}
|
||||
|
||||
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
|
||||
Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
|
||||
vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||
vectorDrawable.draw(canvas);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static ImageRequest getImageRequestForUrl(String url) {
|
||||
return ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
|
||||
.setProgressiveRenderingEnabled(true)
|
||||
.setRotationOptions(RotationOptions.autoRotate())
|
||||
.disableDiskCache()
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ControllerListener getImageControllerListener(SimpleDraweeView draweeView) {
|
||||
return new ControllerListener() {
|
||||
@Override
|
||||
|
|
|
@ -58,10 +58,11 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/avatar_image"
|
||||
android:layout_width="@dimen/avatar_size_big"
|
||||
android:layout_height="@dimen/avatar_size_big"
|
||||
apc:roundAsCircle="true"
|
||||
android:layout_centerHorizontal="true" />
|
||||
|
||||
<TextView
|
||||
|
|
Loading…
Reference in a new issue