use of org.thoughtcrime.securesms.OverlayTransformation in project Signal-Android by WhisperSystems.
the class ConversationListItem method createFinalBodyWithMediaIcon.
private static LiveData<CharSequence> createFinalBodyWithMediaIcon(@NonNull Context context, @NonNull String body, @NonNull ThreadRecord thread, @NonNull GlideRequests glideRequests, @Px int thumbSize, @NonNull GlideLiveDataTarget thumbTarget) {
if (thread.getSnippetUri() == null) {
return LiveDataUtil.just(body);
}
final String bodyWithoutMediaPrefix;
if (body.startsWith(EmojiStrings.GIF)) {
bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.GIF, "");
} else if (body.startsWith(EmojiStrings.VIDEO)) {
bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.VIDEO, "");
} else if (body.startsWith(EmojiStrings.PHOTO)) {
bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.PHOTO, "");
} else if (thread.getExtra() != null && thread.getExtra().getStickerEmoji() != null && body.startsWith(thread.getExtra().getStickerEmoji())) {
bodyWithoutMediaPrefix = body.replaceFirst(thread.getExtra().getStickerEmoji(), "");
} else {
return LiveDataUtil.just(body);
}
glideRequests.asBitmap().load(new DecryptableStreamUriLoader.DecryptableUri(thread.getSnippetUri())).override(thumbSize, thumbSize).transform(new OverlayTransformation(ContextCompat.getColor(context, R.color.transparent_black_08)), new CenterCrop()).into(thumbTarget);
return Transformations.map(thumbTarget.getLiveData(), bitmap -> {
if (bitmap == null) {
return body;
}
RoundedDrawable drawable = RoundedDrawable.fromBitmap(bitmap);
drawable.setBounds(0, 0, thumbSize, thumbSize);
drawable.setCornerRadius(DimensionUnit.DP.toPixels(4));
drawable.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
CharSequence thumbnailSpan = SpanUtil.buildCenteredImageSpan(drawable);
return new SpannableStringBuilder().append(thumbnailSpan).append(bodyWithoutMediaPrefix);
});
}
use of org.thoughtcrime.securesms.OverlayTransformation in project Signal-Android by signalapp.
the class ConversationListItem method createFinalBodyWithMediaIcon.
private static LiveData<CharSequence> createFinalBodyWithMediaIcon(@NonNull Context context, @NonNull String body, @NonNull ThreadRecord thread, @NonNull GlideRequests glideRequests, @Px int thumbSize, @NonNull GlideLiveDataTarget thumbTarget) {
if (thread.getSnippetUri() == null) {
return LiveDataUtil.just(body);
}
final String bodyWithoutMediaPrefix;
if (body.startsWith(EmojiStrings.GIF)) {
bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.GIF, "");
} else if (body.startsWith(EmojiStrings.VIDEO)) {
bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.VIDEO, "");
} else if (body.startsWith(EmojiStrings.PHOTO)) {
bodyWithoutMediaPrefix = body.replaceFirst(EmojiStrings.PHOTO, "");
} else if (thread.getExtra() != null && thread.getExtra().getStickerEmoji() != null && body.startsWith(thread.getExtra().getStickerEmoji())) {
bodyWithoutMediaPrefix = body.replaceFirst(thread.getExtra().getStickerEmoji(), "");
} else {
return LiveDataUtil.just(body);
}
glideRequests.asBitmap().load(new DecryptableStreamUriLoader.DecryptableUri(thread.getSnippetUri())).override(thumbSize, thumbSize).transform(new OverlayTransformation(ContextCompat.getColor(context, R.color.transparent_black_08)), new CenterCrop()).into(thumbTarget);
return Transformations.map(thumbTarget.getLiveData(), bitmap -> {
if (bitmap == null) {
return body;
}
RoundedDrawable drawable = RoundedDrawable.fromBitmap(bitmap);
drawable.setBounds(0, 0, thumbSize, thumbSize);
drawable.setCornerRadius(DimensionUnit.DP.toPixels(4));
drawable.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
CharSequence thumbnailSpan = SpanUtil.buildCenteredImageSpan(drawable);
return new SpannableStringBuilder().append(thumbnailSpan).append(bodyWithoutMediaPrefix);
});
}
Aggregations