Search in sources :

Example 6 with FileClientService

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

the class NotificationService method notifyUser.

// Cleanup: rename to a public api name eg: createApplozicNotification()
public void notifyUser(Contact contact, Channel channel, Message message, int index) {
    if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
        Utils.printLog(context, TAG, "Notification is disabled !!");
        return;
    }
    Bitmap notificationIconBitmap = null;
    unReadMessageList = messageDatabaseService.getUnreadMessages();
    int count = appContactService.getChatConversationCount() + appContactService.getGroupConversationCount();
    int totalCount = messageDatabaseService.getTotalUnreadCount();
    Class activity = null;
    try {
        activity = Class.forName(activityToOpen);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (message.getGroupId() != null) {
        if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
            String userId = ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey());
            if (!TextUtils.isEmpty(userId)) {
                Contact newContact = appContactService.getContactById(userId);
                notificationIconBitmap = appContactService.downloadContactImage(context, newContact);
            }
        } else if (Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
            String userId = message.getTo();
            if (!TextUtils.isEmpty(userId)) {
                Contact newContact = appContactService.getContactById(userId);
                notificationIconBitmap = appContactService.downloadContactImage(context, newContact);
            }
        } else {
            notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
        }
    } else {
        notificationIconBitmap = appContactService.downloadContactImage(context, contact);
    }
    Integer smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
    int colorResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_COLOR_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_COLOR_METADATA) : -1;
    Intent intent;
    intent = new Intent(context, activity);
    if (count < 2) {
        intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
    } else {
        intent.putExtra(MobiComKitConstants.QUICK_LIST, true);
    }
    if (applozicClient.isChatListOnNotificationIsHidden()) {
        intent.putExtra("takeOrder", true);
    }
    if (applozicClient.isContextBasedChat()) {
        intent.putExtra("contextBasedChat", true);
    }
    intent.putExtra("sms_body", "text");
    intent.setType("vnd.android-dir/mms-sms");
    PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) (System.currentTimeMillis() & 0xfffffff), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, notificationChannels.getDefaultChannelId(muteNotifications(index))).setSmallIcon(smallIconResourceId).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(muteNotifications(index) ? NotificationCompat.PRIORITY_LOW : NotificationCompat.PRIORITY_HIGH).setWhen(System.currentTimeMillis());
    if (colorResourceId > 0) {
        mBuilder.setColor(context.getResources().getColor(colorResourceId));
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        mBuilder.setGroup(GROUP_KEY);
        mBuilder.setGroupSummary(true);
    } else {
        if (totalCount != 0) {
            mBuilder.setNumber(totalCount);
        }
    }
    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setAutoCancel(true);
    if (ApplozicClient.getInstance(context).getVibrationOnNotification() && !muteNotifications(index)) {
        mBuilder.setVibrate(pattern);
    }
    if (!muteNotifications(index)) {
        mBuilder.setSound(TextUtils.isEmpty(notificationFilePath) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(notificationFilePath));
    }
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    // Sets a title for the Inbox in expanded layout
    inboxStyle.setBigContentTitle(getNotificationTitle(count, contact, channel, message));
    // Moves events into the expanded layout
    try {
        if (unReadMessageList != null) {
            for (Message messageString : unReadMessageList) {
                if (messageString.getGroupId() != null) {
                    Channel unreadChannel = ChannelService.getInstance(context).getChannelByChannelKey(messageString.getGroupId());
                    if (unreadChannel != null && unreadChannel.getUnreadCount() == 0) {
                        continue;
                    }
                } else {
                    Contact unreadCount = appContactService.getContactById(messageString.getContactIds());
                    if (unreadCount != null && unreadCount.getUnreadCount() == 0) {
                        continue;
                    }
                }
                inboxStyle.addLine(getSpannedText(getMessageBody(messageString, count, channel, contact)));
            }
        }
    // Moves the expanded layout object into the notification object.
    } catch (Exception e) {
        e.printStackTrace();
    }
    String summaryText = "";
    if (count < 1) {
        summaryText = "";
        mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
        mBuilder.setContentText(getSpannedText(getMessageBody(message, count, channel, contact)));
    } else if (count >= 1 && count < 2) {
        summaryText = totalCount < 2 ? totalCount + " new message " : totalCount + " new messages ";
        mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
        mBuilder.setContentText(summaryText);
    } else {
        summaryText = totalCount + " messages from " + count + " chats";
        mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), iconResourceId));
        mBuilder.setContentText(summaryText);
    }
    inboxStyle.setSummaryText(summaryText);
    mBuilder.setContentTitle(getNotificationTitle(count, contact, channel, message));
    mBuilder.setStyle(inboxStyle);
    if (message.hasAttachment()) {
        try {
            InputStream in;
            FileMeta fileMeta = message.getFileMetas();
            HttpURLConnection httpConn = null;
            if (fileMeta.getThumbnailBlobKey() != null) {
                Bitmap bitmap = new FileClientService(context).downloadAndSaveThumbnailImage(context, message, 200, 200);
                mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
            }
        } catch (Throwable ex) {
            ex.printStackTrace();
        }
    }
    WearableNotificationWithVoice notificationWithVoice = new WearableNotificationWithVoice(mBuilder, wearable_action_title, wearable_action_label, wearable_send_icon, NOTIFICATION_ID);
    notificationWithVoice.setCurrentContext(context);
    notificationWithVoice.setPendingIntent(pendingIntent);
    try {
        if (unReadMessageList != null && unReadMessageList.size() > 0) {
            notificationWithVoice.sendNotification();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) InputStream(java.io.InputStream) Channel(com.applozic.mobicommons.people.channel.Channel) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Contact(com.applozic.mobicommons.people.contact.Contact) Bitmap(android.graphics.Bitmap) HttpURLConnection(java.net.HttpURLConnection) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta)

