Search in sources :

Example 71 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method showCreateContactDialog.

@SuppressLint("InflateParams")
protected void showCreateContactDialog(final String prefilledJid, final Invite invite) {
    EnterJidDialog dialog = new EnterJidDialog(this, mKnownHosts, mActivatedAccounts, getString(R.string.create_contact), getString(R.string.create), prefilledJid, null, invite == null || !invite.hasFingerprints(), xmppConnectionService.multipleAccounts());
    dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
        if (!xmppConnectionServiceBound) {
            return false;
        }
        final Account account = xmppConnectionService.findAccountByJid(accountJid);
        if (account == null) {
            return true;
        }
        final Contact contact = account.getRoster().getContact(contactJid);
        if (invite != null && invite.getName() != null) {
            contact.setServerName(invite.getName());
        }
        if (contact.isSelf()) {
            switchToConversation(contact, null);
            return true;
        } else if (contact.showInRoster()) {
            throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
        } else {
            xmppConnectionService.createContact(contact, true);
            if (invite != null && invite.hasFingerprints()) {
                xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
            }
            switchToConversation(contact, invite == null ? null : invite.getBody());
            return true;
        }
    });
    mCurrentDialog = dialog.show();
}
Also used : Account(de.pixart.messenger.entities.Account) Contact(de.pixart.messenger.entities.Contact) SuppressLint(android.annotation.SuppressLint)

Example 72 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method filterContacts.

protected void filterContacts(String needle) {
    this.contacts.clear();
    for (Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            for (Contact contact : account.getRoster().getContacts()) {
                Presence.Status s = contact.getShownStatus();
                if (contact.showInRoster() && contact.match(this, needle) && (!this.mHideOfflineContacts || (needle != null && !needle.trim().isEmpty()) || s.compareTo(Presence.Status.OFFLINE) < 0)) {
                    this.contacts.add(contact);
                }
            }
        }
    }
    Collections.sort(this.contacts);
    mContactsAdapter.notifyDataSetChanged();
}
Also used : Account(de.pixart.messenger.entities.Account) Presence(de.pixart.messenger.entities.Presence) Contact(de.pixart.messenger.entities.Contact)

Example 73 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method deleteConference.

protected void deleteConference() {
    int position = conference_context_id;
    final Bookmark bookmark = (Bookmark) conferences.get(position);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setTitle(R.string.delete_bookmark);
    builder.setMessage(getString(R.string.remove_bookmark_text, bookmark.getJid()));
    builder.setPositiveButton(R.string.delete, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            bookmark.setConversation(null);
            Account account = bookmark.getAccount();
            account.getBookmarks().remove(bookmark);
            xmppConnectionService.pushBookmarks(account);
            filter(mSearchEditText.getText().toString());
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(de.pixart.messenger.entities.Account) Bookmark(de.pixart.messenger.entities.Bookmark) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) SuppressLint(android.annotation.SuppressLint)

Example 74 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method showJoinConferenceDialog.

@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.join_conference);
    final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
    final TextView yourAccount = dialogView.findViewById(R.id.your_account);
    final Spinner spinner = dialogView.findViewById(R.id.account);
    final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid);
    DelayedHintHelper.setHint(R.string.conference_address_example, jid);
    jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
    if (prefilledJid != null) {
        jid.append(prefilledJid);
    }
    if (xmppConnectionService.multipleAccounts()) {
        yourAccount.setVisibility(View.VISIBLE);
        spinner.setVisibility(View.VISIBLE);
    } else {
        yourAccount.setVisibility(View.GONE);
        spinner.setVisibility(View.GONE);
    }
    populateAccountSpinner(this, mActivatedAccounts, spinner);
    final Checkable bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
    builder.setView(dialogView);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.join, null);
    final AlertDialog dialog = builder.create();
    dialog.show();
    mCurrentDialog = dialog;
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (!xmppConnectionServiceBound) {
            return;
        }
        final Account account = getSelectedAccount(spinner);
        if (account == null) {
            return;
        }
        final Jid conferenceJid;
        try {
            conferenceJid = Jid.fromString(jid.getText().toString());
        } catch (final InvalidJidException e) {
            jid.setError(getString(R.string.invalid_jid));
            return;
        }
        if (bookmarkCheckBox.isChecked()) {
            if (account.hasBookmarkFor(conferenceJid)) {
                jid.setError(getString(R.string.bookmark_already_exists));
            } else {
                final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid());
                bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin)));
                String nick = conferenceJid.getResourcepart();
                if (nick != null && !nick.isEmpty()) {
                    bookmark.setNick(nick);
                }
                account.getBookmarks().add(bookmark);
                xmppConnectionService.pushBookmarks(account);
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
                bookmark.setConversation(conversation);
                dialog.dismiss();
                mCurrentDialog = null;
                switchToConversation(conversation);
            }
        } else {
            final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
            dialog.dismiss();
            mCurrentDialog = null;
            switchToConversation(conversation);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) KnownHostsAdapter(de.pixart.messenger.ui.adapter.KnownHostsAdapter) Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Spinner(android.widget.Spinner) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Bookmark(de.pixart.messenger.entities.Bookmark) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Checkable(android.widget.Checkable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SuppressLint(android.annotation.SuppressLint)

Example 75 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class ConferenceDetailsActivity method deleteBookmark.

protected void deleteBookmark() {
    Account account = mConversation.getAccount();
    Bookmark bookmark = mConversation.getBookmark();
    bookmark.setConversation(null);
    account.getBookmarks().remove(bookmark);
    xmppConnectionService.pushBookmarks(account);
    updateView();
}
Also used : Account(de.pixart.messenger.entities.Account) Bookmark(de.pixart.messenger.entities.Bookmark)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6