Search in sources :

Example 1 with ChatMsgComparable

use of com.lingtuan.firefly.custom.ChatMsgComparable 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;
}
Also used : MyDialogFragment(com.lingtuan.firefly.util.MyDialogFragment) Bundle(android.os.Bundle) SuppressLint(android.annotation.SuppressLint) ChatMsg(com.lingtuan.firefly.vo.ChatMsg) ChatMsgComparable(com.lingtuan.firefly.custom.ChatMsgComparable)

Example 2 with ChatMsgComparable

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

the class MessageEventAdapter method addChatMsg.

public void addChatMsg(ChatMsg msg) {
    if (msg == null) {
        return;
    }
    boolean isAdd = false;
    if (mList == null) {
        mList = new ArrayList<>();
        mList.add(msg);
        notifyDataSetChanged();
        return;
    } else if (mList.isEmpty()) {
        mList.add(msg);
        notifyDataSetChanged();
        return;
    }
    int unRead = 0;
    int count = mList.size();
    for (int i = 0; i < count; i++) {
        if (TextUtils.equals(msg.getChatId(), mList.get(i).getChatId())) {
            unRead = mList.get(i).getUnread();
            int isAtGroupMeOld = mList.get(i).isAtGroupMe();
            boolean isTop = mList.get(i).isTop();
            long topTime = mList.get(i).getTopTime();
            mList.remove(i);
            msg.setTop(isTop);
            msg.setTopTime(topTime);
            unRead = unRead + msg.getUnread();
            msg.setUnread(unRead);
            if (msg.isAtGroupMe() <= 0) {
                msg.setAtGroupMe(isAtGroupMeOld);
            }
            mList.add(0, msg);
            isAdd = true;
            break;
        }
    }
    if (!isAdd) {
        mList.add(0, msg);
    }
    Collections.sort(mList, new ChatMsgComparable());
    notifyDataSetChanged();
}
Also used : ChatMsgComparable(com.lingtuan.firefly.custom.ChatMsgComparable)

Aggregations

ChatMsgComparable (com.lingtuan.firefly.custom.ChatMsgComparable)2 SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 MyDialogFragment (com.lingtuan.firefly.util.MyDialogFragment)1 ChatMsg (com.lingtuan.firefly.vo.ChatMsg)1