Search in sources :

Example 1 with ALStoragePermissionListener

use of com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermissionListener 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)

Aggregations

NotificationManager (android.app.NotificationManager)1 NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)1 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)1 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)1 DetailedConversationAdapter (com.applozic.mobicomkit.uiwidgets.conversation.adapter.DetailedConversationAdapter)1 ALStoragePermission (com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermission)1 ALStoragePermissionListener (com.applozic.mobicomkit.uiwidgets.uilistener.ALStoragePermissionListener)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1