Speed up AvatarProvider.
This commit is contained in:
parent
847651ead7
commit
553da1e7e8
2 changed files with 14 additions and 6 deletions
|
@ -174,7 +174,8 @@ public final class AvatarUtil {
|
||||||
|
|
||||||
final GlideRequest<T> request = glideRequest.load(photo)
|
final GlideRequest<T> request = glideRequest.load(photo)
|
||||||
.error(getFallback(context, recipient, targetSize))
|
.error(getFallback(context, recipient, targetSize))
|
||||||
.diskCacheStrategy(DiskCacheStrategy.ALL);
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
||||||
|
.override(targetSize);
|
||||||
|
|
||||||
if (recipient.shouldBlurAvatar()) {
|
if (recipient.shouldBlurAvatar()) {
|
||||||
BlurTransformation blur = new BlurTransformation(context, 0.25f, BlurTransformation.MAX_RADIUS);
|
BlurTransformation blur = new BlurTransformation(context, 0.25f, BlurTransformation.MAX_RADIUS);
|
||||||
|
@ -191,7 +192,7 @@ public final class AvatarUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Drawable getFallback(@NonNull Context context, @NonNull Recipient recipient, int targetSize) {
|
private static Drawable getFallback(@NonNull Context context, @NonNull Recipient recipient, int targetSize) {
|
||||||
String name = Optional.ofNullable(recipient.getDisplayName(context)).orElse("");
|
String name = Optional.of(recipient.getDisplayName(context)).orElse("");
|
||||||
|
|
||||||
return new GeneratedContactPhoto(name, R.drawable.ic_profile_outline_40, targetSize).asDrawable(context, recipient.getAvatarColor());
|
return new GeneratedContactPhoto(name, R.drawable.ic_profile_outline_40, targetSize).asDrawable(context, recipient.getAvatarColor());
|
||||||
}
|
}
|
||||||
|
@ -211,22 +212,26 @@ public final class AvatarUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable Bitmap await() throws InterruptedException {
|
public @Nullable Bitmap await() throws InterruptedException {
|
||||||
if (countDownLatch.await(10, TimeUnit.SECONDS)) {
|
Log.d(TAG, "AvatarTarget#await:");
|
||||||
|
if (countDownLatch.await(1, TimeUnit.SECONDS)) {
|
||||||
return bitmap.get();
|
return bitmap.get();
|
||||||
} else {
|
} else {
|
||||||
|
Log.w(TAG, "AvatarTarget#await: Failed to load avatar in time! Returning null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
||||||
Log.d(TAG, "onResourceReady");
|
Log.d(TAG, "AvatarTarget#onResourceReady:");
|
||||||
bitmap.set(resource);
|
bitmap.set(resource);
|
||||||
countDownLatch.countDown();
|
countDownLatch.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
public void onLoadFailed(@Nullable Drawable errorDrawable) {
|
||||||
|
Log.d(TAG, "AvatarTarget#onLoadFailed:");
|
||||||
|
|
||||||
if (errorDrawable == null) {
|
if (errorDrawable == null) {
|
||||||
throw new AssertionError("Expected an error drawable.");
|
throw new AssertionError("Expected an error drawable.");
|
||||||
}
|
}
|
||||||
|
@ -238,7 +243,10 @@ public final class AvatarUtil {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadCleared(@Nullable Drawable placeholder) {
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
||||||
|
Log.d(TAG, "AvatarTarget#onLoadCleared:");
|
||||||
|
|
||||||
|
bitmap.set(null);
|
||||||
|
countDownLatch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class CallNotificationBuilder {
|
||||||
builder.setCategory(NotificationCompat.CATEGORY_CALL);
|
builder.setCategory(NotificationCompat.CATEGORY_CALL);
|
||||||
builder.setFullScreenIntent(pendingIntent, true);
|
builder.setFullScreenIntent(pendingIntent, true);
|
||||||
|
|
||||||
Person person = ConversationUtil.buildPersonWithoutIcon(context, recipient);
|
Person person = ConversationUtil.buildPerson(context, recipient);
|
||||||
builder.addPerson(person);
|
builder.addPerson(person);
|
||||||
|
|
||||||
if (deviceVersionSupportsIncomingCallStyle()) {
|
if (deviceVersionSupportsIncomingCallStyle()) {
|
||||||
|
@ -102,7 +102,7 @@ public class CallNotificationBuilder {
|
||||||
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
|
||||||
builder.setCategory(NotificationCompat.CATEGORY_CALL);
|
builder.setCategory(NotificationCompat.CATEGORY_CALL);
|
||||||
|
|
||||||
Person person = ConversationUtil.buildPersonWithoutIcon(context, recipient);
|
Person person = ConversationUtil.buildPerson(context, recipient);
|
||||||
builder.addPerson(person);
|
builder.addPerson(person);
|
||||||
|
|
||||||
if (deviceVersionSupportsIncomingCallStyle()) {
|
if (deviceVersionSupportsIncomingCallStyle()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue