Search in sources :

Example 56 with ChatMsg

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

the class FinalUserDataBase method getChatMsgEventList.

/**
 *My chat history record contains information system information
 *
 * @return
 */
public List<ChatMsg> getChatMsgEventList() {
    List<ChatMsg> list = new ArrayList<ChatMsg>();
    if (db != null) {
        String sql = "select * from " + TableField.TABLE_CHAT_EVENT + /*" where "  +TableField.FIELD_RESERVED_DATA7 + " is not 1*/
        " order by " + TableField.FIELD_CHAT_MSGTIME + " desc ";
        Cursor cursor = db.rawQuery(sql, null);
        ChatMsg msg;
        int total = 0;
        int unFriendTotle = 0;
        while (cursor.moveToNext()) {
            msg = new ChatMsg();
            msg.setId(cursor.getInt(cursor.getColumnIndex(TableField._ID)));
            msg.setContent(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_BODY)));
            msg.setGender(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_FRIEND_GENDER)));
            msg.setMsgTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_CHAT_MSGTIME)));
            msg.setType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_TYPE)));
            msg.setUserId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UID)));
            msg.setUserImage(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_PIC)));
            msg.setUsername(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UNAME)));
            msg.setChatId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_ID)));
            msg.setHidden(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_HIDDEN)) == 1 ? true : false);
            msg.setUnread(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_UNREAD)));
            msg.setSystem(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_SYSTEM)) == 1 ? true : false);
            msg.setDismissGroup(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_DISMISSGROUP)) == 1 ? true : false);
            msg.setKickGroup(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_KICKGROUP)) == 1 ? true : false);
            msg.setMessageId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA1)));
            msg.setShareFriendName(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA2)));
            msg.setModifyType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA3)));
            msg.setFriendLog(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA5)));
            msg.setGroupMask(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA6)) == 1 ? true : false);
            msg.setAtGroupMe(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA8)));
            msg.setGroupImage(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_GROUP_IMAGE)));
            msg.setMsgTypeInt(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_OBJECT)));
            msg.setCreateName(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_CREATENAME)));
            msg.setVip_type(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA12)));
            msg.setVip_level(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA13)));
            msg.setIs_vip(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA14)) == 1);
            msg.setTop(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA15)) == 1);
            msg.setRemoteSource(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA18)));
            msg.setInviteType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA19)));
            msg.setInviteSource(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA20)));
            msg.setMoney(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA9)));
            msg.setMode(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA11)));
            msg.setNoticeType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA26)));
            if (msg.isTop()) {
                msg.setTopTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA16)));
            }
            if (msg.getChatId().startsWith("group")) {
                msg.setGroup(true);
                try {
                    List<GroupMemberAvatarVo> lists = new ArrayList<>();
                    GroupMemberAvatarVo vo;
                    String[] split = msg.getUserImage().split("#");
                    for (int i = 0; i < split.length; i++) {
                        vo = new GroupMemberAvatarVo();
                        String[] splitVo = split[i].split("___");
                        int gender = 2;
                        try {
                            gender = Integer.parseInt(splitVo[1]);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        String image = "";
                        try {
                            image = splitVo[0];
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        vo.setGender(gender);
                        vo.setImage(image);
                        lists.add(vo);
                    }
                    msg.setMemberAvatarList(lists);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (!msg.isHidden()) {
                list.add(msg);
                if (msg.getChatId().equals("system-0") || msg.getChatId().equals("system-1") || msg.getChatId().equals("system-3") || msg.getChatId().equals("system-4") || msg.getChatId().equals("system-5")) {
                    total += msg.getUnread();
                } else if (!msg.getGroupMask()) {
                    total += msg.getUnread();
                }
            } else {
                if (!msg.isSystem() && !msg.getGroupMask()) {
                    unFriendTotle += msg.getUnread();
                }
            }
            if (!msg.isGroup() && msg.getMsgTypeInt() != 3 && !TextUtils.isEmpty(msg.getChatId()) && !TextUtils.equals("everyone", msg.getChatId()) && !msg.getChatId().startsWith("system")) {
                UserBaseVo baseVo = FinalUserDataBase.getInstance().getUserBaseVoByUid(msg.getChatId());
                if (baseVo != null && !TextUtils.isEmpty(baseVo.getShowName())) {
                    msg.setUsername(baseVo.getShowName());
                }
            }
        }
        try {
            map.put("totalunread", total);
        } catch (Exception e) {
            e.printStackTrace();
        }
        cursor.close();
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) GroupMemberAvatarVo(com.lingtuan.firefly.contact.vo.GroupMemberAvatarVo) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo)

Example 57 with ChatMsg

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

the class FinalUserDataBase method getChatMsgAddContactList.

/**
 * Add buddy information list
 */
public List<ChatMsg> getChatMsgAddContactList() {
    String sql = "select * from " + TableField.TABLE_CHAT_EVENT + " where " + TableField.FIELD_CHAT_SYSTEM + "=1 and " + TableField.FIELD_CHAT_TYPE + "=0 and " + TableField.FIELD_CHAT_HIDDEN + "=1 " + " order by " + TableField.FIELD_CHAT_MSGTIME + " desc ";
    Cursor cursor = db.rawQuery(sql, null);
    List<ChatMsg> list = new ArrayList<ChatMsg>();
    ChatMsg msg;
    while (cursor.moveToNext()) {
        msg = new ChatMsg();
        msg.setId(cursor.getInt(cursor.getColumnIndex(TableField._ID)));
        msg.setContent(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_BODY)));
        msg.setGender(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_FRIEND_GENDER)));
        msg.setMsgTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_CHAT_MSGTIME)));
        msg.setType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_TYPE)));
        msg.setUserId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UID)));
        msg.setUserImage(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_PIC)));
        msg.setUsername(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UNAME)));
        msg.setChatId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_ID)));
        msg.setUnread(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_UNREAD)));
        msg.setSystem(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_SYSTEM)) == 1);
        msg.setAgree(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_AGREE)) == 1);
        msg.setMessageId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA1)));
        msg.setShareFriendName(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA2)));
        msg.setOffLineMsg(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA7)) == 1 ? true : false);
        msg.setRemoteSource(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA18)));
        msg.setGroupImage(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_GROUP_IMAGE)));
        msg.setMsgTypeInt(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_OBJECT)));
        list.add(msg);
    }
    cursor.close();
    return list;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 58 with ChatMsg

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

