use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class QuickConversationAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == 2) {
FooterViewHolder myHolder = (FooterViewHolder) holder;
myHolder.infoBroadCast.setVisibility(View.GONE);
} else {
Myholder myholder = (Myholder) holder;
final Message message = getItem(position);
myholder.smTime.setVisibility(View.GONE);
if (message != null) {
List<String> items = null;
List<String> userIds = null;
final Channel channel = ChannelDatabaseService.getInstance(context).getChannelByChannelKey(message.getGroupId());
if (channel == null && message.getGroupId() == null) {
items = Arrays.asList(message.getTo().split("\\s*,\\s*"));
if (!TextUtils.isEmpty(message.getContactIds())) {
userIds = Arrays.asList(message.getContactIds().split("\\s*,\\s*"));
}
}
final Contact contactReceiver = contactService.getContactReceiver(items, userIds);
showSenderNameIfRequired(myholder, message);
myholder.contactImage.setVisibility(View.GONE);
myholder.alphabeticTextView.setVisibility(View.GONE);
if (contactReceiver != null) {
String contactInfo = contactReceiver.getDisplayName();
if (items != null && items.size() > 1) {
Contact contact2 = contactService.getContactById(items.get(1));
contactInfo = TextUtils.isEmpty(contactReceiver.getFirstName()) ? contactReceiver.getContactNumber() : contactReceiver.getFirstName() + ", " + (TextUtils.isEmpty(contact2.getFirstName()) ? contact2.getContactNumber() : contact2.getFirstName()) + (items.size() > 2 ? " & others" : "");
}
myholder.smReceivers.setText(contactInfo);
contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
processContactImage(contactReceiver, myholder.onlineTextView, myholder.alphabeticTextView, myholder.contactImage);
} else if (message.getGroupId() != null) {
if (channel != null && Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
contactImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
Contact withUserContact = contactService.getContactById(ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey()));
if (withUserContact != null) {
myholder.smReceivers.setText(withUserContact.getDisplayName());
processContactImage(withUserContact, myholder.onlineTextView, myholder.alphabeticTextView, myholder.contactImage);
}
}
} else {
if (channel != null && Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
channelImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
myholder.contactImage.setImageResource(R.drawable.applozic_ic_contact_picture_holo_light);
} else {
channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
myholder.contactImage.setImageResource(R.drawable.applozic_group_icon);
}
myholder.smReceivers.setText(ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId()));
myholder.alphabeticTextView.setVisibility(View.GONE);
myholder.contactImage.setVisibility(View.VISIBLE);
if (channel != null && !TextUtils.isEmpty(channel.getImageUrl())) {
channelImageLoader.loadImage(channel, myholder.contactImage);
} else if (channel != null && channel.isBroadcastMessage()) {
myholder.contactImage.setImageResource(R.drawable.applozic_ic_applozic_broadcast);
} else if (channel != null && Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
channelImageLoader.setLoadingImage(R.drawable.applozic_ic_contact_picture_holo_light);
} else {
channelImageLoader.setLoadingImage(R.drawable.applozic_group_icon);
}
}
}
myholder.onlineTextView.setVisibility(View.GONE);
if (alCustomizationSettings.isOnlineStatusMasterList()) {
myholder.onlineTextView.setVisibility(contactReceiver != null && contactReceiver.isOnline() ? View.VISIBLE : View.GONE);
}
if (myholder.attachedFile != null) {
myholder.attachedFile.setText("");
myholder.attachedFile.setVisibility(View.GONE);
}
if (myholder.attachmentIcon != null) {
myholder.attachmentIcon.setVisibility(View.GONE);
}
if (message.isVideoCallMessage()) {
createVideoCallView(message, myholder.attachmentIcon, myholder.messageTextView);
} else if (message.hasAttachment() && myholder.attachmentIcon != null && !(message.getContentType() == Message.ContentType.TEXT_URL.getValue())) {
// Todo: handle it for fileKeyStrings when filePaths is empty
String filePath = message.getFileMetas() == null && message.getFilePaths() != null ? message.getFilePaths().get(0).substring(message.getFilePaths().get(0).lastIndexOf("/") + 1) : message.getFileMetas() != null ? message.getFileMetas().getName() : "";
myholder.attachmentIcon.setVisibility(View.VISIBLE);
myholder.attachmentIcon.setImageResource(R.drawable.applozic_ic_action_attachment);
myholder.messageTextView.setText(filePath);
} else if (myholder.attachmentIcon != null && message.getContentType() == Message.ContentType.LOCATION.getValue()) {
myholder.attachmentIcon.setVisibility(View.VISIBLE);
myholder.attachmentIcon.setImageResource(R.drawable.mobicom_notification_location_icon);
myholder.messageTextView.setText(Utils.getString(context, R.string.Location));
} else if (message.getContentType() == Message.ContentType.PRICE.getValue()) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, alCustomizationSettings.getConversationMentionSpanColor()));
spannableStringBuilder.insert(0, ConversationUIService.FINAL_PRICE_TEXT);
myholder.messageTextView.setText(EmoticonUtils.getSmiledText(context, spannableStringBuilder, emojiconHandler));
} else if (message.getContentType() == Message.ContentType.TEXT_HTML.getValue()) {
myholder.messageTextView.setText(Html.fromHtml(message.getMessage()));
} else {
Spannable messageSpannable = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, alCustomizationSettings.getConversationMentionSpanColor());
CharSequence messageSpannableSubString = (!TextUtils.isEmpty(messageSpannable.toString()) ? messageSpannable.subSequence(0, Math.min(messageSpannable.length(), 50)) : new SpannableString(Utils.EMPTY_STRING));
myholder.messageTextView.setText(EmoticonUtils.getSmiledText(context, messageSpannableSubString, emojiconHandler));
}
if (myholder.sentOrReceived != null) {
if (message.isCall()) {
myholder.sentOrReceived.setImageResource(R.drawable.applozic_ic_action_call_holo_light);
myholder.messageTextView.setTextColor(Utils.getColor(context, message.isIncomingCall() ? R.color.incoming_call : R.color.outgoing_call));
} else if (getItemViewType(position) == 0) {
myholder.sentOrReceived.setImageResource(R.drawable.mobicom_social_forward);
} else {
myholder.sentOrReceived.setImageResource(R.drawable.mobicom_social_reply);
}
}
if (myholder.createdAtTime != null) {
myholder.createdAtTime.setText(DateUtils.getFormattedDateAndTime(context, message.getCreatedAtTime(), alCustomizationSettings.getDateFormatCustomization().getSameDayTimeTemplate(), alCustomizationSettings.getDateFormatCustomization().getOtherDayDateTemplate(), R.string.JUST_NOW, R.plurals.MINUTES, R.plurals.HOURS));
}
int messageUnReadCount = 0;
if (message.getGroupId() == null && contactReceiver != null && !TextUtils.isEmpty(contactReceiver.getContactIds())) {
messageUnReadCount = messageDatabaseService.getUnreadMessageCountForContact(contactReceiver.getContactIds());
} else if (channel != null && channel.getKey() != null && channel.getKey() != 0) {
messageUnReadCount = messageDatabaseService.getUnreadMessageCountForChannel(channel.getKey());
}
if (messageUnReadCount > 0) {
myholder.unReadCountTextView.setVisibility(View.VISIBLE);
myholder.unReadCountTextView.setText(String.valueOf(messageUnReadCount));
} else {
myholder.unReadCountTextView.setVisibility(View.GONE);
}
Spannable mentionsMessageString = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, alCustomizationSettings.getConversationMentionSpanColor());
int startIndex = indexOfSearchQuery(mentionsMessageString.toString());
if (startIndex != -1) {
final SpannableString highlightedName = new SpannableString(mentionsMessageString);
// Sets the span to start at the starting point of the match and end at "length"
// characters beyond the starting point
highlightedName.setSpan(highlightTextSpan, startIndex, startIndex + searchString.toString().length(), 0);
myholder.messageTextView.setText(highlightedName);
}
}
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelFragment method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
final Cursor cursor = mAdapter.getCursor();
// Moves to the Cursor row corresponding to the ListView item that was clicked
cursor.moveToPosition(position);
Channel channel = ChannelDatabaseService.getInstance(getContext()).getChannel(cursor);
mOnChannelSelectedListener.onGroupSelected(channel);
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class MobiComKitPeopleActivity method onCustomContactSelected.
@Override
public void onCustomContactSelected(final Contact contact) {
Intent intent = null;
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (contact.isBlocked()) {
Toast.makeText(this, getString(R.string.user_is_blocked), Toast.LENGTH_SHORT).show();
return;
}
if ("text/plain".equals(type)) {
intent = new Intent(this, ConversationActivity.class);
intent.putExtra(USER_ID, contact.getUserId());
intent.putExtra(ConversationUIService.DEFAULT_TEXT, intentExtra.getStringExtra(Intent.EXTRA_TEXT));
startActivity(intent);
finish();
} else if (type.startsWith("image/") || type.startsWith("audio/") || type.startsWith("video/")) {
final Uri fileUri = (Uri) intentExtra.getParcelableExtra(Intent.EXTRA_STREAM);
long maxSize = alCustomizationSettings.getMaxAttachmentSizeAllowed() * 1024 * 1024;
if (FileUtils.isMaxUploadSizeReached(this, fileUri, maxSize)) {
Toast.makeText(this, getString(R.string.info_attachment_max_allowed_file_size), Toast.LENGTH_LONG).show();
return;
}
if (getApplicationContext() instanceof AttachmentFilteringListener) {
((AttachmentFilteringListener) getApplicationContext()).onAttachmentSelected(this, fileUri, new AlCallback() {
@Override
public void onSuccess(Object response) {
processAttachmentUri(fileUri, contact, null);
}
@Override
public void onError(Object error) {
Utils.printLog(getApplicationContext(), TAG, "Error in file : " + GsonUtils.getJsonFromObject(error, Object.class));
}
});
} else {
processAttachmentUri(fileUri, contact, null);
}
}
} else {
if (ApplozicClient.getInstance(this).isStartGroupOfTwo()) {
ProgressDialog progressDialog = ProgressDialog.show(this, "", getString(R.string.please_wait_creating_group_of_two), true);
AlTask.execute(new AlGroupOfTwoCreateTask(MobiComKitPeopleActivity.this, MobiComUserPreference.getInstance(this).getParentGroupKey(), contact, new AlGroupOfTwoCreateTask.ChannelCreateListener() {
@Override
public void onSuccess(@NonNull Channel channel) {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (channel != null) {
Intent intent = new Intent(MobiComKitPeopleActivity.this, ConversationActivity.class);
intent.putExtra(ConversationUIService.GROUP_ID, channel.getKey());
intent.putExtra(ConversationUIService.GROUP_NAME, channel.getName());
startActivity(intent);
}
}
@Override
public void onFailure() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}));
} else {
intent = new Intent();
intent.putExtra(USER_ID, contact.getUserId());
finishActivity(intent);
}
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseServiceTest method addAndRetrieveChannels.
// channel methods >>
@Test
public void addAndRetrieveChannels() {
// getAllChannels for null
assertThat(channelDatabaseService.getAllChannels()).isEmpty();
channelUserMapper = new ChannelUserMapper();
// for channel1
channelUserMapper.setKey(123451);
channelUserMapper.setUserKey("clientId");
channelUserMapper.setUnreadCount(20);
channelUserMapper.setStatus((short) 2);
channelUserMapper.setParentKey(123);
channelUserMapper.setRole(4);
// add two channels
channelDatabaseService.addChannel(channel);
channelDatabaseService.addChannel(channel1);
// test addChannel and getChannelByClientId and getChannelByChannelKey
Channel actualChannelRetrievedByClientGroupId = channelDatabaseService.getChannelByClientGroupId(channel.getClientGroupId());
assertThat(actualChannelRetrievedByClientGroupId.toString()).isEqualTo(channel.toString());
Channel actualChannelRetrievedByChannelKey = channelDatabaseService.getChannelByChannelKey(channel.getKey());
assertThat(actualChannelRetrievedByChannelKey.toString()).isEqualTo(channel.toString());
assertThat(channelDatabaseService.getChannelByChannelKey(999)).isNull();
assertThat(channelDatabaseService.getChannelByClientGroupId("doesn't-exist")).isNull();
// add more channels
channelDatabaseService.addChannel(channel2);
channelDatabaseService.addChannel(channel3);
// test getAllChannels
List<Channel> actualChannelList = channelDatabaseService.getAllChannels();
assertThat(actualChannelList.get(0).toString()).isEqualTo(channel2.toString());
assertThat(actualChannelList.get(1).toString()).isEqualTo(channel1.toString());
assertThat(actualChannelList.get(2).toString()).isEqualTo(channel3.toString());
assertThat(actualChannelList.get(3).toString()).isEqualTo(channel.toString());
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseServiceTest method closeDb.
@After
public void closeDb() throws IOException {
List<Channel> channelList = channelDatabaseService.getAllChannels();
for (Channel channel : channelList) {
channelDatabaseService.deleteChannel(channel.getKey());
channelDatabaseService.deleteChannelUserMappers(channel.getKey());
}
dbHelper.delDatabase();
dbHelper.close();
}
Aggregations