use of com.macbitsgoa.ard.viewholders.ChatMsgViewHolder in project ARD by MobileApplicationsClub.
the class ChatMsgAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
MessageItem mi = messages.get(position);
if (mi.hasAttachments()) {
DocumentItem di = mi.getDocuments().get(0);
if (!di.getLocalUri().equals("") && di.getMimeType().contains("image")) {
ImageViewHolder imvh = (ImageViewHolder) holder;
String imageUrl = di.getLocalThumbnailUri();
if (imageUrl == null)
imageUrl = di.getLocalUri();
if (imageUrl == null)
imageUrl = di.getRemoteThumbnailUrl();
if (imageUrl == null)
imageUrl = di.getRemoteUrl();
imvh.setUri(Uri.parse(di.getLocalUri()), Uri.parse(imageUrl), RequestOptions.centerCropTransform());
} else {
((ImageViewHolder) holder).setUri(di.getLocalUri(), AHC.getImageUrlFromMimeType(di.getMimeType()));
}
} else if (holder.getItemViewType() == RECEIVER || holder.getItemViewType() == SENDER) {
ChatMsgViewHolder cmvh = (ChatMsgViewHolder) holder;
cmvh.populate(mi);
if (position < getItemCount() - 1 && getItemViewType(position + 1) == holder.getItemViewType()) {
cmvh.emptySpace.setVisibility(View.GONE);
} else
cmvh.emptySpace.setVisibility(View.VISIBLE);
}
}
use of com.macbitsgoa.ard.viewholders.ChatMsgViewHolder in project ARD by MobileApplicationsClub.
the class ChatMsgAdapter method onCreateViewHolder.
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (viewType == RECEIVER || viewType == SENDER) {
final View view = inflater.inflate(R.layout.vh_activity_chat_chatmsg, parent, false);
final LinearLayout root = view.findViewById(R.id.ll_chatmsg_root);
final LinearLayout msgBox = view.findViewById(R.id.ll_chatmsg_msg_box);
if (viewType == RECEIVER) {
root.setGravity(Gravity.END);
msgBox.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.bg_chat_rcv));
} else if (viewType == SENDER) {
root.setGravity(Gravity.START);
msgBox.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.bg_chat_sen));
}
final TextView messageTv = view.findViewById(R.id.textView_viewHolder_chatmsg_msg);
final int msgMaxWidth = (int) (AHC.getScreenWidth() * MAX_WIDTH_FRACTION);
messageTv.setMaxWidth(msgMaxWidth);
return new ChatMsgViewHolder(view);
} else {
final View view = inflater.inflate(R.layout.vh_chat_document, parent, false);
return new ImageViewHolder(view, context, R.id.imgView_vh_chat_document, this);
}
}
Aggregations