Search in sources :

Example 21 with Message

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

the class QuickConversationAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (getItemViewType(position) == 2) {
        FooterViewHolder myHolder = (FooterViewHolder) holder;
        // myHolder.loadMoreProgressBar.setVisibility(View.GONE);
        myHolder.infoBroadCast.setVisibility(View.GONE);
    } else {
        Myholder myholder = (Myholder) holder;
        final Message message = getItem(position);
        myholder.smTime.setVisibility(View.GONE);
        if (message != null) {
            List<String> items = null;
            List<String> userIds = null;
            final Channel channel = ChannelDatabaseService.getInstance(context).getChannelByChannelKey(message.getGroupId());
            if (channel == null && message.getGroupId() == null) {
                items = Arrays.asList(message.getTo().split("\\s*,\\s*"));
                if (!TextUtils.isEmpty(message.getContactIds())) {
                    userIds = Arrays.asList(message.getContactIds().split("\\s*,\\s*"));
                }
            }
            final Contact contactReceiver = contactService.getContactReceiver(items, userIds);
            myholder.contactImage.setVisibility(View.GONE);
            myholder.alphabeticTextView.setVisibility(View.GONE);
            if (contactReceiver != null) {
                String contactInfo = contactReceiver.getDisplayName();
                if (items != null && items.size() > 1) {
                    Contact contact2 = contactService.getContactById(items.get(1));
                    contactInfo = TextUtils.isEmpty(contactReceiver.getFirstName()) ? contactReceiver.getContactNumber() : contactReceiver.getFirstName() + ", " + (TextUtils.isEmpty(contact2.getFirstName()) ? contact2.getContactNumber() : contact2.getFirstName()) + (items.size() > 2 ? " & others" : "");
                }
                myholder.smReceivers.setText(contactInfo);
                contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
                processContactImage(contactReceiver, myholder.onlineTextView, myholder.alphabeticTextView, myholder.contactImage);
            } else if (message.getGroupId() != null) {
                if (channel != null && Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
                    contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
                    Contact withUserContact = contactService.getContactById(ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey()));
                    if (withUserContact != null) {
                        myholder.smReceivers.setText(withUserContact.getDisplayName());
                        processContactImage(withUserContact, myholder.onlineTextView, myholder.alphabeticTextView, myholder.contactImage);
                    }
                } else {
                    channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
                    myholder.smReceivers.setText(ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId()));
                    myholder.alphabeticTextView.setVisibility(View.GONE);
                    myholder.contactImage.setImageResource(R.drawable.applozic_group_icon);
                    myholder.contactImage.setVisibility(View.VISIBLE);
                    if (channel != null && !TextUtils.isEmpty(channel.getImageUrl())) {
                        channelImageLoader.loadImage(channel, myholder.contactImage);
                    } else if (channel != null && channel.isBroadcastMessage()) {
                        myholder.contactImage.setImageResource(R.drawable.applozic_ic_applozic_broadcast);
                    } else {
                        channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
                    }
                }
            }
            myholder.onlineTextView.setVisibility(View.GONE);
            if (alCustomizationSettings.isOnlineStatusMasterList()) {
                myholder.onlineTextView.setVisibility(contactReceiver != null && contactReceiver.isOnline() ? View.VISIBLE : View.GONE);
            }
            if (myholder.attachedFile != null) {
                myholder.attachedFile.setText("");
                myholder.attachedFile.setVisibility(View.GONE);
            }
            if (myholder.attachmentIcon != null) {
                myholder.attachmentIcon.setVisibility(View.GONE);
            }
            if (message.isVideoCallMessage()) {
                createVideoCallView(message, myholder.attachmentIcon, myholder.messageTextView);
            } else if (message.hasAttachment() && myholder.attachmentIcon != null && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
                // Todo: handle it for fileKeyStrings when filePaths is empty
                String filePath = message.getFileMetas() == null && message.getFilePaths() != null ? message.getFilePaths().get(0).substring(message.getFilePaths().get(0).lastIndexOf("/") + 1) : message.getFileMetas() != null ? message.getFileMetas().getName() : "";
                myholder.attachmentIcon.setVisibility(View.VISIBLE);
                myholder.attachmentIcon.setImageResource(R.drawable.applozic_ic_action_attachment);
                myholder.messageTextView.setText(filePath);
            } else if (myholder.attachmentIcon != null && message.getContentType() == Message.ContentType.LOCATION.getValue()) {
                myholder.attachmentIcon.setVisibility(View.VISIBLE);
                myholder.attachmentIcon.setImageResource(R.drawable.mobicom_notification_location_icon);
                myholder.messageTextView.setText(context.getString(R.string.Location));
            } else if (message.getContentType() == Message.ContentType.PRICE.getValue()) {
                myholder.messageTextView.setText(EmoticonUtils.getSmiledText(context, ConversationUIService.FINAL_PRICE_TEXT + message.getMessage(), emojiconHandler));
            } else if (message.getContentType() == Message.ContentType.TEXT_HTML.getValue()) {
                myholder.messageTextView.setText(Html.fromHtml(message.getMessage()));
            } else {
                String messageSubString = (!TextUtils.isEmpty(message.getMessage()) ? message.getMessage().substring(0, Math.min(message.getMessage().length(), 50)) : "");
                myholder.messageTextView.setText(EmoticonUtils.getSmiledText(context, messageSubString, emojiconHandler));
            }
            if (myholder.sentOrReceived != null) {
                if (message.isCall()) {
                    myholder.sentOrReceived.setImageResource(R.drawable.applozic_ic_action_call_holo_light);
                    myholder.messageTextView.setTextColor(context.getResources().getColor(message.isIncomingCall() ? R.color.incoming_call : R.color.outgoing_call));
                } else if (getItemViewType(position) == 0) {
                    myholder.sentOrReceived.setImageResource(R.drawable.mobicom_social_forward);
                } else {
                    myholder.sentOrReceived.setImageResource(R.drawable.mobicom_social_reply);
                }
            }
            if (myholder.createdAtTime != null) {
                myholder.createdAtTime.setText(DateUtils.getFormattedDateAndTime(message.getCreatedAtTime()));
            }
            int messageUnReadCount = 0;
            if (message.getGroupId() == null && contactReceiver != null && !TextUtils.isEmpty(contactReceiver.getContactIds())) {
                messageUnReadCount = messageDatabaseService.getUnreadMessageCountForContact(contactReceiver.getContactIds());
            } else if (channel != null && channel.getKey() != null && channel.getKey() != 0) {
                messageUnReadCount = messageDatabaseService.getUnreadMessageCountForChannel(channel.getKey());
            }
            if (messageUnReadCount > 0) {
                myholder.unReadCountTextView.setVisibility(View.VISIBLE);
                myholder.unReadCountTextView.setText(String.valueOf(messageUnReadCount));
            } else {
                myholder.unReadCountTextView.setVisibility(View.GONE);
            }
            int startIndex = indexOfSearchQuery(message.getMessage());
            if (startIndex != -1) {
                final SpannableString highlightedName = new SpannableString(message.getMessage());
                // Sets the span to start at the starting point of the match and end at "length"
                // characters beyond the starting point
                highlightedName.setSpan(highlightTextSpan, startIndex, startIndex + searchString.toString().length(), 0);
                myholder.messageTextView.setText(highlightedName);
            }
        }
    }
}
Also used : SpannableString(android.text.SpannableString) Message(com.applozic.mobicomkit.api.conversation.Message) Channel(com.applozic.mobicommons.people.channel.Channel) SpannableString(android.text.SpannableString) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 22 with Message

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

