Search in sources :

Example 16 with Contact

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

the class ContactListManagerAdapter method updateAvatarsContent.

void updateAvatarsContent(Contact[] contacts) {
    ArrayList<ContentValues> avatars = new ArrayList<ContentValues>();
    ArrayList<String> usernames = new ArrayList<String>();
    for (Contact contact : contacts) {
        byte[] avatarData = contact.getPresence().getAvatarData();
        if (avatarData == null) {
            continue;
        }
        String username = mAdaptee.normalizeAddress(contact.getAddress().getAddress());
        ContentValues values = new ContentValues(2);
        values.put(Imps.Avatars.CONTACT, username);
        values.put(Imps.Avatars.DATA, avatarData);
        avatars.add(values);
        usernames.add(username);
    }
    if (avatars.size() > 0) {
        // ImProvider will replace the avatar content if it already exist.
        mResolver.bulkInsert(mAvatarUrl, avatars.toArray(new ContentValues[avatars.size()]));
        // notify avatar changed
        Intent i = new Intent(ImServiceConstants.ACTION_AVATAR_CHANGED);
        i.putExtra(ImServiceConstants.EXTRA_INTENT_FROM_ADDRESS, usernames);
        i.putExtra(ImServiceConstants.EXTRA_INTENT_PROVIDER_ID, mConn.getProviderId());
        i.putExtra(ImServiceConstants.EXTRA_INTENT_ACCOUNT_ID, mConn.getAccountId());
        mContext.sendBroadcast(i);
    }
}
Also used : ContentValues(android.content.ContentValues) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Contact(org.awesomeapp.messenger.model.Contact)

Example 17 with Contact

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

the class ContactListItem method declineSubscription.

void declineSubscription() {
    ImApp app = ((ImApp) ((Activity) getContext()).getApplication());
    IImConnection mConn = app.getConnection(mHolder.mProviderId, mHolder.mAccountId);
    if (mConn != null) {
        try {
            IContactListManager manager = mConn.getContactListManager();
            manager.declineSubscription(new Contact(new XmppAddress(address), nickname, Imps.Contacts.TYPE_NORMAL));
            app.dismissChatNotification(mHolder.mProviderId, address);
            manager.removeContact(address);
        } catch (RemoteException e) {
            // mHandler.showServiceErrorAlert(e.getLocalizedMessage());
            LogCleaner.error(ImApp.LOG_TAG, "decline sub error", e);
        }
    }
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Activity(android.app.Activity) ImApp(org.awesomeapp.messenger.ImApp) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException) Contact(org.awesomeapp.messenger.model.Contact)

Example 18 with Contact

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

the class ContactListItem method approveSubscription.

/*
    private String queryGroupMembers(ContentResolver resolver, long groupId) {
        String[] projection = { Imps.GroupMembers.NICKNAME };
        Uri uri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, groupId);
        Cursor c = resolver.query(uri, projection, null, null, null);
        StringBuilder buf = new StringBuilder();
        if (c != null) {
            while (c.moveToNext()) {
                buf.append(c.getString(0));
                                                Imps.Avatars.DATA
                if (!c.isLast()) {
                    buf.append(',');
                }
            }
        }
        c.close();

        return buf.toString();
    }*/
void approveSubscription() {
    ImApp app = ((ImApp) ((Activity) getContext()).getApplication());
    IImConnection mConn = app.getConnection(mHolder.mProviderId, mHolder.mAccountId);
    if (mConn != null) {
        try {
            IContactListManager manager = mConn.getContactListManager();
            manager.approveSubscription(new Contact(new XmppAddress(address), nickname, Imps.Contacts.TYPE_NORMAL));
        } catch (RemoteException e) {
            // mHandler.showServiceErrorAlert(e.getLocalizedMessage());
            LogCleaner.error(ImApp.LOG_TAG, "approve sub error", e);
        }
    }
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Activity(android.app.Activity) ImApp(org.awesomeapp.messenger.ImApp) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException) Contact(org.awesomeapp.messenger.model.Contact)

Example 19 with Contact

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

the class ContactDisplayActivity method startChat.

