use of org.thoughtcrime.securesms.mediasend.Media 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;
}
use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by WhisperSystems.
the class AddGroupDetailsFragment method showAvatarPicker.
private void showAvatarPicker() {
Media media = viewModel.getAvatarMedia();
SafeNavigation.safeNavigate(Navigation.findNavController(requireView()), AddGroupDetailsFragmentDirections.actionAddGroupDetailsFragmentToAvatarPicker(null, media).setIsNewGroup(true));
}
use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by signalapp.
the class AddGroupDetailsFragment method handleMediaResult.
private void handleMediaResult(Bundle data) {
if (data.getBoolean(AvatarPickerFragment.SELECT_AVATAR_CLEAR)) {
viewModel.setAvatarMedia(null);
viewModel.setAvatar(null);
return;
}
final Media result = data.getParcelable(AvatarPickerFragment.SELECT_AVATAR_MEDIA);
final DecryptableStreamUriLoader.DecryptableUri decryptableUri = new DecryptableStreamUriLoader.DecryptableUri(result.getUri());
viewModel.setAvatarMedia(result);
GlideApp.with(this).asBitmap().load(decryptableUri).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerCrop().override(AvatarHelper.AVATAR_DIMENSIONS, AvatarHelper.AVATAR_DIMENSIONS).into(new CustomTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, Transition<? super Bitmap> transition) {
viewModel.setAvatar(Objects.requireNonNull(BitmapUtil.toByteArray(resource)));
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
});
}
use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by signalapp.
the class ShareRepository method getResolvedInternal.
@WorkerThread
@Nullable
private ShareData getResolvedInternal(@NonNull List<Uri> uris) throws IOException {
Context context = ApplicationDependencies.getApplication();
Map<Uri, String> mimeTypes = Stream.of(uris).map(uri -> new Pair<>(uri, getMimeType(context, uri, null))).filter(p -> MediaUtil.isImageType(p.second) || MediaUtil.isVideoType(p.second)).collect(Collectors.toMap(p -> p.first, p -> p.second));
if (mimeTypes.isEmpty()) {
return null;
}
List<Media> media = new ArrayList<>(mimeTypes.size());
for (Map.Entry<Uri, String> entry : mimeTypes.entrySet()) {
Uri uri = entry.getKey();
String mimeType = entry.getValue();
InputStream stream;
try {
stream = context.getContentResolver().openInputStream(uri);
if (stream == null) {
throw new IOException("Failed to open stream!");
}
} catch (IOException e) {
Log.w(TAG, "Failed to open: " + uri);
continue;
}
long size = getSize(context, uri);
Pair<Integer, Integer> dimens = MediaUtil.getDimensions(context, mimeType, uri);
long duration = getDuration(context, uri);
Uri blobUri = BlobProvider.getInstance().forData(stream, size).withMimeType(mimeType).createForSingleSessionOnDisk(context);
media.add(new Media(blobUri, mimeType, System.currentTimeMillis(), dimens.first, dimens.second, size, duration, false, false, Optional.of(Media.ALL_MEDIA_BUCKET_ID), Optional.absent(), Optional.absent()));
if (media.size() >= MediaSendConstants.MAX_PUSH) {
Log.w(TAG, "Exceeded the attachment limit! Skipping the rest.");
break;
}
}
if (media.size() > 0) {
boolean isMmsSupported = Stream.of(media).allMatch(m -> isMmsSupported(context, asUriAttachment(m.getUri(), m.getMimeType(), m.getSize())));
return ShareData.forMedia(media, isMmsSupported);
} else {
return null;
}
}
use of org.thoughtcrime.securesms.mediasend.Media in project Signal-Android by signalapp.
the class AttachmentKeyboard method init.
private void init(@NonNull Context context) {
inflate(context, R.layout.attachment_keyboard, this);
this.container = findViewById(R.id.attachment_keyboard_container);
this.mediaList = findViewById(R.id.attachment_keyboard_media_list);
this.permissionText = findViewById(R.id.attachment_keyboard_permission_text);
this.permissionButton = findViewById(R.id.attachment_keyboard_permission_button);
RecyclerView buttonList = findViewById(R.id.attachment_keyboard_button_list);
mediaAdapter = new AttachmentKeyboardMediaAdapter(GlideApp.with(this), media -> {
if (callback != null) {
callback.onAttachmentMediaClicked(media);
}
});
buttonAdapter = new AttachmentKeyboardButtonAdapter(button -> {
if (callback != null) {
callback.onAttachmentSelectorClicked(button);
}
});
mediaList.setAdapter(mediaAdapter);
buttonList.setAdapter(buttonAdapter);
mediaList.setLayoutManager(new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false));
buttonList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
buttonAdapter.setButtons(DEFAULT_BUTTONS);
}
Aggregations