Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Fixes #381: Removes picasso library and uses glide library instead #384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ dependencies {
compile 'com.j256.ormlite:ormlite-android:5.0'
compile 'commons-lang:commons-lang:2.6'
compile 'org.ccil.cowan.tagsoup:tagsoup:1.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
//noinspection GradleCompatible
compile 'com.android.support:customtabs:23.3.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.j256.ormlite.stmt.UpdateBuilder;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.zulip.android.R;
import com.zulip.android.ZulipApp;
import com.zulip.android.filters.NarrowFilterPM;
Expand Down Expand Up @@ -120,7 +122,7 @@ public void onItemClick(int viewId, int position) {
Person[] recipientArray = messageHeaderParent.getRecipients(zulipApp);
narrowListener.onNarrow(new NarrowFilterPM(Arrays.asList(recipientArray)),
messageHeaderParent.getMessageId());
narrowListener.onNarrowFillSendBoxPrivate(recipientArray,false);
narrowListener.onNarrowFillSendBoxPrivate(recipientArray, false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change!

} else {
narrowListener.onNarrow(new NarrowFilterStream(Stream.getByName(zulipApp,
messageHeaderParent.getStream()), null),
Expand Down Expand Up @@ -386,7 +388,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int pos
final String url = message.extractImageUrl(zulipApp);
if (url != null) {
messageHolder.contentImageContainer.setVisibility(View.VISIBLE);
Picasso.with(context).load(url)
Glide.with(context).load(url)
.into(messageHolder.contentImage);

messageHolder.contentImageContainer
Expand All @@ -395,7 +397,7 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int pos
public void onClick(View view) {
Intent i = new Intent(zulipApp.getApplicationContext(), PhotoViewActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(Intent.EXTRA_TEXT , url);
i.putExtra(Intent.EXTRA_TEXT, url);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this chagne!

zulipApp.startActivity(i);
((Activity) context).overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
Expand Down Expand Up @@ -484,6 +486,27 @@ private void setUpTime(Message message, MessageHolder messageHolder) {


private void setUpGravatar(final Message message, final MessageHolder messageHolder) {

int hMapKey = message.getSender().getId();
int avatarColor;

// check if current sender has already been allotted a randomly generated color
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these empty lines!

if (defaultAvatarColorHMap.containsKey(hMapKey)) {

avatarColor = defaultAvatarColorHMap.get(hMapKey);

} else {
// generate a random color for current sender id
avatarColor = getRandomColor(Color.rgb(255, 255, 255));

// add sender id and randomly generated color to hashmap
defaultAvatarColorHMap.put(hMapKey, avatarColor);

}
// square default avatar drawable
final GradientDrawable defaultAvatar = (GradientDrawable) ContextCompat.getDrawable(context, R.drawable.default_avatar);
defaultAvatar.setColor(avatarColor);

//Setup Gravatar
Bitmap gravatarImg = ((ZulipActivity) context).getGravatars().get(message.getSender().getEmail());
if (gravatarImg != null) {
Expand All @@ -495,41 +518,29 @@ private void setUpGravatar(final Message message, final MessageHolder messageHol
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
35, resources.getDisplayMetrics());


String url = message.getSender().getAvatarURL() + "&s=" + px;
url = UrlHelper.addHost(url);

Picasso.with(context)
Glide
.with(context)
.load(url)
.placeholder(android.R.drawable.stat_notify_error)
.error(android.R.drawable.presence_online)
.into(messageHolder.gravatar, new Callback() {
.error(defaultAvatar)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public void onSuccess() {
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about displaying the default gravatar in this onException ?
And using a placeholder like before?

As this method will be called on every onBindViewHolder so we need to make sure these are taking minimal time!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far i know, to display an error placeholder default Avatar the onException method must return false.
Check out this https://futurestud.io/tutorials/glide-exceptions-debugging-and-error-handling

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine but see this we are initiating defaultAvatar even if the gravatar is loaded which is not needed, hence we can display the default blank (solid coloured square) only when an error is occurred!


return false;
}

@Override
public void onError() {
int hMapKey = message.getSender().getId();
int avatarColor;

// check if current sender has already been allotted a randomly generated color
if (defaultAvatarColorHMap.containsKey(hMapKey)) {
avatarColor = defaultAvatarColorHMap.get(hMapKey);
} else {
// generate a random color for current sender id
avatarColor = getRandomColor(Color.rgb(255, 255, 255));

// add sender id and randomly generated color to hashmap
defaultAvatarColorHMap.put(hMapKey, avatarColor);
}
// square default avatar drawable
final GradientDrawable defaultAvatar = (GradientDrawable) ContextCompat.getDrawable(context, R.drawable.default_avatar);
defaultAvatar.setColor(avatarColor);
messageHolder.gravatar.setImageDrawable(defaultAvatar);
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

return false;
}
});
})

.into(messageHolder.gravatar);
}
}

Expand Down