@Override public void processMessage(QBGroupChat groupChat, QBChatMessage chatMessage) { User user = DatabaseManager.getUserById(context, chatMessage.getSenderId()); String attachUrl = ChatUtils.getAttachUrlIfExists(chatMessage); String dialogId = chatMessage.getProperty(ChatUtils.PROPERTY_DIALOG_ID); long time = Long.parseLong(chatMessage.getProperty(ChatUtils.PROPERTY_DATE_SENT).toString()); String messageId = chatMessage.getProperty(ChatUtils.PROPERTY_MESSAGE_ID).toString(); String messageType = chatMessage.getProperty(ChatUtils.PROPERTY_NOTIFICATION_TYPE); if (ChatUtils.PROPERTY_NOTIFICATION_TYPE_CREATE_CHAT.equals(messageType)) { if (chatMessage.getBody().equals("join") || chatMessage.getBody().equals("stay")) { if (dialogId.equals(ChatUtils.joinDialogId) && user != null) { ChatUtils.setJoinUsers(user); if (chatMessage.getBody().equals("join")) { sendOccupantStatusGroup("stay"); } } return; } else if (chatMessage.getBody().equals("leave")) { if (dialogId.equals(ChatUtils.joinDialogId) && user != null) ChatUtils.removeJoinUsers(user); return; } } if (user == null) { user = new User(); user.setUserId(chatMessage.getSenderId()); user.setFullName(chatMessage.getSenderId() + ConstsCore.EMPTY_STRING); } saveMessageToCache( new MessageCache( messageId, dialogId, chatMessage.getSenderId(), chatMessage.getBody(), attachUrl, time, false, false, false)); if (!chatMessage.getSenderId().equals(chatCreator.getId())) { // TODO IS handle logic when friend is not in the friend list notifyMessageReceived(chatMessage, user, dialogId, false); } }
@Override public void bindView(View view, Context context, final Cursor cursor) { final ViewHolder viewHolder = (ViewHolder) view.getTag(); final User friend = DatabaseManager.getUserFromCursor(cursor); viewHolder.nameTextView.setText(friend.getFullName()); // viewHolder.statusMessageTextView.setText(friend.getStatus()); viewHolder.nameTextView.setText(friend.getFullName()); if (friend.isOnline()) { viewHolder.onlineImageView.setVisibility(View.VISIBLE); } else { viewHolder.onlineImageView.setVisibility(View.GONE); } final int position = cursor.getPosition(); viewHolder.selectFriendCheckBox.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { CheckBox checkBox = (CheckBox) view; sparseArrayCheckBoxes.put(position, checkBox.isChecked()); friend.setSelected(checkBox.isChecked()); notifyCounterChanged(checkBox.isChecked()); if (checkBox.isChecked()) { selectedFriends.add(friend); } else if (selectedFriends.contains(friend)) { selectedFriends.remove(friend); } viewHolder.contentRelativeLayout.setBackgroundColor( getBackgroundColorItem(viewHolder.selectFriendCheckBox.isChecked())); } }); boolean checked = sparseArrayCheckBoxes.get(position); viewHolder.selectFriendCheckBox.setChecked(checked); String avatarUrl = getAvatarUrlForFriend(friend); displayAvatarImage(avatarUrl, viewHolder.avatarImageView); viewHolder.contentRelativeLayout.setBackgroundColor(getBackgroundColorItem(checked)); }