use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class NotificationService method notifyUser.
public void notifyUser(Contact contact, Channel channel, Message message) {
if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
Utils.printLog(context, TAG, "Notification is disabled !!");
return;
}
Bitmap notificationIconBitmap = null;
unReadMessageList = messageDatabaseService.getUnreadMessages();
int count = appContactService.getChatConversationCount() + appContactService.getGroupConversationCount();
int totalCount = messageDatabaseService.getTotalUnreadCount();
Class activity = null;
try {
activity = Class.forName(activityToOpen);
} catch (Exception e) {
e.printStackTrace();
}
if (message.getGroupId() != 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);
}
} else {
notificationIconBitmap = appContactService.downloadGroupImage(context, channel);
}
} else {
notificationIconBitmap = appContactService.downloadContactImage(context, contact);
}
Integer smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
Intent intent;
if (count < 2) {
intent = new Intent(context, activity);
intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
} else {
intent = new Intent(context, activity);
intent.putExtra(MobiComKitConstants.QUICK_LIST, true);
}
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, MobiComKitConstants.AL_PUSH_NOTIFICATION).setSmallIcon(smallIconResourceId).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis());
mBuilder.setSound(TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
mBuilder.setGroup(GROUP_KEY);
mBuilder.setGroupSummary(true);
} else {
if (totalCount != 0) {
mBuilder.setNumber(totalCount);
}
}
mBuilder.setContentIntent(pendingIntent);
mBuilder.setAutoCancel(true);
if (ApplozicClient.getInstance(context).getVibrationOnNotification()) {
mBuilder.setVibrate(pattern);
}
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle(getNotificationTitle(count, contact, channel));
// Moves events into the expanded layout
try {
if (unReadMessageList != null) {
for (Message messageString : unReadMessageList) {
if (messageString.getGroupId() != null) {
Channel unreadChannel = ChannelService.getInstance(context).getChannelByChannelKey(messageString.getGroupId());
if (unreadChannel != null && unreadChannel.getUnreadCount() == 0) {
continue;
}
} else {
Contact unreadCount = appContactService.getContactById(messageString.getContactIds());
if (unreadCount != null && unreadCount.getUnreadCount() == 0) {
continue;
}
}
inboxStyle.addLine(getMessageBody(messageString, count, channel, contact));
}
}
// Moves the expanded layout object into the notification object.
} catch (Exception e) {
e.printStackTrace();
}
String summaryText = "";
if (count < 1) {
summaryText = "";
mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
mBuilder.setContentText(getMessageBody(message, count, channel, contact));
} else if (count >= 1 && count < 2) {
summaryText = totalCount < 2 ? totalCount + " new message " : totalCount + " new messages ";
mBuilder.setLargeIcon(notificationIconBitmap != null ? notificationIconBitmap : BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(message.getGroupId() != null ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName())));
mBuilder.setContentText(summaryText);
} else {
summaryText = totalCount + " messages from " + count + " chats";
mBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), iconResourceId));
mBuilder.setContentText(summaryText);
}
inboxStyle.setSummaryText(summaryText);
mBuilder.setContentTitle(getNotificationTitle(count, contact, channel));
mBuilder.setStyle(inboxStyle);
if (message.hasAttachment()) {
try {
InputStream in;
FileMeta fileMeta = message.getFileMetas();
HttpURLConnection httpConn = null;
if (fileMeta.getThumbnailUrl() != null) {
httpConn = new MobiComKitClientService(context).openHttpConnection(fileMeta.getThumbnailUrl());
int response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(in);
String imageName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
File file = FileClientService.getFilePath(imageName, context, "image", true);
ImageUtils.saveImageToInternalStorage(file, bitmap);
if (unReadMessageList != null && unReadMessageList.size() < 2) {
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, NOTIFICATION_ID);
notificationWithVoice.setCurrentContext(context);
notificationWithVoice.setPendingIntent(pendingIntent);
try {
if (unReadMessageList != null && unReadMessageList.size() > 0) {
notificationWithVoice.sendNotification();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class MainActivity method buildSupportContactData.
private void buildSupportContactData() {
Context context = getApplicationContext();
AppContactService appContactService = new AppContactService(context);
// avoid each time update ....
if (!appContactService.isContactExists(getString(R.string.support_contact_userId))) {
Contact contact = new Contact();
contact.setUserId(getString(R.string.support_contact_userId));
contact.setFullName(getString(R.string.support_contact_display_name));
contact.setContactNumber(getString(R.string.support_contact_number));
contact.setImageURL(getString(R.string.support_contact_image_url));
contact.setEmailId(getString(R.string.support_contact_emailId));
appContactService.add(contact);
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class ConversationServiceTest method testDeleteMessage.
@Test
public void testDeleteMessage() {
try {
Message message = (Message) GsonUtils.getObjectFromJson(MockedConstants.Message, Message.class);
Mockito.when(messageDatabaseService.deleteMessage(ArgumentMatchers.any(Message.class), ArgumentMatchers.anyString())).thenReturn("checkMe");
Mockito.when(messageClientService.deleteMessage(ArgumentMatchers.any(Message.class), ArgumentMatchers.nullable(Contact.class))).thenReturn("success");
mobiComConversationService.deleteMessage(message, new Contact());
Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteMessage(ArgumentMatchers.any(Message.class), ArgumentMatchers.nullable(String.class));
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class ConversationServiceTest method testDeleteSyncWithContactReturnSuccess.
@Test
public void testDeleteSyncWithContactReturnSuccess() {
try {
Contact contact = new Contact();
contact.setUserId("testUserId");
Mockito.when(messageClientService.syncDeleteConversationThreadFromServer(contact, null)).thenReturn("success");
Assert.assertEquals("success", mobiComConversationService.deleteSync(contact, null, null));
// Check if method is called...
Mockito.verify(messageDatabaseService, Mockito.times(1)).deleteConversation(ArgumentMatchers.anyString());
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class ConversationRunnables method syncConversation.
private void syncConversation() {
try {
MobiComConversationService mobiComConversationService = new MobiComConversationService(context);
List<Message> messages = mobiComConversationService.getLatestMessagesGroupByPeople();
UserService.getInstance(context).processSyncUserBlock();
for (Message message : messages.subList(0, Math.min(PRE_FETCH_MESSAGES_FOR, messages.size()))) {
Contact contact = null;
Channel channel = null;
if (message.getGroupId() != null) {
channel = new Channel(message.getGroupId());
} else {
contact = new Contact(message.getContactIds());
}
mobiComConversationService.getMessagesWithNetworkMetaData(1L, null, contact, channel, null, true, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations