public AlConversationAdapter(Context context, List<Message> mList) { super(context, mList); this.context = context; messageProperties = new AlMessageProperties(context); }
@Override public void bindConversationViewHolder(RecyclerView.ViewHolder holder, int position) { if (holder instanceof ConversationViewHolder) { Message message = mItems.get(position); messageProperties.setMessage(message); ConversationViewHolder mHolder = (ConversationViewHolder) holder; mHolder.receiverName.setText(messageProperties.getReceiver()); mHolder.createdAtTime.setText(messageProperties.getCreatedAtTime()); messageProperties.setMessageAndAttchmentIcon(mHolder.messageTv, mHolder.attachmentIcon); messageProperties.setUnreadCount(mHolder.unreadCount); messageProperties.loadProfileImage(mHolder.profileImage, mHolder.alphabeticImage); } }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { messageProperties.handleConversationClick(mItems.get(position)); }
/** * This methods saves you a lot of work by check. Use this method in your bindView/getView. * * @param imageView CircularImageView to load the image * @param textView TextView to display AlphabeticImage */ public void loadProfileImage(CircleImageView imageView, TextView textView) { if (channel != null) { loadChannelImage(imageView, textView, channel); } else if (contact != null) { loadContactImage(imageView, textView, contact); } }
@Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case 0: if (properties.getChannel() != null && properties.getChannel().isDeleted()) { uiService.deleteGroupConversation(properties.getChannel()); } else { uiService.deleteConversationThread(properties.getContact(), properties.getChannel()); } break; case 1: uiService.deleteGroupConversation(properties.getChannel()); break; case 2: uiService.channelLeaveProcess(properties.getChannel()); break; default: } return true; } };
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { int position = this.getLayoutPosition(); if (mItems.size() <= position) { return; } Message message = mItems.get(position); menu.setHeaderTitle(R.string.conversation_options); String[] menuItems = context.getResources().getStringArray(R.array.conversation_options_menu); properties.setMessage(message); boolean isChannelDeleted = properties.getChannel() != null && properties.getChannel().isDeleted(); boolean isUserPresentInGroup = properties.getChannel() != null && ChannelService.getInstance(context).processIsUserPresentInChannel(properties.getChannel().getKey()); for (int i = 0; i < menuItems.length; i++) { if ((message.getGroupId() == null || (properties.getChannel() != null && (Channel.GroupType.GROUPOFTWO.getValue().equals(properties.getChannel().getType()) || Channel.GroupType.SUPPORT_GROUP.getValue().equals(properties.getChannel().getType())))) && (menuItems[i].equals(context.getResources().getString(R.string.delete_group)) || menuItems[i].equals(context.getResources().getString(R.string.exit_group)))) { continue; } if (menuItems[i].equals(context.getResources().getString(R.string.exit_group)) && (isChannelDeleted || !isUserPresentInGroup)) { continue; } if (menuItems[i].equals(context.getResources().getString(R.string.delete_group)) && (isUserPresentInGroup || !isChannelDeleted)) { continue; } if (menuItems[i].equals(context.getResources().getString(R.string.delete_conversation))) { continue; } MenuItem item = menu.add(Menu.NONE, i, i, menuItems[i]); item.setOnMenuItemClickListener(onEditMenu); } }
imageView.setImageResource(drawableResourceId); } else if (contact.getImageURL() != null) { loadImage(imageView, textView, contact.getImageURL(), 0); } else { textView.setVisibility(View.VISIBLE);
/** * This method loads the channel's image into the ImageView * * @param imageView CircularImageView in which the image is to be loaded * @param textView Although we do not display alphabeticImage for a group, but this is needed to handle the visibility for recycler view. * @param channel Channel object whose image is to be loaded */ public void loadChannelImage(CircleImageView imageView, TextView textView, Channel channel) { textView.setVisibility(View.GONE); imageView.setVisibility(View.VISIBLE); if (channel.getImageUrl() != null) { loadImage(imageView, textView, channel.getImageUrl(), R.drawable.applozic_group_icon); } else { imageView.setImageResource(R.drawable.applozic_group_icon); } }
@Override public void onClick(View v) { int itemPosition = getLayoutPosition(); if (itemPosition != -1 && !mItems.isEmpty()) { Message message = mItems.get(itemPosition); if (message != null) { messageProperties.handleConversationClick(message); } } }
public ConversationViewHolder(View view) { super(view); alphabeticImage = view.findViewById(R.id.alphabeticImage); profileImage = view.findViewById(R.id.contactImage); receiverName = view.findViewById(R.id.smReceivers); messageTv = view.findViewById(R.id.message); unreadCount = view.findViewById(R.id.unreadSmsCount); createdAtTime = view.findViewById(R.id.createdAtTime); attachmentIcon = view.findViewById(R.id.attachmentIcon); properties = new AlMessageProperties(context); uiService = new AlUIService(context); view.setOnClickListener(this); view.setOnCreateContextMenuListener(this); }