-
Notifications
You must be signed in to change notification settings - Fork 246
Fixes #381: Removes picasso library and uses glide library instead #384
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
} else { | ||
narrowListener.onNarrow(new NarrowFilterStream(Stream.getByName(zulipApp, | ||
messageHeaderParent.getStream()), null), | ||
|
@@ -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 | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about displaying the default gravatar in this onException ? As this method will be called on every onBindViewHolder so we need to make sure these are taking minimal time! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change!