Search in sources :

Example 1 with ContactItemComparator

use of com.lingtuan.firefly.custom.contact.ContactItemComparator in project SmartMesh_Android by SmartMeshFoundation.

the class MainContactFragmentUI method deleteFriends.

/**
 * Remove buddy
 */
private void deleteFriends(final String uid, final boolean isFriendOffline) {
    if (isFriendOffline) {
        FinalUserDataBase.getInstance().deleteFriendByUid(uid);
        int i = 0;
        for (UserBaseVo info : mFriendInfoList) {
            if (uid.equals(info.getLocalId())) {
                mFriendInfoList.remove(i);
                break;
            }
            i++;
        }
        mContactList.clear();
        for (UserBaseVo voT : mFriendInfoList) {
            NewContactVO info = new NewContactVO();
            info.setAge(voT.getAge());
            info.setDistance(voT.getDistance());
            info.setFriendLog(voT.getFriendLog());
            info.setGender(voT.getGender());
            info.setSightml(voT.getSightml());
            info.setThumb(voT.getThumb());
            info.setLocalId(voT.getLocalId());
            info.setUsername(voT.getUserName());
            info.setNote(voT.getNote());
            info.setLogintime(voT.getLogintime());
            info.setFullName(PinYin.getPinYin(voT.getShowName()));
            info.setMid(voT.getMid());
            info.setOffLine(voT.isOffLine());
            mContactList.add(info);
        }
        mNewListView.setFastScrollEnabled(true);
        Collections.sort(mContactList, new ContactItemComparator());
        mNewContactListAdapter.updateList(mContactList);
        contactNum.setText(getString(R.string.contact_num, mContactList.size()));
    } else {
        NetRequestImpl.getInstance().deleteFriends(uid, new RequestListener() {

            @Override
            public void start() {
            }

            @Override
            public void success(JSONObject response) {
                showToast(response.optString("msg"));
                FinalUserDataBase.getInstance().deleteFriendByUid(uid);
                int i = 0;
                for (UserBaseVo info : mFriendInfoList) {
                    if (uid.equals(info.getLocalId())) {
                        mFriendInfoList.remove(i);
                        break;
                    }
                    i++;
                }
                mContactList.clear();
                for (UserBaseVo voT : mFriendInfoList) {
                    NewContactVO info = new NewContactVO();
                    info.setAge(voT.getAge());
                    info.setDistance(voT.getDistance());
                    info.setFriendLog(voT.getFriendLog());
                    info.setGender(voT.getGender());
                    info.setSightml(voT.getSightml());
                    info.setThumb(voT.getThumb());
                    info.setLocalId(voT.getLocalId());
                    info.setUsername(voT.getUserName());
                    info.setNote(voT.getNote());
                    info.setLogintime(voT.getLogintime());
                    info.setFullName(PinYin.getPinYin(voT.getShowName()));
                    info.setMid(voT.getMid());
                    info.setOffLine(voT.isOffLine());
                    mContactList.add(info);
                }
                mNewListView.setFastScrollEnabled(true);
                Collections.sort(mContactList, new ContactItemComparator());
                mNewContactListAdapter.updateList(mContactList);
                contactNum.setText(getString(R.string.contact_num, mContactList.size()));
            }

            @Override
            public void error(int errorCode, String errorMsg) {
                showToast(errorMsg);
            }
        });
    }
}
Also used : RequestListener(com.lingtuan.firefly.listener.RequestListener) JSONObject(org.json.JSONObject) NewContactVO(com.lingtuan.firefly.contact.vo.NewContactVO) ContactItemComparator(com.lingtuan.firefly.custom.contact.ContactItemComparator) SuppressLint(android.annotation.SuppressLint) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 NewContactVO (com.lingtuan.firefly.contact.vo.NewContactVO)1 ContactItemComparator (com.lingtuan.firefly.custom.contact.ContactItemComparator)1 RequestListener (com.lingtuan.firefly.listener.RequestListener)1 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)1 JSONObject (org.json.JSONObject)1