use of org.thoughtcrime.securesms.stickers.StickerRemoteUri in project Signal-Android by WhisperSystems.
the class LinkPreviewRepository method fetchStickerPackLinkPreview.
private static RequestController fetchStickerPackLinkPreview(@NonNull Context context, @NonNull String packUrl, @NonNull Callback callback) {
SignalExecutors.UNBOUNDED.execute(() -> {
try {
Pair<String, String> stickerParams = StickerUrl.parseShareLink(packUrl).or(new Pair<>("", ""));
String packIdString = stickerParams.first();
String packKeyString = stickerParams.second();
byte[] packIdBytes = Hex.fromStringCondensed(packIdString);
byte[] packKeyBytes = Hex.fromStringCondensed(packKeyString);
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
SignalServiceStickerManifest manifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
String title = manifest.getTitle().or(manifest.getAuthor()).or("");
Optional<StickerInfo> firstSticker = Optional.fromNullable(manifest.getStickers().size() > 0 ? manifest.getStickers().get(0) : null);
Optional<StickerInfo> cover = manifest.getCover().or(firstSticker);
if (cover.isPresent()) {
Bitmap bitmap = GlideApp.with(context).asBitmap().load(new StickerRemoteUri(packIdString, packKeyString, cover.get().getId())).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerInside().submit(512, 512).get();
Optional<Attachment> thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.WEBP, MediaUtil.IMAGE_WEBP);
callback.onSuccess(new LinkPreview(packUrl, title, "", 0, thumbnail));
} else {
callback.onError(Error.PREVIEW_NOT_AVAILABLE);
}
} catch (IOException | InvalidMessageException | ExecutionException | InterruptedException e) {
Log.w(TAG, "Failed to fetch sticker pack link preview.");
callback.onError(Error.PREVIEW_NOT_AVAILABLE);
}
});
return () -> Log.i(TAG, "Cancelled sticker pack link preview fetch -- no effect.");
}
use of org.thoughtcrime.securesms.stickers.StickerRemoteUri in project Signal-Android by signalapp.
the class LinkPreviewRepository method fetchStickerPackLinkPreview.
private static RequestController fetchStickerPackLinkPreview(@NonNull Context context, @NonNull String packUrl, @NonNull Callback callback) {
SignalExecutors.UNBOUNDED.execute(() -> {
try {
Pair<String, String> stickerParams = StickerUrl.parseShareLink(packUrl).or(new Pair<>("", ""));
String packIdString = stickerParams.first();
String packKeyString = stickerParams.second();
byte[] packIdBytes = Hex.fromStringCondensed(packIdString);
byte[] packKeyBytes = Hex.fromStringCondensed(packKeyString);
SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
SignalServiceStickerManifest manifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
String title = manifest.getTitle().or(manifest.getAuthor()).or("");
Optional<StickerInfo> firstSticker = Optional.fromNullable(manifest.getStickers().size() > 0 ? manifest.getStickers().get(0) : null);
Optional<StickerInfo> cover = manifest.getCover().or(firstSticker);
if (cover.isPresent()) {
Bitmap bitmap = GlideApp.with(context).asBitmap().load(new StickerRemoteUri(packIdString, packKeyString, cover.get().getId())).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerInside().submit(512, 512).get();
Optional<Attachment> thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.WEBP, MediaUtil.IMAGE_WEBP);
callback.onSuccess(new LinkPreview(packUrl, title, "", 0, thumbnail));
} else {
callback.onError(Error.PREVIEW_NOT_AVAILABLE);
}
} catch (IOException | InvalidMessageException | ExecutionException | InterruptedException e) {
Log.w(TAG, "Failed to fetch sticker pack link preview.");
callback.onError(Error.PREVIEW_NOT_AVAILABLE);
}
});
return () -> Log.i(TAG, "Cancelled sticker pack link preview fetch -- no effect.");
}
Aggregations