Search in sources :

Example 1 with FileMeta

use of com.applozic.mobicomkit.api.attachment.FileMeta in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method setFilePathifExist.

public void setFilePathifExist(Message message) {
    FileMeta fileMeta = message.getFileMetas();
    File file = FileClientService.getFilePath(FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName()), context.getApplicationContext(), fileMeta.getContentType());
    if (file.exists()) {
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add(file.getAbsolutePath());
        message.setFilePaths(arrayList);
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 2 with FileMeta

use of com.applozic.mobicomkit.api.attachment.FileMeta in project Applozic-Android-SDK by AppLozic.

the class MessageClientService method processMessage.

public void processMessage(Message message, Handler handler) throws Exception {
    boolean isBroadcast = (message.getMessageId() == null);
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    message.setSent(Boolean.TRUE);
    message.setSendToDevice(Boolean.FALSE);
    message.setSuUserKeyString(userPreferences.getSuUserKeyString());
    message.processContactIds(context);
    Contact contact = null;
    Channel channel = null;
    boolean isBroadcastOneByOneGroupType = false;
    boolean isOpenGroup = false;
    boolean skipMessage = false;
    if (message.getGroupId() == null) {
        contact = baseContactService.getContactById(message.getContactIds());
    } else {
        channel = ChannelService.getInstance(context).getChannel(message.getGroupId());
        isOpenGroup = Channel.GroupType.OPEN.getValue().equals(channel.getType());
        isBroadcastOneByOneGroupType = Channel.GroupType.BROADCAST_ONE_BY_ONE.getValue().equals(channel.getType());
    }
    long messageId = -1;
    List<String> fileKeys = new ArrayList<String>();
    String keyString = null;
    if (!isBroadcastOneByOneGroupType) {
        keyString = UUID.randomUUID().toString();
        message.setKeyString(keyString);
        message.setSentToServer(false);
    } else {
        message.setSentToServer(true);
    }
    if (Message.MetaDataType.HIDDEN.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue())) || Message.MetaDataType.PUSHNOTIFICATION.getValue().equals(message.getMetaDataValueForKey(Message.MetaDataType.KEY.getValue()))) {
        skipMessage = true;
    }
    if (!skipMessage && !isOpenGroup) {
        messageId = messageDatabaseService.createMessage(message);
    }
    if (isBroadcast && !skipMessage) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
    }
    if (!isBroadcastOneByOneGroupType && message.isUploadRequired() && !isOpenGroup) {
        for (String filePath : message.getFilePaths()) {
            try {
                String fileMetaResponse = new FileClientService(context).uploadBlobImage(filePath, handler);
                if (fileMetaResponse == null) {
                    if (skipMessage) {
                        return;
                    }
                    if (handler != null) {
                        android.os.Message msg = handler.obtainMessage();
                        msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                        msg.getData().putString("error", "Error while uploading");
                        msg.sendToTarget();
                    }
                    if (!message.isContactMessage()) {
                        messageDatabaseService.updateCanceledFlag(messageId, 1);
                    }
                    BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
                    return;
                }
                if (ApplozicClient.getInstance(context).isCustomStorageServiceEnabled()) {
                    if (!TextUtils.isEmpty(fileMetaResponse)) {
                        message.setFileMetas((FileMeta) GsonUtils.getObjectFromJson(fileMetaResponse, FileMeta.class));
                        if (handler != null) {
                            android.os.Message msg = handler.obtainMessage();
                            msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                            msg.getData().putString("error", null);
                            msg.sendToTarget();
                        }
                    }
                } else {
                    JsonParser jsonParser = new JsonParser();
                    JsonObject jsonObject = jsonParser.parse(fileMetaResponse).getAsJsonObject();
                    if (jsonObject.has(FILE_META)) {
                        Gson gson = new Gson();
                        message.setFileMetas(gson.fromJson(jsonObject.get(FILE_META), FileMeta.class));
                        if (handler != null) {
                            android.os.Message msg = handler.obtainMessage();
                            msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                            msg.getData().putString("error", null);
                            msg.sendToTarget();
                        }
                    }
                }
            } catch (Exception ex) {
                Utils.printLog(context, TAG, "Error uploading file to server: " + filePath);
                if (handler != null) {
                    android.os.Message msg = handler.obtainMessage();
                    msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                    msg.getData().putString("error", "Error uploading file to server: " + filePath);
                    msg.sendToTarget();
                }
                /*  recentMessageSentToServer.remove(message);*/
                if (!message.isContactMessage() && !skipMessage) {
                    messageDatabaseService.updateCanceledFlag(messageId, 1);
                }
                if (!skipMessage) {
                    BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
                }
                return;
            }
        }
        if (messageId != -1 && !skipMessage) {
            messageDatabaseService.updateMessageFileMetas(messageId, message);
        }
    }
    Message newMessage = new Message();
    newMessage.setTo(message.getTo());
    newMessage.setKeyString(message.getKeyString());
    newMessage.setMessage(message.getMessage());
    newMessage.setFileMetas(message.getFileMetas());
    newMessage.setCreatedAtTime(message.getCreatedAtTime());
    newMessage.setRead(Boolean.TRUE);
    newMessage.setDeviceKeyString(message.getDeviceKeyString());
    newMessage.setSuUserKeyString(message.getSuUserKeyString());
    newMessage.setSent(message.isSent());
    newMessage.setType(message.getType());
    newMessage.setTimeToLive(message.getTimeToLive());
    newMessage.setSource(message.getSource());
    newMessage.setScheduledAt(message.getScheduledAt());
    newMessage.setStoreOnDevice(message.isStoreOnDevice());
    newMessage.setDelivered(message.getDelivered());
    newMessage.setStatus(message.getStatus());
    newMessage.setMetadata(message.getMetadata());
    newMessage.setSendToDevice(message.isSendToDevice());
    newMessage.setContentType(message.getContentType());
    newMessage.setConversationId(message.getConversationId());
    if (message.getGroupId() != null) {
        newMessage.setGroupId(message.getGroupId());
    }
    if (!TextUtils.isEmpty(message.getClientGroupId())) {
        newMessage.setClientGroupId(message.getClientGroupId());
    }
    if (contact != null && !TextUtils.isEmpty(contact.getApplicationId())) {
        newMessage.setApplicationId(contact.getApplicationId());
    } else {
        newMessage.setApplicationId(getApplicationKey(context));
    }
    try {
        if (!isBroadcastOneByOneGroupType) {
            String response = sendMessage(newMessage);
            if (message.hasAttachment() && TextUtils.isEmpty(response) && !message.isContactMessage() && !skipMessage && !isOpenGroup) {
                messageDatabaseService.updateCanceledFlag(messageId, 1);
                if (handler != null) {
                    android.os.Message msg = handler.obtainMessage();
                    msg.what = MobiComConversationService.UPLOAD_COMPLETED;
                    msg.getData().putString("error", "Error uploading file to server");
                    msg.sendToTarget();
                }
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString(), message);
            }
            MessageResponse messageResponse = (MessageResponse) GsonUtils.getObjectFromJson(response, MessageResponse.class);
            keyString = messageResponse.getMessageKey();
            if (!TextUtils.isEmpty(keyString)) {
                message.setSentMessageTimeAtServer(Long.parseLong(messageResponse.getCreatedAtTime()));
                message.setConversationId(messageResponse.getConversationId());
                message.setSentToServer(true);
                message.setKeyString(keyString);
            }
            if (!skipMessage && !isOpenGroup) {
                messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
            }
        } else {
            message.setSentMessageTimeAtServer(message.getCreatedAtTime());
            messageDatabaseService.updateMessage(messageId, message.getSentMessageTimeAtServer(), keyString, message.isSentToServer());
        }
        if (message.isSentToServer()) {
            if (handler != null) {
                android.os.Message msg = handler.obtainMessage();
                msg.what = MobiComConversationService.MESSAGE_SENT;
                msg.getData().putString("message", message.getKeyString());
                msg.sendToTarget();
            }
        }
        if (!TextUtils.isEmpty(keyString)) {
        // Todo: Handle server message add failure due to internet disconnect.
        } else {
        // Todo: If message type is mtext, tell user that internet is not working, else send update with db id.
        }
        if (!skipMessage || isOpenGroup) {
            BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString(), message);
        }
    } catch (Exception e) {
        if (handler != null) {
            android.os.Message msg = handler.obtainMessage();
            msg.what = MobiComConversationService.UPLOAD_COMPLETED;
            msg.getData().putString("error", "Error uploading file");
            msg.sendToTarget();
        // handler.onCompleted(new ApplozicException("Error uploading file"));
        }
    }