public void startChat() {
    if (mConn == null)
        return;
    try {
        IChatSessionManager manager = mConn.getChatSessionManager();
        if (manager != null) {
            IChatSession session = manager.getChatSession(mUsername);
            if (session == null) {
                new ChatSessionInitTask(((ImApp) getApplication()), mProviderId, mAccountId, Imps.Contacts.TYPE_NORMAL, false) {

                    @Override
                    protected void onPostExecute(Long chatId) {
                        super.onPostExecute(chatId);
                        if (mContactId == -1) {
                            Intent intent = new Intent(ContactDisplayActivity.this, ConversationDetailActivity.class);
                            intent.putExtra("id", chatId);
                            startActivity(intent);
                            finish();
                        }
                    }
                }.executeOnExecutor(ImApp.sThreadPoolExecutor, new Contact(new XmppAddress(mUsername)));
            // Toast.makeText(this, getString(R.string.message_waiting_for_friend), Toast.LENGTH_LONG).show();
            } else {
                Intent intent = new Intent(ContactDisplayActivity.this, ConversationDetailActivity.class);
                intent.putExtra("id", session.getId());
                startActivity(intent);
                finish();
            }
        }
    } catch (RemoteException re) {
    }
    if (mContactId != -1) {
        Intent intent = new Intent(ContactDisplayActivity.this, ConversationDetailActivity.class);
        intent.putExtra("id", mContactId);
        startActivity(intent);
        finish();
    }
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) ChatSessionInitTask(org.awesomeapp.messenger.tasks.ChatSessionInitTask) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Intent(android.content.Intent) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession) Contact(org.awesomeapp.messenger.model.Contact)

Example 20 with Contact

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

the class ContactListManagerAdapter method updatePresenceContent.

void updatePresenceContent(Contact[] contacts) {
    if (mAdaptee == null)
        return;
    ArrayList<String> usernames = new ArrayList<String>();
    ArrayList<String> nicknames = new ArrayList<String>();
    ArrayList<String> statusArray = new ArrayList<String>();
    ArrayList<String> customStatusArray = new ArrayList<String>();
    ArrayList<String> clientTypeArray = new ArrayList<String>();
    ArrayList<String> resourceArray = new ArrayList<String>();
    for (Contact c : contacts) {
        String username = mAdaptee.normalizeAddress(c.getAddress().getAddress());
        Presence p = c.getPresence();
        int status = convertPresenceStatus(p);
        String customStatus = p.getStatusText();
        int clientType = translateClientType(p);
        usernames.add(username);
        nicknames.add(c.getName());
        statusArray.add(String.valueOf(status));
        customStatusArray.add(customStatus);
        clientTypeArray.add(String.valueOf(clientType));
        if (!TextUtils.isEmpty(p.getResource()))
            resourceArray.add(p.getResource());
        else
            resourceArray.add("");
    }
    ContentValues values = new ContentValues();
    values.put(Imps.Contacts.ACCOUNT, mConn.getAccountId());
    values.put(Imps.Contacts.PROVIDER, mConn.getProviderId());
    putStringArrayList(values, Imps.Contacts.USERNAME, usernames);
    putStringArrayList(values, Imps.Contacts.NICKNAME, nicknames);
    mResolver.update(Imps.Contacts.BULK_CONTENT_URI, values, null, null);
    values = new ContentValues();
    values.put(Imps.Contacts.ACCOUNT, mConn.getAccountId());
    values.put(Imps.Contacts.PROVIDER, mConn.getProviderId());
    putStringArrayList(values, Imps.Contacts.USERNAME, usernames);
    putStringArrayList(values, Imps.Presence.PRESENCE_STATUS, statusArray);
    putStringArrayList(values, Imps.Presence.PRESENCE_CUSTOM_STATUS, customStatusArray);
    putStringArrayList(values, Imps.Presence.CONTENT_TYPE, clientTypeArray);
    putStringArrayList(values, Imps.Presence.JID_RESOURCE, resourceArray);
    mResolver.update(Imps.Presence.BULK_CONTENT_URI, values, null, null);
}
Also used : ContentValues(android.content.ContentValues) ArrayList(java.util.ArrayList) Presence(org.awesomeapp.messenger.model.Presence) 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