Example 7 with FileClientService

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

the class MessageClientService method processMessage.

// Cleanup: private
public void processMessage(Message message, Handler handler, String userDisplayName) 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()) && !message.hasAttachment());
        isBroadcastOneByOneGroupType = Channel.GroupType.BROADCAST_ONE_BY_ONE.getValue().equals(channel.getType());
    }
    long messageId = -1;
    List<String> fileKeys = new ArrayList<String>();
    String keyString = null;
    String oldMessageKey = null;
    if (!isBroadcastOneByOneGroupType) {
        keyString = UUID.randomUUID().toString();
        oldMessageKey = keyString;
        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()) {
        for (String filePath : message.getFilePaths()) {
            FileMeta thumbnailFileMeta = null;
            String mimeType = FileUtils.getMimeType(filePath);
            if (mimeType != null && mimeType.startsWith("video")) {
                thumbnailFileMeta = uploadVideoThumbnail(filePath, message.getCreatedAtTime(), oldMessageKey);
            }
            try {
                String fileMetaResponse = new FileClientService(context).uploadBlobImage(filePath, handler, oldMessageKey);
                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.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
                        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).isS3StorageServiceEnabled()) {
                    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(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
                            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(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
                            msg.getData().putString("error", null);
                            msg.sendToTarget();
                        }
                    }
                }
                // update message file-meta with thumbnail data
                if (thumbnailFileMeta != null) {
                    FileMeta messageFileMeta = message.getFileMetas();
                    if (!TextUtils.isEmpty(thumbnailFileMeta.getBlobKeyString())) {
                        messageFileMeta.setThumbnailBlobKey(thumbnailFileMeta.getBlobKeyString());
                    }
                    if (!TextUtils.isEmpty(thumbnailFileMeta.getThumbnailUrl())) {
                        messageFileMeta.setThumbnailUrl(thumbnailFileMeta.getThumbnailUrl());
                    }
                    message.setFileMetas(messageFileMeta);
                }
            } 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(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
                    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.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
                    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 (contact != null && !TextUtils.isEmpty(userDisplayName) && contact.isUserDisplayUpdateRequired()) {
                    UserService.getInstance(context).updateUserDisplayName(message.getTo(), userDisplayName);
                }
            }
            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(MobiComKitConstants.MESSAGE_INTENT_EXTRA, message.getKeyString());
                String messageJson = GsonUtils.getJsonFromObject(message, Message.class);
                msg.getData().putString(MobiComKitConstants.MESSAGE_JSON_INTENT_EXTRA, messageJson);
                msg.getData().putString(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
                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(MobiComKitConstants.OLD_MESSAGE_KEY_INTENT_EXTRA, oldMessageKey);
            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) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Contact(com.applozic.mobicommons.people.contact.Contact) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta) JsonParser(com.google.gson.JsonParser)

Example 8 with FileClientService

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

the class MessageClientService method uploadVideoThumbnail.

