Search in sources :

Example 1 with OnClickReplyInterface

use of com.applozic.mobicomkit.uiwidgets.conversation.activity.OnClickReplyInterface 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()));
                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.getMetadata() != null && !message.getMetadata().isEmpty() && message.getMetadata().containsKey(Message.MetaDataType.AL_REPLY.getValue())) {
                    final Message msg = messageDatabaseService.getMessage(message.getMetaDataValueForKey(Message.MetaDataType.AL_REPLY.getValue()));
                    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(msg.getMessage());
                                }
                                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(msg.getMessage());
                                }
                                myHolder.imageViewPhoto.setVisibility(View.VISIBLE);
                                myHolder.imageViewRLayout.setVisibility(View.VISIBLE);
                                if (msg.getFilePaths() != null && msg.getFilePaths().size() > 0) {
                                    if (imageCache.getBitmapFromMemCache(msg.getKeyString()) != null) {
                                        myHolder.imageViewPhoto.setImageBitmap(imageCache.getBitmapFromMemCache(msg.getKeyString()));
                                    } else {
                                        imageCache.addBitmapToCache(message.getKeyString(), fileClientService.createAndSaveVideoThumbnail(msg.getFilePaths().get(0)));
                                        myHolder.imageViewPhoto.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(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(msg.getMessage());
                                }
                                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(msg.getMessage());
                                }
                                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()), myHolder.imageViewPhoto);
                        } else {
                            myHolder.imageViewForAttachmentType.setVisibility(View.GONE);
                            myHolder.imageViewRLayout.setVisibility(View.GONE);
                            myHolder.imageViewPhoto.setVisibility(View.GONE);
                            myHolder.replyMessageTextView.setText(msg.getMessage());
                        }
                        myHolder.replyRelativeLayout.setVisibility(View.VISIBLE);
                        myHolder.replyRelativeLayout.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                ((OnClickReplyInterface) context).onClickOnMessageReply(msg);
                            }
                        });
                    }
                } else {
                    myHolder.replyRelativeLayout.setVisibility(GONE);
                }
                if (TextUtils.isEmpty(message.getMessage())) {
                    myHolder.messageTextView.setVisibility(View.GONE);
                }
                myHolder.messageTextView.setVisibility(View.GONE);
                myHolder.mapImageView.setVisibility(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 (myHolder.attachmentIcon != null) {
                    myHolder.attachmentIcon.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(context, ConversationActivity.class);
                                intent.putExtra(ConversationUIService.USER_ID, message.getContactIds());
                                if (message.getConversationId() != null) {
                                    intent.putExtra(ConversationUIService.CONVERSATION_ID, message.getConversationId());
                                }
                                context.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()));
                myHolder.attachmentDownloadLayout.setVisibility(View.GONE);
                // myHolder.preview.setVisibility(message.hasAttachment() ? View.VISIBLE : View.GONE);
                myHolder.attachmentView.setVisibility(View.GONE);
                if (message.isTypeOutbox() && !message.isCanceled()) {
                    myHolder.mediaUploadProgressBar.setVisibility(View.GONE);
                    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 (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() || (contact != null && new Support(context).isSupportNumber(contact.getFormattedContactNumber())) ? deliveredIcon : (message.getScheduledAt() != null ? scheduledIcon : sentIcon));
                    }
                    myHolder.createdAtTime.setCompoundDrawablesWithIntrinsicBounds(null, null, statusIcon, null);
                }
                if (message.isCall()) {
                    myHolder.deliveryStatus.setText("");
                }
                if (contactDisplayName != null && myHolder.contactImage != null && alCustomizationSettings.isLaunchChatFromProfilePicOrName()) {
                    myHolder.contactImage.setOnClickListener(new View.OnClickListener() {

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

                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(context, ConversationActivity.class);
                            intent.putExtra(ConversationUIService.USER_ID, message.getContactIds());
                            if (message.getConversationId() != null) {
                                intent.putExtra(ConversationUIService.CONVERSATION_ID, message.getConversationId());
                            }
                            context.startActivity(intent);
                        }
                    });
                }
                if (message.isTypeOutbox()) {
                    loadContactImage(senderContact, contactDisplayName, message, myHolder.contactImage, myHolder.alphabeticTextView, myHolder.onlineTextView);
                } else {
                    loadContactImage(receiverContact, contactDisplayName, message, myHolder.contactImage, myHolder.alphabeticTextView, myHolder.onlineTextView);
                }
                ApplozicDocumentView audioView = new ApplozicDocumentView(this.context);
                audioView.inflateViewWithMessage(myHolder.view, message);
                audioView.hideView(true);
                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.setImageBitmap(null);
                                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);
                                Glide.with(context).load(new File(filePath)).into(myHolder.preview);
                                /*Bitmap bitmap = BitmapFactory.decodeFile(filePath);
                                    myHolder.preview.setImageBitmap(bitmap);*/
                                // Picasso.with(context).load(new File(filePath)).into(myHolder.preview);
                                myHolder.attachmentView.setMessage(message);
                                myHolder.mediaDownloadProgressBar.setVisibility(View.GONE);
                                // myHolder.mediaUploadProgressBar.setVisibility(GONE);
                                myHolder.attachedFile.setVisibility(View.GONE);
                                myHolder.attachmentView.setProressBar(myHolder.mediaDownloadProgressBar);
                                myHolder.attachmentView.setDownloadProgressLayout(myHolder.attachmentDownloadProgressLayout);
                            /**/
                            /*myHolder.attachmentView.setVisibility(View.VISIBLE);
                                    myHolder.videoIcon.setVisibility(View.GONE);
                                    myHolder.preview.setVisibility(View.GONE);*/
                            } 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.createAndSaveVideoThumbnail(filePath));
                                    myHolder.preview.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(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);
                        myHolder.attachmentIcon.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 (isNormalAttachment(message)) {
                        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()));
                    }
                }
                if (message.isCanceled()) {
                    myHolder.attachmentRetry.setVisibility(View.VISIBLE);
                }
                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);
                            conversationService.sendMessage(message, messageIntentClass);
                        } 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()) {
                            showFullView(message);
                        // return;
                        } else {
                            // if (message.isTypeOutbox() || message.isSentToServer()) {
                            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.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) {
                        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()));
                } else if (myHolder.createdAtTime != null && message.isDummyEmptyMessage()) {
                    myHolder.createdAtTime.setText("");
                } else if (myHolder.createdAtTime != null) {
                    myHolder.createdAtTime.setText(DateUtils.getFormattedDate(message.getCreatedAtTime()));
                }
                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);
                            myHolder.messageTextView.setText(message.getMessage());
                            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()), 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));
                                context.startActivity(intent);
                            }
                        });
                    } else if (message.getContentType() == Message.ContentType.PRICE.getValue()) {
                        myHolder.mapImageView.setVisibility(View.GONE);
                        myHolder.messageTextView.setText(ConversationUIService.FINAL_PRICE_TEXT + message.getMessage());
                    } else if ((message.getContentType() == Message.ContentType.VIDEO_MSG.getValue()) && !message.isAttachmentDownloaded()) {
                        myHolder.preview.setVisibility(View.VISIBLE);
                        myHolder.mapImageView.setVisibility(View.GONE);
                        myHolder.preview.setImageResource(R.drawable.applozic_video_default_thumbnail);
                    } else if (message.getContentType() == Message.ContentType.TEXT_HTML.getValue()) {
                        myHolder.mapImageView.setVisibility(View.GONE);
                        myHolder.messageTextView.setText(message.getMessage());
                    } else {
                        myHolder.mapImageView.setVisibility(View.GONE);
                        myHolder.chatLocation.setVisibility(View.GONE);
                        // myHolder.attachedFile.setVisibility(View.GONE);
                        // myHolder.preview.setVisibility(View.GONE);
                        myHolder.messageTextView.setText(EmoticonUtils.getSmiledText(context, message.getMessage(), emojiconHandler));
                    /*if (mimeType != null && myHolder.attachmentIcon != null) {
                            myHolder.messageTextView.setVisibility(TextUtils.isEmpty(message.getMessage()) ? View.GONE : View.VISIBLE);
                            if (mimeType.startsWith("image")) {
                                myHolder.attachmentIcon.setImageResource(R.drawable.applozic_ic_action_camera);
                            } else if (mimeType.startsWith("video")) {
                                myHolder.attachmentIcon.setImageResource(R.drawable.applozic_ic_action_video);
                            }
                        }*/
                    }
                    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.attachedFile.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);
                }
                // 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);
                }
                int startIndex = indexOfSearchQuery(message.getMessage());
                if (startIndex != -1) {
                    final SpannableString highlightedName = new SpannableString(message.getMessage());
                    // Sets the span to start at the starting point of the match and end at "length"
                    // characters beyond the starting point
                    highlightedName.setSpan(highlightTextSpan, startIndex, startIndex + searchString.toString().length(), 0);
                    myHolder.messageTextView.setText(highlightedName);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : VCFContactData(com.applozic.mobicomkit.contact.VCFContactData) Message(com.applozic.mobicomkit.api.conversation.Message) Configuration(android.content.res.Configuration) Support(com.applozic.mobicommons.commons.core.utils.Support) MobiComVCFParser(com.applozic.mobicomkit.contact.MobiComVCFParser) SpannableString(android.text.SpannableString) List(java.util.List) ArrayList(java.util.ArrayList) ApplozicDocumentView(com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicDocumentView) OnClickReplyInterface(com.applozic.mobicomkit.uiwidgets.conversation.activity.OnClickReplyInterface) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) Intent(android.content.Intent) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) ApplozicDocumentView(com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicDocumentView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) 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)

Aggregations

Intent (android.content.Intent)1 Configuration (android.content.res.Configuration)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)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 Support (com.applozic.mobicommons.commons.core.utils.Support)1 Contact (com.applozic.mobicommons.people.contact.Contact)1 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)1 File (java.io.File)1