Search in sources :

Example 6 with MessageDatabaseService

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

the class ChannelDatabaseServiceTest method createDb.

@Before
public void createDb() {
    Context context = ApplicationProvider.getApplicationContext();
    dbHelper = new MobiComDatabaseHelper(ApplicationProvider.getApplicationContext(), null, null, MobiComDatabaseHelper.DB_VERSION);
    channelDatabaseService = ChannelDatabaseService.getTestInstance(context, dbHelper);
    messageDatabaseService = new MessageDatabaseService(context, dbHelper);
    channel = new Channel();
    Map<String, String> metadata = new HashMap<>();
    metadata.put("met1", "1");
    metadata.put("met2", "2");
    channel.setMetadata(metadata);
    channel.setKey(12345);
    channel.setParentKey(123);
    channel.setParentClientGroupId("parentId");
    channel.setClientGroupId("clientId");
    channel.setName("dname");
    channel.setAdminKey("adminKey");
    channel.setType((short) 1);
    channel.setUnreadCount(10);
    channel.setImageUrl("imageUrl");
    channel.setLocalImageUri("localImageUri");
    channel.setNotificationAfterTime(123456L);
    channel.setDeletedAtTime(123456L);
    channel.setKmStatus(1);
    channel1 = new Channel();
    Map<String, String> metadata1 = new HashMap<>();
    metadata.put("met11", "1");
    metadata.put("met21", "2");
    channel1.setMetadata(metadata1);
    channel1.setKey(123451);
    channel1.setParentKey(1231);
    channel1.setParentClientGroupId("parentId1");
    channel1.setClientGroupId("clientId");
    channel1.setName("bname1");
    channel1.setAdminKey("adminKey1");
    channel1.setType((short) 11);
    channel1.setUnreadCount(101);
    channel1.setImageUrl("imageUrl1");
    channel1.setLocalImageUri("localImageUri1");
    channel1.setNotificationAfterTime(12345L);
    channel1.setDeletedAtTime(12345L);
    channel1.setKmStatus(11);
    channel2 = new Channel();
    Map<String, String> metadata2 = new HashMap<>();
    metadata.put("met12", "1");
    metadata.put("met22", "2");
    channel2.setMetadata(metadata2);
    channel2.setKey(123452);
    channel2.setParentKey(1232);
    channel2.setParentClientGroupId("parentId2");
    channel2.setClientGroupId("clientId2");
    channel2.setName("aname2");
    channel2.setAdminKey("adminKey2");
    channel2.setType((short) 12);
    channel2.setUnreadCount(102);
    channel2.setImageUrl("imageUrl2");
    channel2.setLocalImageUri("localImageUri2");
    channel2.setNotificationAfterTime(1234L);
    channel2.setDeletedAtTime(1234L);
    channel2.setKmStatus(12);
    channel3 = new Channel();
    Map<String, String> metadata3 = new HashMap<>();
    metadata.put("met13", "1");
    metadata.put("met23", "2");
    channel3.setMetadata(metadata3);
    channel3.setKey(123453);
    channel3.setParentKey(1233);
    channel3.setParentClientGroupId("parentId3");
    channel3.setClientGroupId("clientId3");
    channel3.setName("cname3");
    channel3.setAdminKey("adminKey3");
    channel3.setType((short) 13);
    channel3.setUnreadCount(103);
    channel3.setImageUrl("imageUrl3");
    channel3.setLocalImageUri("localImageUri3");
    channel3.setNotificationAfterTime(123L);
    channel3.setDeletedAtTime(123L);
    channel3.setKmStatus(13);
    // ChannelUserMapper objects
    channelUserMapper = new ChannelUserMapper();
    // for channel1
    channelUserMapper.setKey(123451);
    channelUserMapper.setUserKey("clientId");
    channelUserMapper.setUnreadCount(20);
    channelUserMapper.setStatus((short) 2);
    channelUserMapper.setParentKey(123);
    channelUserMapper.setRole(4);
    channelUserMapper1 = new ChannelUserMapper();
    // for channel1
    channelUserMapper1.setKey(123451);
    channelUserMapper1.setUserKey("clientId1");
    channelUserMapper1.setUnreadCount(201);
    channelUserMapper1.setStatus((short) 2);
    channelUserMapper1.setParentKey(1231);
    channelUserMapper1.setRole(41);
    channelUserMapper2 = new ChannelUserMapper();
    // for channel2
    channelUserMapper2.setKey(123452);
    channelUserMapper2.setUserKey("clientId2");
    channelUserMapper2.setUnreadCount(202);
    channelUserMapper2.setStatus((short) 3);
    channelUserMapper2.setParentKey(1232);
    channelUserMapper2.setRole(42);
}
Also used : Context(android.content.Context) HashMap(java.util.HashMap) Channel(com.applozic.mobicommons.people.channel.Channel) ChannelUserMapper(com.applozic.mobicommons.people.channel.ChannelUserMapper) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService) Before(org.junit.Before)