// Cleanup: private
public FileMeta uploadVideoThumbnail(String filePath, Long createdAtTimeForSuffix, String oldMessageKey) {
    FileMeta thumbnailFileMeta = null;
    try {
        FileClientService fileClientService = new FileClientService(context);
        fileClientService.getOrCreateVideoThumbnail(filePath);
        String videoThumbnailPath = fileClientService.getThumbnailPath(filePath);
        if (!TextUtils.isEmpty(videoThumbnailPath) && new File(videoThumbnailPath).exists()) {
            String fileMetaResponseVideoThumbnail = fileClientService.uploadBlobImage(videoThumbnailPath, null, oldMessageKey);
            if (ApplozicClient.getInstance(context).isS3StorageServiceEnabled()) {
                if (!TextUtils.isEmpty(fileMetaResponseVideoThumbnail)) {
                    thumbnailFileMeta = (FileMeta) GsonUtils.getObjectFromJson(fileMetaResponseVideoThumbnail, FileMeta.class);
                }
            } else {
                JsonParser jsonParser = new JsonParser();
                JsonObject jsonObject = jsonParser.parse(fileMetaResponseVideoThumbnail).getAsJsonObject();
                if (jsonObject.has(FILE_META)) {
                    Gson gson = new Gson();
                    thumbnailFileMeta = gson.fromJson(jsonObject.get(FILE_META), FileMeta.class);
                }
            }
        }
    } catch (Exception exception) {
        exception.printStackTrace();
        return null;
    }
    return thumbnailFileMeta;
}
Also used : FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) File(java.io.File) FileMeta(com.applozic.mobicomkit.api.attachment.FileMeta) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonParser(com.google.gson.JsonParser)

Example 9 with FileClientService

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

the class MobiComConversationFragment method updateDownloadStatus.

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

        @Override
        public void run() {
            try {
                int index = messageList.indexOf(message);
                if (index != -1) {
                    Message smListItem = messageList.get(index);
                    smListItem.setKeyString(message.getKeyString());
                    smListItem.setFileMetaKeyStrings(message.getFileMetaKeyStrings());
                    if (messageList.get(index) != null) {
                        messageList.get(index).setKeyString(message.getKeyString());
                        messageList.get(index).setFileMetaKeyStrings(message.getFileMetaKeyStrings());
                    }
                    View view = recyclerView.getChildAt(index - linearLayoutManager.findFirstVisibleItemPosition());
                    if (view != null) {
                        final RelativeLayout attachmentDownloadProgressLayout = (RelativeLayout) view.findViewById(R.id.attachment_download_progress_layout);
                        final AttachmentView attachmentView = (AttachmentView) view.findViewById(R.id.main_attachment_view);
                        final ImageView preview = (ImageView) view.findViewById(R.id.preview);
                        TextView audioDurationTextView = (TextView) view.findViewById(R.id.audio_duration_textView);
                        final ImageView videoIcon = (ImageView) view.findViewById(R.id.video_icon);
                        String audioDuration;
                        if (message.getFileMetas() != null && message.getFileMetas().getContentType().contains("image")) {
                            attachmentView.setVisibility(VISIBLE);
                            preview.setVisibility(View.GONE);
                            attachmentView.setMessage(smListItem);
                            attachmentDownloadProgressLayout.setVisibility(View.GONE);
                        } else if (message.getFileMetas() != null && message.getFileMetas().getContentType().contains("video")) {
                            FileClientService fileClientService = new FileClientService(getContext());
                            attachedFile.setVisibility(View.GONE);
                            preview.setVisibility(VISIBLE);
                            videoIcon.setVisibility(VISIBLE);
                            preview.setImageBitmap(fileClientService.getOrCreateVideoThumbnail(message.getFilePaths().get(0)));
                        } else if (message.getFileMetas() != null) {
                            // Hide Attachment View...
                            RelativeLayout applozicDocRelativeLayout = (RelativeLayout) view.findViewById(R.id.applozic_doc_downloaded);
                            ImageView imageViewDoc = (ImageView) applozicDocRelativeLayout.findViewById(R.id.doc_icon);
                            if (message.getFileMetas() != null && message.getFilePaths() == null) {
                                if (message.getFileMetas().getContentType().contains("audio")) {
                                    imageViewDoc.setImageResource(R.drawable.ic_play_circle_outline);
                                } else {
                                    imageViewDoc.setImageResource(R.drawable.ic_documentreceive);
                                }
                                applozicDocRelativeLayout.setVisibility(VISIBLE);
                            } else if (message.getFilePaths() != null) {
                                String filePath = message.getFilePaths().get(0);
                                final String mimeType = FileUtils.getMimeType(filePath);
                                if (mimeType.contains("audio")) {
                                    if (message.isAttachmentDownloaded()) {
                                        audioDuration = ApplozicAudioManager.getInstance(getContext()).refreshAudioDuration(filePath);
                                        audioDurationTextView.setVisibility(View.VISIBLE);
                                        audioDurationTextView.setText(audioDuration);
                                    } else {
                                        audioDurationTextView.setVisibility(View.VISIBLE);
                                        audioDurationTextView.setText("00:00");
                                    }
                                    imageViewDoc.setImageResource(R.drawable.ic_play_circle_outline);
                                } else {
                                    imageViewDoc.setImageResource(R.drawable.ic_documentreceive);
                                }
                                applozicDocRelativeLayout.setVisibility(VISIBLE);
                            }
                            view.findViewById(R.id.applozic_doc_download_progress_rl).setVisibility(View.GONE);
                        }
                    }
                }
            } catch (Exception ex) {
                Utils.printLog(getContext(), TAG, "Exception while updating download status: " + ex.getMessage());
            }
        }
    });
}
Also used : AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) Message(com.applozic.mobicomkit.api.conversation.Message) AttachmentView(com.applozic.mobicomkit.api.attachment.AttachmentView) RelativeLayout(android.widget.RelativeLayout) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) MentionAutoCompleteTextView(com.applozic.mobicomkit.uiwidgets.conversation.mention.MentionAutoCompleteTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) MentionAutoCompleteTextView(com.applozic.mobicomkit.uiwidgets.conversation.mention.MentionAutoCompleteTextView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) AttachmentView(com.applozic.mobicomkit.api.attachment.AttachmentView) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 10 with FileClientService

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

