use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class ConversationReadService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
if (intent == null) {
return;
}
MessageClientService messageClientService = new MessageClientService(getApplicationContext());
Integer unreadCount = intent.getIntExtra(UNREAD_COUNT, 0);
boolean singleMessageRead = intent.getBooleanExtra(SINGLE_MESSAGE_READ, false);
Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
if (unreadCount != 0) {
Intent readIntent = new Intent(MobiComKitConstants.APPLOZIC_UNREAD_COUNT);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(readIntent);
}
if (unreadCount != 0 || singleMessageRead) {
messageClientService.updateReadStatus(contact, channel);
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class NotificationIntentService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
if (intent != null) {
final String action = intent.getAction();
if (ACTION_AL_NOTIFICATION.equals(action)) {
String messageKey = intent.getStringExtra(MobiComKitConstants.AL_MESSAGE_KEY);
Message message = messageDatabaseService.getMessage(messageKey);
if (message != null) {
int notificationId = Utils.getLauncherIcon(getApplicationContext());
final NotificationService notificationService = new NotificationService(notificationId == 0 ? resourceArray[0] : notificationId, NotificationIntentService.this, resourceArray[1], resourceArray[2], resourceArray[3]);
if (MobiComUserPreference.getInstance(NotificationIntentService.this).isLoggedIn()) {
Channel channel = ChannelService.getInstance(NotificationIntentService.this).getChannelInfo(message.getGroupId());
Contact contact = null;
if (message.getConversationId() != null) {
ConversationService.getInstance(NotificationIntentService.this).getConversation(message.getConversationId());
}
if (message.getGroupId() == null) {
contact = appContactService.getContactById(message.getContactIds());
}
if (ApplozicClient.getInstance(NotificationIntentService.this).isNotificationStacking()) {
notificationService.notifyUser(contact, channel, message);
} else {
notificationService.notifyUserForNormalMessage(contact, channel, message);
}
}
}
}
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class NotificationService method notifyUserForNormalMessage.
public void notifyUserForNormalMessage(Contact contact, Channel channel, Message message) {
if (ApplozicClient.getInstance(context).isNotificationDisabled()) {
Utils.printLog(context, TAG, "Notification is disabled");
return;
}
String title = null;
String notificationText;
Bitmap notificationIconBitmap = null;
Contact displayNameContact = null;
if (message.getGroupId() != null) {
if (channel == null) {
return;
}
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 {
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);
}
if (message.getContentType() == Message.ContentType.LOCATION.getValue()) {
notificationText = MobiComKitConstants.LOCATION;
} else if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) {
notificationText = MobiComKitConstants.AUDIO;
} else if (message.getContentType() == Message.ContentType.VIDEO_MSG.getValue()) {
notificationText = MobiComKitConstants.VIDEO;
} else if (message.hasAttachment() && TextUtils.isEmpty(message.getMessage())) {
notificationText = MobiComKitConstants.ATTACHMENT;
} else {
notificationText = message.getMessage();
}
Class activity = null;
try {
activity = Class.forName(activityToOpen);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Integer smallIconResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_SMALL_ICON_METADATA) : iconResourceId;
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, MobiComKitConstants.AL_PUSH_NOTIFICATION);
mBuilder.setSmallIcon(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()) ? applozicClient.getDefaultChannelImage() : applozicClient.getDefaultContactImage(), "drawable", context.getPackageName()))).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(NotificationCompat.PRIORITY_MAX).setWhen(System.currentTimeMillis()).setContentTitle(title).setContentText(channel != null && !Channel.GroupType.GROUPOFTWO.getValue().equals(channel.getType()) ? displayNameContact.getDisplayName() + ": " + notificationText : notificationText).setSound(TextUtils.isEmpty(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(MobiComUserPreference.getInstance(context).getNotificationSoundFilePath()));
mBuilder.setContentIntent(pendingIntent);
mBuilder.setAutoCancel(true);
if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
int totalCount = messageDatabaseService.getTotalUnreadCount();
if (totalCount != 0) {
mBuilder.setNumber(totalCount);
}
}
if (message.hasAttachment()) {
try {
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) {
Bitmap bitmap = BitmapFactory.decodeStream(httpConn.getInputStream());
String imageName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
File file = FileClientService.getFilePath(imageName, context, "image", true);
ImageUtils.saveImageToInternalStorage(file, bitmap);
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 UserIntentService method onHandleWork.
@Override
protected void onHandleWork(@NonNull Intent intent) {
Integer unreadCount = intent.getIntExtra(UNREAD_COUNT, 0);
boolean singleMessageRead = intent.getBooleanExtra(SINGLE_MESSAGE_READ, false);
Contact contact = (Contact) intent.getSerializableExtra(CONTACT);
Channel channel = (Channel) intent.getSerializableExtra(CHANNEL);
if (unreadCount != 0 || singleMessageRead) {
messageClientService.updateReadStatus(contact, channel);
} else {
String userId = intent.getStringExtra(USER_ID);
if (!TextUtils.isEmpty(userId)) {
SyncCallService.getInstance(UserIntentService.this).processUserStatus(userId);
} else if (intent.getBooleanExtra(USER_LAST_SEEN_AT_STATUS, false)) {
mobiComConversationService.processLastSeenAtStatus();
}
}
}
use of com.applozic.mobicommons.people.contact.Contact in project Applozic-Android-SDK by AppLozic.
the class ScheduledMessageAdapter method getView.
public View getView(int position, View convertView, ViewGroup parent) {
View customView = convertView;
if (customView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
customView = inflater.inflate(R.layout.mobicom_message_row_view, null);
ImageView sentOrReceived = (ImageView) customView.findViewById(R.id.sentOrReceivedIcon);
sentOrReceived.setVisibility(View.GONE);
TextView unreadSmsTxtView = (TextView) customView.findViewById(R.id.unreadSmsCount);
unreadSmsTxtView.setVisibility(View.GONE);
}
Message messageListItem = getItem(position);
if (messageListItem != null) {
TextView smReceivers = (TextView) customView.findViewById(R.id.smReceivers);
TextView smTime = (TextView) customView.findViewById(R.id.createdAtTime);
// TextView createdAtTime = (TextView) customView.findViewById(R.id.createdAtTime);
TextView scheduledMessage = (TextView) customView.findViewById(R.id.message);
ImageView contactImage = (ImageView) customView.findViewById(R.id.contactImage);
if (smReceivers != null) {
List<String> items = Arrays.asList(messageListItem.getTo().split("\\s*,\\s*"));
Contact contact1 = ContactUtils.getContact(getContext(), items.get(0));
String contactinfo = TextUtils.isEmpty(contact1.getFirstName()) ? contact1.getContactNumber() : contact1.getFirstName();
if (items.size() > 1) {
Contact contact2 = baseContactService.getContactById(items.get(1));
contactinfo = contactinfo + " , " + (TextUtils.isEmpty(contact2.getFirstName()) ? contact2.getContactNumber() : contact2.getFirstName());
}
smReceivers.setText(contactinfo.length() > 22 ? contactinfo.substring(0, 22) + "..." : contactinfo);
String contactId = ContactUtils.getContactId(items.get(0), getContext().getContentResolver());
// Todo: Check if contactId is working or not.
Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactId);
mImageLoader.loadImage(contactUri, contactImage);
}
if (smTime != null) {
Calendar calendarForCurrent = Calendar.getInstance();
Calendar calendarForScheduled = Calendar.getInstance();
Date currentDate = new Date();
Date date = new Date(messageListItem.getScheduledAt());
calendarForCurrent.setTime(currentDate);
calendarForScheduled.setTime(date);
boolean sameDay = calendarForCurrent.get(Calendar.YEAR) == calendarForScheduled.get(Calendar.YEAR) && calendarForCurrent.get(Calendar.DAY_OF_YEAR) == calendarForScheduled.get(Calendar.DAY_OF_YEAR);
String formattedDate = sameDay ? DateFormat.getTimeInstance().format(date) : DateFormat.getDateInstance().format(date);
smTime.setText(formattedDate);
}
if (scheduledMessage != null) {
scheduledMessage.setText(messageListItem.getMessage());
}
}
return customView;
}
Aggregations