use of org.thoughtcrime.securesms.stickers.StickerLocator in project Signal-Android by WhisperSystems.
the class AttachmentDatabase method getAttachments.
public List<DatabaseAttachment> getAttachments(@NonNull Cursor cursor) {
try {
if (cursor.getColumnIndex(AttachmentDatabase.ATTACHMENT_JSON_ALIAS) != -1) {
if (cursor.isNull(cursor.getColumnIndexOrThrow(ATTACHMENT_JSON_ALIAS))) {
return new LinkedList<>();
}
List<DatabaseAttachment> result = new LinkedList<>();
JSONArray array = new JSONArray(cursor.getString(cursor.getColumnIndexOrThrow(ATTACHMENT_JSON_ALIAS)));
for (int i = 0; i < array.length(); i++) {
JsonUtils.SaneJSONObject object = new JsonUtils.SaneJSONObject(array.getJSONObject(i));
if (!object.isNull(ROW_ID)) {
String contentType = object.getString(CONTENT_TYPE);
result.add(new DatabaseAttachment(new AttachmentId(object.getLong(ROW_ID), object.getLong(UNIQUE_ID)), object.getLong(MMS_ID), !TextUtils.isEmpty(object.getString(DATA)), MediaUtil.isImageType(contentType) || MediaUtil.isVideoType(contentType), contentType, object.getInt(TRANSFER_STATE), object.getLong(SIZE), object.getString(FILE_NAME), object.getInt(CDN_NUMBER), object.getString(CONTENT_LOCATION), object.getString(CONTENT_DISPOSITION), object.getString(NAME), null, object.getString(FAST_PREFLIGHT_ID), object.getInt(VOICE_NOTE) == 1, object.getInt(BORDERLESS) == 1, object.getInt(VIDEO_GIF) == 1, object.getInt(WIDTH), object.getInt(HEIGHT), object.getInt(QUOTE) == 1, object.getString(CAPTION), object.getInt(STICKER_ID) >= 0 ? new StickerLocator(object.getString(STICKER_PACK_ID), object.getString(STICKER_PACK_KEY), object.getInt(STICKER_ID), object.getString(STICKER_EMOJI)) : null, MediaUtil.isAudioType(contentType) ? null : BlurHash.parseOrNull(object.getString(VISUAL_HASH)), MediaUtil.isAudioType(contentType) ? AudioHash.parseOrNull(object.getString(VISUAL_HASH)) : null, TransformProperties.parse(object.getString(TRANSFORM_PROPERTIES)), object.getInt(DISPLAY_ORDER), object.getLong(UPLOAD_TIMESTAMP)));
}
}
return result;
} else {
return Collections.singletonList(getAttachment(cursor));
}
} catch (JSONException e) {
throw new AssertionError(e);
}
}
use of org.thoughtcrime.securesms.stickers.StickerLocator in project Signal-Android by WhisperSystems.
the class MessageContentProcessor method getStickerAttachment.
private Optional<Attachment> getStickerAttachment(Optional<SignalServiceDataMessage.Sticker> sticker) {
if (!sticker.isPresent()) {
return Optional.absent();
}
if (sticker.get().getPackId() == null || sticker.get().getPackKey() == null || sticker.get().getAttachment() == null) {
warn("Malformed sticker!");
return Optional.absent();
}
String packId = Hex.toStringCondensed(sticker.get().getPackId());
String packKey = Hex.toStringCondensed(sticker.get().getPackKey());
int stickerId = sticker.get().getStickerId();
String emoji = sticker.get().getEmoji();
StickerLocator stickerLocator = new StickerLocator(packId, packKey, stickerId, emoji);
StickerDatabase stickerDatabase = SignalDatabase.stickers();
StickerRecord stickerRecord = stickerDatabase.getSticker(stickerLocator.getPackId(), stickerLocator.getStickerId(), false);
if (stickerRecord != null) {
return Optional.of(new UriAttachment(stickerRecord.getUri(), stickerRecord.getContentType(), AttachmentDatabase.TRANSFER_PROGRESS_DONE, stickerRecord.getSize(), StickerSlide.WIDTH, StickerSlide.HEIGHT, null, String.valueOf(new SecureRandom().nextLong()), false, false, false, false, null, stickerLocator, null, null, null));
} else {
return Optional.of(PointerAttachment.forPointer(Optional.of(sticker.get().getAttachment()), stickerLocator).get());
}
}
use of org.thoughtcrime.securesms.stickers.StickerLocator in project Signal-Android by WhisperSystems.
the class ConversationParentFragment method sendSticker.
private void sendSticker(@NonNull StickerRecord stickerRecord, boolean clearCompose) {
sendSticker(new StickerLocator(stickerRecord.getPackId(), stickerRecord.getPackKey(), stickerRecord.getStickerId(), stickerRecord.getEmoji()), stickerRecord.getContentType(), stickerRecord.getUri(), stickerRecord.getSize(), clearCompose);
SignalExecutors.BOUNDED.execute(() -> SignalDatabase.stickers().updateStickerLastUsedTime(stickerRecord.getRowId(), System.currentTimeMillis()));
}
use of org.thoughtcrime.securesms.stickers.StickerLocator in project Signal-Android by WhisperSystems.
the class ConversationParentFragment method initializeDraft.
// /// Initializers
private ListenableFuture<Boolean> initializeDraft(@NonNull ConversationIntents.Args args) {
final SettableFuture<Boolean> result = new SettableFuture<>();
final CharSequence draftText = args.getDraftText();
final Uri draftMedia = requireActivity().getIntent().getData();
final String draftContentType = requireActivity().getIntent().getType();
final MediaType draftMediaType = MediaType.from(draftContentType);
final List<Media> mediaList = args.getMedia();
final StickerLocator stickerLocator = args.getStickerLocator();
final boolean borderless = args.isBorderless();
if (stickerLocator != null && draftMedia != null) {
Log.d(TAG, "Handling shared sticker.");
sendSticker(stickerLocator, Objects.requireNonNull(draftContentType), draftMedia, 0, true);
return new SettableFuture<>(false);
}
if (draftMedia != null && draftContentType != null && borderless) {
SimpleTask.run(getLifecycle(), () -> getKeyboardImageDetails(draftMedia), details -> sendKeyboardImage(draftMedia, draftContentType, details));
return new SettableFuture<>(false);
}
if (!Util.isEmpty(mediaList)) {
Log.d(TAG, "Handling shared Media.");
Intent sendIntent = MediaSelectionActivity.editor(requireContext(), sendButton.getSelectedTransport(), mediaList, recipient.getId(), draftText);
startActivityForResult(sendIntent, MEDIA_SENDER);
return new SettableFuture<>(false);
}
if (draftText != null) {
composeText.setText("");
composeText.append(draftText);
result.set(true);
}
if (draftMedia != null && draftMediaType != null) {
Log.d(TAG, "Handling shared Data.");
return setMedia(draftMedia, draftMediaType);
}
if (draftText == null && draftMedia == null && draftMediaType == null) {
return initializeDraftFromDatabase();
} else {
updateToggleButtonState();
result.set(false);
}
return result;
}
Aggregations