the class MobiComAttachmentSelectorActivity method initViews.

/**
 * views initialisation.
 */
private void initViews() {
    sendAttachment = (Button) findViewById(R.id.mobicom_attachment_send_btn);
    cancelAttachment = (Button) findViewById(R.id.mobicom_attachment_cancel_btn);
    galleryImagesGridView = (GridView) findViewById(R.id.mobicom_attachment_grid_View);
    messageEditText = (EditText) findViewById(R.id.mobicom_attachment_edit_text);
    cancelAttachment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            setResult(RESULT_CANCELED, intent);
            finish();
        }
    });
    sendAttachment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (attachmentFileList.isEmpty()) {
                Toast.makeText(getApplicationContext(), R.string.mobicom_select_attachment_text, Toast.LENGTH_SHORT).show();
                return;
            }
            if (imageUri != null) {
                for (Uri uri : attachmentFileList) {
                    try {
                        String filePath = uri.getPath();
                        if (TextUtils.isEmpty(filePath)) {
                            Toast.makeText(MobiComAttachmentSelectorActivity.this, R.string.info_file_attachment_error, Toast.LENGTH_LONG).show();
                            return;
                        }
                        Message messageToSend = new Message();
                        if (groupID != 0) {
                            messageToSend.setGroupId(groupID);
                        } else {
                            messageToSend.setTo(userID);
                            messageToSend.setContactIds(userID);
                        }
                        messageToSend.setContentType(Message.ContentType.ATTACHMENT.getValue());
                        messageToSend.setRead(Boolean.TRUE);
                        messageToSend.setStoreOnDevice(Boolean.TRUE);
                        if (messageToSend.getCreatedAtTime() == null) {
                            messageToSend.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
                        }
                        messageToSend.setSendToDevice(Boolean.FALSE);
                        messageToSend.setType(Message.MessageType.MT_OUTBOX.getValue());
                        messageToSend.setMessage(messageEditText.getText().toString());
                        messageToSend.setDeviceKeyString(userPreferences.getDeviceKeyString());
                        messageToSend.setSource(Message.Source.MT_MOBILE_APP.getValue());
                        if (!TextUtils.isEmpty(filePath)) {
                            List<String> filePaths = new ArrayList<String>();
                            filePaths.add(filePath);
                            messageToSend.setFilePaths(filePaths);
                        }
                        Intent startConversationActivity = new Intent(MobiComAttachmentSelectorActivity.this, ConversationActivity.class);
                        if (groupID != 0) {
                            startConversationActivity.putExtra(ConversationUIService.GROUP_ID, groupID);
                            startConversationActivity.putExtra(ConversationUIService.GROUP_NAME, groupName);
                            startConversationActivity.putExtra(ConversationUIService.FORWARD_MESSAGE, GsonUtils.getJsonFromObject(messageToSend, messageToSend.getClass()));
                        } else {
                            startConversationActivity.putExtra(ConversationUIService.USER_ID, userID);
                            startConversationActivity.putExtra(ConversationUIService.DISPLAY_NAME, displayName);
                            startConversationActivity.putExtra(ConversationUIService.FORWARD_MESSAGE, GsonUtils.getJsonFromObject(messageToSend, messageToSend.getClass()));
                        }
                        startActivity(startConversationActivity);
                        finish();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else {
                Intent intent = new Intent();
                intent.putParcelableArrayListExtra(MULTISELECT_SELECTED_FILES, attachmentFileList);
                intent.putExtra(MULTISELECT_MESSAGE, messageEditText.getText().toString());
                setResult(RESULT_OK, intent);
                finish();
            }
        }
    });
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Intent(android.content.Intent) ArrayList(java.util.ArrayList) List(java.util.List) GridView(android.widget.GridView) View(android.view.View) Uri(android.net.Uri)

