Search in sources :

Example 46 with Conversation

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

the class ConversationsOverviewFragment method getSuggestion.

public static Conversation getSuggestion(Activity activity) {
    final Conversation exception;
    Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
    if (fragment instanceof ConversationsOverviewFragment) {
        exception = ((ConversationsOverviewFragment) fragment).swipedConversation.peek();
    } else {
        exception = null;
    }
    return getSuggestion(activity, exception);
}
Also used : Conversation(eu.siacs.conversations.entities.Conversation) Fragment(android.app.Fragment)

Example 47 with Conversation

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

the class ConversationsOverviewFragment method refresh.

@Override
void refresh() {
    if (this.binding == null || this.activity == null) {
        Log.d(Config.LOGTAG, "ConversationsOverviewFragment.refresh() skipped updated because view binding or activity was null");
        return;
    }
    this.activity.xmppConnectionService.populateWithOrderedConversations(this.conversations);
    Conversation removed = this.swipedConversation.peek();
    if (removed != null) {
        if (removed.isRead()) {
            this.conversations.remove(removed);
        } else {
            pendingActionHelper.execute();
        }
    }
    this.conversationsAdapter.notifyDataSetChanged();
    ScrollState scrollState = pendingScrollState.pop();
    if (scrollState != null) {
        setScrollPosition(scrollState);
    }
}
Also used : ScrollState(eu.siacs.conversations.ui.util.ScrollState) Conversation(eu.siacs.conversations.entities.Conversation)

Example 48 with Conversation

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

the class ConversationFragment method updateSendButton.

public void updateSendButton() {
    boolean hasAttachments = mediaPreviewAdapter != null && mediaPreviewAdapter.hasAttachments();
    final Conversation c = this.conversation;
    final Presence.Status status;
    final String text = this.binding.textinput == null ? "" : this.binding.textinput.getText().toString();
    final SendButtonAction action;
    if (hasAttachments) {
        action = SendButtonAction.TEXT;
    } else {
        action = SendButtonTool.getAction(getActivity(), c, text);
    }
    if (c.getAccount().getStatus() == Account.State.ONLINE) {
        if (activity != null && activity.xmppConnectionService != null && activity.xmppConnectionService.getMessageArchiveService().isCatchingUp(c)) {
            status = Presence.Status.OFFLINE;
        } else if (c.getMode() == Conversation.MODE_SINGLE) {
            status = c.getContact().getShownStatus();
        } else {
            status = c.getMucOptions().online() ? Presence.Status.ONLINE : Presence.Status.OFFLINE;
        }
    } else {
        status = Presence.Status.OFFLINE;
    }
    this.binding.textSendButton.setTag(action);
    final Activity activity = getActivity();
    if (activity != null) {
        this.binding.textSendButton.setImageResource(SendButtonTool.getSendButtonImageResource(activity, action, status));
    }
}
Also used : SendButtonAction(eu.siacs.conversations.ui.util.SendButtonAction) Presence(eu.siacs.conversations.entities.Presence) Activity(android.app.Activity) Conversation(eu.siacs.conversations.entities.Conversation)

Example 49 with Conversation

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

the class ConversationFragment method sendMessage.

private void sendMessage() {
    if (mediaPreviewAdapter.hasAttachments()) {
        commitAttachments();
        return;
    }
    final Editable text = this.binding.textinput.getText();
    final String body = text == null ? "" : text.toString();
    final Conversation conversation = this.conversation;
    if (body.length() == 0 || conversation == null) {
        return;
    }
    if (trustKeysIfNeeded(conversation, REQUEST_TRUST_KEYS_TEXT)) {
        return;
    }
    final Message message;
    if (conversation.getCorrectingMessage() == null) {
        message = new Message(conversation, body, conversation.getNextEncryption());
        Message.configurePrivateMessage(message);
    } else {
        message = conversation.getCorrectingMessage();
        message.setBody(body);
        message.putEdited(message.getUuid(), message.getServerMsgId());
        message.setServerMsgId(null);
        message.setUuid(UUID.randomUUID().toString());
    }
    switch(conversation.getNextEncryption()) {
        case Message.ENCRYPTION_PGP:
            sendPgpMessage(message);
            break;
        default:
            sendMessage(message);
    }
}
Also used : EditMessage(eu.siacs.conversations.ui.widget.EditMessage) Message(eu.siacs.conversations.entities.Message) Editable(android.text.Editable) Conversation(eu.siacs.conversations.entities.Conversation)

Example 50 with Conversation

