fix an issue with avatars in notifications loading on the wrong thread
This commit is contained in:
parent
9df3836665
commit
fcb8a23343
@ -22,7 +22,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.BitmapFactory;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@ -38,11 +38,11 @@ import com.keylesspalace.tusky.entity.Notification;
|
|||||||
import com.keylesspalace.tusky.receiver.NotificationClearBroadcastReceiver;
|
import com.keylesspalace.tusky.receiver.NotificationClearBroadcastReceiver;
|
||||||
import com.keylesspalace.tusky.view.RoundedTransformation;
|
import com.keylesspalace.tusky.view.RoundedTransformation;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
import com.squareup.picasso.Target;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -129,28 +129,20 @@ public class NotificationMaker {
|
|||||||
builder.setContentTitle(titleForType(context, body))
|
builder.setContentTitle(titleForType(context, body))
|
||||||
.setContentText(truncateWithEllipses(bodyForType(body), 40));
|
.setContentText(truncateWithEllipses(bodyForType(body), 40));
|
||||||
|
|
||||||
Target target = new Target() {
|
//load the avatar synchronously
|
||||||
@Override
|
Bitmap accountAvatar;
|
||||||
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
|
try {
|
||||||
builder.setLargeIcon(bitmap);
|
accountAvatar = Picasso.with(context)
|
||||||
|
.load(body.account.avatar)
|
||||||
NotificationManager notificationManager = (NotificationManager)
|
.transform(new RoundedTransformation(7, 0))
|
||||||
context.getSystemService(Context.NOTIFICATION_SERVICE);
|
.get();
|
||||||
notificationManager.notify(notifyId, builder.build());
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, "error loading account avatar", e);
|
||||||
|
accountAvatar = BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
builder.setLargeIcon(accountAvatar);
|
||||||
public void onBitmapFailed(Drawable errorDrawable) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareLoad(Drawable placeHolderDrawable) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
Picasso.with(context)
|
|
||||||
.load(body.account.avatar)
|
|
||||||
.placeholder(R.drawable.avatar_default)
|
|
||||||
.transform(new RoundedTransformation(7, 0))
|
|
||||||
.into(target);
|
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
String format = context.getString(R.string.notification_title_summary);
|
String format = context.getString(R.string.notification_title_summary);
|
||||||
|
Loading…
Reference in New Issue
Block a user