Search in sources :

Example 1 with ApplozicException

use of com.applozic.mobicomkit.exception.ApplozicException in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method sendMessage.

public void sendMessage(Message message, MediaUploadProgressHandler handler) {
    if (message == null) {
        return;
    }
    ApplozicException e = null;
    if (!message.hasAttachment()) {
        e = new ApplozicException("Message does not have any attachment");
        if (handler != null) {
            handler.onUploadStarted(e);
            handler.onProgressUpdate(0, e);
            handler.onCancelled(e);
        }
    }
    sendMessage(message, handler, MessageIntentService.class);
}
Also used : ApplozicException(com.applozic.mobicomkit.exception.ApplozicException)

Example 2 with ApplozicException

use of com.applozic.mobicomkit.exception.ApplozicException in project Applozic-Android-SDK by AppLozic.

the class MessageListTask method onPostExecute.

@Override
protected void onPostExecute(List<Message> messageList) {
    super.onPostExecute(messageList);
    if (messageList == null && exception == null) {
        exception = new ApplozicException("Some internal error occurred");
    }
    List<String> recList = new ArrayList<String>();
    List<Message> messages = new ArrayList<Message>();
    if (isForMessageList) {
        if (messageList != null) {
            for (Message message : messageList) {
                if ((message.getGroupId() == null || message.getGroupId() == 0) && !recList.contains(message.getContactIds())) {
                    recList.add(message.getContactIds());
                    messages.add(message);
                } else if (message.getGroupId() != null && !recList.contains("group" + message.getGroupId())) {
                    recList.add("group" + message.getGroupId());
                    messages.add(message);
                }
            }
            MobiComUserPreference.getInstance(context.get()).setStartTimeForPagination(messageList.get(messageList.size() - 1).getCreatedAtTime());
        }
    }
    if (handler != null) {
        if (isForMessageList) {
            handler.onResult(messages, exception);
        } else if (messageList != null) {
            handler.onResult(messageList, exception);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException)

Example 3 with ApplozicException

use of com.applozic.mobicomkit.exception.ApplozicException in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationService method handleState.

private void handleState(android.os.Message message, MediaUploadProgressHandler progressHandler) {
    if (message != null) {
        Bundle b = message.getData();
        String e = null;
        if (b != null) {
            e = b.getString("error");
        }
        switch(message.what) {
            case UPLOAD_STARTED:
                if (progressHandler != null) {
                    progressHandler.onUploadStarted(e != null ? new ApplozicException(e) : null);
                }
                break;
            case UPLOAD_PROGRESS:
                if (progressHandler != null) {
                    progressHandler.onProgressUpdate(message.arg1, e != null ? new ApplozicException(e) : null);
                }
                break;
            case UPLOAD_COMPLETED:
                if (progressHandler != null) {
                    progressHandler.onCompleted(e != null ? new ApplozicException(e) : null);
                }
                break;
            case UPLOAD_CANCELLED:
                if (progressHandler != null) {
                    progressHandler.onCancelled(e != null ? new ApplozicException(e) : null);
                }
                break;
            case MESSAGE_SENT:
                if (b != null) {
                    if (progressHandler != null) {
                        progressHandler.onSent(messageDatabaseService.getMessage(b.getString("message")));
                    }
                }
                break;
        }
    }
}
Also used : Bundle(android.os.Bundle) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException)

Example 4 with ApplozicException

use of com.applozic.mobicomkit.exception.ApplozicException in project Applozic-Android-SDK by AppLozic.

the class ApplozicConversation method downloadMessage.

public static void downloadMessage(Context context, Message message, MediaDownloadProgressHandler handler) {
    ApplozicException e;
    if (message == null || handler == null) {
        return;
    }
    if (!message.hasAttachment()) {
        e = new ApplozicException("Message does not have Attachment");
        handler.onProgressUpdate(0, e);
        handler.onCompleted(null, e);
    } else if (message.isAttachmentDownloaded()) {
        e = new ApplozicException("Attachment for the message already downloaded");
        handler.onProgressUpdate(0, e);
        handler.onCompleted(null, e);
    } else {
        AttachmentTask mDownloadThread = null;
        if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
            // Starts downloading this View, using the current cache setting
            mDownloadThread = AttachmentManager.startDownload(null, true, message, handler, context);
        // After successfully downloading the image, this marks that it's available.
        }
        if (mDownloadThread == null) {
            mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
            if (mDownloadThread != null) {
                mDownloadThread.setAttachment(message, handler, context);
            }
        }
    }
}
Also used : AttachmentTask(com.applozic.mobicomkit.api.attachment.AttachmentTask) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException)

Aggregations

ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)4 Bundle (android.os.Bundle)1 AttachmentTask (com.applozic.mobicomkit.api.attachment.AttachmentTask)1 ArrayList (java.util.ArrayList)1