Commit b0497388 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix user avatar blink.

parent ad861a84
package chat.rocket.android.helper;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
......@@ -64,27 +65,29 @@ public class Avatar {
* render avatar into imageView.
*/
public void into(final ImageView imageView) {
Picasso.with(imageView.getContext())
.load(getImageUrl())
.into(imageView, new Callback() {
@Override public void onSuccess() {
}
Object tag = imageView.getTag();
if (tag != null && tag instanceof String) {
String username = (String) tag;
if (this.username.equals(username)) {
return;
}
}
imageView.setTag(this.username);
@Override public void onError() {
textInto(imageView);
}
});
final Context context = imageView.getContext();
Picasso.with(context)
.load(getImageUrl())
.placeholder(getTextDrawable(context))
.into(imageView);
}
private void textInto(final ImageView imageView) {
int round = (int) (4 * imageView.getContext().getResources().getDisplayMetrics().density);
private Drawable getTextDrawable(Context context) {
int round = (int) (4 * context.getResources().getDisplayMetrics().density);
imageView.setImageDrawable(TextDrawable.builder()
return TextDrawable.builder()
.beginConfig()
.useFont(Typeface.SANS_SERIF)
.endConfig()
.buildRoundRect(getInitialsForUser(username), getColorForUser(username), round));
.buildRoundRect(getInitialsForUser(username), getColorForUser(username), round);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment