Search in sources :

Example 1 with Attachment

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));
}
Also used : Attachment(eu.siacs.conversations.ui.util.Attachment)

Example 2 with 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));
}
Also used : Context(android.content.Context) Attachment(eu.siacs.conversations.ui.util.Attachment)

Example 3 with 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);
        }
    }
}
Also used : ScrollState(eu.siacs.conversations.ui.util.ScrollState) Attachment(eu.siacs.conversations.ui.util.Attachment) Uri(android.net.Uri)

Example 4 with Attachment

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;
}
Also used : ScrollState(eu.siacs.conversations.ui.util.ScrollState) Conversation(eu.siacs.conversations.entities.Conversation) Attachment(eu.siacs.conversations.ui.util.Attachment)

Example 5 with Attachment

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;
    }
}
Also used : Attachment(eu.siacs.conversations.ui.util.Attachment) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint)

Aggregations

Attachment (eu.siacs.conversations.ui.util.Attachment)6 Uri (android.net.Uri)2 ScrollState (eu.siacs.conversations.ui.util.ScrollState)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 Conversation (eu.siacs.conversations.entities.Conversation)1 DownloadableFile (eu.siacs.conversations.entities.DownloadableFile)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1