the class FinalUserDataBase method getChatMsgListByChatId.

/**
 * Access to chat
 *
 * @param chatId Chat with who
 * @param limit  From which to take
 * @param count  Article take how much
 * @return
 */
public List<ChatMsg> getChatMsgListByChatId(String chatId, int limit, int count) {
    String sql = "select * from " + TableField.TABLE_CHAT + " where " + TableField.FIELD_CHAT_ID + "=? " + /*and " + TableField.FIELD_RESERVED_DATA7 + "!=1*/
    " order by " + TableField._ID + " desc " + " limit " + limit + "," + count;
    String sql1 = "select * from (" + sql + ") order by " + TableField._ID;
    Cursor cursor = db.rawQuery(sql1, new String[] { chatId });
    List<ChatMsg> list = new ArrayList<ChatMsg>();
    ChatMsg msg;
    while (cursor.moveToNext()) {
        msg = new ChatMsg();
        msg.setId(cursor.getInt(cursor.getColumnIndex(TableField._ID)));
        msg.setContent(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_BODY)));
        msg.setGender(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_FRIEND_GENDER)));
        msg.setMsgTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_CHAT_MSGTIME)));
        msg.setType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_TYPE)));
        msg.setUserId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UID)));
        msg.setUserImage(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_PIC)));
        msg.setRealname(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UNAME)));
        msg.setUnread(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_UNREAD)));
        msg.setUsername(msg.getRealname());
        msg.setChatId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_ID)));
        msg.setSend(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_ISSEND)));
        msg.setGroupImage(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_GROUP_IMAGE)));
        msg.setMsgTypeInt(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_OBJECT)));
        msg.setCover(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_COVER)));
        msg.setSecond(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_SECOND)));
        msg.setLon(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_LON)));
        msg.setLat(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_LAT)));
        msg.setThirdName(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_THIRDNAME)));
        msg.setThirdImage(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_THIRDIMAGE)));
        msg.setThirdId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_THIRDID)));
        msg.setShopAddress(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_SHOPADDRESS)));
        msg.setCardSign(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_CARDSIGN)));
        msg.setLocalUrl(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_LOCALURL)));
        msg.setShowTime(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_SHOWTIME)) == 1 ? true : false);
        msg.setMessageId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA1)));
        msg.setThirdGender(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA2)));
        msg.setDatingSOSId(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA3)));
        msg.setFriendLog(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA4)));
        msg.setInviteType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA5)));
        msg.setOffLineMsg(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA7)) == 1 ? true : false);
        msg.setNumber(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA6)));
        msg.setShareUrl(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA8)));
        msg.setShareTitle(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA9)));
        msg.setShareThumb(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA10)));
        msg.setRedpacketId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA11)));
        msg.setCreateName(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA12)));
        msg.setSource(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA13)));
        msg.setRemoteSource(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA14)));
        msg.setCreateTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA15)));
        msg.setUsersource(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA16)));
        msg.setUserfrom(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA17)));
        if (!TextUtils.isEmpty(msg.getUserId())) {
            UserBaseVo baseVo = FinalUserDataBase.getInstance().getUserBaseVoByUid(msg.getUserId());
            if (baseVo != null && !TextUtils.isEmpty(baseVo.getShowName())) {
                msg.setUsername(baseVo.getShowName());
            }
        }
        list.add(msg);
    }
    cursor.close();
    return list;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) UserBaseVo(com.lingtuan.firefly.vo.UserBaseVo)

