Search in sources :

Example 1 with ALStoragePermission

use of com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission in project Applozic-Android-SDK by AppLozic.

the class MultimediaOptionsGridView method executeMethod.

public void executeMethod(String key) {
    if (key.equals(context.getResources().getString(R.string.al_location))) {
        ((ConversationActivity) context).processLocation();
    } else if (key.equals(context.getString(R.string.al_camera))) {
        if (storagePermissionListener.isPermissionGranted()) {
            ((ConversationActivity) context).isTakePhoto(true);
            ((ConversationActivity) context).processCameraAction();
        } else {
            storagePermissionListener.checkPermission(new ALStoragePermission() {

                @Override
                public void onAction(boolean didGrant) {
                    if (didGrant) {
                        ((ConversationActivity) context).isTakePhoto(true);
                        ((ConversationActivity) context).processCameraAction();
                    }
                }
            });
        }
    } else if (key.equals(context.getString(R.string.al_file))) {
        if (storagePermissionListener.isPermissionGranted()) {
            ((ConversationActivity) context).isAttachment(true);
            ((ConversationActivity) context).processAttachment();
        } else {
            storagePermissionListener.checkPermission(new ALStoragePermission() {

                @Override
                public void onAction(boolean didGrant) {
                    if (didGrant) {
                        ((ConversationActivity) context).isAttachment(true);
                        ((ConversationActivity) context).processAttachment();
                    }
                }
            });
        }
    } else if (key.equals(context.getString(R.string.al_audio))) {
        if (storagePermissionListener.isPermissionGranted()) {
            ((ConversationActivity) context).showAudioRecordingDialog();
        } else {
            storagePermissionListener.checkPermission(new ALStoragePermission() {

                @Override
                public void onAction(boolean didGrant) {
                    if (didGrant) {
                        ((ConversationActivity) context).showAudioRecordingDialog();
                    }
                }
            });
        }
    } else if (key.equals(context.getString(R.string.al_video))) {
        if (storagePermissionListener.isPermissionGranted()) {
            ((ConversationActivity) context).isTakePhoto(false);
            ((ConversationActivity) context).processVideoRecording();
        } else {
            storagePermissionListener.checkPermission(new ALStoragePermission() {

                @Override
                public void onAction(boolean didGrant) {
                    if (didGrant) {
                        ((ConversationActivity) context).isTakePhoto(false);
                        ((ConversationActivity) context).processVideoRecording();
                    }
                }
            });
        }
    } else if (key.equals(context.getString(R.string.al_gif))) {
        ((ConversationActivity) context).processGif();
    } else if (key.equals(context.getString(R.string.al_price))) {
        new ConversationUIService(context).sendPriceMessage();
    }
    multimediaOptions.setVisibility(View.GONE);
}
Also used : ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) ALStoragePermission(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission)

Example 2 with ALStoragePermission

use of com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method loadConversation.

