Search in sources :

Example 51 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class MobiComMessageService method addMTMessage.

// Cleanup: private
public Contact addMTMessage(Message message, int index) {
    MobiComUserPreference userPreferences = MobiComUserPreference.getInstance(context);
    Contact receiverContact = null;
    message.processContactIds(context);
    String currentId = message.getCurrentId();
    if (message.getGroupId() == null) {
        receiverContact = baseContactService.getContactById(message.getContactIds());
    }
    if (message.getMessage() != null && PersonalizedMessage.isPersonalized(message.getMessage()) && receiverContact != null) {
        message.setMessage(PersonalizedMessage.prepareMessageFromTemplate(message.getMessage(), receiverContact));
    }
    if (isHideActionMessage && message.isActionMessage()) {
        message.setHidden(true);
    }
    messageDatabaseService.createMessage(message);
    // Check if we are........container is already opened...don't send broadcast
    boolean isContainerOpened;
    if (message.getConversationId() != null && BroadcastService.isContextBasedChatEnabled()) {
        if (BroadcastService.currentConversationId == null) {
            BroadcastService.currentConversationId = message.getConversationId();
        }
        isContainerOpened = (currentId.equals(BroadcastService.currentUserId) && message.getConversationId().equals(BroadcastService.currentConversationId));
    } else {
        isContainerOpened = currentId.equals(BroadcastService.currentUserId);
    }
    if (message.isVideoNotificationMessage()) {
        Utils.printLog(context, TAG, "Got notifications for Video call...");
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper helper = new VideoCallNotificationHelper(context);
        helper.handleVideoCallNotificationMessages(message);
    } else if (message.isVideoCallMessage()) {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        VideoCallNotificationHelper.buildVideoCallNotification(context, message, index);
    } else if (!isContainerOpened) {
        if (message.isConsideredForCount() && !message.hasHideKey()) {
            if (message.getTo() != null && message.getGroupId() == null && !message.isHidden()) {
                messageDatabaseService.updateContactUnreadCount(message.getTo());
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Contact contact = new ContactDatabase(context).getContactById(message.getTo());
                if (contact != null && !contact.isNotificationMuted()) {
                    sendNotification(message, index);
                }
            }
            if (message.getGroupId() != null && !Message.GroupMessageMetaData.FALSE.getValue().equals(message.getMetaDataValueForKey(Message.GroupMessageMetaData.KEY.getValue()))) {
                if (!Message.ContentType.CHANNEL_CUSTOM_MESSAGE.getValue().equals(message.getContentType()) && !message.isHidden()) {
                    messageDatabaseService.updateChannelUnreadCount(message.getGroupId());
                }
                BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
                Channel currentChannel = ChannelService.getInstance(context).getChannelInfo(message.getGroupId());
                if (currentChannel != null && (!currentChannel.isNotificationMuted() || MentionHelper.isLoggedInUserMentionedInChannelMessage(context, message))) {
                    sendNotification(message, index);
                }
            }
            MobiComUserPreference.getInstance(context).setNewMessageFlag(true);
        } else {
            BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
        }
    } else {
        BroadcastService.sendMessageUpdateBroadcast(context, BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString(), message);
    }
    return receiverContact;
}
Also used : VideoCallNotificationHelper(com.applozic.mobicomkit.api.notification.VideoCallNotificationHelper) MobiComUserPreference(com.applozic.mobicomkit.api.account.user.MobiComUserPreference) Channel(com.applozic.mobicommons.people.channel.Channel) ContactDatabase(com.applozic.mobicomkit.contact.database.ContactDatabase) Contact(com.applozic.mobicommons.people.contact.Contact)