Example 59 with ChatMsg

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

the class FinalUserDataBase method updateChatEventContent.

/**
 * Modify the recent chat last one
 *
 * @param msg2
 */
public void updateChatEventContent(String chatId, ChatMsg msg2) {
    String sql = "select * from " + TableField.TABLE_CHAT + " where " + TableField.FIELD_CHAT_ID + "=? " + /*and " + TableField.FIELD_RESERVED_DATA7 +
                (msg2.isOffLineMsg() ? "=1 " : "=0 ")*/
    " order by " + TableField._ID + " desc " + " limit " + 0 + "," + 1;
    String sql1 = "select * from (" + sql + ") order by " + TableField._ID;
    Cursor cursor = db.rawQuery(sql1, new String[] { chatId });
    ChatMsg msg = null;
    if (cursor.moveToNext()) {
        msg = new ChatMsg();
        msg.setContent(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_BODY)));
        msg.setMsgTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_CHAT_MSGTIME)));
        msg.setType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_TYPE)));
        msg.setUserId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_FRIEND_UID)));
        msg.setChatId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_ID)));
        msg.setLocalUrl(cursor.getString(cursor.getColumnIndex(TableField.FIELD_CHAT_LOCALURL)));
        msg.setShowTime(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_SHOWTIME)) == 1 ? true : false);
        msg.setOffLineMsg(msg2.isOffLineMsg());
    }
    if (msg == null) {
        msg = msg2;
        msg.setContent("");
    }
    updateChatEventMsg(msg, false, false);
    cursor.close();
}
Also used : Cursor(android.database.Cursor) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Example 60 with ChatMsg

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

the class FinalUserDataBase method getChatMsgTransList.

/**
 * Add trans message list
 */
public List<ChatMsg> getChatMsgTransList() {
    String sql = "select * from " + TableField.TABLE_CHAT_EVENT + " where " + TableField.FIELD_CHAT_SYSTEM + "=1 and " + TableField.FIELD_CHAT_TYPE + "=300 and " + TableField.FIELD_CHAT_HIDDEN + "=1 " + " order by " + TableField.FIELD_CHAT_MSGTIME + " desc ";
    Cursor cursor = db.rawQuery(sql, null);
    List<ChatMsg> list = new ArrayList<>();
    ChatMsg msg;
    while (cursor.moveToNext()) {
        msg = new ChatMsg();
        msg.setId(cursor.getInt(cursor.getColumnIndex(TableField._ID)));
        msg.setMsgTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_CHAT_MSGTIME)));
        msg.setType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_TYPE)));
        msg.setMessageId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA1)));
        msg.setCreateTime(cursor.getLong(cursor.getColumnIndex(TableField.FIELD_CHAT_CREATETIME)));
        msg.setMoney(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA9)));
        msg.setNumber(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA10)));
        msg.setMode(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA11)));
        msg.setInviteType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA19)));
        msg.setFee(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA21)));
        msg.setFromAddress(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA22)));
        msg.setToAddress(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA23)));
        msg.setTxBlockNumber(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA24)));
        msg.setShareUrl(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA25)));
        msg.setNoticeType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA26)));
        list.add(msg);
    }
    cursor.close();
    return list;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) ChatMsg(com.lingtuan.firefly.vo.ChatMsg)

Aggregations

ChatMsg (com.lingtuan.firefly.vo.ChatMsg)61 Bundle (android.os.Bundle)17 Intent (android.content.Intent)12 ArrayList (java.util.ArrayList)11 UserBaseVo (com.lingtuan.firefly.vo.UserBaseVo)9 Cursor (android.database.Cursor)8 SuppressLint (android.annotation.SuppressLint)6 WifiPeopleVO (com.lingtuan.firefly.offline.vo.WifiPeopleVO)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 GroupMemberAvatarVo (com.lingtuan.firefly.contact.vo.GroupMemberAvatarVo)4 PendingIntent (android.app.PendingIntent)3 TextView (android.widget.TextView)3 MyDialogFragment (com.lingtuan.firefly.util.MyDialogFragment)3 LoginThread (com.lingtuan.firefly.xmpp.LoginThread)3 File (java.io.File)3 JSONObject (org.json.JSONObject)3 Bitmap (android.graphics.Bitmap)2 Message (android.os.Message)2 Editable (android.text.Editable)2