Search in sources :

Example 1 with MessageDatabaseService

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

the class NotificationIntentService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    appContactService = new AppContactService(NotificationIntentService.this);
    messageDatabaseService = new MessageDatabaseService(NotificationIntentService.this);
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 2 with MessageDatabaseService

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

the class AlMessageMetadataUpdateTask method onPostExecute.

@Override
protected void onPostExecute(ApiResponse apiResponse) {
    super.onPostExecute(apiResponse);
    if (apiResponse == null) {
        listener.onFailure(context.get(), "Some error occurred");
    } else if (!"success".equals(apiResponse.getStatus()) && apiResponse.getErrorResponse() != null) {
        listener.onFailure(context.get(), apiResponse.getErrorResponse().toString());
    } else if ("success".equals(apiResponse.getStatus())) {
        new MessageDatabaseService(context.get()).updateMessageMetadata(key, metadata);
        listener.onSuccess(context.get(), "Metadata updated successfully for messsage key : " + key);
    }
}
Also used : MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 3 with MessageDatabaseService

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

the class FileClientService method loadContactsvCard.

/**
 * Downloads and saves the contact attachment card for the given message object (if it has one i.e {@link Message#hasAttachment()} returns true).
 *
 * <p>Note: Multiple calls to this method <i>DO NOT</i> download the contact multiple times.</p>
 *
 * <p>To, in the future, get the local path of the contact card use:
 * <code>
 *     Message updatedMessage = new MessageDatabaseService(context).getMessage(messageKeyString); //message.getKeyString();
 *     updatedMessage.getFilePaths();
 * </code></p>
 *
 * @param message the message object to download the contact card for
 */
public void loadContactsvCard(Message message) {
    File file = null;
    HttpURLConnection connection = null;
    try {
        InputStream inputStream = null;
        FileMeta fileMeta = message.getFileMetas();
        String contentType = fileMeta.getContentType();
        String fileName = fileMeta.getName();
        file = FileClientService.getFilePath(fileName, context.getApplicationContext(), contentType);
        if (!file.exists()) {
            connection = new URLServiceProvider(context).getDownloadConnection(message);
            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
                inputStream = connection.getInputStream();
            } else {
                // TODO: Error Handling...
                Utils.printLog(context, TAG, "Got Error response while uploading file : " + connection.getResponseCode());
                return;
            }
            OutputStream output = new FileOutputStream(file);
            byte[] data = new byte[1024];
            int count = 0;
            while ((count = inputStream.read(data)) != -1) {
                output.write(data, 0, count);
            }
            output.flush();
            output.close();
            inputStream.close();
        }
        // Todo: Fix this, so that attach package can be moved to mobicom mobicom.
        new MessageDatabaseService(context).updateInternalFilePath(message.getKeyString(), file.getAbsolutePath());
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add(file.getAbsolutePath());
        message.setFilePaths(arrayList);
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        Utils.printLog(context, TAG, "File not found on server");
    } catch (Exception ex) {
        // If partial file got created delete it, we try to download it again
        if (file != null && file.exists()) {
            Utils.printLog(context, TAG, " Exception occured while downloading :" + file.getAbsolutePath());
            file.delete();
        }
        ex.printStackTrace();
        Utils.printLog(context, TAG, "Exception fetching file from server");
    } finally {
        if (connection != null) {
            connection.disconnect();
        }
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URLServiceProvider(com.applozic.mobicomkit.api.attachment.urlservice.URLServiceProvider) HttpURLConnection(java.net.HttpURLConnection) FileOutputStream(java.io.FileOutputStream) File(java.io.File) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 4 with MessageDatabaseService

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

the class ApplozicConversation method markAsRead.

/**
 * Mark a conversation as read. Either one of the <i>userId</i> or the <i>groupId</i> can be null.
 *
 * @param pairedMessageKey not used. pass null
 * @param userId for one-to-one conversation
 * @param groupId for group conversation
 */
public static void markAsRead(@NonNull Context context, @Nullable String pairedMessageKey, @Nullable String userId, @Nullable Integer groupId) {
    try {
        int unreadCount = 0;
        Contact contact = null;
        Channel channel = null;
        if (userId != null) {
            contact = new AppContactService(context).getContactById(userId);
            unreadCount = contact.getUnreadCount();
            new MessageDatabaseService(context).updateReadStatusForContact(userId);
        } else if (groupId != null && groupId != 0) {
            channel = ChannelService.getInstance(context).getChannelByChannelKey(groupId);
            unreadCount = channel.getUnreadCount();
            new MessageDatabaseService(context).updateReadStatusForChannel(String.valueOf(groupId));
        }
        UserWorker.enqueueWork(context, null, contact, channel, pairedMessageKey, unreadCount, false);
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}
Also used : AppContactService(com.applozic.mobicomkit.contact.AppContactService) Channel(com.applozic.mobicommons.people.channel.Channel) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) Contact(com.applozic.mobicommons.people.contact.Contact) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 5 with MessageDatabaseService

use of com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService 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

MessageDatabaseService (com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)10 AppContactService (com.applozic.mobicomkit.contact.AppContactService)4 Message (com.applozic.mobicomkit.api.conversation.Message)3 URLServiceProvider (com.applozic.mobicomkit.api.attachment.urlservice.URLServiceProvider)2 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)2 AlCustomizationSettings (com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings)2 ConversationUIService (com.applozic.mobicomkit.uiwidgets.conversation.ConversationUIService)2 Channel (com.applozic.mobicommons.people.channel.Channel)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 Bitmap (android.graphics.Bitmap)1 MediaScannerConnection (android.media.MediaScannerConnection)1 Uri (android.net.Uri)1 View (android.view.View)1