@Override public Cursor loadInBackground() { SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor; StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("SELECT ").append(MobiComDatabaseHelper._ID).append(",").append(MobiComDatabaseHelper.CHANNEL_KEY).append(",").append(MobiComDatabaseHelper.CLIENT_GROUP_ID).append(",").append(MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME).append(","). append(MobiComDatabaseHelper.ADMIN_ID).append(",").append(MobiComDatabaseHelper.TYPE).append(",").append(MobiComDatabaseHelper.UNREAD_COUNT).append(",").append(MobiComDatabaseHelper.CHANNEL_IMAGE_URL).append(",").append(MobiComDatabaseHelper.CHANNEL_IMAGE_LOCAL_URI).append(","). append(MobiComDatabaseHelper.NOTIFICATION_AFTER_TIME).append(" , ").append(MobiComDatabaseHelper.AL_CATEGORY).append(","). append(MobiComDatabaseHelper.DELETED_AT).append(",").append(MobiComDatabaseHelper.CHANNEL_META_DATA).append(",").append(MobiComDatabaseHelper.PARENT_GROUP_KEY).append(",").append(MobiComDatabaseHelper.PARENT_CLIENT_GROUP_ID). append(" FROM ").append(MobiComDatabaseHelper.CHANNEL).append(" where ").append(MobiComDatabaseHelper.TYPE).append(" NOT IN ('").append(Channel.GroupType.CONTACT_GROUP.getValue()).append("')"); if (!TextUtils.isEmpty(searchString)) { stringBuffer.append(" AND " + MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME + " like '%" + searchString.replaceAll("'", "''") + "%'"); } stringBuffer.append(" order by " + MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME + " COLLATE NOCASE asc "); cursor = db.rawQuery(stringBuffer.toString(), null); return cursor; } };
@Override protected Channel doInBackground(Void... params) { if (localParentGroupKey != null && localParentGroupKey != 0 && withUserContact != null) { List<String> userIdList = new ArrayList<>(); userIdList.add(withUserContact.getContactIds()); int result = loggedInUserId.compareTo(withUserContact.getContactIds()); StringBuffer stringBuffer = new StringBuffer(); if (result == 0) { stringBuffer.append(localParentGroupKey).append(":").append(loggedInUserId).append(":").append(withUserContact.getContactIds()); } else if (result < 0) { stringBuffer.append(localParentGroupKey).append(":").append(loggedInUserId).append(":").append(withUserContact.getContactIds()); } else { stringBuffer.append(localParentGroupKey).append(":").append(withUserContact.getContactIds()).append(":").append(loggedInUserId); } ChannelInfo channelInfo = new ChannelInfo(stringBuffer.toString(), userIdList); channelInfo.setClientGroupId(stringBuffer.toString()); channelInfo.setType(Channel.GroupType.GROUPOFTWO.getValue()); channelInfo.setParentKey(localParentGroupKey); channel = channelService.createGroupOfTwo(channelInfo); } return channel; }
public static String getWithUserId(Channel channel, String loggedInUserId) { try { if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) { String[] userIdSplit = new String[2]; if (!TextUtils.isEmpty(channel.getClientGroupId())) { userIdSplit = channel.getClientGroupId().split(":"); String userId1 = userIdSplit[1]; String userId2 = userIdSplit[2]; if (!loggedInUserId.equals(userId2)) { return userId2; } else if (!loggedInUserId.equals(userId1)) { return userId1; } } } } catch (Exception e) { Log.i("ChannelUtils", "Got exception in Group of two"); } return ""; }
continue; if (menuItems[i].equals(getString(R.string.make_admin_text_info)) && (!isUserPresent || ChannelUserMapper.UserRole.ADMIN.getValue().equals(channelUserMapper.getRole()) || (channel != null && Channel.GroupType.BROADCAST.getValue().equals(channel.getType())))) { continue;
public CharSequence getMessageBody(Message message, int count, Channel channel, Contact contact) { String notificationText; if (message.getContentType() == Message.ContentType.LOCATION.getValue()) { notificationText = getText(0); } else if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) { notificationText = getText(1); } else if (message.getContentType() == Message.ContentType.VIDEO_MSG.getValue()) { notificationText = getText(2); } else if (message.hasAttachment() && TextUtils.isEmpty(message.getMessage())) { notificationText = getText(3); } else { notificationText = message.getMessage(); } CharSequence messageBody; Contact messageContactDisplayName = contact != null ? contact : appContactService.getContactById(message.getTo()); if (message.getGroupId() != null) { if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) || Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) { messageBody = Utils.getStyleStringForMessage(notificationText); } else { messageBody = Utils.getStyledStringForChannel(messageContactDisplayName.getDisplayName(), channel.getName(), notificationText); } } else { if (count < 2) { messageBody = Utils.getStyleStringForMessage(notificationText); } else { messageBody = Utils.getStyledStringForContact(messageContactDisplayName.getDisplayName(), notificationText); } } return messageBody; }
/** * This method returns the receiver's name from the message object that this instance holds currently. * * @return If the message belongs to group it will return group's name and if it belongs to user, the display name of the user will be returned. */ public String getReceiver() { if (message.getGroupId() == null) { return contact.getDisplayName(); } else { if (channel != null) { if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) { Contact withUserContact = contactService.getContactById(ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey())); if (withUserContact != null) { return withUserContact.getDisplayName(); } } else { return ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId()); } } } return null; }
@Override public void afterTextChanged(Editable s) { try { if (!TextUtils.isEmpty(s.toString()) && s.toString().trim().length() > 0 && !typingStarted) { typingStarted = true; if (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()))) { Applozic.publishTypingStatus(getContext(), channel, contact, true); } } else if (s.toString().trim().length() == 0 && typingStarted) { typingStarted = false; if (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()))) { Applozic.publishTypingStatus(getContext(), channel, contact, false); } } if (listener != null) { listener.onTyping(editText, typingStarted); } } catch (Exception e) { } } });
public void afterTextChanged(Editable s) { try { if (!TextUtils.isEmpty(s.toString()) && s.toString().trim().length() > 0 && !typingStarted) { typingStarted = true; handleSendAndRecordButtonView(true); if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) { Applozic.publishTypingStatus(getContext(), channel, contact, typingStarted); } } else if (s.toString().trim().length() == 0 && typingStarted) { typingStarted = false; handleSendAndRecordButtonView(false); if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) { Applozic.publishTypingStatus(getContext(), channel, contact, typingStarted); } } } catch (Exception e) { } //sendButton.setVisibility((s == null || s.toString().trim().length() == 0) && TextUtils.isEmpty(filePath) ? View.GONE : View.VISIBLE); //attachButton.setVisibility(s == null || s.toString().trim().length() == 0 ? View.VISIBLE : View.GONE); } });
public void updateTitle() { StringBuffer stringBufferTitle = new StringBuffer(); if (contact != null) { stringBufferTitle.append(contact.getDisplayName()); } else if (channel != null) { if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) { String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey()); if (!TextUtils.isEmpty(userId)) { Contact withUserContact = appContactService.getContactById(userId); stringBufferTitle.append(withUserContact.getDisplayName()); } } else { stringBufferTitle.append(ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(getActivity()).getUserId())); } } if (stringBufferTitle != null && getActivity() != null) { setToolbarTitle(stringBufferTitle.toString()); } }
public void leaveChannel(final Channel channel) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(this). setPositiveButton(R.string.channel_exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { new ChannelAsync(channel, ChannelInfoActivity.this).execute(); } }); alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }); if (channel.getType() != null) { alertDialog.setMessage(getString(R.string.leave_channel).replace(getString(R.string.groupType_info), Channel.GroupType.BROADCAST.getValue().equals(channel.getType()) ? getString(R.string.broadcast_string) : getString(R.string.group_string))); } alertDialog.setCancelable(true); alertDialog.create().show(); }
public void deleteChannel(final Channel channel) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(this). setPositiveButton(R.string.channel_deleting, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { new ChannelMemberAdd(channel, ChannelInfoActivity.this).execute(); } }); alertDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { } }); if (channel.getType() != null) { alertDialog.setMessage(getString(R.string.delete_channel_messages_and_channel_info).replace(getString(R.string.group_name_info), channel.getName()).replace(getString(R.string.groupType_info), Channel.GroupType.BROADCAST.getValue().equals(channel.getType()) ? getString(R.string.broadcast_string) : getString(R.string.group_string))); } alertDialog.setCancelable(true); alertDialog.create().show(); }
public static String getChannelTitleName(Channel channel, String loggedInUserId) { if (!TextUtils.isEmpty(loggedInUserId)) { if (Channel.GroupType.SELLER.getValue().equals(channel.getType())) { String[] userIdSplit = new String[1]; if (!TextUtils.isEmpty(channel.getName())) { userIdSplit = channel.getName().split(":"); } if (loggedInUserId.equals(channel.getAdminKey())) { return channel.getName(); } else { return userIdSplit[0]; } } else { return channel.getName(); } } return ""; }
public void updateLastSeenStatus() { if (this.getActivity() == null) { return; } if (contact != null) { contact = appContactService.getContactById(contact.getContactIds()); } if (contact != null) { processUpdateLastSeenStatus(contact); } else if (channel != null && Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) { String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey()); if (!TextUtils.isEmpty(userId)) { Contact withUserContact = appContactService.getContactById(userId); processUpdateLastSeenStatus(withUserContact); } } }
public String getNameForInviteDialog() { if (contact != null) { return contact.getDisplayName(); } else if (channel != null) { if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) { String userId = ChannelService.getInstance(getActivity()).getGroupOfTwoReceiverUserId(channel.getKey()); if (!TextUtils.isEmpty(userId)) { Contact withUserContact = appContactService.getContactById(userId); return withUserContact.getDisplayName(); } } else { return ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(getActivity()).getUserId()); } } return ""; }
@Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { if (typingStarted) { if (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType()) || contact != null) { Intent intent = new Intent(getActivity(), ApplozicMqttIntentService.class); intent.putExtra(ApplozicMqttIntentService.CHANNEL, channel); intent.putExtra(ApplozicMqttIntentService.CONTACT, contact); intent.putExtra(ApplozicMqttIntentService.TYPING, typingStarted); ApplozicMqttIntentService.enqueueWork(getActivity(), intent); } } emoticonsFrameLayout.setVisibility(View.GONE); multimediaPopupGrid.setVisibility(View.GONE); } }
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(); } } }
public void handleSendAndRecordButtonView(boolean isSendButtonVisible) { sendButton.setVisibility(alCustomizationSettings.isRecordButton() && (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())) ? isSendButtonVisible ? View.VISIBLE : View.GONE : View.VISIBLE); recordButton.setVisibility(alCustomizationSettings.isRecordButton() && (contact != null || channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())) ? isSendButtonVisible ? View.GONE : View.VISIBLE : View.GONE); }
public void updateChannelTitle() { if (!Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) { Channel newChannel = ChannelService.getInstance(getActivity()).getChannelByChannelKey(channel.getKey()); if (newChannel != null && !TextUtils.isEmpty(channel.getName()) && !channel.getName().equals(newChannel.getName())) { title = ChannelUtils.getChannelTitleName(newChannel, MobiComUserPreference.getInstance(getActivity()).getUserId()); channel = newChannel; if (getActivity() != null) { setToolbarTitle(title); } } } }
@Override public void onFocusChange(View v, boolean hasFocus) { if (listener != null) { listener.onFocus(editText, hasFocus); } if (hasFocus && typingStarted && (contact != null || (channel != null && !Channel.GroupType.OPEN.getValue().equals(channel.getType())))) { Applozic.publishTypingStatus(getContext(), channel, contact, typingStarted); } } });