public void loadConversation(final Contact contact, final Channel channel, final Integer conversationId, final String searchString) {
    try {
        if (downloadConversation != null) {
            downloadConversation.cancel(true);
        }
        if (this.contact != null && contact != null && !contact.getUserId().equals(this.contact.getUserId())) {
            userDisplayName = null;
        }
        setContact(contact);
        setChannel(channel);
        BroadcastService.currentUserId = contact != null ? contact.getContactIds() : String.valueOf(channel.getKey());
        typingStarted = false;
        onSelected = false;
        messageMetaData = null;
        Applozic.subscribeToTyping(getContext(), channel, contact);
        checkForUserNotAbleToChatAndToggleViews(contact, channel);
        if (contact != null && this.channel != null) {
            if (getActivity() != null) {
                setToolbarSubtitle("");
                setToolbarImage(contact, channel);
            }
            if (menu != null) {
                menu.findItem(R.id.unmuteGroup).setVisible(false);
                menu.findItem(R.id.muteGroup).setVisible(false);
            }
        }
        if (replayRelativeLayout != null) {
            replayRelativeLayout.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(filePath) && attachmentLayout != null) {
            attachmentLayout.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(defaultText) && messageEditText != null) {
            messageEditText.setText(defaultText);
            defaultText = "";
        }
        extendedSendingOptionLayout.setVisibility(VISIBLE);
        unregisterForContextMenu(recyclerView);
        if (getActivity() != null) {
            if (ApplozicClient.getInstance(getActivity()).isNotificationStacking()) {
                NotificationManagerCompat nMgr = NotificationManagerCompat.from(getActivity());
                nMgr.cancel(NotificationService.NOTIFICATION_ID);
            } else {
                if (contact != null) {
                    if (!TextUtils.isEmpty(contact.getContactIds())) {
                        NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
                        if (notificationManager != null) {
                            notificationManager.cancel(contact.getContactIds().hashCode());
                        }
                    }
                }
                if (channel != null) {
                    NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
                    if (notificationManager != null) {
                        notificationManager.cancel(String.valueOf(channel.getKey()).hashCode());
                    }
                }
            }
        }
        clearList();
        updateTitle(contact, channel);
        swipeLayout.setEnabled(true);
        loadMore = true;
        if (selfDestructMessageSpinner != null) {
            selfDestructMessageSpinner.setSelection(0);
        }
        if (contact != null) {
            recyclerDetailConversationAdapter = new DetailedConversationAdapter(getActivity(), messageList, contact, messageIntentClass, emojiIconHandler);
            recyclerDetailConversationAdapter.setAlCustomizationSettings(alCustomizationSettings);
            recyclerDetailConversationAdapter.setRichMessageCallbackListener(richMessageActionProcessor.getRichMessageListener());
            recyclerDetailConversationAdapter.setContextMenuClickListener(this);
            recyclerDetailConversationAdapter.setSendMessageInterfaceCallBack(this);
            if (getActivity() instanceof ALStoragePermissionListener) {
                recyclerDetailConversationAdapter.setStoragePermissionListener((ALStoragePermissionListener) getActivity());
            } else {
                recyclerDetailConversationAdapter.setStoragePermissionListener(new ALStoragePermissionListener() {

                    @Override
                    public boolean isPermissionGranted() {
                        return false;
                    }

                    @Override
                    public void checkPermission(ALStoragePermission storagePermission) {
                    }
                });
            }
        } else if (channel != null) {
            Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    if (!ChannelService.getInstance(getContext()).isUserAlreadyPresentInChannel(channel.getKey(), loggedInUserId) && messageTemplate != null && messageTemplate.isEnabled() && templateAdapter != null) {
                        if (getActivity() == null) {
                            return;
                        }
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                templateAdapter.removeTemplates();
                            }
                        });
                    }
                }
            });
            thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            thread.start();
            recyclerDetailConversationAdapter = new DetailedConversationAdapter(getActivity(), messageList, channel, messageIntentClass, emojiIconHandler);
            recyclerDetailConversationAdapter.setAlCustomizationSettings(alCustomizationSettings);
            recyclerDetailConversationAdapter.setContextMenuClickListener(this);
            recyclerDetailConversationAdapter.setSendMessageInterfaceCallBack(this);
            recyclerDetailConversationAdapter.setRichMessageCallbackListener(richMessageActionProcessor.getRichMessageListener());
            if (getActivity() instanceof ALStoragePermissionListener) {
                recyclerDetailConversationAdapter.setStoragePermissionListener((ALStoragePermissionListener) getActivity());
            } else {
                recyclerDetailConversationAdapter.setStoragePermissionListener(new ALStoragePermissionListener() {

                    @Override
                    public boolean isPermissionGranted() {
                        return false;
                    }

                    @Override
                    public void checkPermission(ALStoragePermission storagePermission) {
                    }
                });
            }
        }
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        if (getActivity() == null) {
            return;
        }
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                linearLayoutManager.setStackFromEnd(true);
            }
        });
        recyclerView.setAdapter(recyclerDetailConversationAdapter);
        registerForContextMenu(recyclerView);
        processMobiTexterUserCheck();
        downloadConversation = new DownloadConversation(recyclerView, true, 1, 0, 0, contact, channel, conversationId);
        AlTask.execute(downloadConversation);
        if (hideExtendedSendingOptionLayout) {
            extendedSendingOptionLayout.setVisibility(View.GONE);
        }
        emoticonsFrameLayout.setVisibility(View.GONE);
        MobiComConversationService mobiComConversationService = new MobiComConversationService(requireContext().getApplicationContext());
        if (contact != null) {
            mobiComConversationService.syncUserDetail(contact.getUserId());
        }
        if (channel != null) {
            if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
                String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
                if (!TextUtils.isEmpty(userId)) {
                    mobiComConversationService.syncUserDetail(userId);
                }
            } else {
                Thread thread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        updateChannelSubTitle(channel);
                    }
                });
                thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
                thread.start();
            }
        }
        if (alCustomizationSettings.isMessageFastScrollEnabled()) {
            if (getActivity() == null) {
                return;
            }
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    recyclerView.smoothScrollToPosition(messageList.size());
                    recyclerView.getLayoutManager().scrollToPosition(messageList.size());
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ALStoragePermissionListener(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermissionListener) NotificationManager(android.app.NotificationManager) DetailedConversationAdapter(com.applozic.mobicomkit.uiwidgets.conversation.adapter.DetailedConversationAdapter) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) ALStoragePermission(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 3 with ALStoragePermission

use of com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission 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)

