Search in sources :

Example 16 with IContactListManager

use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.

the class ContactsListFragment method archiveContact.

private static void archiveContact(Activity activity, String address, int contactType, long providerId, long accountId) {
    try {
        IImConnection mConn;
        ImApp app = ((ImApp) activity.getApplication());
        mConn = app.getConnection(providerId, accountId);
        // then delete the contact from our list
        IContactListManager manager = mConn.getContactListManager();
        int res = manager.archiveContact(address, contactType, true);
        if (res != ImErrorInfo.NO_ERROR) {
        // mHandler.showAlert(R.string.error,
        // ErrorResUtils.getErrorRes(getResources(), res, address));
        }
    } catch (RemoteException re) {
    }
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) ImApp(org.awesomeapp.messenger.ImApp) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException) Paint(android.graphics.Paint)

Example 17 with IContactListManager

use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.

the class ConversationView method unregisterChatListener.

void unregisterChatListener() {
    if (Log.isLoggable(ImApp.LOG_TAG, Log.DEBUG)) {
        log("unregisterChatListener " + mLastChatId);
    }
    try {
        if (getChatSession() != null) {
            getChatSession().unregisterChatListener(mChatListener);
        }
        checkConnection();
        if (mConn != null) {
            IContactListManager listMgr = mConn.getContactListManager();
            listMgr.unregisterContactListListener(mContactListListener);
            listMgr.unregisterSubscriptionListener(mSubscriptionListener);
        }
    } catch (Exception e) {
        Log.w(ImApp.LOG_TAG, "<ChatView> unregisterChatListener fail:" + e.getMessage());
    }
}
Also used : IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException) IOException(java.io.IOException) CursorIndexOutOfBoundsException(android.database.CursorIndexOutOfBoundsException)

Example 18 with IContactListManager

use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.

the class GroupDisplayActivity method updateMembers.

private synchronized void updateMembers() {
    if (mThreadUpdate != null) {
        mThreadUpdate.interrupt();
        mThreadUpdate = null;
    }
    mThreadUpdate = new Thread(new Runnable() {

        @Override
        public void run() {
            final HashMap<String, GroupMemberDisplay> members = new HashMap<>();
            IContactListManager contactManager = null;
            try {
                if (mConn != null) {
                    contactManager = mConn.getContactListManager();
                }
            } catch (RemoteException re) {
            }
            String[] projection = { Imps.GroupMembers.USERNAME, Imps.GroupMembers.NICKNAME, Imps.GroupMembers.ROLE, Imps.GroupMembers.AFFILIATION };
            Uri memberUri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, mLastChatId);
            ContentResolver cr = getContentResolver();
            Cursor c = cr.query(memberUri, projection, null, null, null);
            if (c != null) {
                int colUsername = c.getColumnIndex(Imps.GroupMembers.USERNAME);
                int colNickname = c.getColumnIndex(Imps.GroupMembers.NICKNAME);
                int colRole = c.getColumnIndex(Imps.GroupMembers.ROLE);
                int colAffiliation = c.getColumnIndex(Imps.GroupMembers.AFFILIATION);
                while (c.moveToNext()) {
                    GroupMemberDisplay member = new GroupMemberDisplay();
                    member.username = new XmppAddress(c.getString(colUsername)).getBareAddress();
                    member.nickname = c.getString(colNickname);
                    member.role = c.getString(colRole);
                    member.affiliation = c.getString(colAffiliation);
                    try {
                        member.avatar = DatabaseUtils.getAvatarFromAddress(cr, member.username, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
                    } catch (DecoderException e) {
                        e.printStackTrace();
                    }
                    if (member.affiliation != null) {
                        if (member.affiliation.contentEquals("owner") || member.affiliation.contentEquals("admin")) {
                            if (member.username.equals(mLocalAddress))
                                mIsOwner = true;
                        }
                    }
                    members.put(member.username, member);
                }
                c.close();
            }
            if (!Thread.currentThread().isInterrupted()) {
                final ArrayList<GroupMemberDisplay> listMembers = new ArrayList<>(members.values());
                // Sort members by name, but keep owners at the top
                Collections.sort(listMembers, new Comparator<GroupMemberDisplay>() {

                    @Override
                    public int compare(GroupMemberDisplay member1, GroupMemberDisplay member2) {
                        if (member1.affiliation == null || member2.affiliation == null)
                            return 1;
                        boolean member1isImportant = (member1.affiliation.contentEquals("owner") || member1.affiliation.contentEquals("admin"));
                        boolean member2isImportant = (member2.affiliation.contentEquals("owner") || member2.affiliation.contentEquals("admin"));
                        if (member1isImportant != member2isImportant) {
                            if (member1isImportant) {
                                return -1;
                            } else {
                                return 1;
                            }
                        }
                        return member1.nickname.compareTo(member2.nickname);
                    }
                });
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        mMembers = listMembers;
                        if (mRecyclerView != null && mRecyclerView.getAdapter() != null)
                            mRecyclerView.getAdapter().notifyDataSetChanged();
                    }
                });
            }
        }
    });
    mThreadUpdate.start();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) DecoderException(org.apache.commons.codec.DecoderException) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException)

