Search in sources :

Example 26 with Contact

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

the class ChooseContactActivity method filterContacts.

protected void filterContacts(final String needle) {
    getListItems().clear();
    for (final Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            for (final Contact contact : account.getRoster().getContacts()) {
                if (contact.showInRoster() && !filterContacts.contains(contact.getJid().toBareJid().toString()) && contact.match(this, needle)) {
                    getListItems().add(contact);
                }
            }
        }
    }
    Collections.sort(getListItems());
    getListItemAdapter().notifyDataSetChanged();
}
Also used : Account(eu.siacs.conversations.entities.Account) Contact(eu.siacs.conversations.entities.Contact)

Example 27 with Contact

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

the class XmppActivity method showPresenceSelectionDialog.

private void showPresenceSelectionDialog(Presences presences, final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.choose_presence));
    final String[] resourceArray = presences.toResourceArray();
    Pair<Map<String, String>, Map<String, String>> typeAndName = presences.toTypeAndNameMap();
    final Map<String, String> resourceTypeMap = typeAndName.first;
    final Map<String, String> resourceNameMap = typeAndName.second;
    final String[] readableIdentities = new String[resourceArray.length];
    final AtomicInteger selectedResource = new AtomicInteger(0);
    for (int i = 0; i < resourceArray.length; ++i) {
        String resource = resourceArray[i];
        if (resource.equals(contact.getLastResource())) {
            selectedResource.set(i);
        }
        String type = resourceTypeMap.get(resource);
        String name = resourceNameMap.get(resource);
        if (type != null) {
            if (Collections.frequency(resourceTypeMap.values(), type) == 1) {
                readableIdentities[i] = UIHelper.tranlasteType(this, type);
            } else if (name != null) {
                if (Collections.frequency(resourceNameMap.values(), name) == 1 || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
                    readableIdentities[i] = UIHelper.tranlasteType(this, type) + "  (" + name + ")";
                } else {
                    readableIdentities[i] = UIHelper.tranlasteType(this, type) + " (" + name + " / " + resource + ")";
                }
            } else {
                readableIdentities[i] = UIHelper.tranlasteType(this, type) + " (" + resource + ")";
            }
        } else {
            readableIdentities[i] = resource;
        }
    }
    builder.setSingleChoiceItems(readableIdentities, selectedResource.get(), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            selectedResource.set(which);
        }
    });
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                Jid next = Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), resourceArray[selectedResource.get()]);
                conversation.setNextCounterpart(next);
            } catch (InvalidJidException e) {
                conversation.setNextCounterpart(null);
            }
            listener.onPresenceSelected();
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) Jid(eu.siacs.conversations.xmpp.jid.Jid) DialogInterface(android.content.DialogInterface) Builder(android.app.AlertDialog.Builder) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Builder(android.app.AlertDialog.Builder) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Contact(eu.siacs.conversations.entities.Contact) OnClickListener(android.content.DialogInterface.OnClickListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OnClickListener(android.content.DialogInterface.OnClickListener) Map(java.util.Map)

Example 28 with Contact

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

the class StartConversationActivity method openDetailsForContact.

protected void openDetailsForContact() {
    int position = contact_context_id;
    Contact contact = (Contact) contacts.get(position);
    switchToContactDetails(contact);
}
Also used : SuppressLint(android.annotation.SuppressLint) Contact(eu.siacs.conversations.entities.Contact)

Example 29 with Contact

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

the class StartConversationActivity method deleteContact.

protected void deleteContact() {
    final int position = contact_context_id;
    final Contact contact = (Contact) contacts.get(position);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setTitle(R.string.action_delete_contact);
    builder.setMessage(getString(R.string.remove_contact_text, contact.getJid()));
    builder.setPositiveButton(R.string.delete, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            xmppConnectionService.deleteContactOnServer(contact);
            filter(mSearchEditText.getText().toString());
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) SuppressLint(android.annotation.SuppressLint) Contact(eu.siacs.conversations.entities.Contact)

Example 30 with Contact

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

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(eu.siacs.conversations.entities.Account) Presence(eu.siacs.conversations.entities.Presence) Contact(eu.siacs.conversations.entities.Contact)

Aggregations

Contact (eu.siacs.conversations.entities.Contact)32 Account (eu.siacs.conversations.entities.Account)9 Jid (eu.siacs.conversations.xmpp.jid.Jid)9 Conversation (eu.siacs.conversations.entities.Conversation)8 Element (eu.siacs.conversations.xml.Element)7 SuppressLint (android.annotation.SuppressLint)5 DialogInterface (android.content.DialogInterface)5 OnClickListener (android.content.DialogInterface.OnClickListener)4 AlertDialog (android.app.AlertDialog)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 Builder (android.app.AlertDialog.Builder)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 Toast (android.widget.Toast)2 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)2