Search in sources :

Example 1 with HttpDownloadConnection

use of de.pixart.messenger.http.HttpDownloadConnection in project Pix-Art-Messenger by kriztan.

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;
        final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED || m.getEncryption() == Message.ENCRYPTION_PGP;
        activity.getMenuInflater().inflate(R.menu.message_context, menu);
        menu.setHeaderTitle(R.string.message_options);
        MenuItem copyMessage = menu.findItem(R.id.copy_message);
        MenuItem quoteMessage = menu.findItem(R.id.quote_message);
        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 cancelTransmission = menu.findItem(R.id.cancel_transmission);
        MenuItem downloadFile = menu.findItem(R.id.download_file);
        MenuItem deleteFile = menu.findItem(R.id.delete_file);
        MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
        if (!treatAsFile && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) {
            copyMessage.setVisible(true);
            quoteMessage.setVisible(MessageUtils.prepareQuote(m).length() > 0);
        }
        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 || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) {
            shareWith.setVisible(true);
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED && !m.isFileOrImage()) {
            sendAgain.setVisible(true);
        }
        if (m.hasFileOnRemoteHost() || m.isGeoUri() || m.isXmppUri() || m.treatAsDownloadable() || (t != null && t instanceof HttpDownloadConnection)) {
            copyUrl.setVisible(true);
        }
        if ((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();
            Log.d(Config.LOGTAG, "Path = " + path);
            if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory("null", false))) {
                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(de.pixart.messenger.entities.TransferablePlaceholder) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) Transferable(de.pixart.messenger.entities.Transferable) MenuItem(android.view.MenuItem) HttpDownloadConnection(de.pixart.messenger.http.HttpDownloadConnection)

Aggregations

MenuItem (android.view.MenuItem)1 Message (de.pixart.messenger.entities.Message)1 Transferable (de.pixart.messenger.entities.Transferable)1 TransferablePlaceholder (de.pixart.messenger.entities.TransferablePlaceholder)1 HttpDownloadConnection (de.pixart.messenger.http.HttpDownloadConnection)1 EditMessage (de.pixart.messenger.ui.widget.EditMessage)1