use of eu.siacs.conversations.ui.util.Attachment in project Conversations by siacs.
the class MediaAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull MediaViewHolder holder, int position) {
final Attachment attachment = attachments.get(position);
if (attachment.renderThumbnail()) {
holder.binding.media.setImageAlpha(255);
loadPreview(attachment, holder.binding.media);
} else {
cancelPotentialWork(attachment, holder.binding.media);
renderPreview(activity, attachment, holder.binding.media);
}
holder.binding.getRoot().setOnClickListener(v -> ViewUtil.view(activity, attachment));
}
use of eu.siacs.conversations.ui.util.Attachment in project Conversations by siacs.
the class MediaPreviewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull MediaPreviewViewHolder holder, int position) {
final Context context = conversationFragment.getActivity();
final Attachment attachment = mediaPreviews.get(position);
if (attachment.renderThumbnail()) {
holder.binding.mediaPreview.setImageAlpha(255);
loadPreview(attachment, holder.binding.mediaPreview);
} else {
cancelPotentialWork(attachment, holder.binding.mediaPreview);
MediaAdapter.renderPreview(context, attachment, holder.binding.mediaPreview);
}
holder.binding.deleteButton.setOnClickListener(v -> {
final int pos = mediaPreviews.indexOf(attachment);
mediaPreviews.remove(pos);
notifyItemRemoved(pos);
conversationFragment.toggleInputMethod();
});
holder.binding.mediaPreview.setOnClickListener(v -> view(context, attachment));
}
use of eu.siacs.conversations.ui.util.Attachment in project Conversations by siacs.
the class ConversationFragment method onSaveInstanceState.
@Override
public void onSaveInstanceState(@NotNull Bundle outState) {
super.onSaveInstanceState(outState);
if (conversation != null) {
outState.putString(STATE_CONVERSATION_UUID, conversation.getUuid());
outState.putString(STATE_LAST_MESSAGE_UUID, lastMessageUuid);
final Uri uri = pendingTakePhotoUri.peek();
if (uri != null) {
outState.putString(STATE_PHOTO_URI, uri.toString());
}
final ScrollState scrollState = getScrollPosition();
if (scrollState != null) {
outState.putParcelable(STATE_SCROLL_POSITION, scrollState);
}
final ArrayList<Attachment> attachments = mediaPreviewAdapter == null ? new ArrayList<>() : mediaPreviewAdapter.getAttachments();
if (attachments.size() > 0) {
outState.putParcelableArrayList(STATE_MEDIA_PREVIEWS, attachments);
}
}
}
use of eu.siacs.conversations.ui.util.Attachment in project Conversations by siacs.
the class ConversationFragment method findAndReInitByUuidOrArchive.
private boolean findAndReInitByUuidOrArchive(@NonNull final String uuid) {
Conversation conversation = activity.xmppConnectionService.findConversationByUuid(uuid);
if (conversation == null) {
clearPending();
activity.onConversationArchived(null);
return false;
}
reInit(conversation);
ScrollState scrollState = pendingScrollState.pop();
String lastMessageUuid = pendingLastMessageUuid.pop();
List<Attachment> attachments = pendingMediaPreviews.pop();
if (scrollState != null) {
setScrollPosition(scrollState, lastMessageUuid);
}
if (attachments != null && attachments.size() > 0) {
Log.d(Config.LOGTAG, "had attachments on restore");
mediaPreviewAdapter.addMediaPreviews(attachments);
toggleInputMethod();
}
return true;
}
use of eu.siacs.conversations.ui.util.Attachment in project Conversations by siacs.
the class ConversationFragment method handlePositiveActivityResult.
private void handlePositiveActivityResult(int requestCode, final Intent data) {
switch(requestCode) {
case REQUEST_TRUST_KEYS_TEXT:
sendMessage();
break;
case REQUEST_TRUST_KEYS_ATTACHMENTS:
commitAttachments();
break;
case REQUEST_START_AUDIO_CALL:
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
break;
case REQUEST_START_VIDEO_CALL:
triggerRtpSession(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
break;
case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
final List<Attachment> imageUris = Attachment.extractAttachments(getActivity(), data, Attachment.Type.IMAGE);
mediaPreviewAdapter.addMediaPreviews(imageUris);
toggleInputMethod();
break;
case ATTACHMENT_CHOICE_TAKE_PHOTO:
final Uri takePhotoUri = pendingTakePhotoUri.pop();
if (takePhotoUri != null) {
mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), takePhotoUri, Attachment.Type.IMAGE));
toggleInputMethod();
} else {
Log.d(Config.LOGTAG, "lost take photo uri. unable to to attach");
}
break;
case ATTACHMENT_CHOICE_CHOOSE_FILE:
case ATTACHMENT_CHOICE_RECORD_VIDEO:
case ATTACHMENT_CHOICE_RECORD_VOICE:
final Attachment.Type type = requestCode == ATTACHMENT_CHOICE_RECORD_VOICE ? Attachment.Type.RECORDING : Attachment.Type.FILE;
final List<Attachment> fileUris = Attachment.extractAttachments(getActivity(), data, type);
mediaPreviewAdapter.addMediaPreviews(fileUris);
toggleInputMethod();
break;
case ATTACHMENT_CHOICE_LOCATION:
final double latitude = data.getDoubleExtra("latitude", 0);
final double longitude = data.getDoubleExtra("longitude", 0);
final int accuracy = data.getIntExtra("accuracy", 0);
final Uri geo;
if (accuracy > 0) {
geo = Uri.parse(String.format("geo:%s,%s;u=%s", latitude, longitude, accuracy));
} else {
geo = Uri.parse(String.format("geo:%s,%s", latitude, longitude));
}
mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), geo, Attachment.Type.LOCATION));
toggleInputMethod();
break;
case REQUEST_INVITE_TO_CONVERSATION:
XmppActivity.ConferenceInvite invite = XmppActivity.ConferenceInvite.parse(data);
if (invite != null) {
if (invite.execute(activity)) {
activity.mToast = Toast.makeText(activity, R.string.creating_conference, Toast.LENGTH_LONG);
activity.mToast.show();
}
}
break;
}
}
Aggregations