Example 52 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class ContactSelectionFragment method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.Done) {
        if (userIdList != null && userIdList.size() == 0) {
            Toast.makeText(getActivity(), R.string.select_at_least, Toast.LENGTH_SHORT).show();
        } else {
            final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), "", getActivity().getString(TextUtils.isEmpty(channelName) ? R.string.broadcast_creating_info : R.string.group_creating_info), true);
            AlChannelCreateAsyncTask.TaskListenerInterface taskListenerInterface = new AlChannelCreateAsyncTask.TaskListenerInterface() {

                @Override
                public void onSuccess(Channel channel, Context context) {
                    if (progressDialog != null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    if (channel != null) {
                        Intent intent = new Intent(getActivity(), ConversationActivity.class);
                        if (ApplozicClient.getInstance(getActivity().getApplicationContext()).isContextBasedChat()) {
                            intent.putExtra(ConversationUIService.CONTEXT_BASED_CHAT, true);
                        }
                        intent.putExtra(ConversationUIService.GROUP_ID, channel.getKey());
                        intent.putExtra(ConversationUIService.GROUP_NAME, channel.getName());
                        getActivity().startActivity(intent);
                    }
                    if (bundle != null && bundle.getString(CHANNEL) != null) {
                        getActivity().sendBroadcast(new Intent(ChannelCreateActivity.ACTION_FINISH_CHANNEL_CREATE));
                    }
                    if (getActivity() != null) {
                        getActivity().finish();
                    }
                }

                @Override
                public void onFailure(ChannelFeedApiResponse channelFeedApiResponse, Context context) {
                    if (progressDialog != null && progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    if (channelFeedApiResponse != null) {
                        List<ErrorResponseFeed> error = channelFeedApiResponse.getErrorResponse();
                        if (error != null && error.size() > 0) {
                            ErrorResponseFeed errorResponseFeed = error.get(0);
                            String errorDescription = errorResponseFeed.getDescription();
                            if (!TextUtils.isEmpty(errorDescription)) {
                                if (MobiComKitConstants.GROUP_USER_LIMIT_EXCEED.equalsIgnoreCase(errorDescription)) {
                                    Toast.makeText(context, R.string.group_members_limit_exceeds, Toast.LENGTH_SHORT).show();
                                } else {
                                    Toast.makeText(context, R.string.applozic_server_error, Toast.LENGTH_SHORT).show();
                                }
                            }
                        }
                    } else {
                        Toast.makeText(context, Utils.isInternetAvailable(context) ? R.string.applozic_server_error : R.string.you_dont_have_any_network_access_info, Toast.LENGTH_SHORT).show();
                    }
                }
            };
            if (userIdList != null && userIdList.size() > 0) {
                if (TextUtils.isEmpty(channelName)) {
                    StringBuffer stringBuffer = new StringBuffer();
                    int i = 0;
                    for (String userId : userIdList) {
                        i++;
                        if (i > 10)
                            break;
                        Contact contactDisplayName = appContactService.getContactById(userId);
                        stringBuffer.append(contactDisplayName.getDisplayName()).append(",");
                    }
                    int lastIndex = stringBuffer.lastIndexOf(",");
                    channelName = stringBuffer.replace(lastIndex, lastIndex + 1, "").toString();
                }
                ChannelInfo channelInfo = new ChannelInfo(channelName, userIdList);
                if (!TextUtils.isEmpty(imageUrl)) {
                    channelInfo.setImageUrl(imageUrl);
                }
                if (groupType == Channel.GroupType.BROADCAST.getValue()) {
                    channelInfo.setType(groupType);
                } else if (alCustomizationSettings != null) {
                    channelInfo.setType(alCustomizationSettings.getDefaultGroupType());
                } else {
                    channelInfo.setType(groupType);
                }
                if (MobiComUserPreference.getInstance(getActivity()).getParentGroupKey() != null && MobiComUserPreference.getInstance(getActivity()).getParentGroupKey() != 0) {
                    channelInfo.setParentKey(MobiComUserPreference.getInstance(getActivity()).getParentGroupKey());
                }
                AlChannelCreateAsyncTask alChannelCreateAsyncTask = new AlChannelCreateAsyncTask(getActivity(), channelInfo, taskListenerInterface);
                AlTask.execute(alChannelCreateAsyncTask);
            }
        }
        return true;
    }
    return false;
}
Also used : Context(android.content.Context) ErrorResponseFeed(com.applozic.mobicomkit.feed.ErrorResponseFeed) Channel(com.applozic.mobicommons.people.channel.Channel) Intent(android.content.Intent) ChannelInfo(com.applozic.mobicomkit.api.people.ChannelInfo) SpannableString(android.text.SpannableString) ProgressDialog(android.app.ProgressDialog) SuppressLint(android.annotation.SuppressLint) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) Contact(com.applozic.mobicommons.people.contact.Contact) AlChannelCreateAsyncTask(com.applozic.mobicomkit.uiwidgets.async.AlChannelCreateAsyncTask)

Example 53 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method updateContextBasedGroup.

public void updateContextBasedGroup() {
    if (channel != null) {
        Channel channelInfo = ChannelService.getInstance(getActivity()).getChannelInfo(channel.getKey());
        if ((Channel.GroupType.GROUPOFTWO.getValue().equals(channelInfo.getType())) && channel.isContextBasedChat()) {
            Conversation conversation = new Conversation();
            TopicDetail topic = new TopicDetail();
            topic.setTitle(channelInfo.getMetadata().get(Channel.GroupMetaDataType.TITLE.getValue()));
            topic.setSubtitle(channelInfo.getMetadata().get(Channel.GroupMetaDataType.PRICE.getValue()));
            topic.setLink(channelInfo.getMetadata().get(Channel.GroupMetaDataType.LINK.getValue()));
            conversation.setTopicDetail(topic.getJson());
            conversationList.get(0).setTopicDetail(topic.getJson());
            applozicContextSpinnerAdapter.notifyDataSetChanged();
        }
    }
}
Also used : TopicDetail(com.applozic.mobicomkit.feed.TopicDetail) Channel(com.applozic.mobicommons.people.channel.Channel) Conversation(com.applozic.mobicommons.people.channel.Conversation)