Example 23 with Message

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

the class MobiComKitBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    Message message = null;
    String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
    if (!TextUtils.isEmpty(messageJson)) {
        message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
    }
    Utils.printLog(context, TAG, "Received broadcast, action: " + action + ", message: " + message);
    if (message != null && !message.isSentToMany()) {
        conversationUIService.addMessage(message);
    } else if (message != null && message.isSentToMany() && BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString().equals(intent.getAction())) {
        for (String toField : message.getTo().split(",")) {
            Message singleMessage = new Message(message);
            singleMessage.setKeyString(message.getKeyString());
            singleMessage.setTo(toField);
            singleMessage.processContactIds(context);
            conversationUIService.addMessage(message);
        }
    }
    String keyString = intent.getStringExtra("keyString");
    String userId = message != null ? message.getContactIds() : "";
    if (BroadcastService.INTENT_ACTIONS.INSTRUCTION.toString().equals(action)) {
        InstructionUtil.showInstruction(context, intent.getIntExtra("resId", -1), intent.getBooleanExtra("actionable", false), R.color.instruction_color);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_CHANNEL_NAME.toString().equals(action)) {
        conversationUIService.updateChannelName();
    } else if (BroadcastService.INTENT_ACTIONS.FIRST_TIME_SYNC_COMPLETE.toString().equals(action)) {
        conversationUIService.downloadConversations(true);
    } else if (BroadcastService.INTENT_ACTIONS.LOAD_MORE.toString().equals(action)) {
        conversationUIService.setLoadMore(intent.getBooleanExtra("loadMore", true));
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString().equals(action)) {
        conversationUIService.updateMessageKeyString(message);
    } else if (BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString().equals(intent.getAction())) {
        conversationUIService.syncMessages(message, keyString);
    } else if (BroadcastService.INTENT_ACTIONS.DELETE_MESSAGE.toString().equals(intent.getAction())) {
        userId = intent.getStringExtra("contactNumbers");
        conversationUIService.deleteMessage(keyString, userId);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_DELIVERY.toString().equals(action) || BroadcastService.INTENT_ACTIONS.MESSAGE_READ_AND_DELIVERED.toString().equals(action)) {
        conversationUIService.updateDeliveryStatus(message, userId);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_DELIVERY_FOR_CONTACT.toString().equals(action)) {
        conversationUIService.updateDeliveryStatusForContact(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_READ_AND_DELIVERED_FOR_CONTECT.toString().equals(action)) {
        conversationUIService.updateReadStatusForContact(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString().equals(action)) {
        String contactNumber = intent.getStringExtra("contactNumber");
        Integer channelKey = intent.getIntExtra("channelKey", 0);
        String response = intent.getStringExtra("response");
        Contact contact = null;
        if (contactNumber != null) {
            contact = baseContactService.getContactById(contactNumber);
        }
        conversationUIService.deleteConversation(contact, channelKey, response);
    } else if (BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString().equals(action) && message != null) {
        conversationUIService.updateUploadFailedStatus(message);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_DONE.toString().equals(action) && message != null) {
        conversationUIService.updateDownloadStatus(message);
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_FAILD.toString().equals(action) && message != null) {
        conversationUIService.updateDownloadFailed(message);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_TYPING_STATUS.toString().equals(action)) {
        String currentUserId = intent.getStringExtra("userId");
        String isTyping = intent.getStringExtra("isTyping");
        conversationUIService.updateTypingStatus(currentUserId, isTyping);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_LAST_SEEN_AT_TIME.toString().equals(action)) {
        conversationUIService.updateLastSeenStatus(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.MQTT_DISCONNECTED.toString().equals(action)) {
        conversationUIService.reconnectMQTT();
    } else if (BroadcastService.INTENT_ACTIONS.CHANNEL_SYNC.toString().equals(action)) {
        conversationUIService.updateChannelSync();
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_TITLE_SUBTITLE.toString().equals(action)) {
        conversationUIService.updateTitleAndSubtitle();
    } else if (BroadcastService.INTENT_ACTIONS.CONVERSATION_READ.toString().equals(action)) {
        String currentId = intent.getStringExtra("currentId");
        boolean isGroup = intent.getBooleanExtra("isGroup", false);
        conversationUIService.updateConversationRead(currentId, isGroup);
    } else if (BroadcastService.INTENT_ACTIONS.UPDATE_USER_DETAIL.toString().equals(action)) {
        conversationUIService.updateUserInfo(intent.getStringExtra("contactId"));
    } else if (BroadcastService.INTENT_ACTIONS.MESSAGE_METADATA_UPDATE.toString().equals(action)) {
        conversationUIService.updateMessageMetadata(keyString);
    } else if (BroadcastService.INTENT_ACTIONS.MUTE_USER_CHAT.toString().equals(action)) {
        conversationUIService.muteUserChat(intent.getBooleanExtra("mute", false), intent.getStringExtra("userId"));
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 24 with Message

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

the class BroadcastService method sendMessageUpdateBroadcast.

public static void sendMessageUpdateBroadcast(Context context, String action, Message message) {
    Utils.printLog(context, TAG, "Sending message update broadcast for " + action + ", " + message.getKeyString());
    Intent intentUpdate = new Intent();
    intentUpdate.setAction(action);
    intentUpdate.addCategory(Intent.CATEGORY_DEFAULT);
    intentUpdate.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
    sendBroadcast(context, intentUpdate);
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Intent(android.content.Intent)

Example 25 with Message

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

the class NotificationBroadcastReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String actionName = intent.getAction();
    String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
    String activityToOpen = Utils.getMetaDataValueForReceiver(context, NotificationBroadcastReceiver.class.getName(), "activity.open.on.notification");
    Intent newIntent;
    if (actionName.equals(LAUNCH_APP)) {
        String messageText = getMessageText(intent) == null ? null : getMessageText(intent).toString();
        if (!TextUtils.isEmpty(messageText)) {
            Message message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
            Message replyMessage = new Message();
            replyMessage.setTo(message.getTo());
            replyMessage.setStoreOnDevice(Boolean.TRUE);
            replyMessage.setSendToDevice(Boolean.FALSE);
            replyMessage.setType(Message.MessageType.MT_OUTBOX.getValue());
            replyMessage.setMessage(messageText);
            replyMessage.setDeviceKeyString(MobiComUserPreference.getInstance(context).getDeviceKeyString());
            replyMessage.setSource(Message.Source.MT_MOBILE_APP.getValue());
            newIntent = new Intent(context, MessageIntentService.class);
            newIntent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(replyMessage, Message.class));
            MessageIntentService.enqueueWork(context, newIntent, null);
            return;
        }
        // TODO: get activity name in intent...
        Class activity = null;
        try {
            activity = Class.forName(activityToOpen);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        if (activity == null) {
        }
        newIntent = new Intent(context, activity);
        newIntent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, messageJson);
        newIntent.putExtra("sms_body", "text");
        newIntent.setType("vnd.android-dir/mms-sms");
        newIntent.setAction(NotificationBroadcastReceiver.LAUNCH_APP);
        newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(newIntent);
    }
}
Also used : MessageIntentService(com.applozic.mobicomkit.api.conversation.MessageIntentService) Message(com.applozic.mobicomkit.api.conversation.Message) Intent(android.content.Intent)

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