Example 4 with ALStoragePermission

use of com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission in project Applozic-Android-SDK by AppLozic.

the class ApplozicDocumentView method registerEvents.

public void registerEvents() {
    previewLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (alStoragePermissionListener.isPermissionGranted()) {
                if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
                    // Starts downloading this View, using the current cache setting
                    mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
                    // After successfully downloading the image, this marks that it's available.
                    showDownloadInProgress();
                }
                if (mDownloadThread == null) {
                    mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
                    if (mDownloadThread != null)
                        mDownloadThread.setAttachementViewNew(attachmentViewProperties);
                }
            } else {
                alStoragePermissionListener.checkPermission(new ALStoragePermission() {

                    @Override
                    public void onAction(boolean didGrant) {
                        if (didGrant) {
                            if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
                                // Starts downloading this View, using the current cache setting
                                mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
                                // After successfully downloading the image, this marks that it's available.
                                showDownloadInProgress();
                            }
                            if (mDownloadThread == null) {
                                mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
                                if (mDownloadThread != null)
                                    mDownloadThread.setAttachementViewNew(attachmentViewProperties);
                            }
                        }
                    }
                });
            }
        }
    });
    downloadedLayout.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (alStoragePermissionListener.isPermissionGranted()) {
                playAudio();
            } else {
                alStoragePermissionListener.checkPermission(new ALStoragePermission() {

                    @Override
                    public void onAction(boolean didGrant) {
                        if (didGrant) {
                            playAudio();
                        }
                    }
                });
            }
        }
    });
    downloadInProgressLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            cancelDownload();
        }
    });
    retryLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            message.setCanceled(false);
            MessageDatabaseService messageDatabaseService = new MessageDatabaseService(context);
            messageDatabaseService.updateCanceledFlag(message.getMessageId(), 0);
            new MobiComConversationService(context).sendMessage(message, null);
            showDownloadInProgress();
        }
    });
}
Also used : ALStoragePermission(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 5 with ALStoragePermission

use of com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission in project Applozic-Android-SDK by AppLozic.

the class DetailedConversationAdapter method setupContactShareView.

private void setupContactShareView(final Message message, MyViewHolder myViewHolder) {
    myViewHolder.mainContactShareLayout.setVisibility(View.VISIBLE);
    myViewHolder.mainContactShareLayout.setLayoutParams(getImageLayoutParam(false));
    MobiComVCFParser parser = new MobiComVCFParser();
    try {
        VCFContactData data = parser.parseCVFContactData(message.getFilePaths().get(0));
        myViewHolder.shareContactName.setText(data.getName());
        int resId = message.isTypeOutbox() ? Color.parseColor(alCustomizationSettings.getSentMessageTextColor()) : Color.parseColor(alCustomizationSettings.getReceivedMessageTextColor());
        myViewHolder.shareContactName.setTextColor(resId);
        myViewHolder.shareContactNo.setTextColor(resId);
        myViewHolder.shareEmailContact.setTextColor(resId);
        myViewHolder.addContactButton.setTextColor(resId);
        if (data.getProfilePic() != null) {
            if (imageCache.getBitmapFromMemCache(message.getKeyString()) == null) {
                imageCache.addBitmapToCache(message.getKeyString(), data.getProfilePic());
            }
            myViewHolder.shareContactImage.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString()));
        }
        if (!TextUtils.isEmpty(data.getTelephoneNumber())) {
            myViewHolder.shareContactNo.setText(data.getTelephoneNumber());
        } else {
            myViewHolder.shareContactNo.setVisibility(View.GONE);
        }
        if (data.getEmail() != null) {
            myViewHolder.shareEmailContact.setText(data.getEmail());
        } else {
            myViewHolder.shareEmailContact.setVisibility(View.GONE);
        }
        myViewHolder.addContactButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (storagePermissionListener.isPermissionGranted()) {
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    Uri outputUri = null;
                    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    if (Utils.hasNougat()) {
                        outputUri = ALFileProvider.getUriForFile(context, Utils.getMetaDataValue(context, MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", new File(message.getFilePaths().get(0)));
                    } else {
                        outputUri = Uri.fromFile(new File(message.getFilePaths().get(0)));
                    }
                    if (intent.resolveActivity(context.getPackageManager()) != null) {
                        intent.setDataAndType(outputUri, "text/x-vcard");
                        activityContext.startActivity(intent);
                    } else {
                        Toast.makeText(context, R.string.info_app_not_found_to_open_file, Toast.LENGTH_LONG).show();
                    }
                } else {
                    storagePermissionListener.checkPermission(new ALStoragePermission() {

                        @Override
                        public void onAction(boolean didGrant) {
                            Intent intent = new Intent();
                            intent.setAction(Intent.ACTION_VIEW);
                            Uri outputUri = null;
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                            if (Utils.hasNougat()) {
                                outputUri = ALFileProvider.getUriForFile(context, Utils.getMetaDataValue(context, MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", new File(message.getFilePaths().get(0)));
                            } else {
                                outputUri = Uri.fromFile(new File(message.getFilePaths().get(0)));
                            }
                            if (intent.resolveActivity(context.getPackageManager()) != null) {
                                intent.setDataAndType(outputUri, "text/x-vcard");
                                activityContext.startActivity(intent);
                            } else {
                                Toast.makeText(context, R.string.info_app_not_found_to_open_file, Toast.LENGTH_LONG).show();
                            }
                        }
                    });
                }
            }
        });
    } catch (Exception e) {
        Utils.printLog(context, "DetailedConvAdapter", "Exception in parsing");
    }
}
Also used : VCFContactData(com.applozic.mobicomkit.contact.VCFContactData) MobiComVCFParser(com.applozic.mobicomkit.contact.MobiComVCFParser) Intent(android.content.Intent) ALStoragePermission(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission) 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) Uri(android.net.Uri) File(java.io.File)

Aggregations

ALStoragePermission (com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission)5 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 Intent (android.content.Intent)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 AttachmentView (com.applozic.mobicomkit.api.attachment.AttachmentView)2 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)2 MobiComVCFParser (com.applozic.mobicomkit.contact.MobiComVCFParser)2 VCFContactData (com.applozic.mobicomkit.contact.VCFContactData)2 ApplozicDocumentView (com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicDocumentView)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 File (java.io.File)2 NotificationManager (android.app.NotificationManager)1 Configuration (android.content.res.Configuration)1 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 Uri (android.net.Uri)1 Spannable (android.text.Spannable)1 SpannableString (android.text.SpannableString)1