/*  if (recentMessageSentToServer.size() > 20) {
            recentMessageSentToServer.subList(0, 10).clear();
        }*/
}
Also used : MessageResponse(com.applozic.mobicomkit.feed.MessageResponse) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ArrayList(java.util.ArrayList) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Contact(com.applozic.mobicommons.people.contact.Contact) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta) JsonParser(com.google.gson.JsonParser)

Example 3 with FileMeta

use of com.applozic.mobicomkit.api.attachment.FileMeta in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method onItemClick.

@Override
public boolean onItemClick(int position, MenuItem item) {
    if (messageList.size() <= position) {
        return true;
    }
    Message message = messageList.get(position);
    if (message.isTempDateType() || message.isCustom()) {
        return true;
    }
    switch(item.getItemId()) {
        case 0:
            if (android.os.Build.VERSION.SDK_INT < android.os.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) Context(android.content.Context) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 4 with FileMeta

use of com.applozic.mobicomkit.api.attachment.FileMeta 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 5 with FileMeta

use of com.applozic.mobicomkit.api.attachment.FileMeta in project Applozic-Android-SDK by AppLozic.

the class MessageInfoFragment method setupAttachmentView.

private void setupAttachmentView(Message message, RelativeLayout defaultRelativeLayout) {
    FileMeta fileMeta = message.getFileMetas();
    ImageView attachmentInconView = (ImageView) defaultRelativeLayout.findViewById(R.id.applozic_message_info_attachment_icon);
    TextView attachmentFilename = (TextView) defaultRelativeLayout.findViewById(R.id.applozic_message_info_attachment_filename);
    TextView messageText = (TextView) defaultRelativeLayout.findViewById(R.id.messageText);
    if (TextUtils.isEmpty(message.getMessage())) {
        messageText.setVisibility(View.GONE);
    }
    if (message.getMessage() != null) {
        messageText.setText(message.getMessage());
    }
    if (fileMeta.getContentType().contains("image")) {
        attachmentView.setVisibility(View.VISIBLE);
        attachmentInconView.setVisibility(View.GONE);
        attachmentFilename.setVisibility(View.GONE);
    } else {
        attachmentView.setVisibility(View.GONE);
        attachmentInconView.setVisibility(View.VISIBLE);
        attachmentFilename.setVisibility(View.VISIBLE);
        attachmentFilename.setText(fileMeta.getName());
    }
}
Also used : TextView(android.widget.TextView) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Aggregations

FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)12 Message (com.applozic.mobicomkit.api.conversation.Message)7 File (java.io.File)6 Intent (android.content.Intent)5 Contact (com.applozic.mobicommons.people.contact.Contact)5 Configuration (android.content.res.Configuration)3 Uri (android.net.Uri)3 MobiComVCFParser (com.applozic.mobicomkit.contact.MobiComVCFParser)3 VCFContactData (com.applozic.mobicomkit.contact.VCFContactData)3 Channel (com.applozic.mobicommons.people.channel.Channel)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2 ContentValues (android.content.ContentValues)2 Context (android.content.Context)2 Bitmap (android.graphics.Bitmap)2 NotificationCompat (android.support.v4.app.NotificationCompat)2 ViewConfiguration (android.view.ViewConfiguration)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MobiComKitClientService (com.applozic.mobicomkit.api.MobiComKitClientService)2