Example 19 with IContactListManager

use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.

the class ContactListFilterView method blockContact.

void blockContact(Cursor c) {
    final IImConnection conn = getConnection(c);
    String nickname = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.NICKNAME));
    final String address = c.getString(c.getColumnIndexOrThrow(Imps.Contacts.USERNAME));
    DialogInterface.OnClickListener confirmListener = new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            try {
                IContactListManager manager = conn.getContactListManager();
                int res = -1;
                if (manager.isBlocked(address))
                    res = manager.unBlockContact(address);
                else {
                    res = manager.blockContact(address);
                    if (res != ImErrorInfo.NO_ERROR) {
                        mHandler.showAlert(R.string.error, ErrorResUtils.getErrorRes(getResources(), res, address));
                    }
                }
            } catch (RemoteException e) {
                mHandler.showServiceErrorAlert(e.getLocalizedMessage());
                LogCleaner.error(ImApp.LOG_TAG, "remote error", e);
            }
        }
    };
    Resources r = getResources();
    new AlertDialog.Builder(mContext).setTitle(R.string.confirm).setMessage(r.getString(R.string.confirm_block_contact, nickname)).setPositiveButton(R.string.yes, // default button
    confirmListener).setNegativeButton(R.string.no, null).setCancelable(false).show();
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) DialogInterface(android.content.DialogInterface) Resources(android.content.res.Resources) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException)

Example 20 with IContactListManager

use of org.awesomeapp.messenger.service.IContactListManager in project Zom-Android by zom.

the class ContactListFilterView method setContactNickname.

protected void setContactNickname(String aAddress, String aNickname, IImConnection conn) {
    try {
        IContactListManager listManager = conn.getContactListManager();
        int result = listManager.setContactName(aAddress, aNickname);
        if (result != ImErrorInfo.NO_ERROR) {
            // TODO -LS error handling
            Toast.makeText(mContext, mContext.getString(R.string.error_prefix) + result, Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        // TODO -LS error handling
        Toast.makeText(mContext, mContext.getString(R.string.error_prefix) + e.getMessage(), Toast.LENGTH_LONG).show();
    }
    mFilterList.invalidate();
    final InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(getWindowToken(), 0);
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) IContactListManager(org.awesomeapp.messenger.service.IContactListManager) RemoteException(android.os.RemoteException)

Aggregations

RemoteException (android.os.RemoteException)21 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)21 IImConnection (org.awesomeapp.messenger.service.IImConnection)9 ImApp (org.awesomeapp.messenger.ImApp)6 IOException (java.io.IOException)5 Contact (org.awesomeapp.messenger.model.Contact)5 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)5 CursorIndexOutOfBoundsException (android.database.CursorIndexOutOfBoundsException)4 IContactList (org.awesomeapp.messenger.service.IContactList)4 Activity (android.app.Activity)3 DialogInterface (android.content.DialogInterface)3 Resources (android.content.res.Resources)3 Paint (android.graphics.Paint)3 IBinder (android.os.IBinder)3 IChatSession (org.awesomeapp.messenger.service.IChatSession)2 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)2 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1