Search in sources :

Example 1 with ApplozicDocumentView

use of com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicDocumentView in project Applozic-Android-SDK by AppLozic.

the class DetailedConversationAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    int type = getItemViewType(position);
    final Message message = getItem(position);
    try {
        if (type == 2) {
            MyViewHolder2 myViewHolder2 = (MyViewHolder2) holder;
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy");
            SimpleDateFormat simpleDateFormatDay = new SimpleDateFormat("EEEE");
            Date date = new Date(message.getCreatedAtTime());
            myViewHolder2.dateView.setTextColor(Color.parseColor(alCustomizationSettings.getConversationDateTextColor().trim()));
            myViewHolder2.dayTextView.setTextColor(Color.parseColor(alCustomizationSettings.getConversationDayTextColor().trim()));
            if (DateUtils.isSameDay(message.getCreatedAtTime())) {
                myViewHolder2.dayTextView.setVisibility(View.VISIBLE);
                myViewHolder2.dateView.setVisibility(GONE);
                myViewHolder2.dayTextView.setText(R.string.today);
            } else {
                myViewHolder2.dayTextView.setVisibility(View.VISIBLE);
                myViewHolder2.dateView.setVisibility(View.VISIBLE);
                myViewHolder2.dayTextView.setText(simpleDateFormatDay.format(date));
                myViewHolder2.dateView.setText(simpleDateFormat.format(date));
            }
            return;
        } else if (type == 3) {
            MyViewHolder3 myViewHolder3 = (MyViewHolder3) holder;
            myViewHolder3.customContentTextView.setText(message.getMessage());
            myViewHolder3.customContentTextView.setVisibility(View.VISIBLE);
            return;
        } else if (type == 4) {
            MyViewHolder4 myViewHolder4 = (MyViewHolder4) holder;
            GradientDrawable bgGradientDrawable = (GradientDrawable) myViewHolder4.channelMessageTextView.getBackground();
            bgGradientDrawable.setColor(Color.parseColor(alCustomizationSettings.getChannelCustomMessageBgColor()));
            bgGradientDrawable.setStroke(3, Color.parseColor(alCustomizationSettings.getChannelCustomMessageBorderColor()));
            myViewHolder4.channelMessageTextView.setTextColor(Color.parseColor(alCustomizationSettings.getChannelCustomMessageTextColor()));
            myViewHolder4.channelMessageTextView.setText(message.getMessage());
            return;
        } else if (type == 5) {
            MyViewHolder5 myViewHolder5 = (MyViewHolder5) holder;
            if (message != null) {
                myViewHolder5.timeTextView.setText(DateUtils.getFormattedDate(message.getCreatedAtTime(), alCustomizationSettings.getDateFormatCustomization().getTimeTemplate()));
                if (message.getMetadata() != null) {
                    myViewHolder5.statusTextView.setText(VideoCallNotificationHelper.getStatus(message.getMetadata()));
                }
                if (VideoCallNotificationHelper.isMissedCall(message)) {
                    myViewHolder5.imageView.setImageResource(R.drawable.ic_communication_call_missed);
                }
                if (VideoCallNotificationHelper.isAudioCall(message)) {
                    myViewHolder5.imageView.setImageResource(R.drawable.applozic_ic_action_call);
                } else {
                    myViewHolder5.imageView.setImageResource(R.drawable.ic_videocam_white_24px);
                }
                if (message.getMetadata() != null) {
                    if (message.getMetadata().get(VideoCallNotificationHelper.MSG_TYPE).equals(VideoCallNotificationHelper.CALL_END)) {
                        String duration = message.getMetadata().get(VideoCallNotificationHelper.CALL_DURATION);
                        if (!TextUtils.isEmpty(duration)) {
                            myViewHolder5.durationTextView.setVisibility(View.VISIBLE);
                            duration = Utils.getTimeDurationInFormat(Long.parseLong(duration));
                            myViewHolder5.durationTextView.setText(duration);
                        }
                    } else {
                        myViewHolder5.durationTextView.setVisibility(View.GONE);
                    }
                }
            }
        } else {
            final MyViewHolder myHolder = (MyViewHolder) holder;
            if (message != null) {
                Contact receiverContact = null;
                Contact contactDisplayName = null;
                if (message.getGroupId() == null) {
                    List<String> items = Arrays.asList(message.getContactIds().split("\\s*,\\s*"));
                    List<String> userIds = null;
                    if (!TextUtils.isEmpty(message.getContactIds())) {
                        userIds = Arrays.asList(message.getContactIds().split("\\s*,\\s*"));
                    }
                    if (individual) {
                        receiverContact = contact;
                        contact.setContactNumber(items.get(0));
                        if (userIds != null) {
                            contact.setUserId(userIds.get(0));
                        }
                    } else {
                        receiverContact = contactService.getContactReceiver(items, userIds);
                    }
                } else {
                    if (!TextUtils.isEmpty(message.getContactIds())) {
                        contactDisplayName = contactService.getContactById(message.getContactIds());
                    }
                }
                Configuration config = context.getResources().getConfiguration();
                if (message.isCall() || message.isDummyEmptyMessage()) {
                    myHolder.createdAtTime.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                } else if (!message.isSentToServer() && message.isTypeOutbox() && (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()))) {
                    myHolder.createdAtTime.setCompoundDrawablesWithIntrinsicBounds(null, null, message.getScheduledAt() != null ? scheduledIcon : pendingIcon, null);
                } else if (message.getKeyString() != null && message.isTypeOutbox() && message.isSentToServer() && (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()))) {
                    Drawable statusIcon;
                    if (message.isDeliveredAndRead()) {
                        statusIcon = context.getResources().getDrawable(R.drawable.applozic_ic_action_message_read);
                    } else {
                        statusIcon = (message.getDelivered() ? deliveredIcon : (message.getScheduledAt() != null ? scheduledIcon : sentIcon));
                    }
                    myHolder.createdAtTime.setCompoundDrawablesWithIntrinsicBounds(null, null, statusIcon, null);
                }
                if (message.isCall()) {
                    myHolder.deliveryStatus.setText("");
                }
                ApplozicDocumentView audioView = new ApplozicDocumentView(activityContext, storagePermissionListener);
                audioView.inflateViewWithMessage(myHolder.view, message);
                audioView.hideView(true);
                if (message.isDeletedForAll()) {
                    myHolder.messageTextView.setCompoundDrawablesWithIntrinsicBounds(context.getResources().getDrawable(R.drawable.round_not_interested_black_24), null, null, null);
                    if (android.os.Build.VERSION.SDK_INT >= 21) {
                        myHolder.messageTextView.getCompoundDrawables()[0].setTint(Color.parseColor(message.isTypeOutbox() ? alCustomizationSettings.getSentMessageTextColor() : alCustomizationSettings.getReceivedMessageTextColor()));
                    }
                    myHolder.messageTextView.setText(R.string.deleted_message_text);
                    myHolder.messageTextView.setTypeface(null, Typeface.ITALIC);
                    myHolder.messageTextView.setVisibility(View.VISIBLE);
                    myHolder.createdAtTime.setText(DateUtils.getFormattedDate(message.getCreatedAtTime(), alCustomizationSettings.getDateFormatCustomization().getTimeTemplate()));
                    myHolder.replyRelativeLayout.setVisibility(GONE);
                    myHolder.richMessageLayout.setVisibility(View.GONE);
                    myHolder.preview.setVisibility(View.GONE);
                    myHolder.attachedFile.setVisibility(View.GONE);
                    myHolder.mainAttachmentLayout.setVisibility(View.GONE);
                    myHolder.attachmentView.setVisibility(View.GONE);
                    myHolder.videoIcon.setVisibility(View.GONE);
                    myHolder.mainContactShareLayout.setVisibility(View.GONE);
                    myHolder.mapImageView.setVisibility(View.GONE);
                    myHolder.urlLoadLayout.setVisibility(View.GONE);
                } else {
                    myHolder.messageTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                    myHolder.messageTextView.setTypeface(null, Typeface.NORMAL);
                    if (message.getMetadata() != null && !message.getMetadata().isEmpty() && message.getMetadata().containsKey(Message.MetaDataType.AL_REPLY.getValue())) {
                        String keyString = message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue());
                        Message messageToBeReplied = new Message();
                        messageToBeReplied.setKeyString(keyString);
                        int indexOfObject = messageList.indexOf(messageToBeReplied);
                        if (indexOfObject != -1) {
                            messageToBeReplied = messageList.get(indexOfObject);
                        } else {
                            messageToBeReplied = messageDatabaseService.getMessage(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
                        }
                        final Message msg = messageToBeReplied;
                        if (msg != null) {
                            String displayName;
                            myHolder.replyRelativeLayout.setBackgroundColor(message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getReplyMessageLayoutSentMessageBackground()) : Color.parseColor(alCustomizationSettings.getReplyMessageLayoutReceivedMessageBackground()));
                            myHolder.replyNameTextView.setTextColor(message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getSentMessageTextColor()) : Color.parseColor(alCustomizationSettings.getReceivedMessageTextColor()));
                            myHolder.replyMessageTextView.setTextColor(message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getSentMessageTextColor()) : Color.parseColor(alCustomizationSettings.getReceivedMessageTextColor()));
                            if (msg.getGroupId() != null) {
                                if (MobiComUserPreference.getInstance(context).getUserId().equals(msg.getContactIds()) || TextUtils.isEmpty(msg.getContactIds())) {
                                    displayName = context.getString(R.string.you_string);
                                } else {
                                    displayName = contactService.getContactById(msg.getContactIds()).getDisplayName();
                                }
                            } else {
                                if (msg.isTypeOutbox()) {
                                    displayName = context.getString(R.string.you_string);
                                } else {
                                    displayName = contactService.getContactById(msg.getContactIds()).getDisplayName();
                                }
                            }
                            myHolder.replyNameTextView.setText(displayName);
                            if (msg.hasAttachment()) {
                                FileMeta fileMeta = msg.getFileMetas();
                                myHolder.imageViewForAttachmentType.setVisibility(View.VISIBLE);
                                if (fileMeta.getContentType().contains("image")) {
                                    myHolder.imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_image_camera_alt);
                                    if (TextUtils.isEmpty(msg.getMessage())) {
                                        myHolder.replyMessageTextView.setText(context.getString(R.string.photo_string));
                                    } else {
                                        myHolder.replyMessageTextView.setText(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, msg, true, alCustomizationSettings.getConversationMentionSpanColor()));
                                    }
                                    myHolder.imageViewPhoto.setVisibility(View.VISIBLE);
                                    myHolder.imageViewRLayout.setVisibility(View.VISIBLE);
                                    imageThumbnailLoader.loadImage(msg, myHolder.imageViewPhoto);
                                } else if (fileMeta.getContentType().contains("video")) {
                                    myHolder.imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_video);
                                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                                        if (config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
                                            myHolder.imageViewForAttachmentType.setScaleX(-1);
                                        }
                                    }
                                    if (TextUtils.isEmpty(msg.getMessage())) {
                                        myHolder.replyMessageTextView.setText(context.getString(R.string.video_string));
                                    } else {
                                        myHolder.replyMessageTextView.setText(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, msg, true, alCustomizationSettings.getConversationMentionSpanColor()));
                                    }
                                    myHolder.imageViewPhoto.setVisibility(View.VISIBLE);
                                    myHolder.imageViewRLayout.setVisibility(View.VISIBLE);
                                    if (msg.getFilePaths() != null && msg.getFilePaths().size() > 0) {
                                        if (imageCache != null && imageCache.getBitmapFromMemCache(msg.getKeyString()) != null) {
                                            myHolder.imageViewPhoto.setImageBitmap(imageCache.getBitmapFromMemCache(msg.getKeyString()));
                                        } else {
                                            if (imageCache != null) {
                                                imageCache.addBitmapToCache(message.getKeyString(), fileClientService.getOrCreateVideoThumbnail(msg.getFilePaths().get(0)));
                                            }
                                            myHolder.imageViewPhoto.setImageBitmap(fileClientService.getOrCreateVideoThumbnail(msg.getFilePaths().get(0)));
                                        }
                                    }
                                } else if (fileMeta.getContentType().contains("audio")) {
                                    myHolder.imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_music_note);
                                    if (TextUtils.isEmpty(msg.getMessage())) {
                                        myHolder.replyMessageTextView.setText(context.getString(R.string.audio_string));
                                    } else {
                                        myHolder.replyMessageTextView.setText(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, msg, true, alCustomizationSettings.getConversationMentionSpanColor()));
                                    }
                                    myHolder.imageViewPhoto.setVisibility(View.GONE);
                                    myHolder.imageViewRLayout.setVisibility(View.GONE);
                                } else if (msg.isContactMessage()) {
                                    MobiComVCFParser parser = new MobiComVCFParser();
                                    try {
                                        VCFContactData data = parser.parseCVFContactData(msg.getFilePaths().get(0));
                                        if (data != null) {
                                            myHolder.imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
                                            myHolder.replyMessageTextView.setText(context.getString(R.string.contact_string));
                                            myHolder.replyMessageTextView.append(" " + data.getName());
                                        }
                                    } catch (Exception e) {
                                        myHolder.imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
                                        myHolder.replyMessageTextView.setText(context.getString(R.string.contact_string));
                                    }
                                    myHolder.imageViewPhoto.setVisibility(View.GONE);
                                    myHolder.imageViewRLayout.setVisibility(View.GONE);
                                } else {
                                    myHolder.imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_attachment);
                                    if (TextUtils.isEmpty(msg.getMessage())) {
                                        myHolder.replyMessageTextView.setText(context.getString(R.string.attachment_string));
                                    } else {
                                        myHolder.replyMessageTextView.setText(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, msg, true, alCustomizationSettings.getConversationMentionSpanColor()));
                                    }
                                    myHolder.imageViewPhoto.setVisibility(View.GONE);
                                    myHolder.imageViewRLayout.setVisibility(View.GONE);
                                }
                                myHolder.imageViewForAttachmentType.setColorFilter(Color.parseColor(message.isTypeOutbox() ? alCustomizationSettings.getSentMessageTextColor() : alCustomizationSettings.getReceivedMessageTextColor()));
                            } else if (msg.getContentType() == Message.ContentType.LOCATION.getValue()) {
                                myHolder.imageViewForAttachmentType.setVisibility(View.VISIBLE);
                                myHolder.imageViewPhoto.setVisibility(View.VISIBLE);
                                myHolder.imageViewRLayout.setVisibility(View.VISIBLE);
                                myHolder.replyMessageTextView.setText(context.getString(R.string.al_location_string));
                                myHolder.imageViewForAttachmentType.setColorFilter(Color.parseColor(message.isTypeOutbox() ? alCustomizationSettings.getSentMessageTextColor() : alCustomizationSettings.getReceivedMessageTextColor()));
                                myHolder.imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_location_on_white_24dp);
                                loadImage.setLoadingImage(R.drawable.applozic_map_offline_thumbnail);
                                loadImage.loadImage(LocationUtils.loadStaticMap(msg.getMessage(), geoApiKey), myHolder.imageViewPhoto);
                            } else {
                                myHolder.imageViewForAttachmentType.setVisibility(View.GONE);
                                myHolder.imageViewRLayout.setVisibility(View.GONE);
                                myHolder.imageViewPhoto.setVisibility(View.GONE);
                                myHolder.replyMessageTextView.setText(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, msg, true, alCustomizationSettings.getConversationMentionSpanColor()));
                            }
                            myHolder.replyRelativeLayout.setVisibility(View.VISIBLE);
                            myHolder.replyRelativeLayout.setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    ((OnClickReplyInterface) activityContext).onClickOnMessageReply(msg);
                                }
                            });
                        }
                    } else {
                        myHolder.replyRelativeLayout.setVisibility(GONE);
                    }
                    if (TextUtils.isEmpty(message.getMessage())) {
                        myHolder.messageTextView.setVisibility(View.GONE);
                    }
                    if (channel != null) {
                        if (!message.hasAttachment() && TextUtils.isEmpty(message.getMessage()) && message.getMetadata() == null) {
                            myHolder.messageTextView.setText("");
                        }
                    }
                    if (myHolder.chatLocation != null) {
                        myHolder.chatLocation.setVisibility(View.GONE);
                    }
                    if (myHolder.attachedFile != null) {
                        // myHolder.attachedFile.setText("");
                        myHolder.attachedFile.setVisibility(View.GONE);
                    }
                    if (channel != null && myHolder.nameTextView != null && contactDisplayName != null) {
                        myHolder.nameTextView.setVisibility(Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) ? View.GONE : View.VISIBLE);
                        if (alCustomizationSettings.isLaunchChatFromProfilePicOrName()) {
                            myHolder.nameTextView.setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View view) {
                                    Intent intent = new Intent(activityContext, ConversationActivity.class);
                                    intent.putExtra(ConversationUIService.USER_ID, message.getContactIds());
                                    if (message.getConversationId() != null) {
                                        intent.putExtra(ConversationUIService.CONVERSATION_ID, message.getConversationId());
                                    }
                                    activityContext.startActivity(intent);
                                }
                            });
                        }
                        String userId = contactDisplayName.getDisplayName();
                        char firstLetter = contactDisplayName.getDisplayName().charAt(0);
                        if (userId.length() > 0) {
                            myHolder.nameTextView.setText(String.valueOf(userId));
                        }
                        Character colorKey = AlphaNumberColorUtil.alphabetBackgroundColorMap.containsKey(firstLetter) ? firstLetter : null;
                        myHolder.nameTextView.setTextColor(context.getResources().getColor(AlphaNumberColorUtil.alphabetBackgroundColorMap.get(colorKey)));
                    }
                    myHolder.createdAtTime.setTextColor(Color.parseColor(alCustomizationSettings.getMessageTimeTextColor()));
                    if (message.isTypeOutbox() && !message.isCanceled()) {
                        myHolder.mediaUploadProgressBar.setVisibility(message.isAttachmentUploadInProgress() ? View.VISIBLE : View.GONE);
                    } else {
                        myHolder.mediaUploadProgressBar.setVisibility(View.GONE);
                    }
                    if (myHolder.attachedFile != null) {
                        myHolder.attachedFile.setVisibility(message.hasAttachment() ? View.VISIBLE : View.GONE);
                    }
                    if (individual && message.getTimeToLive() != null) {
                        myHolder.selfDestruct.setText("Self destruct in " + message.getTimeToLive() + " mins");
                        myHolder.selfDestruct.setVisibility(View.VISIBLE);
                    } else {
                        myHolder.selfDestruct.setText("");
                        myHolder.selfDestruct.setVisibility(View.GONE);
                    }
                    if (myHolder.sentOrReceived != null) {
                        if ((!message.isCall()) || message.isDummyEmptyMessage()) {
                            myHolder.sentOrReceived.setVisibility(View.GONE);
                        } else if (message.isCall()) {
                            myHolder.sentOrReceived.setImageResource(R.drawable.applozic_ic_action_call_holo_light);
                        } else if (getItemViewType(position) == 0) {
                            myHolder.sentOrReceived.setImageResource(R.drawable.mobicom_social_forward);
                        } else {
                            myHolder.sentOrReceived.setImageResource(R.drawable.mobicom_social_reply);
                        }
                        if (message.isCall()) {
                            myHolder.messageTextView.setTextColor(context.getResources().getColor(message.isIncomingCall() ? R.color.incoming_call : R.color.outgoing_call));
                        }
                    }
                    if (myHolder.nameTextLayout != null && contact != null) {
                        myHolder.nameTextLayout.setVisibility(View.GONE);
                    }
                    if (contactDisplayName != null && myHolder.contactImage != null && alCustomizationSettings.isLaunchChatFromProfilePicOrName()) {
                        myHolder.contactImage.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                Intent intent = new Intent(activityContext, ConversationActivity.class);
                                intent.putExtra(ConversationUIService.USER_ID, message.getContactIds());
                                if (message.getConversationId() != null) {
                                    intent.putExtra(ConversationUIService.CONVERSATION_ID, message.getConversationId());
                                }
                                activityContext.startActivity(intent);
                            }
                        });
                        myHolder.alphabeticTextView.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                Intent intent = new Intent(activityContext, ConversationActivity.class);
                                intent.putExtra(ConversationUIService.USER_ID, message.getContactIds());
                                if (message.getConversationId() != null) {
                                    intent.putExtra(ConversationUIService.CONVERSATION_ID, message.getConversationId());
                                }
                                activityContext.startActivity(intent);
                            }
                        });
                    }
                    if (!message.isTypeOutbox()) {
                        loadContactImage(receiverContact, contactDisplayName, message, myHolder.contactImage, myHolder.alphabeticTextView, myHolder.onlineTextView);
                    }
                    if (message.hasAttachment() && myHolder.attachedFile != null & !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                        myHolder.mainAttachmentLayout.setLayoutParams(getImageLayoutParam(false));
                        myHolder.mainAttachmentLayout.setVisibility(View.VISIBLE);
                        if (message.getFileMetas() != null && (message.getFileMetas().getContentType().contains("image") || message.getFileMetas().getContentType().contains("video"))) {
                            myHolder.attachedFile.setVisibility(View.GONE);
                        }
                        if (message.isAttachmentDownloaded()) {
                            myHolder.mapImageView.setVisibility(View.GONE);
                            // myHolder.preview.setVisibility(View.GONE);
                            String[] filePaths = new String[message.getFilePaths().size()];
                            int i = 0;
                            for (final String filePath : message.getFilePaths()) {
                                filePaths[i++] = filePath;
                                final String mimeType = FileUtils.getMimeType(filePath);
                                if (mimeType != null && mimeType.startsWith("image")) {
                                    myHolder.attachmentView.setVisibility(View.GONE);
                                    myHolder.videoIcon.setVisibility(View.GONE);
                                    myHolder.preview.setVisibility(View.VISIBLE);
                                    myHolder.preview.setImageBitmap(null);
                                    myHolder.attachmentDownloadLayout.setVisibility(View.GONE);
                                    myHolder.attachmentDownloadProgressLayout.setVisibility(View.GONE);
                                    if (mimeType.contains("gif")) {
                                        Glide.with(context).asGif().load(new File(filePath)).into(myHolder.preview);
                                    } else {
                                        Glide.with(context).load(new File(filePath)).into(myHolder.preview);
                                    }
                                    myHolder.attachmentView.setMessage(message);
                                    myHolder.mediaDownloadProgressBar.setVisibility(View.GONE);
                                    myHolder.attachedFile.setVisibility(View.GONE);
                                    myHolder.attachmentView.setProressBar(myHolder.mediaDownloadProgressBar);
                                    myHolder.attachmentView.setDownloadProgressLayout(myHolder.attachmentDownloadProgressLayout);
                                } else if (mimeType != null && mimeType.startsWith("video")) {
                                    myHolder.preview.setVisibility(View.VISIBLE);
                                    myHolder.videoIcon.setVisibility(View.VISIBLE);
                                    myHolder.mediaDownloadProgressBar.setVisibility(View.GONE);
                                    myHolder.attachmentDownloadLayout.setVisibility(View.GONE);
                                    myHolder.attachmentDownloadProgressLayout.setVisibility(View.GONE);
                                    myHolder.attachedFile.setVisibility(View.GONE);
                                    if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) {
                                        myHolder.preview.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString()));
                                    } else {
                                        imageCache.addBitmapToCache(message.getKeyString(), fileClientService.getOrCreateVideoThumbnail(filePath));
                                        myHolder.preview.setImageBitmap(fileClientService.getOrCreateVideoThumbnail(filePath));
                                    }
                                } else {
                                    myHolder.preview.setVisibility(View.GONE);
                                    myHolder.mediaDownloadProgressBar.setVisibility(View.GONE);
                                    myHolder.attachmentDownloadLayout.setVisibility(View.GONE);
                                    myHolder.attachmentDownloadProgressLayout.setVisibility(View.GONE);
                                    showAttachmentIconAndText(myHolder.attachedFile, message, mimeType);
                                }
                            }
                        } else if (message.isAttachmentUploadInProgress()) {
                            // showPreview(smListItem, preview, attachmentDownloadLayout);
                            myHolder.preview.setImageDrawable(null);
                            myHolder.preview.setImageBitmap(null);
                            myHolder.attachmentDownloadProgressLayout.setVisibility(View.VISIBLE);
                            myHolder.mediaDownloadProgressBar.setVisibility(View.VISIBLE);
                            myHolder.videoIcon.setVisibility(GONE);
                            myHolder.attachmentView.setProressBar(myHolder.mediaDownloadProgressBar);
                            myHolder.attachmentView.setDownloadProgressLayout(myHolder.attachmentDownloadProgressLayout);
                            myHolder.attachmentView.setMessage(message);
                            myHolder.attachmentView.setVisibility(View.VISIBLE);
                            myHolder.attachedFile.setVisibility(GONE);
                        } else if (AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
                            // ondraw is called and thread is assigned to the attachment view...
                            myHolder.preview.setImageDrawable(null);
                            myHolder.preview.setImageBitmap(null);
                            myHolder.attachmentView.setMessage(message);
                            myHolder.attachmentView.setVisibility(View.VISIBLE);
                            myHolder.mediaDownloadProgressBar.setVisibility(View.VISIBLE);
                            myHolder.attachmentView.setProressBar(myHolder.mediaDownloadProgressBar);
                            myHolder.attachmentView.setDownloadProgressLayout(myHolder.attachmentDownloadProgressLayout);
                            myHolder.preview.setVisibility(View.VISIBLE);
                            showPreview(message, myHolder.preview, myHolder.attachmentDownloadLayout);
                            FileMeta fileMeta = message.getFileMetas();
                            final String mimeType = FileUtils.getMimeType(fileMeta.getName());
                            if (!fileMeta.getContentType().contains("image") && !fileMeta.getContentType().contains("video")) {
                                showAttachmentIconAndText(myHolder.attachedFile, message, mimeType);
                            }
                            myHolder.downloadSizeTextView.setText(fileMeta.getSizeInReadableFormat());
                            myHolder.attachmentView.setDownloadProgressLayout(myHolder.attachmentDownloadProgressLayout);
                            myHolder.attachmentDownloadProgressLayout.setVisibility(View.VISIBLE);
                        } else {
                            String fileKeys = message.getFileMetaKeyStrings();
                            int i = 0;
                            myHolder.preview.setVisibility(View.GONE);
                            // showPreview(null, myHolder.preview, myHolder.attachmentDownloadLayout);
                            showPreview(message, myHolder.preview, myHolder.attachmentDownloadLayout);
                            myHolder.preview.setVisibility(View.VISIBLE);
                            myHolder.videoIcon.setVisibility(View.GONE);
                            // for (String fileKey : message.getFileMetaKeyStrings()) {
                            if (message.getFileMetas() != null) {
                                FileMeta fileMeta = message.getFileMetas();
                                myHolder.attachmentDownloadLayout.setVisibility(View.VISIBLE);
                                myHolder.attachmentDownloadProgressLayout.setVisibility(View.GONE);
                                myHolder.downloadSizeTextView.setText(fileMeta.getSizeInReadableFormat());
                                final String mimeType = FileUtils.getMimeType(fileMeta.getName());
                                if (!fileMeta.getContentType().contains("image") && !fileMeta.getContentType().contains("video")) {
                                    showAttachmentIconAndText(myHolder.attachedFile, message, mimeType);
                                }
                            }
                        }
                        if (message.isNormalAttachment()) {
                            myHolder.videoIcon.setVisibility(View.GONE);
                            myHolder.attachedFile.setVisibility(View.GONE);
                            myHolder.mainAttachmentLayout.setVisibility(View.GONE);
                            myHolder.mainContactShareLayout.setVisibility(View.GONE);
                            myHolder.chatLocation.setVisibility(View.GONE);
                            myHolder.preview.setVisibility(View.GONE);
                            audioView.hideView(false);
                            myHolder.createdAtTime.setText(DateUtils.getFormattedDate(message.getCreatedAtTime(), alCustomizationSettings.getDateFormatCustomization().getTimeTemplate()));
                        }
                    }
                    if (message.isCanceled()) {
                        myHolder.attachmentRetry.setVisibility(View.VISIBLE);
                    } else {
                        myHolder.attachmentRetry.setVisibility(View.GONE);
                    }
                    myHolder.attachmentRetry.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            if (Utils.isInternetAvailable(context)) {
                                File file = null;
                                if (message != null && message.getFilePaths() != null) {
                                    file = new File(message.getFilePaths().get(0));
                                }
                                if (file != null && !file.exists()) {
                                    Toast.makeText(context, context.getString(R.string.file_does_not_exist), Toast.LENGTH_SHORT).show();
                                    return;
                                }
                                Toast.makeText(context, context.getString(R.string.applozic_resending_attachment), Toast.LENGTH_LONG).show();
                                myHolder.mediaUploadProgressBar.setVisibility(View.VISIBLE);
                                myHolder.attachmentRetry.setVisibility(View.GONE);
                                // updating Cancel Flag to smListItem....
                                message.setCanceled(false);
                                messageDatabaseService.updateCanceledFlag(message.getMessageId(), 0);
                                if (sendMessageInterfaceCallBack != null) {
                                    sendMessageInterfaceCallBack.sendMessage(message);
                                }
                            } else {
                                Toast.makeText(context, context.getString(R.string.internet_connection_not_available), Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                    myHolder.attachmentDownloadProgressLayout.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View view) {
                            myHolder.attachmentView.setVisibility(View.GONE);
                            myHolder.attachmentView.cancelDownload();
                            myHolder.attachmentDownloadProgressLayout.setVisibility(View.GONE);
                            message.setAttDownloadInProgress(false);
                        }
                    });
                    // final ProgressBar mediaDownloadProgressBar = mediaDownloadProgressBar;
                    myHolder.preview.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // 3. if deleted from sd crad only ...ask user to download it again or skip ...
                            if (message.getContentType() == Message.ContentType.TEXT_URL.getValue()) {
                                return;
                            }
                            if (message.isAttachmentDownloaded()) {
                                if (storagePermissionListener.isPermissionGranted()) {
                                    showFullView(message);
                                } else {
                                    storagePermissionListener.checkPermission(new ALStoragePermission() {

                                        @Override
                                        public void onAction(boolean didGrant) {
                                            if (didGrant) {
                                                showFullView(message);
                                            }
                                        }
                                    });
                                }
                            } else {
                                if (storagePermissionListener.isPermissionGranted()) {
                                    myHolder.attachmentDownloadLayout.setVisibility(View.GONE);
                                    myHolder.mediaDownloadProgressBar.setVisibility(View.VISIBLE);
                                    myHolder.attachmentView.setProressBar(myHolder.mediaDownloadProgressBar);
                                    myHolder.attachmentView.setDownloadProgressLayout(myHolder.attachmentDownloadProgressLayout);
                                    myHolder.attachmentView.setMessage(message);
                                    myHolder.attachmentView.setGifDownloadListener(new GifDownloadImpl(context));
                                    myHolder.attachmentView.setVisibility(View.VISIBLE);
                                    myHolder.attachmentDownloadProgressLayout.setVisibility(View.VISIBLE);
                                } else {
                                    storagePermissionListener.checkPermission(new ALStoragePermission() {

                                        @Override
                                        public void onAction(boolean didGrant) {
                                            if (didGrant) {
                                                myHolder.attachmentDownloadLayout.setVisibility(View.GONE);
                                                myHolder.mediaDownloadProgressBar.setVisibility(View.VISIBLE);
                                                myHolder.attachmentView.setProressBar(myHolder.mediaDownloadProgressBar);
                                                myHolder.attachmentView.setDownloadProgressLayout(myHolder.attachmentDownloadProgressLayout);
                                                myHolder.attachmentView.setMessage(message);
                                                myHolder.attachmentView.setGifDownloadListener(new GifDownloadImpl(context));
                                                myHolder.attachmentView.setVisibility(View.VISIBLE);
                                                myHolder.attachmentDownloadProgressLayout.setVisibility(View.VISIBLE);
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    });
                    myHolder.preview.setOnLongClickListener(new View.OnLongClickListener() {

                        @Override
                        public boolean onLongClick(View v) {
                            return false;
                        }
                    });
                    myHolder.attachmentView.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            if (storagePermissionListener.isPermissionGranted()) {
                                showFullView(message);
                            } else {
                                storagePermissionListener.checkPermission(new ALStoragePermission() {

                                    @Override
                                    public void onAction(boolean didGrant) {
                                        if (didGrant) {
                                            showFullView(message);
                                        }
                                    }
                                });
                            }
                        }
                    });
                    myHolder.attachmentView.setOnLongClickListener(new View.OnLongClickListener() {

                        @Override
                        public boolean onLongClick(View v) {
                            return false;
                        }
                    });
                    if (myHolder.attachedFile != null) {
                        myHolder.attachedFile.setOnLongClickListener(new View.OnLongClickListener() {

                            @Override
                            public boolean onLongClick(View v) {
                                return false;
                            }
                        });
                    }
                    if (message.getScheduledAt() != null) {
                        myHolder.createdAtTime.setText(DateUtils.getFormattedDate(message.getScheduledAt(), alCustomizationSettings.getDateFormatCustomization().getTimeTemplate()));
                    } else if (myHolder.createdAtTime != null && message.isDummyEmptyMessage()) {
                        myHolder.createdAtTime.setText("");
                    } else if (myHolder.createdAtTime != null) {
                        myHolder.createdAtTime.setText(DateUtils.getFormattedDate(message.getCreatedAtTime(), alCustomizationSettings.getDateFormatCustomization().getTimeTemplate()));
                    }
                    String mimeType = "";
                    if (TextUtils.isEmpty(message.getMessage())) {
                        myHolder.messageTextView.setVisibility(message.hasAttachment() ? View.GONE : View.GONE);
                    } else {
                        myHolder.messageTextView.setVisibility(message.getContentType() == Message.ContentType.LOCATION.getValue() ? View.GONE : View.VISIBLE);
                    }
                    if (myHolder.messageTextView != null) {
                        myHolder.messageTextView.setTextColor(message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getSentMessageTextColor()) : Color.parseColor(alCustomizationSettings.getReceivedMessageTextColor()));
                        myHolder.messageTextView.setLinkTextColor(message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getSentMessageLinkTextColor()) : Color.parseColor(alCustomizationSettings.getReceivedMessageLinkTextColor()));
                        if (message.getContentType() == Message.ContentType.TEXT_URL.getValue()) {
                            try {
                                myHolder.mapImageView.setVisibility(View.GONE);
                                myHolder.attachedFile.setVisibility(View.GONE);
                                myHolder.preview.setVisibility(View.VISIBLE);
                                setMessageText(myHolder.messageTextView, message);
                                loadImage.setImageFadeIn(false);
                                loadImage.loadImage(message.getFileMetas().getBlobKeyString(), myHolder.preview);
                                myHolder.attachmentDownloadLayout.setVisibility(View.GONE);
                            } catch (Exception e) {
                            }
                        } else if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
                            // attachedFile.setVisibility(View.GONE);
                            // preview.setVisibility(View.GONE);
                            myHolder.chatLocation.setLayoutParams(getImageLayoutParam(false));
                            myHolder.chatLocation.setVisibility(View.VISIBLE);
                            loadImage.setImageFadeIn(false);
                            // Default image while loading image.
                            myHolder.mapImageView.setVisibility(View.VISIBLE);
                            loadImage.setLoadingImage(R.drawable.applozic_map_offline_thumbnail);
                            loadImage.loadImage(LocationUtils.loadStaticMap(message.getMessage(), geoApiKey), myHolder.mapImageView);
                            myHolder.messageTextView.setVisibility(View.GONE);
                            myHolder.preview.setVisibility(View.GONE);
                            myHolder.mapImageView.setOnClickListener(new View.OnClickListener() {

                                @Override
                                public void onClick(View v) {
                                    String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?q=" + LocationUtils.getLocationFromMessage(message.getMessage()));
                                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                                    activityContext.startActivity(intent);
                                }
                            });
                        } else if (message.getContentType() == Message.ContentType.PRICE.getValue()) {
                            myHolder.mapImageView.setVisibility(View.GONE);
                            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, true, alCustomizationSettings.getConversationMentionSpanColor()));
                            spannableStringBuilder.insert(0, ConversationUIService.FINAL_PRICE_TEXT);
                            myHolder.messageTextView.setText(spannableStringBuilder);
                        } else if ((message.getContentType() == Message.ContentType.VIDEO_MSG.getValue()) && !message.isAttachmentDownloaded()) {
                            myHolder.preview.setVisibility(View.VISIBLE);
                            myHolder.mapImageView.setVisibility(View.GONE);
                        } else if (message.getContentType() == Message.ContentType.TEXT_HTML.getValue()) {
                            myHolder.mapImageView.setVisibility(View.GONE);
                            setMessageText(myHolder.messageTextView, message);
                        } else {
                            myHolder.mapImageView.setVisibility(View.GONE);
                            myHolder.chatLocation.setVisibility(View.GONE);
                            myHolder.messageTextView.setText(EmoticonUtils.getSmiledText(activityContext, MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, true, alCustomizationSettings.getConversationMentionSpanColor()), emojiconHandler));
                        }
                        if (myHolder.messageTextLayout != null) {
                            GradientDrawable bgShape = (GradientDrawable) myHolder.messageTextLayout.getBackground();
                            bgShape.setColor(message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getSentMessageBackgroundColor()) : Color.parseColor(alCustomizationSettings.getReceivedMessageBackgroundColor()));
                            bgShape.setStroke(3, message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getSentMessageBorderColor()) : Color.parseColor(alCustomizationSettings.getReceivedMessageBackgroundColor()));
                        }
                    }
                    if (!message.hasAttachment()) {
                        myHolder.preview.setVisibility(View.GONE);
                        myHolder.mainAttachmentLayout.setVisibility(View.GONE);
                        myHolder.mediaDownloadProgressBar.setVisibility(View.VISIBLE);
                        myHolder.attachmentView.setVisibility(View.GONE);
                        myHolder.videoIcon.setVisibility(View.GONE);
                        myHolder.attachedFile.setVisibility(View.GONE);
                        myHolder.mainContactShareLayout.setVisibility(View.GONE);
                    }
                    if (message.isTypeUrl()) {
                        new AlLinkPreview(activityContext, message, myHolder.urlLoadLayout, alCustomizationSettings).createView();
                    } else {
                        myHolder.urlLoadLayout.setVisibility(View.GONE);
                    }
                    if (message.getMetadata() != null && "300".equals(message.getMetadata().get("contentType"))) {
                        myHolder.richMessageLayout.setVisibility(View.VISIBLE);
                        if (!TextUtils.isEmpty(message.getMessage())) {
                            myHolder.messageTextLayout.setVisibility(View.VISIBLE);
                        } else {
                            myHolder.messageTextLayout.setVisibility(GONE);
                        }
                        try {
                            new AlRichMessage(activityContext, myHolder.richMessageLayout, message, listener, alCustomizationSettings).createRichMessage();
                        } catch (Exception e) {
                            e.printStackTrace();
                            myHolder.richMessageLayout.setVisibility(View.GONE);
                        }
                    } else {
                        myHolder.richMessageLayout.setVisibility(View.GONE);
                        myHolder.messageTextLayout.setVisibility(View.VISIBLE);
                    }
                    // Handling contact share
                    if (message.isContactMessage()) {
                        myHolder.attachedFile.setVisibility(View.GONE);
                        myHolder.mainAttachmentLayout.setVisibility(View.GONE);
                        setupContactShareView(message, myHolder);
                    } else {
                        myHolder.mainContactShareLayout.setVisibility(View.GONE);
                    }
                    Spannable mentionsMessageString = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, true, alCustomizationSettings.getConversationMentionSpanColor());
                    int startIndex = indexOfSearchQuery(mentionsMessageString.toString());
                    if (startIndex != -1) {
                        final SpannableString highlightedName = new SpannableString(mentionsMessageString);
                        // Sets the span to start at the starting point of the match and end at "length"
                        // characters beyond the starting point
                        highlightedName.setSpan(new ForegroundColorSpan(Color.parseColor(alCustomizationSettings.getMessageSearchTextColor())), startIndex, startIndex + searchString.toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        myHolder.messageTextView.setText(highlightedName);
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : VCFContactData(com.applozic.mobicomkit.contact.VCFContactData) AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) Message(com.applozic.mobicomkit.api.conversation.Message) Configuration(android.content.res.Configuration) MobiComVCFParser(com.applozic.mobicomkit.contact.MobiComVCFParser) ALStoragePermission(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission) SpannableString(android.text.SpannableString) ArrayList(java.util.ArrayList) List(java.util.List) ApplozicDocumentView(com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicDocumentView) OnClickReplyInterface(com.applozic.mobicomkit.uiwidgets.conversation.activity.OnClickReplyInterface) AlLinkPreview(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.views.AlLinkPreview) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) Intent(android.content.Intent) AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) ApplozicDocumentView(com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicDocumentView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AttachmentView(com.applozic.mobicomkit.api.attachment.AttachmentView) Date(java.util.Date) GradientDrawable(android.graphics.drawable.GradientDrawable) Contact(com.applozic.mobicommons.people.contact.Contact) SpannableString(android.text.SpannableString) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta) SpannableStringBuilder(android.text.SpannableStringBuilder) Spannable(android.text.Spannable)

Aggregations

Intent (android.content.Intent)1 Configuration (android.content.res.Configuration)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 Spannable (android.text.Spannable)1 SpannableString (android.text.SpannableString)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AttachmentView (com.applozic.mobicomkit.api.attachment.AttachmentView)1 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)1 Message (com.applozic.mobicomkit.api.conversation.Message)1 MobiComVCFParser (com.applozic.mobicomkit.contact.MobiComVCFParser)1 VCFContactData (com.applozic.mobicomkit.contact.VCFContactData)1 ApplozicDocumentView (com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicDocumentView)1 OnClickReplyInterface (com.applozic.mobicomkit.uiwidgets.conversation.activity.OnClickReplyInterface)1 AlRichMessage (com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage)1