Search in sources :

Example 51 with Message

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

the class MobiComConversationFragment method updateMessageList.

public synchronized boolean updateMessageList(Message message, boolean update) {
    boolean toAdd = !messageList.contains(message);
    loadMore = true;
    if (update) {
        messageList.remove(message);
        messageList.add(message);
    } else if (toAdd) {
        Message firstDateMessage = new Message();
        firstDateMessage.setTempDateType(Short.valueOf("100"));
        firstDateMessage.setCreatedAtTime(message.getCreatedAtTime());
        if (!messageList.contains(firstDateMessage)) {
            messageList.add(firstDateMessage);
        }
        messageList.add(message);
    }
    return toAdd;
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message)

Example 52 with Message

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

the class MobiComConversationFragment method updateMessageMetadata.

public void updateMessageMetadata(String keyString) {
    int i = -1;
    if (!messageList.isEmpty()) {
        for (Message message : messageList) {
            if (keyString.equals(message.getKeyString())) {
                i = messageList.indexOf(message);
            }
        }
    }
    if (i != -1) {
        messageList.get(i).setMetadata(messageDatabaseService.getMessage(keyString).getMetadata());
        conversationAdapter.notifyDataSetChanged();
        if (messageList.get(messageList.size() - 1).getMetadata().containsKey("isDoneWithClicking")) {
            templateAdapter.setMessageList(new HashMap<String, String>());
            templateAdapter.notifyDataSetChanged();
        }
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Collections.disjoint(java.util.Collections.disjoint)

Example 53 with Message

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

the class MobiComConversationFragment method sendBroadcastMessage.

public void sendBroadcastMessage(String message, String path) {
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
    if (channelUserMapperList != null && channelUserMapperList.size() > 0) {
        for (ChannelUserMapper channelUserMapper : channelUserMapperList) {
            if (!userPreferences.getUserId().equals(channelUserMapper.getUserKey())) {
                Message messageToSend = new Message();
                messageToSend.setTo(channelUserMapper.getUserKey());
                messageToSend.setContactIds(channelUserMapper.getUserKey());
                messageToSend.setRead(Boolean.TRUE);
                messageToSend.setStoreOnDevice(Boolean.TRUE);
                if (messageToSend.getCreatedAtTime() == null) {
                    messageToSend.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
                }
                if (currentConversationId != null && currentConversationId != 0) {
                    messageToSend.setConversationId(currentConversationId);
                }
                messageToSend.setSendToDevice(Boolean.FALSE);
                messageToSend.setType(sendType.getSelectedItemId() == 1 ? Message.MessageType.MT_OUTBOX.getValue() : Message.MessageType.OUTBOX.getValue());
                messageToSend.setTimeToLive(getTimeToLive());
                messageToSend.setMessage(message);
                messageToSend.setDeviceKeyString(userPreferences.getDeviceKeyString());
                messageToSend.setScheduledAt(scheduledTimeHolder.getTimestamp());
                messageToSend.setSource(Message.Source.MT_MOBILE_APP.getValue());
                if (!TextUtils.isEmpty(path)) {
                    List<String> filePaths = new ArrayList<String>();
                    filePaths.add(path);
                    messageToSend.setFilePaths(filePaths);
                }
                conversationService.sendMessage(messageToSend, MessageIntentService.class);
                if (selfDestructMessageSpinner != null) {
                    selfDestructMessageSpinner.setSelection(0);
                }
                attachmentLayout.setVisibility(View.GONE);
            }
        }
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) ArrayList(java.util.ArrayList) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper)

Example 54 with Message

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

the class MobiComConversationFragment method deleteMessageFromDeviceList.

public void deleteMessageFromDeviceList(String messageKeyString) {
    try {
        int position;
        boolean updateQuickConversation = false;
        int index;
        for (Message message : messageList) {
            boolean value = message.getKeyString() != null ? message.getKeyString().equals(messageKeyString) : false;
            if (value) {
                index = messageList.indexOf(message);
                if (index != -1) {
                    int aboveIndex = index - 1;
                    int belowIndex = index + 1;
                    Message aboveMessage = messageList.get(aboveIndex);
                    if (belowIndex != messageList.size()) {
                        Message belowMessage = messageList.get(belowIndex);
                        if (aboveMessage.isTempDateType() && belowMessage.isTempDateType()) {
                            messageList.remove(aboveMessage);
                        }
                    } else if (belowIndex == messageList.size() && aboveMessage.isTempDateType()) {
                        messageList.remove(aboveMessage);
                    }
                }
            }
            if (message.getKeyString() != null && message.getKeyString().equals(messageKeyString)) {
                position = messageList.indexOf(message);
                if (position == messageList.size() - 1) {
                    updateQuickConversation = true;
                }
                if (message.getScheduledAt() != null && message.getScheduledAt() != 0) {
                    messageDatabaseService.deleteScheduledMessage(messageKeyString);
                }
                messageList.remove(position);
                recyclerDetailConversationAdapter.notifyDataSetChanged();
                if (messageList.isEmpty()) {
                    emptyTextView.setVisibility(VISIBLE);
                    ((MobiComKitActivityInterface) getActivity()).removeConversation(message, channel != null ? String.valueOf(channel.getKey()) : contact.getFormattedContactNumber());
                }
                break;
            }
        }
        int messageListSize = messageList.size();
        if (messageListSize > 0 && updateQuickConversation) {
            ((MobiComKitActivityInterface) getActivity()).updateLatestMessage(messageList.get(messageListSize - 1), channel != null ? String.valueOf(channel.getKey()) : contact.getFormattedContactNumber());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) MobiComKitActivityInterface(com.applozic.mobicomkit.uiwidgets.conversation.activity.MobiComKitActivityInterface) Collections.disjoint(java.util.Collections.disjoint)

Example 55 with Message

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

the class MobiComConversationFragment method sendProductMessage.

public void sendProductMessage(final String messageToSend, final FileMeta fileMeta, final Contact contact, final short messageContentType) {
    final Message message = new Message();
    new Thread(new Runnable() {

        @Override
        public void run() {
            String topicId;
            MobiComConversationService conversationService = new MobiComConversationService(getActivity());
            MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
            topicId = new MessageClientService(getActivity()).getTopicId(currentConversationId);
            if (getChannel() != null) {
                message.setGroupId(channelKey);
            } else {
                message.setContactIds(contact.getUserId());
                message.setTo(contact.getUserId());
            }
            message.setMessage(messageToSend);
            message.setRead(Boolean.TRUE);
            message.setStoreOnDevice(Boolean.TRUE);
            message.setSendToDevice(Boolean.FALSE);
            message.setContentType(messageContentType);
            message.setType(Message.MessageType.MT_OUTBOX.getValue());
            message.setDeviceKeyString(userPreferences.getDeviceKeyString());
            message.setSource(Message.Source.MT_MOBILE_APP.getValue());
            message.setTopicId(messageToSend);
            message.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
            message.setTopicId(topicId);
            message.setConversationId(currentConversationId);
            message.setFileMetas(fileMeta);
            conversationService.sendMessage(message, MessageIntentService.class);
        }
    }).start();
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) MessageClientService(com.applozic.mobicomkit.api.conversation.MessageClientService) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService)

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