use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.
the class FinalUserDataBase method getChatMsgTrans.
/**
* Add Trans after the new one
*/
public ChatMsg getChatMsgTrans() {
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 " + " limit " + 0 + "," + 1;
Cursor cursor = db.rawQuery(sql, null);
ChatMsg msg = null;
if (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.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.setMessageId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA1)));
msg.setMsgTypeInt(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_OBJECT)));
msg.setMoney(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA9)));
msg.setNoticeType(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA26)));
}
cursor.close();
return msg;
}
use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.
the class MainMessageFragmentUI method onItemLongClick.
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
int itemArrayId;
final ChatMsg msg = mList.get(position);
if (msg.getChatId().equals("everyone")) {
itemArrayId = mList.get(position).isTop() ? R.array.delete_clear_top_chat_array : R.array.clear_to_top_chat_array;
} else {
itemArrayId = mList.get(position).isTop() ? R.array.delete_remove_top_chat_array : R.array.delete_to_top_chat_array;
}
MyDialogFragment mdf = new MyDialogFragment(MyDialogFragment.DIALOG_LIST, itemArrayId);
mdf.setItemClickCallback(new MyDialogFragment.ItemClickCallback() {
@Override
public void itemClickCallback(int which) {
switch(which) {
case // Placed at the top, cancel placed at the top
0:
{
long topTime = System.currentTimeMillis() / 1000;
msg.setTop(!msg.isTop());
if (msg.isTop()) {
msg.setTopTime(topTime);
}
Collections.sort(mList, new ChatMsgComparable());
mAdapter.updateList(mList);
FinalUserDataBase.getInstance().updateChatEventTop(msg.getChatId(), msg.isTop(), topTime);
for (int i = 0; i < mList.size(); i++) {
if (msg.equals(mList.get(i))) {
mListView.setSelection(i);
break;
}
}
}
break;
case 1:
{
Bundle bundle = new Bundle();
bundle.putInt("unread", -msg.getUnread());
Utils.intentAction(getActivity(), XmppAction.ACTION_MESSAGE_EVENT_LISTENER, bundle);
if (msg.getChatId().equals("everyone")) {
FinalUserDataBase.getInstance().clearChatMsgByChatId(msg.getChatId(), msg);
msg.setContent("");
msg.setUnread(0);
mAdapter.updateList(mList);
} else {
FinalUserDataBase.getInstance().deleteChatMsgByChatId(msg.getChatId());
mList.remove(position);
mAdapter.updateList(mList);
}
}
break;
}
}
});
mdf.show(getFragmentManager(), "mdf");
return true;
}
use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.
the class MainMessageFragmentUI method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (mList != null && !mList.isEmpty()) {
if (position >= mList.size()) {
return;
}
ChatMsg msg = mList.get(position);
String uid = msg.getChatId();
String username = msg.getUsername();
boolean isGroup = false;
if (TextUtils.isEmpty(uid)) {
return;
}
if (!msg.isSystem()) {
// Normal chat messages
if (uid.equals("everyone")) {
XmppMessageUtil.getInstance().sendEnterLeaveEveryOne(msg.getMsgTime(), false);
}
String avatarPath = msg.getUserImage();
if (uid.startsWith("group-") || uid.startsWith("superGroup-")) {
// Is group chat
uid = msg.getChatId();
isGroup = true;
if (uid.startsWith("superGroup-")) {
avatarPath = msg.getGroupImage();
}
}
Utils.intentChattingUI(getActivity(), uid, avatarPath, username, msg.getGender() + "", msg.getFriendLog(), isGroup, msg.isDismissGroup(), msg.isKickGroup(), msg.getUnread(), false);
if (// The shielding
!msg.getGroupMask()) {
Bundle bundle = new Bundle();
bundle.putInt("unread", -msg.getUnread());
Utils.intentAction(getActivity(), XmppAction.ACTION_MESSAGE_EVENT_LISTENER, bundle);
}
msg.setUnread(0);
msg.setAtGroupMe(0);
int firstPosition = mListView.getFirstVisiblePosition();
int lastPosition = mListView.getLastVisiblePosition();
if (position >= firstPosition && position <= lastPosition) {
int currentPostion = position - firstPosition;
View childView = mListView.getChildAt(currentPostion);
TextView unread = (TextView) childView.findViewById(R.id.item_unread);
childView.findViewById(R.id.item_at).setVisibility(View.GONE);
unread.setVisibility(View.GONE);
}
} else {
if (msg.getType() == 0) {
// Friend request
Intent intent = new Intent(getActivity(), MsgAddContactListUI.class);
intent.putExtra("chatid", msg.getChatId());
startActivity(intent);
Utils.openNewActivityAnim(getActivity(), false);
Bundle bundle = new Bundle();
bundle.putInt("unread", -msg.getUnread());
Utils.intentAction(getActivity(), XmppAction.ACTION_MESSAGE_EVENT_LISTENER, bundle);
int firstPosition = mListView.getFirstVisiblePosition();
int lastPosition = mListView.getLastVisiblePosition();
if (position >= firstPosition && position <= lastPosition) {
int currentPostion = position - firstPosition;
View childView = mListView.getChildAt(currentPostion);
TextView unread = (TextView) childView.findViewById(R.id.item_unread);
unread.setVisibility(View.GONE);
}
} else if (msg.getType() == 300) {
// Trans request
Intent intent = new Intent(getActivity(), MsgTransListUI.class);
intent.putExtra("chatid", msg.getChatId());
startActivity(intent);
Utils.openNewActivityAnim(getActivity(), false);
Bundle bundle = new Bundle();
bundle.putInt("unread", -msg.getUnread());
Utils.intentAction(getActivity(), XmppAction.ACTION_MESSAGE_EVENT_LISTENER, bundle);
int firstPosition = mListView.getFirstVisiblePosition();
int lastPosition = mListView.getLastVisiblePosition();
if (position >= firstPosition && position <= lastPosition) {
int currentPostion = position - firstPosition;
View childView = mListView.getChildAt(currentPostion);
TextView unread = (TextView) childView.findViewById(R.id.item_unread);
unread.setVisibility(View.GONE);
}
}
}
}
}
use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.
the class FinalUserDataBase method getChatMsgEventListChat.
/**
* Get my message history chat records only chat records (forward) used in the
*/
public List<ChatMsg> getChatMsgEventListChat() {
String sql = "select * from " + TableField.TABLE_CHAT_EVENT + " where " + /*+ TableField.FIELD_CHAT_HIDDEN + "=0 and "*/
TableField.FIELD_CHAT_SYSTEM + "=0 " + /*and "
+ TableField.FIELD_RESERVED_DATA7 + "!=1*/
" order by " + TableField.FIELD_CHAT_MSGTIME + " desc ";
Cursor cursor = db.rawQuery(sql, null);
List<ChatMsg> list = new ArrayList<ChatMsg>();
ChatMsg msg;
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.setUnread(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_UNREAD)));
msg.setSystem(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_SYSTEM)) == 1);
msg.setDismissGroup(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_DISMISSGROUP)) == 1);
msg.setKickGroup(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_CHAT_KICKGROUP)) == 1);
msg.setMessageId(cursor.getString(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA1)));
msg.setFriendLog(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA5)));
msg.setGroupMask(cursor.getInt(cursor.getColumnIndex(TableField.FIELD_RESERVED_DATA6)) == 1);
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.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);
} else {
if (!msg.getGroupMask()) {
unFriendTotle++;
}
}
}
try {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getChatId().equals("system-2")) {
list.get(i).setUnread(unFriendTotle);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
cursor.close();
return list;
}
use of com.lingtuan.firefly.vo.ChatMsg in project SmartMesh_Android by SmartMeshFoundation.
the class FinalUserDataBase method deleteChatEventTransByMessageId.
/**
* Delete my trans list item
*
* @param messageid
*/
public void deleteChatEventTransByMessageId(String messageid) {
db.delete(TableField.TABLE_CHAT_EVENT, TableField.FIELD_CHAT_ID + "='system-5' and " + TableField.FIELD_CHAT_HIDDEN + "=1 and " + TableField.FIELD_CHAT_SYSTEM + "=1 and " + TableField.FIELD_RESERVED_DATA1 + "=?", new String[] { messageid });
ChatMsg msg = getChatMsgTrans();
if (msg != null) {
updateChatEventMsg(msg, true, false);
} else {
db.delete(TableField.TABLE_CHAT_EVENT, TableField.FIELD_CHAT_ID + "='system-5' and " + TableField.FIELD_CHAT_HIDDEN + "=0 and " + TableField.FIELD_CHAT_SYSTEM + "=1 and " + TableField.FIELD_RESERVED_DATA1 + "=?", new String[] { messageid });
}
}
Aggregations