Search in sources :

Example 1 with TransferablePlaceholder

use of eu.siacs.conversations.entities.TransferablePlaceholder in project Conversations by siacs.

the class ConversationFragment method populateContextMenu.

private void populateContextMenu(ContextMenu menu) {
    final Message m = this.selectedMessage;
    final Transferable t = m.getTransferable();
    Message relevantForCorrection = m;
    while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
        relevantForCorrection = relevantForCorrection.next();
    }
    if (m.getType() != Message.TYPE_STATUS) {
        final boolean treatAsFile = m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE && t == null;
        activity.getMenuInflater().inflate(R.menu.message_context, menu);
        menu.setHeaderTitle(R.string.message_options);
        MenuItem copyText = menu.findItem(R.id.copy_text);
        MenuItem selectText = menu.findItem(R.id.select_text);
        MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
        MenuItem correctMessage = menu.findItem(R.id.correct_message);
        MenuItem shareWith = menu.findItem(R.id.share_with);
        MenuItem sendAgain = menu.findItem(R.id.send_again);
        MenuItem copyUrl = menu.findItem(R.id.copy_url);
        MenuItem downloadFile = menu.findItem(R.id.download_file);
        MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
        MenuItem deleteFile = menu.findItem(R.id.delete_file);
        MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
        if (!treatAsFile && !GeoHelper.isGeoUri(m.getBody()) && m.treatAsDownloadable() != Message.Decision.MUST) {
            copyText.setVisible(true);
            selectText.setVisible(ListSelectionManager.isSupported());
        }
        if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED) {
            retryDecryption.setVisible(true);
        }
        if (relevantForCorrection.getType() == Message.TYPE_TEXT && relevantForCorrection.isLastCorrectableMessage() && (m.getConversation().getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) {
            correctMessage.setVisible(true);
        }
        if (treatAsFile || (GeoHelper.isGeoUri(m.getBody()))) {
            shareWith.setVisible(true);
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED) {
            sendAgain.setVisible(true);
        }
        if (m.hasFileOnRemoteHost() || GeoHelper.isGeoUri(m.getBody()) || m.treatAsDownloadable() == Message.Decision.MUST || (t != null && t instanceof HttpDownloadConnection)) {
            copyUrl.setVisible(true);
        }
        if ((m.getType() == Message.TYPE_TEXT && t == null && m.treatAsDownloadable() != Message.Decision.NEVER) || (m.isFileOrImage() && t instanceof TransferablePlaceholder && m.hasFileOnRemoteHost())) {
            downloadFile.setVisible(true);
            downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
        }
        boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING || m.getStatus() == Message.STATUS_UNSEND || m.getStatus() == Message.STATUS_OFFERED;
        if ((t != null && !(t instanceof TransferablePlaceholder)) || waitingOfferedSending && m.needsUploading()) {
            cancelTransmission.setVisible(true);
        }
        if (treatAsFile) {
            String path = m.getRelativeFilePath();
            if (path == null || !path.startsWith("/")) {
                deleteFile.setVisible(true);
                deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
            }
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) {
            showErrorMessage.setVisible(true);
        }
    }
}
Also used : TransferablePlaceholder(eu.siacs.conversations.entities.TransferablePlaceholder) Message(eu.siacs.conversations.entities.Message) Transferable(eu.siacs.conversations.entities.Transferable) MenuItem(android.view.MenuItem) HttpDownloadConnection(eu.siacs.conversations.http.HttpDownloadConnection)

Example 2 with TransferablePlaceholder

use of eu.siacs.conversations.entities.TransferablePlaceholder in project Conversations by siacs.

the class ConversationFragment method deleteFile.

private void deleteFile(Message message) {
    if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) {
        message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
        activity.updateConversationList();
        updateMessages();
    }
}
Also used : TransferablePlaceholder(eu.siacs.conversations.entities.TransferablePlaceholder)

Example 3 with TransferablePlaceholder

use of eu.siacs.conversations.entities.TransferablePlaceholder in project Conversations by siacs.

the class HttpDownloadConnection method cancel.

@Override
public void cancel() {
    this.canceled = true;
    mHttpConnectionManager.finishConnection(this);
    if (message.isFileOrImage()) {
        message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
    } else {
        message.setTransferable(null);
    }
    mHttpConnectionManager.updateConversationUi(true);
}
Also used : TransferablePlaceholder(eu.siacs.conversations.entities.TransferablePlaceholder)

Example 4 with TransferablePlaceholder

use of eu.siacs.conversations.entities.TransferablePlaceholder in project Conversations by siacs.

the class ConversationFragment method resendMessage.

private void resendMessage(Message message) {
    if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
        DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
        if (!file.exists()) {
            Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
            message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
            activity.updateConversationList();
            updateMessages();
            return;
        }
    }
    activity.xmppConnectionService.resendFailedMessages(message);
}
Also used : TransferablePlaceholder(eu.siacs.conversations.entities.TransferablePlaceholder) DownloadableFile(eu.siacs.conversations.entities.DownloadableFile)

Example 5 with TransferablePlaceholder

use of eu.siacs.conversations.entities.TransferablePlaceholder in project Conversations by siacs.

the class JingleConnection method cancel.

public void cancel() {
    this.disconnectSocks5Connections();
    if (this.transport != null && this.transport instanceof JingleInbandTransport) {
        this.transport.disconnect();
    }
    this.sendCancel();
    this.mJingleConnectionManager.finishConnection(this);
    if (this.responder.equals(account.getJid())) {
        this.message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_FAILED));
        if (this.file != null) {
            file.delete();
        }
        this.mJingleConnectionManager.updateConversationUi(true);
    } else {
        this.mXmppConnectionService.markMessage(this.message, Message.STATUS_SEND_FAILED);
        this.message.setTransferable(null);
    }
}
Also used : TransferablePlaceholder(eu.siacs.conversations.entities.TransferablePlaceholder)

Aggregations

TransferablePlaceholder (eu.siacs.conversations.entities.TransferablePlaceholder)6 MenuItem (android.view.MenuItem)1 DownloadableFile (eu.siacs.conversations.entities.DownloadableFile)1 Message (eu.siacs.conversations.entities.Message)1 Transferable (eu.siacs.conversations.entities.Transferable)1 HttpDownloadConnection (eu.siacs.conversations.http.HttpDownloadConnection)1