Search in sources :

Example 1 with OverlayTransformation

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);
    });
}
Also used : RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) OverlayTransformation(org.thoughtcrime.securesms.OverlayTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) SpannableString(android.text.SpannableString) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with OverlayTransformation

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);
    });
}
Also used : RoundedDrawable(com.makeramen.roundedimageview.RoundedDrawable) OverlayTransformation(org.thoughtcrime.securesms.OverlayTransformation) CenterCrop(com.bumptech.glide.load.resource.bitmap.CenterCrop) SpannableString(android.text.SpannableString) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

SpannableString (android.text.SpannableString)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 CenterCrop (com.bumptech.glide.load.resource.bitmap.CenterCrop)2 RoundedDrawable (com.makeramen.roundedimageview.RoundedDrawable)2 OverlayTransformation (org.thoughtcrime.securesms.OverlayTransformation)2