Search in sources :

Example 11 with MobiComConversationService

use of com.applozic.mobicomkit.api.conversation.MobiComConversationService 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 12 with MobiComConversationService

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

the class MobiComConversationFragment method loadConversation.

public void loadConversation(final Contact contact, final Channel channel, final Integer conversationId, final String searchString) {
    try {
        if (downloadConversation != null) {
            downloadConversation.cancel(true);
        }
        if (this.contact != null && contact != null && !contact.getUserId().equals(this.contact.getUserId())) {
            userDisplayName = null;
        }
        setContact(contact);
        setChannel(channel);
        BroadcastService.currentUserId = contact != null ? contact.getContactIds() : String.valueOf(channel.getKey());
        typingStarted = false;
        onSelected = false;
        messageMetaData = null;
        Applozic.subscribeToTyping(getContext(), channel, contact);
        checkForUserNotAbleToChatAndToggleViews(contact, channel);
        if (contact != null && this.channel != null) {
            if (getActivity() != null) {
                setToolbarSubtitle("");
                setToolbarImage(contact, channel);
            }
            if (menu != null) {
                menu.findItem(R.id.unmuteGroup).setVisible(false);
                menu.findItem(R.id.muteGroup).setVisible(false);
            }
        }
        if (replayRelativeLayout != null) {
            replayRelativeLayout.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(filePath) && attachmentLayout != null) {
            attachmentLayout.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(defaultText) && messageEditText != null) {
            messageEditText.setText(defaultText);
            defaultText = "";
        }
        extendedSendingOptionLayout.setVisibility(VISIBLE);
        unregisterForContextMenu(recyclerView);
        if (getActivity() != null) {
            if (ApplozicClient.getInstance(getActivity()).isNotificationStacking()) {
                NotificationManagerCompat nMgr = NotificationManagerCompat.from(getActivity());
                nMgr.cancel(NotificationService.NOTIFICATION_ID);
            } else {
                if (contact != null) {
                    if (!TextUtils.isEmpty(contact.getContactIds())) {
                        NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
                        if (notificationManager != null) {
                            notificationManager.cancel(contact.getContactIds().hashCode());
                        }
                    }
                }
                if (channel != null) {
                    NotificationManager notificationManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
                    if (notificationManager != null) {
                        notificationManager.cancel(String.valueOf(channel.getKey()).hashCode());
                    }
                }
            }
        }
        clearList();
        updateTitle(contact, channel);
        swipeLayout.setEnabled(true);
        loadMore = true;
        if (selfDestructMessageSpinner != null) {
            selfDestructMessageSpinner.setSelection(0);
        }
        if (contact != null) {
            recyclerDetailConversationAdapter = new DetailedConversationAdapter(getActivity(), messageList, contact, messageIntentClass, emojiIconHandler);
            recyclerDetailConversationAdapter.setAlCustomizationSettings(alCustomizationSettings);
            recyclerDetailConversationAdapter.setRichMessageCallbackListener(richMessageActionProcessor.getRichMessageListener());
            recyclerDetailConversationAdapter.setContextMenuClickListener(this);
            recyclerDetailConversationAdapter.setSendMessageInterfaceCallBack(this);
            if (getActivity() instanceof ALStoragePermissionListener) {
                recyclerDetailConversationAdapter.setStoragePermissionListener((ALStoragePermissionListener) getActivity());
            } else {
                recyclerDetailConversationAdapter.setStoragePermissionListener(new ALStoragePermissionListener() {

                    @Override
                    public boolean isPermissionGranted() {
                        return false;
                    }

                    @Override
                    public void checkPermission(ALStoragePermission storagePermission) {
                    }
                });
            }
        } else if (channel != null) {
            Thread thread = new Thread(new Runnable() {

                @Override
                public void run() {
                    if (!ChannelService.getInstance(getContext()).isUserAlreadyPresentInChannel(channel.getKey(), loggedInUserId) && messageTemplate != null && messageTemplate.isEnabled() && templateAdapter != null) {
                        if (getActivity() == null) {
                            return;
                        }
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                templateAdapter.removeTemplates();
                            }
                        });
                    }
                }
            });
            thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            thread.start();
            recyclerDetailConversationAdapter = new DetailedConversationAdapter(getActivity(), messageList, channel, messageIntentClass, emojiIconHandler);
            recyclerDetailConversationAdapter.setAlCustomizationSettings(alCustomizationSettings);
            recyclerDetailConversationAdapter.setContextMenuClickListener(this);
            recyclerDetailConversationAdapter.setSendMessageInterfaceCallBack(this);
            recyclerDetailConversationAdapter.setRichMessageCallbackListener(richMessageActionProcessor.getRichMessageListener());
            if (getActivity() instanceof ALStoragePermissionListener) {
                recyclerDetailConversationAdapter.setStoragePermissionListener((ALStoragePermissionListener) getActivity());
            } else {
                recyclerDetailConversationAdapter.setStoragePermissionListener(new ALStoragePermissionListener() {

                    @Override
                    public boolean isPermissionGranted() {
                        return false;
                    }

                    @Override
                    public void checkPermission(ALStoragePermission storagePermission) {
                    }
                });
            }
        }
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        if (getActivity() == null) {
            return;
        }
        getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                linearLayoutManager.setStackFromEnd(true);
            }
        });
        recyclerView.setAdapter(recyclerDetailConversationAdapter);
        registerForContextMenu(recyclerView);
        processMobiTexterUserCheck();
        downloadConversation = new DownloadConversation(recyclerView, true, 1, 0, 0, contact, channel, conversationId);
        AlTask.execute(downloadConversation);
        if (hideExtendedSendingOptionLayout) {
            extendedSendingOptionLayout.setVisibility(View.GONE);
        }
        emoticonsFrameLayout.setVisibility(View.GONE);
        MobiComConversationService mobiComConversationService = new MobiComConversationService(requireContext().getApplicationContext());
        if (contact != null) {
            mobiComConversationService.syncUserDetail(contact.getUserId());
        }
        if (channel != null) {
            if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
                String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey());
                if (!TextUtils.isEmpty(userId)) {
                    mobiComConversationService.syncUserDetail(userId);
                }
            } else {
                Thread thread = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        updateChannelSubTitle(channel);
                    }
                });
                thread.setPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
                thread.start();
            }
        }
        if (alCustomizationSettings.isMessageFastScrollEnabled()) {
            if (getActivity() == null) {
                return;
            }
            getActivity().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    recyclerView.smoothScrollToPosition(messageList.size());
                    recyclerView.getLayoutManager().scrollToPosition(messageList.size());
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ALStoragePermissionListener(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermissionListener) NotificationManager(android.app.NotificationManager) DetailedConversationAdapter(com.applozic.mobicomkit.uiwidgets.conversation.adapter.DetailedConversationAdapter) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) ALStoragePermission(com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) ApplozicException(com.applozic.mobicomkit.exception.ApplozicException) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 13 with MobiComConversationService

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

