Search in sources :

Example 6 with PhoneContactVo

use of com.lingtuan.firefly.contact.vo.PhoneContactVo in project SmartMesh_Android by SmartMeshFoundation.

the class FinalUserDataBase method getPhoneContactGroup.

/**
 * get local save three friends information
 *
 * @ param type 1. The mobile phone address book, 2. Sina weibo friends, 3. Tencent weibo friends
 * @ return
 */
public List<PhoneContactGroupVo> getPhoneContactGroup(int type) {
    String sql = "select * from " + TableField.TABLE_CONTACT + " where " + TableField.FIELD_CHAT_TYPE + "=? " + " order by " + TableField.FIELD_FRIEND_RELATION + "," + TableField.FIELD_FRIEND_UNAME;
    Cursor cursor = db.rawQuery(sql, new String[] { String.valueOf(type) });
    List<PhoneContactGroupVo> mGList = new ArrayList<PhoneContactGroupVo>();
    PhoneContactGroupVo gVo = null;
    List<PhoneContactVo> mCList = new ArrayList<PhoneContactVo>();
    PhoneContactVo vo = null;
    int relation = 0;
    while (cursor.moveToNext()) {
        vo = new PhoneContactVo();
        vo.setId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_THIRDID)));
        vo.setName(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UNAME)));
        vo.setNote(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_NOTE)));
        vo.setRelation(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_FRIEND_RELATION)));
        vo.setUid(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_FRIEND_UID)));
        vo.setType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_TYPE)));
        if (vo.getRelation() != relation) {
            // 新的组
            gVo = new PhoneContactGroupVo();
            gVo.setContactList(mCList);
            gVo.setType(relation);
            mGList.add(gVo);
            relation = vo.getRelation();
            mCList = new ArrayList<>();
            mCList.add(vo);
        } else {
            mCList.add(vo);
        }
    }
    cursor.close();
    gVo = new PhoneContactGroupVo();
    gVo.setContactList(mCList);
    if (vo != null) {
        gVo.setType(vo.getRelation());
    }
    mGList.add(gVo);
    return mGList;
}
Also used : PhoneContactGroupVo(com.lingtuan.firefly.contact.vo.PhoneContactGroupVo) PhoneContactVo(com.lingtuan.firefly.contact.vo.PhoneContactVo) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

PhoneContactVo (com.lingtuan.firefly.contact.vo.PhoneContactVo)6 Cursor (android.database.Cursor)4 ArrayList (java.util.ArrayList)3 Resources (android.content.res.Resources)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 LatLonPoint (com.amap.api.services.core.LatLonPoint)1 FriendRecommentVo (com.lingtuan.firefly.contact.vo.FriendRecommentVo)1 PhoneContactGroupVo (com.lingtuan.firefly.contact.vo.PhoneContactGroupVo)1