use of com.applozic.mobicommons.people.contact.Contact 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;
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MobiComMessageService method prepareMessage.
// Cleanup: private
public Message prepareMessage(Message messageToProcess, String tofield) {
Message message = new Message(messageToProcess);
message.setMessageId(messageToProcess.getMessageId());
message.setKeyString(messageToProcess.getKeyString());
message.setPairedMessageKeyString(messageToProcess.getPairedMessageKeyString());
if (message.getMessage() != null && PersonalizedMessage.isPersonalized(message.getMessage())) {
Contact contact = null;
if (message.getGroupId() == null) {
contact = baseContactService.getContactById(tofield);
}
if (contact != null) {
message.setMessage(PersonalizedMessage.prepareMessageFromTemplate(message.getMessage(), contact));
}
}
return message;
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class NotificationService method getMessageBody.
// Cleanup: private
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 = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, null).toString();
}
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;
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class NotificationService method notifyUserForNormalMessage.
// Cleanup: rename to a public api method eg: createApplozicMessageNotification()
public void notifyUserForNormalMessage(Contact contact, Channel channel, Message message, int index) {
String notificationText;
NotificationInfo notificationInfo = getNotificationInfo(contact, channel, message);
if (notificationInfo == null) {
return;
}
Bitmap notificationIconBitmap = notificationInfo.notificationIconBitmap;
Contact displayNameContact = notificationInfo.displayNameContact;
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 = MentionHelper.getMessageSpannableStringForMentionsDisplay(context, message, false, null).toString();
}
Class activity = null;
try {
activity = Class.forName(activityToOpen);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Intent intent = new Intent(context, activity);
intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
if (applozicClient.isChatListOnNotificationIsHidden()) {
intent.putExtra("takeOrder", true);
}
if (applozicClient.isContextBasedChat()) {
intent.putExtra("contextBasedChat", true);
}
intent.putExtra("sms_body", "text");
intent.setType("vnd.android-dir/mms-sms");
PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) (System.currentTimeMillis() & 0xfffffff), intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, notificationChannels.getDefaultChannelId(muteNotifications(index)));
mBuilder.setSmallIcon(notificationInfo.smallIconResourceId).setLargeIcon(ApplozicClient.getInstance(context).isShowAppIconInNotification() ? BitmapFactory.decodeResource(context.getResources(), iconResourceId) : notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(channel != null && !(Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) || Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName()))).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(muteNotifications(index) ? NotificationCompat.PRIORITY_LOW : NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis()).setContentTitle(notificationInfo.title).setContentText(channel != null && !(Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) || Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) ? (displayNameContact != null ? (displayNameContact.getDisplayName() + ": " + getSpannedText(notificationText)) : "" + getSpannedText(notificationText)) : getSpannedText(notificationText));
mBuilder.setContentIntent(pendingIntent);
mBuilder.setAutoCancel(true);
if (notificationInfo.colorResourceId != null && notificationInfo.colorResourceId > 0) {
mBuilder.setColor(context.getResources().getColor(notificationInfo.colorResourceId));
}
if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
int totalCount = messageDatabaseService.getTotalUnreadCount();
if (totalCount != 0) {
mBuilder.setNumber(totalCount);
}
}
if (!muteNotifications(index)) {
mBuilder.setSound(TextUtils.isEmpty(notificationFilePath) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(notificationFilePath));
}
if (message.hasAttachment()) {
try {
FileMeta fileMeta = message.getFileMetas();
HttpURLConnection httpConn = null;
if (fileMeta.getThumbnailBlobKey() != null) {
Bitmap bitmap = new FileClientService(context).downloadAndSaveThumbnailImage(context, message, 200, 200);
mBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
WearableNotificationWithVoice notificationWithVoice = new WearableNotificationWithVoice(mBuilder, wearable_action_title, wearable_action_label, wearable_send_icon, message.getGroupId() != null ? String.valueOf(message.getGroupId()).hashCode() : message.getContactIds().hashCode());
notificationWithVoice.setCurrentContext(context);
notificationWithVoice.setPendingIntent(pendingIntent);
try {
notificationWithVoice.sendNotification();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class NotificationService method getNotificationInfo.
// Cleanup: private
private NotificationInfo getNotificationInfo(Contact contact, Channel channel, Message message) {
if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
Utils.printLog(context, TAG, "Notification is disabled");
return null;
}
String title = null;
Bitmap notificationIconBitmap = null;
Contact displayNameContact = null;
if (message.getGroupId() != null) {
if (channel == null) {
return null;
}
if (Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType())) {
String userId = ChannelService.getInstance(context).getGroupOfTwoReceiverUserId(channel.getKey());
if (!TextUtils.isEmpty(userId)) {
Contact newContact = appContactService.getContactById(userId);
notificationIconBitmap = appContactService.downloadContactImage(context, newContact);
title = newContact.getDisplayName();
}
} else if (Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
String userId = message.getTo();
if (!TextUtils.isEmpty(userId)) {
Contact newContact = appContactService.getContactById(userId);
notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
title = newContact.getDisplayName();
}
} else {
displayNameContact = appContactService.getContactById(message.getTo());
title = ChannelUtils.getChannelTitleName(channel, MobiComUserPreference.getInstance(context).getUserId());
notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
}
} else {
title = contact.getDisplayName();
notificationIconBitmap = appContactService.downloadContactImage(context, contact);
}
NotificationInfo notificationInfo = new NotificationInfo();
notificationInfo.displayNameContact = displayNameContact;
notificationInfo.notificationIconBitmap = notificationIconBitmap;
notificationInfo.smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
notificationInfo.colorResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_COLOR_METADATA);
notificationInfo.title = title;
return notificationInfo;
}
Aggregations