Search in sources :

Example 21 with Contact

use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.

the class ContactListManagerAdapter method init.

private void init() {
    mContactListListenerAdapter = new ContactListListenerAdapter();
    mSubscriptionListenerAdapter = new SubscriptionRequestListenerAdapter();
    mContactLists = new HashMap<String, ContactListAdapter>();
    mTemporaryContacts = new HashMap<String, Contact>();
    // mOfflineContacts = new HashMap<String, Contact>();
    mValidatedContacts = new HashSet<String>();
    mValidatedContactLists = new HashSet<String>();
    mValidatedBlockedContacts = new HashSet<String>();
    mAdaptee.addContactListListener(mContactListListenerAdapter);
    mAdaptee.setSubscriptionRequestListener(mSubscriptionListenerAdapter);
    Uri.Builder builder = Imps.Avatars.CONTENT_URI_AVATARS_BY.buildUpon();
    ContentUris.appendId(builder, mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());
    mAvatarUrl = builder.build();
    builder = Imps.Contacts.CONTENT_URI_CONTACTS_BY.buildUpon();
    ContentUris.appendId(builder, mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());
    mContactUrl = builder.build();
    if (mConn.getAccountId() != -1)
        seedInitialPresences();
}
Also used : Uri(android.net.Uri) Builder(android.net.Uri.Builder) Contact(org.awesomeapp.messenger.model.Contact)

Example 22 with Contact

use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.

the class ContactListManagerAdapter method addContactListContent.

void addContactListContent(ContactList list) {
    String selection = Imps.ContactList.NAME + "=? AND " + Imps.ContactList.PROVIDER + "=? AND " + Imps.ContactList.ACCOUNT + "=?";
    String[] selectionArgs = { list.getName(), Long.toString(mConn.getProviderId()), Long.toString(mConn.getAccountId()) };
    Cursor cursor = mResolver.query(Imps.ContactList.CONTENT_URI, CONTACT_LIST_ID_PROJECTION, selection, selectionArgs, // no sort order
    null);
    long listId = 0;
    Uri uri = null;
    try {
        if (cursor.moveToFirst()) {
            listId = cursor.getLong(0);
            uri = ContentUris.withAppendedId(Imps.ContactList.CONTENT_URI, listId);
        }
    } finally {
        cursor.close();
    }
    if (uri == null) {
        ContentValues contactListValues = new ContentValues(3);
        contactListValues.put(Imps.ContactList.NAME, list.getName());
        contactListValues.put(Imps.ContactList.PROVIDER, mConn.getProviderId());
        contactListValues.put(Imps.ContactList.ACCOUNT, mConn.getAccountId());
        uri = mResolver.insert(Imps.ContactList.CONTENT_URI, contactListValues);
        listId = ContentUris.parseId(uri);
    }
    mValidatedContactLists.add(list.getName());
    mContactLists.put(list.getAddress().getAddress(), new ContactListAdapter(list, listId));
    Cursor contactCursor = mResolver.query(mContactUrl, new String[] { Imps.Contacts.USERNAME, Imps.Contacts.NICKNAME, Imps.Contacts.TYPE }, Imps.Contacts.CONTACTLIST + "=?", new String[] { "" + listId }, null);
    Set<String> existingUsernames = new HashSet<String>();
    while (contactCursor.moveToNext()) {
        String address = contactCursor.getString(0);
        existingUsernames.add(address);
        Contact contact = list.getContact(address);
        if (contact != null) {
            contact.setName(contactCursor.getString(1));
            contact.setType(contactCursor.getInt(2));
        }
    }
    contactCursor.close();
    Collection<Contact> contacts = list.getContacts();
    if (contacts == null || contacts.size() == 0) {
        return;
    }
    Iterator<Contact> iter = contacts.iterator();
    while (iter.hasNext()) {
        Contact c = iter.next();
        String address = mAdaptee.normalizeAddress(c.getAddress().getAddress());
        /**
         *            if (isTemporary(address)) {
         *                if (!existingUsernames.contains(address)) {
         *                    moveTemporaryContactToList(address, listId);
         *                }
         *                iter.remove();
         *            }*
         */
        mValidatedContacts.add(address);
    }
    ArrayList<String> usernames = new ArrayList<String>();
    ArrayList<String> nicknames = new ArrayList<String>();
    ArrayList<String> contactTypeArray = new ArrayList<String>();
    for (Contact c : contacts) {
        if (updateContact(c, listId))
            // contact existed and was updated to this list
            continue;
        String username = mAdaptee.normalizeAddress(c.getAddress().getAddress());
        String nickname = c.getName();
        int type = c.getType();
        /**
         *            if (isTemporary(username)) {
         *                type = Imps.Contacts.TYPE_TEMPORARY;
         *            }*
         */
        if (isBlocked(username)) {
            type = Imps.Contacts.TYPE_BLOCKED;
        }
        usernames.add(username);
        nicknames.add(nickname);
        contactTypeArray.add(String.valueOf(type));
    }
    ContentValues values = new ContentValues(6);
    values.put(Imps.Contacts.PROVIDER, mConn.getProviderId());
    values.put(Imps.Contacts.ACCOUNT, mConn.getAccountId());
    values.put(Imps.Contacts.CONTACTLIST, listId);
    putStringArrayList(values, Imps.Contacts.USERNAME, usernames);
    putStringArrayList(values, Imps.Contacts.NICKNAME, nicknames);
    putStringArrayList(values, Imps.Contacts.TYPE, contactTypeArray);
    mResolver.insert(Imps.Contacts.BULK_CONTENT_URI, values);
}
Also used : ContentValues(android.content.ContentValues) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) Contact(org.awesomeapp.messenger.model.Contact) HashSet(java.util.HashSet)

