Search in sources :

Example 1 with AlMessageReportTask

use of com.applozic.mobicomkit.api.conversation.AlMessageReportTask in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method onItemClick.

@Override
public boolean onItemClick(int position, MenuItem item) {
    if (messageList.size() <= position || position == -1) {
        return true;
    }
    final Message message = messageList.get(position);
    if (message.isTempDateType() || message.isCustom()) {
        return true;
    }
    switch(item.getItemId()) {
        case 0:
            if (getActivity() == null) {
                break;
            }
            if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) ApplozicService.getContext(getContext()).getSystemService(Context.CLIPBOARD_SERVICE);
                clipboard.setText(message.getMessage());
            } else {
                android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                android.content.ClipData clip = android.content.ClipData.newPlainText(ApplozicService.getContext(getContext()).getString(R.string.copied_message), message.getMessage());
                clipboard.setPrimaryClip(clip);
            }
            break;
        case 1:
            conversationUIService.startContactActivityForResult(message, null);
            break;
        case 2:
            messageDatabaseService.deleteMessageFromDb(message);
            deleteMessageFromDeviceList(message.getKeyString());
            Message messageToResend = new Message(message);
            messageToResend.setCreatedAtTime(System.currentTimeMillis() + MobiComUserPreference.getInstance(getActivity()).getDeviceTimeOffset());
            conversationService.sendMessage(messageToResend, userDisplayName);
            break;
        case 3:
            String messageKeyString = message.getKeyString();
            AlTask.execute(new DeleteConversationAsyncTask(conversationService, message, contact));
            deleteMessageFromDeviceList(messageKeyString);
            break;
        case 4:
            final String deleteForAllMessageKey = message.getKeyString();
            final ProgressDialog progressBar = new ProgressDialog(getContext());
            progressBar.show();
            progressBar.setMessage(Utils.getString(getContext(), R.string.delete_thread_text));
            AlTask.execute(new MessageDeleteTask(getContext(), deleteForAllMessageKey, true, new AlCallback() {

                @Override
                public void onSuccess(Object response) {
                    int index = messageList.indexOf(message);
                    message.setAsDeletedForAll();
                    messageDatabaseService.replaceExistingMessage(message);
                    updateMessageAtIndex(index, message, recyclerDetailConversationAdapter);
                    if (progressBar != null) {
                        progressBar.dismiss();
                    }
                }

                @Override
                public void onError(Object error) {
                    if (progressBar != null) {
                        progressBar.dismiss();
                    }
                    Toast.makeText(ApplozicService.getContext(getContext()), Utils.getString(getContext(), R.string.delete_conversation_failed), Toast.LENGTH_SHORT).show();
                }
            }));
            break;
        case 5:
            String messageJson = GsonUtils.getJsonFromObject(message, Message.class);
            conversationUIService.startMessageInfoFragment(messageJson);
            break;
        case 6:
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            if (message.getFilePaths() != null) {
                Uri shareUri = null;
                if (Utils.hasNougat()) {
                    shareUri = ALFileProvider.getUriForFile(ApplozicService.getContext(getContext()), Utils.getMetaDataValue(getActivity(), MobiComKitConstants.PACKAGE_NAME) + ".applozic.provider", new File(message.getFilePaths().get(0)));
                } else {
                    shareUri = Uri.fromFile(new File(message.getFilePaths().get(0)));
                }
                shareIntent.setDataAndType(shareUri, "text/x-vcard");
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                shareIntent.putExtra(Intent.EXTRA_STREAM, shareUri);
                if (!TextUtils.isEmpty(message.getMessage())) {
                    shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
                }
                shareIntent.setType(FileUtils.getMimeType(new File(message.getFilePaths().get(0))));
            } else {
                shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMessage());
                shareIntent.setType("text/plain");
            }
            startActivity(Intent.createChooser(shareIntent, ApplozicService.getContext(getContext()).getString(R.string.send_message_to)));
            break;
        case 7:
            try {
                Configuration config = ApplozicService.getContext(getContext()).getResources().getConfiguration();
                messageMetaData = new HashMap<>();
                String displayName;
                if (message.getGroupId() != null) {
                    if (loggedInUserId.equals(message.getContactIds()) || TextUtils.isEmpty(message.getContactIds())) {
                        displayName = ApplozicService.getContext(getContext()).getString(R.string.you_string);
                    } else {
                        displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
                    }
                } else {
                    if (message.isTypeOutbox()) {
                        displayName = ApplozicService.getContext(getContext()).getString(R.string.you_string);
                    } else {
                        displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
                    }
                }
                nameTextView.setText(displayName);
                if (message.hasAttachment()) {
                    FileMeta fileMeta = message.getFileMetas();
                    imageViewForAttachmentType.setVisibility(VISIBLE);
                    if (fileMeta.getContentType().contains("image")) {
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_image_camera_alt);
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.photo_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        galleryImageView.setVisibility(VISIBLE);
                        imageViewRLayout.setVisibility(VISIBLE);
                        imageThumbnailLoader.loadImage(message, galleryImageView);
                    } else if (fileMeta.getContentType().contains("video")) {
                        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) {
                                imageViewForAttachmentType.setScaleX(-1);
                            }
                        }
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.video_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        if (message.getFilePaths() != null && message.getFilePaths().size() > 0) {
                            if (imageCache.getBitmapFromMemCache(message.getKeyString()) != null) {
                                galleryImageView.setImageBitmap(imageCache.getBitmapFromMemCache(message.getKeyString()));
                            } else {
                                imageCache.addBitmapToCache(message.getKeyString(), fileClientService.getOrCreateVideoThumbnail(message.getFilePaths().get(0)));
                                galleryImageView.setImageBitmap(fileClientService.getOrCreateVideoThumbnail(message.getFilePaths().get(0)));
                            }
                        }
                        galleryImageView.setVisibility(VISIBLE);
                        imageViewRLayout.setVisibility(VISIBLE);
                    } else if (fileMeta.getContentType().contains("audio")) {
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_music_note);
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.audio_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        galleryImageView.setVisibility(View.GONE);
                        imageViewRLayout.setVisibility(View.GONE);
                    } else if (message.isContactMessage()) {
                        MobiComVCFParser parser = new MobiComVCFParser();
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
                        try {
                            VCFContactData data = parser.parseCVFContactData(message.getFilePaths().get(0));
                            if (data != null) {
                                messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.contact_string));
                                messageTextView.append(" " + data.getName());
                            }
                        } catch (Exception e) {
                            imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.contact_string));
                        }
                        galleryImageView.setVisibility(View.GONE);
                        imageViewRLayout.setVisibility(View.GONE);
                    } else {
                        imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_action_attachment);
                        if (TextUtils.isEmpty(message.getMessage())) {
                            messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.attachment_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        galleryImageView.setVisibility(View.GONE);
                        imageViewRLayout.setVisibility(View.GONE);
                    }
                    imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(ApplozicService.getContext(getContext()), R.color.apploizc_lite_gray_color));
                } else if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
                    imageViewForAttachmentType.setVisibility(VISIBLE);
                    galleryImageView.setVisibility(VISIBLE);
                    imageViewRLayout.setVisibility(VISIBLE);
                    messageTextView.setText(ApplozicService.getContext(getContext()).getString(R.string.al_location_string));
                    imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_location_on_white_24dp);
                    imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(ApplozicService.getContext(getContext()), R.color.apploizc_lite_gray_color));
                    messageImageLoader.setLoadingImage(R.drawable.applozic_map_offline_thumbnail);
                    messageImageLoader.loadImage(LocationUtils.loadStaticMap(message.getMessage(), geoApiKey), galleryImageView);
                } else {
                    imageViewForAttachmentType.setVisibility(View.GONE);
                    imageViewRLayout.setVisibility(View.GONE);
                    galleryImageView.setVisibility(View.GONE);
                    messageTextView.setText(message.getMessage());
                }
                messageMetaData.put(Message.MetaDataType.AL_REPLY.getValue(), message.getKeyString());
                if (messageMetaData != null && !messageMetaData.isEmpty()) {
                    String replyMessageKey = messageMetaData.get(Message.MetaDataType.AL_REPLY.getValue());
                    if (!TextUtils.isEmpty(replyMessageKey) && (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())))) {
                        messageDatabaseService.updateMessageReplyType(replyMessageKey, Message.ReplyMessage.REPLY_MESSAGE.getValue());
                    }
                }
                attachReplyCancelLayout.setVisibility(VISIBLE);
                replayRelativeLayout.setVisibility(VISIBLE);
            } catch (Exception e) {
            }
            break;
        case 8:
            AlTask.execute(new AlMessageReportTask(message.getKeyString(), conversationService, new AlCallback() {

                @Override
                public void onSuccess(Object response) {
                    Toast.makeText(getContext(), ApplozicService.getContext(getContext()).getString(R.string.message_reported_successfully), Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onError(Object error) {
                    Toast.makeText(getContext(), ApplozicService.getContext(getContext()).getString(R.string.failed_to_report_message), Toast.LENGTH_SHORT).show();
                }
            }));
            break;
    }
    return true;
}
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) ViewConfiguration(android.view.ViewConfiguration) MobiComVCFParser(com.applozic.mobicomkit.contact.MobiComVCFParser) DeleteConversationAsyncTask(com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) Context(android.content.Context) AlMessageReportTask(com.applozic.mobicomkit.api.conversation.AlMessageReportTask) Intent(android.content.Intent) AlCallback(com.applozic.mobicomkit.listners.AlCallback) Collections.disjoint(java.util.Collections.disjoint) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException) MessageDeleteTask(com.applozic.mobicomkit.api.conversation.MessageDeleteTask) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Aggregations

ProgressDialog (android.app.ProgressDialog)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Configuration (android.content.res.Configuration)1 Uri (android.net.Uri)1 ViewConfiguration (android.view.ViewConfiguration)1 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)1 AlMessageReportTask (com.applozic.mobicomkit.api.conversation.AlMessageReportTask)1 Message (com.applozic.mobicomkit.api.conversation.Message)1 MessageDeleteTask (com.applozic.mobicomkit.api.conversation.MessageDeleteTask)1 MobiComVCFParser (com.applozic.mobicomkit.contact.MobiComVCFParser)1 VCFContactData (com.applozic.mobicomkit.contact.VCFContactData)1 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)1 AlCallback (com.applozic.mobicomkit.listners.AlCallback)1 DeleteConversationAsyncTask (com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask)1 AlRichMessage (com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage)1 File (java.io.File)1 Collections.disjoint (java.util.Collections.disjoint)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1