the class MobiComConversationFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    geoApiKey = Applozic.getInstance(getContext()).getGeoApiKey();
    String jsonString = FileUtils.loadSettingsJsonFile(ApplozicService.getContext(getContext()));
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    richMessageActionProcessor = new RichMessageActionProcessor(this);
    restrictedWords = FileUtils.loadRestrictedWordsFile(getContext());
    conversationUIService = new ConversationUIService(getActivity());
    syncCallService = SyncCallService.getInstance(getActivity());
    appContactService = new AppContactService(getActivity());
    messageDatabaseService = new MessageDatabaseService(getActivity());
    fileClientService = new FileClientService(getActivity());
    setHasOptionsMenu(true);
    imageThumbnailLoader = new ImageLoader(getContext(), ImageUtils.getLargestScreenDimension((Activity) getContext())) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return fileClientService.downloadAndSaveThumbnailImage(getContext(), (Message) data, getImageLayoutParam(false).width, getImageLayoutParam(false).height);
        }
    };
    imageCache = ImageCache.getInstance((getActivity()).getSupportFragmentManager(), 0.1f);
    imageThumbnailLoader.setImageFadeIn(false);
    imageThumbnailLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);
    messageImageLoader = new ImageLoader(getContext(), ImageUtils.getLargestScreenDimension((Activity) getContext())) {

        @Override
        protected Bitmap processBitmap(Object data) {
            return fileClientService.loadMessageImage(getContext(), (String) data);
        }
    };
    messageImageLoader.setImageFadeIn(false);
    messageImageLoader.addImageCache((getActivity()).getSupportFragmentManager(), 0.1f);
    applozicAudioRecordManager = new ApplozicAudioRecordManager(getActivity());
    mDetector = new GestureDetectorCompat(getContext(), this);
}
Also used : AlCustomizationSettings(com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings) ConversationUIService(com.applozic.mobicomkit.uiwidgets.conversation.ConversationUIService) AppContactService(com.applozic.mobicomkit.contact.AppContactService) AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) Message(com.applozic.mobicomkit.api.conversation.Message) FileClientService(com.applozic.mobicomkit.api.attachment.FileClientService) GestureDetectorCompat(androidx.core.view.GestureDetectorCompat) Bitmap(android.graphics.Bitmap) RichMessageActionProcessor(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.RichMessageActionProcessor) ImageLoader(com.applozic.mobicommons.commons.image.ImageLoader) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService) ApplozicAudioRecordManager(com.applozic.mobicomkit.uiwidgets.attachmentview.ApplozicAudioRecordManager)

Aggregations

FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)15 Intent (android.content.Intent)7 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)7 Contact (com.applozic.mobicommons.people.contact.Contact)7 Channel (com.applozic.mobicommons.people.channel.Channel)6 ArrayList (java.util.ArrayList)6 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)5 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)5 Gson (com.google.gson.Gson)5 JsonParser (com.google.gson.JsonParser)5 Message (com.applozic.mobicomkit.api.conversation.Message)4 AlCustomizationSettings (com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings)4 JSONException (org.json.JSONException)4 IntentFilter (android.content.IntentFilter)3 Bitmap (android.graphics.Bitmap)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 ConnectivityReceiver (com.applozic.mobicomkit.broadcast.ConnectivityReceiver)3 JsonObject (com.google.gson.JsonObject)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3