Search in sources :

Example 1 with ChatMsgViewHolder

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);
    }
}
Also used : MessageItem(com.macbitsgoa.ard.models.MessageItem) ImageViewHolder(com.macbitsgoa.ard.viewholders.ImageViewHolder) ChatMsgViewHolder(com.macbitsgoa.ard.viewholders.ChatMsgViewHolder) DocumentItem(com.macbitsgoa.ard.models.DocumentItem)

Example 2 with ChatMsgViewHolder

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);
    }
}
Also used : ChatMsgViewHolder(com.macbitsgoa.ard.viewholders.ChatMsgViewHolder) ImageViewHolder(com.macbitsgoa.ard.viewholders.ImageViewHolder) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout) NonNull(android.support.annotation.NonNull)

Aggregations

ChatMsgViewHolder (com.macbitsgoa.ard.viewholders.ChatMsgViewHolder)2 ImageViewHolder (com.macbitsgoa.ard.viewholders.ImageViewHolder)2 NonNull (android.support.annotation.NonNull)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 DocumentItem (com.macbitsgoa.ard.models.DocumentItem)1 MessageItem (com.macbitsgoa.ard.models.MessageItem)1