Example 7 with MessageDatabaseService

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

the class ScheduleMessageService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    Calendar c = Calendar.getInstance();
    long time = c.getTimeInMillis();
    MessageDatabaseService messageDatabaseService = new MessageDatabaseService(getApplicationContext());
    MobiComConversationService conversationService = new MobiComConversationService(getApplicationContext());
    List<Message> messages = messageDatabaseService.getScheduledMessages(time);
    for (Message message : messages) {
        message.setScheduledAt(null);
        conversationService.sendMessage(message);
    // Todo: broadcast for scheduled message fragment.
    }
    messageDatabaseService.deleteScheduledMessages(time);
}
Also used : Message(com.applozic.mobicomkit.api.conversation.Message) Calendar(java.util.Calendar) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 8 with MessageDatabaseService

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

the class MobiComQuickConversationFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String jsonString = FileUtils.loadSettingsJsonFile(ApplozicService.getContext(getContext()));
    if (!TextUtils.isEmpty(jsonString)) {
        alCustomizationSettings = (AlCustomizationSettings) GsonUtils.getObjectFromJson(jsonString, AlCustomizationSettings.class);
    } else {
        alCustomizationSettings = new AlCustomizationSettings();
    }
    syncCallService = SyncCallService.getInstance(getActivity());
    conversationUIService = new ConversationUIService(getActivity());
    baseContactService = new AppContactService(getActivity());
    messageDatabaseService = new MessageDatabaseService(getActivity());
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            MobiComUserPreference.getInstance(getActivity()).setDeviceTimeOffset(DateUtils.getTimeDiffFromUtc());
        }
    });
    thread.setPriority(Process.THREAD_PRIORITY_BACKGROUND);
    thread.start();
    setHasOptionsMenu(true);
    BroadcastService.lastIndexForChats = 0;
}
Also used : AlCustomizationSettings(com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings) ConversationUIService(com.applozic.mobicomkit.uiwidgets.conversation.ConversationUIService) AppContactService(com.applozic.mobicomkit.contact.AppContactService) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 9 with MessageDatabaseService

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

the class AttachmentDownloader method loadAttachmentImage.