the class MobiComConversationFragment method deleteConversationThread.

public void deleteConversationThread() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()).setPositiveButton(R.string.delete_conversation, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            AlTask.execute(new DeleteConversationAsyncTask(new MobiComConversationService(getActivity()), contact, channel, currentConversationId, getActivity()));
        }
    });
    alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }
    });
    alertDialog.setTitle(ApplozicService.getContext(getContext()).getString(R.string.dialog_delete_conversation_title).replace("[name]", getNameForInviteDialog()));
    alertDialog.setMessage(ApplozicService.getContext(getContext()).getString(R.string.dialog_delete_conversation_confir).replace("[name]", getNameForInviteDialog()));
    alertDialog.setCancelable(true);
    alertDialog.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) DeleteConversationAsyncTask(com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService) Collections.disjoint(java.util.Collections.disjoint)

Example 14 with MobiComConversationService

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

the class MobiComConversationFragment method sendProductMessage.

public void sendProductMessage(final String messageToSend, final FileMeta fileMeta, final Contact contact, final short messageContentType) {
    final Message message = new Message();
    new Thread(new Runnable() {

        @Override
        public void run() {
            String topicId;
            MobiComConversationService conversationService = new MobiComConversationService(getActivity());
            MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(getActivity());
            topicId = new MessageClientService(getActivity()).getTopicId(currentConversationId);
            if (getChannel() != null) {
                message.setGroupId(channelKey);
            } else {
                message.setContactIds(contact.getUserId());
                message.setTo(contact.getUserId());
            }
            message.setMessage(messageToSend);
            message.setRead(Boolean.TRUE);
            message.setStoreOnDevice(Boolean.TRUE);
            message.setSendToDevice(Boolean.FALSE);
            message.setContentType(messageContentType);
            message.setType(Message.MessageType.MT_OUTBOX.getValue());
            message.setDeviceKeyString(userPreferences.getDeviceKeyString());
            message.setSource(Message.Source.MT_MOBILE_APP.getValue());
            message.setTopicId(messageToSend);
            message.setCreatedAtTime(System.currentTimeMillis() + userPreferences.getDeviceTimeOffset());
            message.setTopicId(topicId);
            message.setConversationId(currentConversationId);
            message.setFileMetas(fileMeta);
            conversationService.sendMessage(message, userDisplayName);
        }
    }).start();
}
Also used : AlRichMessage(com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage) Message(com.applozic.mobicomkit.api.conversation.Message) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) MessageClientService(com.applozic.mobicomkit.api.conversation.MessageClientService) MobiComConversationService(com.applozic.mobicomkit.api.conversation.MobiComConversationService)

Example 15 with MobiComConversationService

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

MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)17 Message (com.applozic.mobicomkit.api.conversation.Message)5 DialogInterface (android.content.DialogInterface)4 Contact (com.applozic.mobicommons.people.contact.Contact)4 AlertDialog (android.app.AlertDialog)3 View (android.view.View)2 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)2 MessageClientService (com.applozic.mobicomkit.api.conversation.MessageClientService)2 MessageDatabaseService (com.applozic.mobicomkit.api.conversation.database.MessageDatabaseService)2 AppContactService (com.applozic.mobicomkit.contact.AppContactService)2 DeleteConversationAsyncTask (com.applozic.mobicomkit.uiwidgets.conversation.DeleteConversationAsyncTask)2 ALStoragePermission (com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission)2 Before (org.junit.Before)2 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1