Search in sources :

Example 16 with Contact

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

the class XmppActivity method selectPresence.

public void selectPresence(final Conversation conversation, final PresenceSelector.OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    if (conversation.hasValidOtrSession()) {
        SessionID id = conversation.getOtrSession().getSessionID();
        Jid jid;
        try {
            jid = Jid.fromString(id.getAccountID() + "/" + id.getUserID());
        } catch (InvalidJidException e) {
            jid = null;
        }
        conversation.setNextCounterpart(jid);
        listener.onPresenceSelected();
    } else if (!contact.showInRoster()) {
        showAddToRosterDialog(conversation);
    } else {
        final Presences presences = contact.getPresences();
        if (presences.size() == 0) {
            if (!contact.getOption(Contact.Options.TO) && !contact.getOption(Contact.Options.ASKING) && contact.getAccount().getStatus() == Account.State.ONLINE) {
                showAskForPresenceDialog(contact);
            } else if (!contact.getOption(Contact.Options.TO) || !contact.getOption(Contact.Options.FROM)) {
                PresenceSelector.warnMutualPresenceSubscription(this, conversation, listener);
            } else {
                conversation.setNextCounterpart(null);
                listener.onPresenceSelected();
            }
        } else if (presences.size() == 1) {
            String presence = presences.toResourceArray()[0];
            try {
                conversation.setNextCounterpart(Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), presence));
            } catch (InvalidJidException e) {
                conversation.setNextCounterpart(null);
            }
            listener.onPresenceSelected();
        } else {
            PresenceSelector.showPresenceSelectionDialog(this, conversation, listener);
        }
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Presences(de.pixart.messenger.entities.Presences) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) SessionID(net.java.otr4j.session.SessionID) Contact(de.pixart.messenger.entities.Contact)

Example 17 with Contact

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

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] = PresenceSelector.translateType(this, type);
            } else if (name != null) {
                if (Collections.frequency(resourceNameMap.values(), name) == 1 || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
                    readableIdentities[i] = PresenceSelector.translateType(this, type) + "  (" + name + ")";
                } else {
                    readableIdentities[i] = PresenceSelector.translateType(this, type) + " (" + name + " / " + resource + ")";
                }
            } else {
                readableIdentities[i] = PresenceSelector.translateType(this, type) + " (" + resource + ")";
            }
        } else {
            readableIdentities[i] = resource;
        }
    }
    builder.setSingleChoiceItems(readableIdentities, selectedResource.get(), (dialog, which) -> selectedResource.set(which));
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, (dialog, 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.support.v7.app.AlertDialog) Jid(de.pixart.messenger.xmpp.jid.Jid) Builder(android.app.AlertDialog.Builder) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Builder(android.app.AlertDialog.Builder) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) Contact(de.pixart.messenger.entities.Contact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map)

Example 18 with Contact

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

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(de.pixart.messenger.entities.Contact)

Example 19 with Contact

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

the class StartConversationActivity method openConversationForContact.

protected void openConversationForContact(int position) {
    Contact contact = (Contact) contacts.get(position);
    openConversationForContact(contact);
}
Also used : Contact(de.pixart.messenger.entities.Contact)

Example 20 with Contact

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

the class PresenceSelector method showPresenceSelectionDialog.

public static void showPresenceSelectionDialog(Activity activity, final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    final Presences presences = contact.getPresences();
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(activity.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] = translateType(activity, type);
            } else if (name != null) {
                if (Collections.frequency(resourceNameMap.values(), name) == 1 || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
                    readableIdentities[i] = translateType(activity, type) + "  (" + name + ")";
                } else {
                    readableIdentities[i] = translateType(activity, type) + " (" + name + " / " + resource + ")";
                }
            } else {
                readableIdentities[i] = translateType(activity, type) + " (" + resource + ")";
            }
        } else {
            readableIdentities[i] = resource;
        }
    }
    builder.setSingleChoiceItems(readableIdentities, selectedResource.get(), (dialog, which) -> selectedResource.set(which));
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, (dialog, 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(de.pixart.messenger.xmpp.jid.Jid) Presences(de.pixart.messenger.entities.Presences) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Contact(de.pixart.messenger.entities.Contact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map)

Aggregations

Contact (de.pixart.messenger.entities.Contact)39 Jid (de.pixart.messenger.xmpp.jid.Jid)16 Account (de.pixart.messenger.entities.Account)12 Conversation (de.pixart.messenger.entities.Conversation)11 Element (de.pixart.messenger.xml.Element)9 SuppressLint (android.annotation.SuppressLint)7 MucOptions (de.pixart.messenger.entities.MucOptions)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)5 ArrayList (java.util.ArrayList)5 PendingIntent (android.app.PendingIntent)4 Intent (android.content.Intent)4 AlertDialog (android.support.v7.app.AlertDialog)4 MenuItem (android.view.MenuItem)4 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)4 DialogInterface (android.content.DialogInterface)3 Bitmap (android.graphics.Bitmap)3 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3 Message (de.pixart.messenger.entities.Message)3 Presence (de.pixart.messenger.entities.Presence)3