public void loadAttachmentImage(Message message, Context context) {
    File file = null;
    HttpURLConnection connection = null;
    InputStream inputStream = null;
    OutputStream output = null;
    try {
        FileMeta fileMeta = message.getFileMetas();
        String contentType = fileMeta.getContentType();
        String fileName = null;
        if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) {
            fileName = fileMeta.getName();
        } else {
            fileName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
        }
        file = FileClientService.getFilePath(fileName, context.getApplicationContext(), contentType);
        try {
            if (!file.exists()) {
                connection = new URLServiceProvider(context).getDownloadConnection(message);
                if (connection.getResponseCode() == HttpURLConnection.HTTP_OK || connection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
                    inputStream = connection.getInputStream();
                } else {
                    // TODO: Error Handling...
                    Utils.printLog(context, TAG, "Got Error response while uploading file : " + connection.getResponseCode());
                    return;
                }
                output = new FileOutputStream(file);
                byte[] data = new byte[1024];
                long totalSize = fileMeta.getSize();
                long progressCount = 0;
                int count = 0;
                int prevPrecentage = 0;
                while ((count = inputStream.read(data)) != -1) {
                    output.write(data, 0, count);
                    progressCount = progressCount + count;
                    long percentage = progressCount * 100 / totalSize;
                    android.os.Message msg = new android.os.Message();
                    // Message code 2 represents image is successfully downloaded....
                    if (percentage + 1 != prevPrecentage) {
                        mPhotoTask.handleDownloadState(5);
                        mPhotoTask.downloadProgress((int) percentage + 1);
                        msg.what = 5;
                        msg.arg1 = (int) percentage + 1;
                        msg.obj = this;
                        // msg.sendToTarget();
                        prevPrecentage = (int) percentage + 1;
                    }
                    if ((percentage % 10 == 0)) {
                        msg.what = 1;
                        msg.obj = this;
                    }
                    if (Thread.interrupted()) {
                        if (file != null && file.exists()) {
                            file.delete();
                            Utils.printLog(context, TAG, "Downloading cancelled : " + file.getAbsolutePath());
                        }
                        throw new InterruptedException();
                    }
                }
                output.flush();
            }
        } finally {
            if (output != null) {
                output.close();
            }
            if (inputStream != null) {
                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);
        MediaScannerConnection.scanFile(mPhotoTask.getContext(), new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {

            public void onScanCompleted(String path, Uri uri) {
                Log.i("ExternalStorage", "Scanned " + path + ":");
                Log.i("ExternalStorage", "-> uri=" + uri);
            }
        });
    } 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 : Message(com.applozic.mobicomkit.api.conversation.Message) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Uri(android.net.Uri) FileNotFoundException(java.io.FileNotFoundException) URLServiceProvider(com.applozic.mobicomkit.api.attachment.urlservice.URLServiceProvider) HttpURLConnection(java.net.HttpURLConnection) FileOutputStream(java.io.FileOutputStream) MediaScannerConnection(android.media.MediaScannerConnection) File(java.io.File) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

Example 10 with MessageDatabaseService

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

the class ApplozicDocumentView method registerEvents.

public void registerEvents() {
    previewLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (alStoragePermissionListener.isPermissionGranted()) {
                if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
                    // Starts downloading this View, using the current cache setting
                    mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
                    // After successfully downloading the image, this marks that it's available.
                    showDownloadInProgress();
                }
                if (mDownloadThread == null) {
                    mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
                    if (mDownloadThread != null)
                        mDownloadThread.setAttachementViewNew(attachmentViewProperties);
                }
            } else {
                alStoragePermissionListener.checkPermission(new ALStoragePermission() {

                    @Override
                    public void onAction(boolean didGrant) {
                        if (didGrant) {
                            if (!AttachmentManager.isAttachmentInProgress(message.getKeyString())) {
                                // Starts downloading this View, using the current cache setting
                                mDownloadThread = AttachmentManager.startDownload(attachmentViewProperties, mCacheFlag);
                                // After successfully downloading the image, this marks that it's available.
                                showDownloadInProgress();
                            }
                            if (mDownloadThread == null) {
                                mDownloadThread = AttachmentManager.getBGThreadForAttachment(message.getKeyString());
                                if (mDownloadThread != null)
                                    mDownloadThread.setAttachementViewNew(attachmentViewProperties);
                            }
                        }
                    }
                });
            }
        }
    });
    downloadedLayout.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (alStoragePermissionListener.isPermissionGranted()) {
                playAudio();
            } else {
                alStoragePermissionListener.checkPermission(new ALStoragePermission() {

                    @Override
                    public void onAction(boolean didGrant) {
                        if (didGrant) {
                            playAudio();
                        }
                    }
                });
            }
        }
    });
    downloadInProgressLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            cancelDownload();
        }
    });
    retryLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            message.setCanceled(false);
            MessageDatabaseService messageDatabaseService = new MessageDatabaseService(context);
            messageDatabaseService.updateCanceledFlag(message.getMessageId(), 0);
            new MobiComConversationService(context).sendMessage(message, null);
            showDownloadInProgress();
        }
    });
}
Also used : ALStoragePermission(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) MessageDatabaseService(com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)

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