Search in sources :

Example 16 with Message

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

the class MobiComConversationFragment method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    int position = positionInSmsList;
    if (messageList.size() <= position) {
        return true;
    }
    Message message = messageList.get(position);
    if (message.isTempDateType() || message.isCustom()) {
        return true;
    }
    switch(item.getItemId()) {
        case 0:
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity().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(getContext().getString(R.string.copied_message), message.getMessage());
                clipboard.setPrimaryClip(clip);
            }
            break;
        case 1:
            conversationUIService.startContactActivityForResult(message, null);
            break;
        case 2:
            Message messageToResend = new Message(message);
            // messageToResend.setCreatedAtTime(new Date().getTime());
            messageToResend.setCreatedAtTime(System.currentTimeMillis() + MobiComUserPreference.getInstance(getActivity()).getDeviceTimeOffset());
            conversationService.sendMessage(messageToResend, messageIntentClass);
            break;
        case 3:
            String messageKeyString = message.getKeyString();
            new DeleteConversationAsyncTask(conversationService, message, contact).execute();
            deleteMessageFromDeviceList(messageKeyString);
            break;
        case 4:
            String messageJson = GsonUtils.getJsonFromObject(message, Message.class);
            conversationUIService.startMessageInfoFragment(messageJson);
            break;
        case 5:
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            if (message.getFilePaths() != null) {
                Uri shareUri = null;
                if (Utils.hasNougat()) {
                    shareUri = FileProvider.getUriForFile(getActivity(), Utils.getMetaDataValue(getActivity(), MobiComKitConstants.PACKAGE_NAME) + ".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, getString(R.string.send_message_to)));
            break;
        case 6:
            try {
                Configuration config = getActivity().getResources().getConfiguration();
                messageMetaData = new HashMap<>();
                String displayName;
                if (message.getGroupId() != null) {
                    if (MobiComUserPreference.getInstance(getActivity()).getUserId().equals(message.getContactIds()) || TextUtils.isEmpty(message.getContactIds())) {
                        displayName = getString(R.string.you_string);
                    } else {
                        displayName = appContactService.getContactById(message.getContactIds()).getDisplayName();
                    }
                } else {
                    if (message.isTypeOutbox()) {
                        displayName = 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(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(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.createAndSaveVideoThumbnail(message.getFilePaths().get(0)));
                                galleryImageView.setImageBitmap(fileClientService.createAndSaveVideoThumbnail(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(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(getString(R.string.contact_string));
                                messageTextView.append(" " + data.getName());
                            }
                        } catch (Exception e) {
                            imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_person_white);
                            messageTextView.setText(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(getString(R.string.attachment_string));
                        } else {
                            messageTextView.setText(message.getMessage());
                        }
                        galleryImageView.setVisibility(View.GONE);
                        imageViewRLayout.setVisibility(View.GONE);
                    }
                    imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(getActivity(), 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(getString(R.string.al_location_string));
                    imageViewForAttachmentType.setImageResource(R.drawable.applozic_ic_location_on_white_24dp);
                    imageViewForAttachmentType.setColorFilter(ContextCompat.getColor(getActivity(), R.color.apploizc_lite_gray_color));
                    messageImageLoader.setLoadingImage(R.drawable.applozic_map_offline_thumbnail);
                    messageImageLoader.loadImage(LocationUtils.loadStaticMap(message.getMessage()), 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)) {
                        messageDatabaseService.updateMessageReplyType(replyMessageKey, Message.ReplyMessage.REPLY_MESSAGE.getValue());
                    }
                }
                attachReplyCancelLayout.setVisibility(VISIBLE);
                replayRelativeLayout.setVisibility(VISIBLE);
            } catch (Exception e) {
            }
            break;
    }
    return true;
}
Also used : VCFContactData(com.applozic.mobicomkit.contact.VCFContactData) 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) Intent(android.content.Intent) Uri(android.net.Uri) Collections.disjoint(java.util.Collections.disjoint) Context(android.content.Context) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 17 with Message

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

the class MobiComQuickConversationFragment method addMessage.

public void addMessage(final Message message) {
    if (this.getActivity() == null) {
        return;
    }
    final Context context = getActivity();
    this.getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            message.processContactIds(context);
            Message recentMessage;
            if (message.getGroupId() != null) {
                recentMessage = latestMessageForEachContact.get(ConversationUIService.GROUP + message.getGroupId());
            } else {
                recentMessage = latestMessageForEachContact.get(message.getContactIds());
            }
            if (recentMessage != null && message.getCreatedAtTime() >= recentMessage.getCreatedAtTime()) {
                messageList.remove(recentMessage);
            } else if (recentMessage != null) {
                return;
            }
            if (message.getGroupId() != null) {
                latestMessageForEachContact.put(ConversationUIService.GROUP + message.getGroupId(), message);
            } else {
                latestMessageForEachContact.put(message.getContactIds(), message);
            }
            messageList.add(0, message);
            recyclerAdapter.notifyDataSetChanged();
            // listView.smoothScrollToPosition(messageList.size());
            // listView.setSelection(0);
            emptyTextView.setVisibility(View.GONE);
            emptyTextView.setText(!TextUtils.isEmpty(alCustomizationSettings.getNoConversationLabel()) ? alCustomizationSettings.getNoConversationLabel() : getResources().getString(R.string.no_conversation));
        // startQNewButton.setVisibility(View.GONE);
        }
    });
}
Also used : Context(android.content.Context) Message(com.applozic.mobicomkit.api.conversation.Message)