Example 23 with Contact

use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.

the class MainActivity method startChat.

public void startChat(long providerId, long accountId, String username, final boolean openChat) {
    if (username != null)
        new ChatSessionInitTask(((ImApp) getApplication()), providerId, accountId, Imps.Contacts.TYPE_NORMAL, true) {

            @Override
            protected void onPostExecute(Long chatId) {
                if (chatId != -1 && openChat) {
                    Intent intent = new Intent(MainActivity.this, ConversationDetailActivity.class);
                    intent.putExtra("id", chatId);
                    startActivity(intent);
                }
                super.onPostExecute(chatId);
            }
        }.executeOnExecutor(ImApp.sThreadPoolExecutor, new Contact(new XmppAddress(username)));
}
Also used : ChatSessionInitTask(org.awesomeapp.messenger.tasks.ChatSessionInitTask) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Intent(android.content.Intent) Contact(org.awesomeapp.messenger.model.Contact)

Example 24 with Contact

use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.

the class XmppConnection method setPresence.

private void setPresence(Jid from, int presenceType) {
    Presence p = null;
    Contact contact = mContactListManager.getContact(from.asBareJid().toString());
    if (contact == null)
        return;
    p = new Presence(presenceType, "", null, null, Presence.CLIENT_TYPE_MOBILE);
    if (from.hasResource())
        p.setResource(from.getResourceOrEmpty().toString());
    if (presenceType == Presence.AVAILABLE)
        p.setLastSeen(new Date());
    else if (contact.getPresence() != null)
        p.setLastSeen(contact.getPresence().getLastSeen());
    contact.setPresence(p);
    Collection<Contact> contactsUpdate = new ArrayList<Contact>();
    contactsUpdate.add(contact);
    mContactListManager.notifyContactsPresenceUpdated(contactsUpdate.toArray(new Contact[contactsUpdate.size()]));
}
Also used : ArrayList(java.util.ArrayList) Presence(org.awesomeapp.messenger.model.Presence) Date(java.util.Date) Contact(org.awesomeapp.messenger.model.Contact)

Example 25 with Contact

use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.

the class XmppConnection method handleChatState.

private void handleChatState(String from, String chatStateXml) throws RemoteException {
    Presence p = null;
    Contact contact = mContactListManager.getContact(from);
    if (contact == null)
        return;
    boolean isTyping = false;
    // handle is-typing, probably some indication on screen
    if (chatStateXml.contains("'error'") || chatStateXml.contains("'cancel'")) {
    // do nothing
    } else if (chatStateXml.contains(ChatState.active.toString())) {
        p = new Presence(Presence.AVAILABLE, "", null, null, Presence.CLIENT_TYPE_MOBILE);
        p.setLastSeen(new Date());
    } else if (chatStateXml.contains(ChatState.inactive.toString())) {
        p = new Presence(Presence.AWAY, "", null, null, Presence.CLIENT_TYPE_MOBILE);
        p.setLastSeen(new Date());
    } else if (chatStateXml.contains(ChatState.composing.toString())) {
        p = new Presence(Presence.AVAILABLE, "", null, null, Presence.CLIENT_TYPE_MOBILE);
        isTyping = true;
        p.setLastSeen(new Date());
    } else if (chatStateXml.contains(ChatState.inactive.toString()) || chatStateXml.contains(ChatState.paused.toString())) {
    } else if (chatStateXml.contains(ChatState.gone.toString())) {
    }
    IChatSession csa = mSessionManager.getAdapter().getChatSession(from);
    if (csa != null)
        csa.setContactTyping(contact, isTyping);
    if (p != null) {
        String[] presenceParts = from.split("/");
        if (presenceParts.length > 1)
            p.setResource(presenceParts[1]);
        contact.setPresence(p);
        Collection<Contact> contactsUpdate = new ArrayList<Contact>();
        contactsUpdate.add(contact);
        mContactListManager.notifyContactsPresenceUpdated(contactsUpdate.toArray(new Contact[contactsUpdate.size()]));
    }
}
Also used : ArrayList(java.util.ArrayList) Presence(org.awesomeapp.messenger.model.Presence) IChatSession(org.awesomeapp.messenger.service.IChatSession) Date(java.util.Date) Contact(org.awesomeapp.messenger.model.Contact)

Aggregations

Contact (org.awesomeapp.messenger.model.Contact)33 RemoteException (android.os.RemoteException)11 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)10 Presence (org.awesomeapp.messenger.model.Presence)6 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)6 Intent (android.content.Intent)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ImException (org.awesomeapp.messenger.model.ImException)5 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)5 ContentValues (android.content.ContentValues)4 Uri (android.net.Uri)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 KeyManagementException (java.security.KeyManagementException)4 KeyStoreException (java.security.KeyStoreException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 CertificateException (java.security.cert.CertificateException)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 ContactList (org.awesomeapp.messenger.model.ContactList)4 IChatSession (org.awesomeapp.messenger.service.IChatSession)4