use of eu.siacs.conversations.entities.Conversation 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 && m.getType() != Message.TYPE_RTP_SESSION) {
        if (m.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE || m.getEncryption() == Message.ENCRYPTION_AXOLOTL_FAILED) {
            return;
        }
        if (m.getStatus() == Message.STATUS_RECEIVED && t != null && (t.getStatus() == Transferable.STATUS_CANCELLED || t.getStatus() == Transferable.STATUS_FAILED)) {
            return;
        }
        final boolean deleted = m.isDeleted();
        final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED || m.getEncryption() == Message.ENCRYPTION_PGP;
        final boolean receiving = m.getStatus() == Message.STATUS_RECEIVED && (t instanceof JingleFileTransferConnection || t instanceof HttpDownloadConnection);
        activity.getMenuInflater().inflate(R.menu.message_context, menu);
        menu.setHeaderTitle(R.string.message_options);
        MenuItem openWith = menu.findItem(R.id.open_with);
        MenuItem copyMessage = menu.findItem(R.id.copy_message);
        MenuItem copyLink = menu.findItem(R.id.copy_link);
        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 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);
        final boolean unInitiatedButKnownSize = MessageUtils.unInitiatedButKnownSize(m);
        final boolean showError = m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null && !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage());
        if (!m.isFileOrImage() && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable() && !unInitiatedButKnownSize && t == null) {
            copyMessage.setVisible(true);
            quoteMessage.setVisible(!showError && MessageUtils.prepareQuote(m).length() > 0);
            String body = m.getMergedBody().toString();
            if (ShareUtil.containsXmppUri(body)) {
                copyLink.setTitle(R.string.copy_jabber_id);
                copyLink.setVisible(true);
            } else if (Patterns.AUTOLINK_WEB_URL.matcher(body).find()) {
                copyLink.setVisible(true);
            }
        }
        if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED && !deleted) {
            retryDecryption.setVisible(true);
        }
        if (!showError && relevantForCorrection.getType() == Message.TYPE_TEXT && !m.isGeoUri() && relevantForCorrection.isLastCorrectableMessage() && m.getConversation() instanceof Conversation) {
            correctMessage.setVisible(true);
        }
        if ((m.isFileOrImage() && !deleted && !receiving) || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable()) && !unInitiatedButKnownSize && t == null) {
            shareWith.setVisible(true);
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED) {
            sendAgain.setVisible(true);
        }
        if (m.hasFileOnRemoteHost() || m.isGeoUri() || m.treatAsDownloadable() || unInitiatedButKnownSize || t instanceof HttpDownloadConnection) {
            copyUrl.setVisible(true);
        }
        if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) {
            downloadFile.setVisible(true);
            downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
        }
        final boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING || m.getStatus() == Message.STATUS_UNSEND || m.getStatus() == Message.STATUS_OFFERED;
        final boolean cancelable = (t != null && !deleted) || waitingOfferedSending && m.needsUploading();
        if (cancelable) {
            cancelTransmission.setVisible(true);
        }
        if (m.isFileOrImage() && !deleted && !cancelable) {
            String path = m.getRelativeFilePath();
            if (path == null || !path.startsWith("/") || FileBackend.isInDirectoryThatShouldNotBeScanned(getActivity(), path)) {
                deleteFile.setVisible(true);
                deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
            }
        }
        if (showError) {
            showErrorMessage.setVisible(true);
        }
        final String mime = m.isFileOrImage() ? m.getMimeType() : null;
        if ((m.isGeoUri() && GeoHelper.openInOsmAnd(getActivity(), m)) || (mime != null && mime.startsWith("audio/"))) {
            openWith.setVisible(true);
        }
    }
}
Also used : EditMessage(eu.siacs.conversations.ui.widget.EditMessage) Message(eu.siacs.conversations.entities.Message) Transferable(eu.siacs.conversations.entities.Transferable) MenuItem(android.view.MenuItem) Conversation(eu.siacs.conversations.entities.Conversation) JingleFileTransferConnection(eu.siacs.conversations.xmpp.jingle.JingleFileTransferConnection) HttpDownloadConnection(eu.siacs.conversations.http.HttpDownloadConnection)

Aggregations

Conversation (eu.siacs.conversations.entities.Conversation)110 Account (eu.siacs.conversations.entities.Account)27 Message (eu.siacs.conversations.entities.Message)24 Jid (eu.siacs.conversations.xmpp.Jid)22 Contact (eu.siacs.conversations.entities.Contact)17 MucOptions (eu.siacs.conversations.entities.MucOptions)10 Intent (android.content.Intent)9 Element (eu.siacs.conversations.xml.Element)9 PendingIntent (android.app.PendingIntent)8 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)8 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)8 Uri (android.net.Uri)7 Conversational (eu.siacs.conversations.entities.Conversational)7 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)7 SuppressLint (android.annotation.SuppressLint)6 SpannableString (android.text.SpannableString)6 XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)6 Jid (eu.siacs.conversations.xmpp.jid.Jid)6 ArrayList (java.util.ArrayList)6 Fragment (android.app.Fragment)4