Example 18 with Message

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

the class MTNotificationBroadcastReceiver method onReceive.

@Override
public void onReceive(final Context context, Intent intent) {
    String action = intent.getAction();
    String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
    Utils.printLog(context, TAG, "Received broadcast, action: " + action + ", message: " + messageJson);
    if (!TextUtils.isEmpty(messageJson) && MobiComUserPreference.getInstance(context).isLoggedIn()) {
        final Message message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
        Intent notificationIntentService = new Intent(context, NotificationIntentService.class);
        notificationIntentService.setAction(NotificationIntentService.ACTION_AL_NOTIFICATION);
        notificationIntentService.putExtra(MobiComKitConstants.AL_MESSAGE, message);
        NotificationIntentService.enqueueWork(context, notificationIntentService, R.drawable.mobicom_ic_launcher, R.string.wearable_action_label, R.string.wearable_action_title, R.drawable.mobicom_ic_action_send);
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Intent(android.content.Intent)

Example 19 with Message

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

the class DetailedConversationAdapter method showFullView.

private void showFullView(Message smListItem) {
    try {
        final String mimeType = FileUtils.getMimeType(smListItem.getFilePaths().get(0));
        if (mimeType != null) {
            if (mimeType.startsWith("image")) {
                Intent intent = new Intent(context, FullScreenImageActivity.class);
                intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(smListItem, Message.class));
                ((MobiComKitActivityInterface) context).startActivityForResult(intent, MobiComKitActivityInterface.REQUEST_CODE_FULL_SCREEN_ACTION);
            }
            if (mimeType.startsWith("video")) {
                if (smListItem.isAttachmentDownloaded()) {
                    Intent intentVideo = new Intent();
                    intentVideo.setAction(Intent.ACTION_VIEW);
                    Uri outputUri;
                    if (Utils.hasNougat()) {
                        outputUri = FileProvider.getUriForFile(context, Utils.getMetaDataValue(context, MobiComKitConstants.PACKAGE_NAME) + ".provider", new File(smListItem.getFilePaths().get(0)));
                    } else {
                        outputUri = Uri.fromFile(new File(smListItem.getFilePaths().get(0)));
                    }
                    intentVideo.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    if (intentVideo.resolveActivity(context.getPackageManager()) != null) {
                        intentVideo.setDataAndType(outputUri, "video/*");
                        context.startActivity(intentVideo);
                    } else {
                        Toast.makeText(context, R.string.info_app_not_found_to_open_file, Toast.LENGTH_LONG).show();
                    }
                }
            }
        }
    } catch (Exception e) {
        Utils.printLog(context, TAG, "No application found to open this file");
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) MobiComKitActivityInterface(com.applozic.mobicomkit.uiwidgets.conversation.activity.MobiComKitActivityInterface) Intent(android.content.Intent) SpannableString(android.text.SpannableString) Uri(android.net.Uri) File(java.io.File)

Example 20 with Message

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

the class QuickConversationAdapter method getFilter.

@Override
public Filter getFilter() {
    return new Filter() {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            final FilterResults oReturn = new FilterResults();
            final List<Message> results = new ArrayList<Message>();
            if (originalList == null)
                originalList = messageList;
            if (constraint != null) {
                searchString = constraint.toString();
                if (originalList != null && originalList.size() > 0) {
                    for (final Message message : originalList) {
                        if (message.getMessage().toLowerCase().contains(constraint.toString())) {
                            results.add(message);
                        }
                    }
                }
                oReturn.values = results;
            } else {
                oReturn.values = originalList;
            }
            return oReturn;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            messageList = (ArrayList<Message>) results.values;
            notifyDataSetChanged();
        }
    };
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Filter(android.widget.Filter) ArrayList(java.util.ArrayList)

Aggregations

Message (com.applozic.mobicomkit.api.conversation.Message)55 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)13 Contact (com.applozic.mobicommons.people.contact.Contact)11 Cursor (android.database.Cursor)8 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)8 Uri (android.net.Uri)7 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)7 File (java.io.File)7 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 Context (android.content.Context)5 View (android.view.View)5 MessageDatabaseService (com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)5 Channel (com.applozic.mobicommons.people.channel.Channel)5 Configuration (android.content.res.Configuration)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Collections.disjoint (java.util.Collections.disjoint)4 Bitmap (android.graphics.Bitmap)3 RecyclerView (android.support.v7.widget.RecyclerView)3