Example 54 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (MobiComUserPreference.getInstance(getActivity()).isChannelDeleted()) {
        MobiComUserPreference.getInstance(getActivity()).setDeleteChannel(false);
        if (getActivity().getSupportFragmentManager() != null) {
            getActivity().getSupportFragmentManager().popBackStack();
        }
        return;
    }
    ((ConversationActivity) getActivity()).setChildFragmentLayoutBGToTransparent();
    if (contact != null || channel != null) {
        BroadcastService.currentUserId = contact != null ? contact.getContactIds() : String.valueOf(channel.getKey());
        BroadcastService.currentConversationId = currentConversationId;
        if (BroadcastService.currentUserId != null) {
            NotificationManagerCompat nMgr = NotificationManagerCompat.from(getActivity());
            if (ApplozicClient.getInstance(getActivity()).isNotificationStacking()) {
                nMgr.cancel(NotificationService.NOTIFICATION_ID);
            } else {
                if (contact != null && !TextUtils.isEmpty(contact.getContactIds())) {
                    nMgr.cancel(contact.getContactIds().hashCode());
                }
                if (channel != null) {
                    nMgr.cancel(String.valueOf(channel.getKey()).hashCode());
                }
            }
        }
        if (downloadConversation != null) {
            downloadConversation.cancel(true);
        }
        if (channel != null) {
            Channel newChannel = ChannelService.getInstance(getActivity()).getChannelByChannelKey(channel.getKey());
            if (newChannel != null && newChannel.getType() != null && Channel.GroupType.OPEN.getValue().equals(newChannel.getType())) {
                MobiComUserPreference.getInstance(getActivity()).setNewMessageFlag(true);
            }
            enableOrDisableChannel(newChannel);
            if (ChannelService.isUpdateTitle) {
                updateChannelSubTitle(newChannel);
                ChannelService.isUpdateTitle = false;
            }
        }
        if (messageList.isEmpty()) {
            loadConversation(contact, channel, currentConversationId, null);
        } else if (MobiComUserPreference.getInstance(getContext()).getNewMessageFlag()) {
            MobiComUserPreference.getInstance(getContext()).setNewMessageFlag(false);
            loadNewMessageOnResume(contact, channel, currentConversationId);
        } else {
            Applozic.subscribeToTyping(getContext(), channel, contact);
        }
        if (SyncCallService.refreshView) {
            SyncCallService.refreshView = false;
        }
    }
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        public void onRefresh() {
            downloadConversation = new DownloadConversation(recyclerView, false, 1, 1, 1, contact, channel, currentConversationId);
            AlTask.execute(downloadConversation);
        }
    });
    activateOrDeactivateChat();
}
Also used : ConversationActivity(com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity) Channel(com.applozic.mobicommons.people.channel.Channel) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout)

Example 55 with Channel

use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.

the class MobiComConversationFragment method updateChannelMuteMenuOptionForGroupId.

public void updateChannelMuteMenuOptionForGroupId(Integer groupId) {
    if (getActivity() == null) {
        return;
    }
    Channel channelObject = ChannelService.getInstance(getActivity()).getChannel(groupId);
    if (channelObject != null && menu != null && alCustomizationSettings != null) {
        if (alCustomizationSettings.isMuteOption() && !Channel.GroupType.BROADCAST.getValue().equals(channelObject.getType())) {
            menu.findItem(R.id.unmuteGroup).setVisible(!Channel.GroupType.OPEN.getValue().equals(channelObject.getType()) && !channelObject.isDeleted() && channelObject.isNotificationMuted());
            menu.findItem(R.id.muteGroup).setVisible(!Channel.GroupType.OPEN.getValue().equals(channelObject.getType()) && !channelObject.isDeleted() && !channelObject.isNotificationMuted());
        }
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel)

Aggregations

Channel (com.applozic.mobicommons.people.channel.Channel)70 Contact (com.applozic.mobicommons.people.contact.Contact)26 Intent (android.content.Intent)12 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)10 ArrayList (java.util.ArrayList)10 Message (com.applozic.mobicomkit.api.conversation.Message)8 MobiComUserPreference (com.applozic.mobicomkit.api.account.user.MobiComUserPreference)7 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)7 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)7 ChannelUserMapper (com.applozic.mobicommons.people.channel.ChannelUserMapper)7 NonNull (androidx.annotation.NonNull)6 FileClientService (com.applozic.mobicomkit.api.attachment.FileClientService)6 Context (android.content.Context)4 Cursor (android.database.Cursor)4 Bitmap (android.graphics.Bitmap)4 FileMeta (com.applozic.mobicomkit.api.attachment.FileMeta)4 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)4 ChannelUsersFeed (com.applozic.mobicomkit.feed.ChannelUsersFeed)4 Conversation (com.applozic.mobicommons.people.channel.Conversation)4 JSONException (org.json.JSONException)4