Add support for animated stickers.

This commit is contained in:
Greyson Parrelli
2020-09-02 12:46:58 -04:00
committed by Cody Henthorne
parent bb708e0aa3
commit f4a199f621
26 changed files with 146 additions and 72 deletions

View File

@@ -4,6 +4,7 @@ import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.thoughtcrime.securesms.util.MediaUtil;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.ArrayList;
@@ -66,18 +67,20 @@ public final class StickerManifest {
private final String packKey;
private final int id;
private final String emoji;
private final String contentType;
private final Optional<Uri> uri;
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @NonNull String emoji) {
this(packId, packKey, id, emoji, null);
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @NonNull String emoji, @Nullable String contentType) {
this(packId, packKey, id, emoji, contentType, null);
}
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @NonNull String emoji, @Nullable Uri uri) {
this.packId = packId;
this.packKey = packKey;
this.id = id;
this.emoji = emoji;
this.uri = Optional.fromNullable(uri);
public Sticker(@NonNull String packId, @NonNull String packKey, int id, @NonNull String emoji, @Nullable String contentType, @Nullable Uri uri) {
this.packId = packId;
this.packKey = packKey;
this.id = id;
this.emoji = emoji;
this.contentType = contentType;
this.uri = Optional.fromNullable(uri);
}
public @NonNull String getPackId() {
@@ -96,6 +99,10 @@ public final class StickerManifest {
return emoji;
}
public @Nullable String getContentType() {
return contentType;
}
public Optional<Uri> getUri() {
return uri;
}

View File

@@ -126,11 +126,11 @@ public final class StickerPackPreviewRepository {
@NonNull String packKey,
@NonNull SignalServiceStickerManifest.StickerInfo remoteSticker)
{
return new StickerManifest.Sticker(packId, packKey, remoteSticker.getId(), remoteSticker.getEmoji());
return new StickerManifest.Sticker(packId, packKey, remoteSticker.getId(), remoteSticker.getEmoji(), remoteSticker.getContentType());
}
private StickerManifest.Sticker toSticker(@NonNull StickerRecord record) {
return new StickerManifest.Sticker(record.getPackId(), record.getPackKey(), record.getStickerId(), record.getEmoji(), record.getUri());
return new StickerManifest.Sticker(record.getPackId(), record.getPackKey(), record.getStickerId(), record.getEmoji(), record.getContentType(), record.getUri());
}
static class StickerManifestResult {

View File

@@ -10,6 +10,8 @@ import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.mms.GlideRequests;
@@ -37,6 +39,7 @@ final class StickerPreviewPopup extends PopupWindow {
void presentSticker(@NonNull Object stickerGlideModel, @Nullable String emoji) {
emojiText.setText(emoji);
glideRequests.load(stickerGlideModel)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(image);
}
}

View File

@@ -14,12 +14,15 @@ import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.whispersystems.libsignal.util.Pair;
import java.lang.ref.WeakReference;
public class StickerRolloverTouchListener implements RecyclerView.OnItemTouchListener {
private final StickerPreviewPopup popup;
private final RolloverEventListener eventListener;
private final RolloverStickerRetriever stickerRetriever;
private boolean hoverMode;
private WeakReference<View> currentView;
private boolean hoverMode;
StickerRolloverTouchListener(@NonNull Context context,
@NonNull GlideRequests glideRequests,
@@ -29,6 +32,8 @@ public class StickerRolloverTouchListener implements RecyclerView.OnItemTouchLis
this.eventListener = eventListener;
this.stickerRetriever = stickerRetriever;
this.popup = new StickerPreviewPopup(context, glideRequests);
this.currentView = new WeakReference<>(null);
popup.setAnimationStyle(R.style.StickerPopupAnimation);
}
@@ -45,15 +50,19 @@ public class StickerRolloverTouchListener implements RecyclerView.OnItemTouchLis
hoverMode = false;
popup.dismiss();
eventListener.onStickerPopupEnded();
currentView.clear();
break;
default:
for (int i = 0, len = recyclerView.getChildCount(); i < len; i++) {
View child = recyclerView.getChildAt(i);
if (ViewUtil.isPointInsideView(recyclerView, motionEvent.getRawX(), motionEvent.getRawY()) &&
ViewUtil.isPointInsideView(child, motionEvent.getRawX(), motionEvent.getRawY()))
ViewUtil.isPointInsideView(child, motionEvent.getRawX(), motionEvent.getRawY()) &&
child != currentView.get())
{
showStickerForView(recyclerView, child);
currentView = new WeakReference<>(child);
break;
}
}
}