Search in sources :

Example 66 with Account

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

the class XmppConnectionService method checkForAvatar.

public void checkForAvatar(Account account, final UiCallback<Avatar> callback) {
    IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
                if (pubsub != null) {
                    Element items = pubsub.findChild("items");
                    if (items != null) {
                        Avatar avatar = Avatar.parseMetadata(items);
                        if (avatar != null) {
                            avatar.owner = account.getJid().toBareJid();
                            if (fileBackend.isAvatarCached(avatar)) {
                                if (account.setAvatar(avatar.getFilename())) {
                                    databaseBackend.updateAccount(account);
                                }
                                getAvatarService().clear(account);
                                callback.success(avatar);
                            } else {
                                fetchAvatarPep(account, avatar, callback);
                            }
                            return;
                        }
                    }
                }
            }
            callback.error(0, null);
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) Avatar(eu.siacs.conversations.xmpp.pep.Avatar) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 67 with Account

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

the class ConversationFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_conversation, container, false);
    view.setOnClickListener(null);
    String[] allImagesMimeType = { "image/*" };
    mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
    mEditMessage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (activity != null) {
                activity.hideConversationsOverview();
            }
        }
    });
    mEditMessage.setOnEditorActionListener(mEditorActionListener);
    mEditMessage.setRichContentListener(allImagesMimeType, mEditorContentListener);
    mSendButton = (ImageButton) view.findViewById(R.id.textSendButton);
    mSendButton.setOnClickListener(this.mSendButtonListener);
    snackbar = (RelativeLayout) view.findViewById(R.id.snackbar);
    snackbarMessage = (TextView) view.findViewById(R.id.snackbar_message);
    snackbarAction = (TextView) view.findViewById(R.id.snackbar_action);
    messagesView = (ListView) view.findViewById(R.id.messages_view);
    messagesView.setOnScrollListener(mOnScrollListener);
    messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
    messageListAdapter = new MessageAdapter((ConversationActivity) getActivity(), this.messageList);
    messageListAdapter.setOnContactPictureClicked(new OnContactPictureClicked() {

        @Override
        public void onContactPictureClicked(Message message) {
            if (message.getStatus() <= Message.STATUS_RECEIVED) {
                if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
                    Jid user = message.getCounterpart();
                    if (user != null && !user.isBareJid()) {
                        if (!message.getConversation().getMucOptions().isUserInRoom(user)) {
                            Toast.makeText(activity, activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                        }
                        highlightInConference(user.getResourcepart());
                    }
                } else {
                    if (!message.getContact().isSelf()) {
                        String fingerprint;
                        if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
                            fingerprint = "pgp";
                        } else {
                            fingerprint = message.getFingerprint();
                        }
                        activity.switchToContactDetails(message.getContact(), fingerprint);
                    }
                }
            } else {
                Account account = message.getConversation().getAccount();
                Intent intent;
                if (activity.manuallyChangePresence()) {
                    intent = new Intent(activity, SetPresenceActivity.class);
                    intent.putExtra(SetPresenceActivity.EXTRA_ACCOUNT, account.getJid().toBareJid().toString());
                } else {
                    intent = new Intent(activity, EditAccountActivity.class);
                    intent.putExtra("jid", account.getJid().toBareJid().toString());
                    String fingerprint;
                    if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
                        fingerprint = "pgp";
                    } else {
                        fingerprint = message.getFingerprint();
                    }
                    intent.putExtra("fingerprint", fingerprint);
                }
                startActivity(intent);
            }
        }
    });
    messageListAdapter.setOnContactPictureLongClicked(new OnContactPictureLongClicked() {

        @Override
        public void onContactPictureLongClicked(Message message) {
            if (message.getStatus() <= Message.STATUS_RECEIVED) {
                if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
                    Jid user = message.getCounterpart();
                    if (user != null && !user.isBareJid()) {
                        if (message.getConversation().getMucOptions().isUserInRoom(user)) {
                            privateMessageWith(user);
                        } else {
                            Toast.makeText(activity, activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            } else {
                activity.showQrCode();
            }
        }
    });
    messageListAdapter.setOnQuoteListener(new MessageAdapter.OnQuoteListener() {

        @Override
        public void onQuote(String text) {
            if (mEditMessage.isEnabled()) {
                text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", "");
                Editable editable = mEditMessage.getEditableText();
                int position = mEditMessage.getSelectionEnd();
                if (position == -1)
                    position = editable.length();
                if (position > 0 && editable.charAt(position - 1) != '\n') {
                    editable.insert(position++, "\n");
                }
                editable.insert(position, text);
                position += text.length();
                editable.insert(position++, "\n");
                if (position < editable.length() && editable.charAt(position) != '\n') {
                    editable.insert(position, "\n");
                }
                mEditMessage.setSelection(position);
                mEditMessage.requestFocus();
                InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                if (inputMethodManager != null) {
                    inputMethodManager.showSoftInput(mEditMessage, InputMethodManager.SHOW_IMPLICIT);
                }
            }
        }
    });
    messagesView.setAdapter(messageListAdapter);
    registerForContextMenu(messagesView);
    return view;
}
Also used : MessageAdapter(eu.siacs.conversations.ui.adapter.MessageAdapter) Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) OnContactPictureLongClicked(eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked) OnContactPictureClicked(eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked) OnClickListener(android.view.View.OnClickListener) Editable(android.text.Editable)

Example 68 with Account

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

the class ConversationActivity method selectPresenceToAttachFile.

protected void selectPresenceToAttachFile(final int attachmentChoice, final int encryption) {
    final Conversation conversation = getSelectedConversation();
    final Account account = conversation.getAccount();
    final OnPresenceSelected callback = new OnPresenceSelected() {

        @Override
        public void onPresenceSelected() {
            Intent intent = new Intent();
            boolean chooser = false;
            String fallbackPackageId = null;
            switch(attachmentChoice) {
                case ATTACHMENT_CHOICE_CHOOSE_IMAGE:
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
                    }
                    intent.setType("image/*");
                    chooser = true;
                    break;
                case ATTACHMENT_CHOICE_TAKE_PHOTO:
                    Uri uri = xmppConnectionService.getFileBackend().getTakePhotoUri();
                    intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                    mPendingImageUris.clear();
                    mPendingImageUris.add(uri);
                    break;
                case ATTACHMENT_CHOICE_CHOOSE_FILE:
                    chooser = true;
                    intent.setType("*/*");
                    intent.addCategory(Intent.CATEGORY_OPENABLE);
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    break;
                case ATTACHMENT_CHOICE_RECORD_VOICE:
                    intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
                    fallbackPackageId = "eu.siacs.conversations.voicerecorder";
                    break;
                case ATTACHMENT_CHOICE_LOCATION:
                    intent.setAction("eu.siacs.conversations.location.request");
                    fallbackPackageId = "eu.siacs.conversations.sharelocation";
                    break;
            }
            if (intent.resolveActivity(getPackageManager()) != null) {
                if (chooser) {
                    startActivityForResult(Intent.createChooser(intent, getString(R.string.perform_action_with)), attachmentChoice);
                } else {
                    startActivityForResult(intent, attachmentChoice);
                }
            } else if (fallbackPackageId != null) {
                startActivity(getInstallApkIntent(fallbackPackageId));
            }
        }
    };
    if ((account.httpUploadAvailable() || attachmentChoice == ATTACHMENT_CHOICE_LOCATION) && encryption != Message.ENCRYPTION_OTR) {
        conversation.setNextCounterpart(null);
        callback.onPresenceSelected();
    } else {
        selectPresence(conversation, callback);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Conversation(eu.siacs.conversations.entities.Conversation) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Uri(android.net.Uri)

Example 69 with Account

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

the class ConversationActivity method redirectToStartConversationActivity.

private void redirectToStartConversationActivity() {
    Account pendingAccount = xmppConnectionService.getPendingAccount();
    if (pendingAccount == null) {
        Intent startConversationActivity = new Intent(this, StartConversationActivity.class);
        startConversationActivity.putExtra("init", true);
        startActivity(startConversationActivity);
    } else {
        switchToAccount(pendingAccount, true);
    }
    finish();
}
Also used : Account(eu.siacs.conversations.entities.Account) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Example 70 with Account

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

the class XmppConnectionService method fetchBookmarks.

public void fetchBookmarks(final Account account) {
    final IqPacket iqPacket = new IqPacket(IqPacket.TYPE.GET);
    final Element query = iqPacket.query("jabber:iq:private");
    query.addChild("storage", "storage:bookmarks");
    final OnIqPacketReceived callback = new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(final Account account, final IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                final Element query = packet.query();
                final HashMap<Jid, Bookmark> bookmarks = new HashMap<>();
                final Element storage = query.findChild("storage", "storage:bookmarks");
                final boolean autojoin = respectAutojoin();
                if (storage != null) {
                    for (final Element item : storage.getChildren()) {
                        if (item.getName().equals("conference")) {
                            final Bookmark bookmark = Bookmark.parse(item, account);
                            Bookmark old = bookmarks.put(bookmark.getJid(), bookmark);
                            if (old != null && old.getBookmarkName() != null && bookmark.getBookmarkName() == null) {
                                bookmark.setBookmarkName(old.getBookmarkName());
                            }
                            Conversation conversation = find(bookmark);
                            if (conversation != null) {
                                conversation.setBookmark(bookmark);
                            } else if (bookmark.autojoin() && bookmark.getJid() != null && autojoin) {
                                conversation = findOrCreateConversation(account, bookmark.getJid(), true, true);
                                conversation.setBookmark(bookmark);
                            }
                        }
                    }
                }
                account.setBookmarks(new ArrayList<>(bookmarks.values()));
            } else {
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fetch bookmarks");
            }
        }
    };
    sendIqPacket(account, iqPacket, callback);
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Jid(eu.siacs.conversations.xmpp.jid.Jid) Bookmark(eu.siacs.conversations.entities.Bookmark) HashMap(java.util.HashMap) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5