use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class VideoCallNotificationHelper method sendVideoCallStarted.
// public void updateVideoMessageStatus(String callId,String type){
// messageDatabaseService.updateVideoCallMetaData(callId,type);
// }
public void sendVideoCallStarted(Contact contact, String videoCallId) {
Message statusMessage = getVideoCallStatusMessage(contact);
statusMessage.setMetadata(getVideoCallStartedMap());
statusMessage.setMessage(videoCallId);
conversationService.sendMessage(statusMessage, MessageIntentService.class);
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class VideoCallNotificationHelper method sendVideoCallRequest.
public String sendVideoCallRequest(Contact contact, boolean audioOnly) {
Message notificationMessage = getNotificationMessage(contact);
this.videoCallId = MobiComUserPreference.getInstance(context).getDeviceKeyString() + ":" + notificationMessage.getCreatedAtTime();
notificationMessage.setMessage(videoCallId);
notificationMessage.setMetadata(getDialCallMetaData());
if (audioOnly) {
notificationMessage.getMetadata().put(CALL_AUDIO_ONLY, "true");
}
conversationService.sendMessage(notificationMessage, MessageIntentService.class);
return videoCallId;
}
use of com.applozic.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class ApplozicBroadcastReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Message message = null;
String messageJson = intent.getStringExtra(MobiComKitConstants.MESSAGE_JSON_INTENT);
if (!TextUtils.isEmpty(messageJson)) {
message = (Message) GsonUtils.getObjectFromJson(messageJson, Message.class);
}
Utils.printLog(context, TAG, "Received broadcast, action: " + action + ", message: " + message);
if (message != null && !message.isSentToMany()) {
if (!message.isTypeOutbox()) {
applozicUIListener.onMessageReceived(message);
}
} else if (message != null && message.isSentToMany() && BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString().equals(intent.getAction())) {
for (String toField : message.getTo().split(",")) {
Message singleMessage = new Message(message);
singleMessage.setKeyString(message.getKeyString());
singleMessage.setTo(toField);
singleMessage.processContactIds(context);
if (!message.isTypeOutbox()) {
applozicUIListener.onMessageReceived(message);
}
}
}
String keyString = intent.getStringExtra("keyString");
String userId = message != null ? message.getContactIds() : "";
if (BroadcastService.INTENT_ACTIONS.INSTRUCTION.toString().equals(action)) {
// InstructionUtil.showInstruction(context, intent.getIntExtra("resId", -1), intent.getBooleanExtra("actionable", false), R.color.instruction_color);
} else if (BroadcastService.INTENT_ACTIONS.UPDATE_CHANNEL_NAME.toString().equals(action)) {
// applozicUIListener.onChannelNameUpdated();
} else if (BroadcastService.INTENT_ACTIONS.FIRST_TIME_SYNC_COMPLETE.toString().equals(action)) {
// applozicUIListener.downloadConversations(true);
} else if (BroadcastService.INTENT_ACTIONS.LOAD_MORE.toString().equals(action)) {
applozicUIListener.onLoadMore(intent.getBooleanExtra("loadMore", true));
} else if (BroadcastService.INTENT_ACTIONS.MESSAGE_SYNC_ACK_FROM_SERVER.toString().equals(action)) {
applozicUIListener.onMessageSent(message);
} else if (BroadcastService.INTENT_ACTIONS.SYNC_MESSAGE.toString().equals(intent.getAction())) {
applozicUIListener.onMessageSync(message, keyString);
} else if (BroadcastService.INTENT_ACTIONS.DELETE_MESSAGE.toString().equals(intent.getAction())) {
userId = intent.getStringExtra("contactNumbers");
applozicUIListener.onMessageDeleted(keyString, userId);
} else if (BroadcastService.INTENT_ACTIONS.MESSAGE_DELIVERY.toString().equals(action) || BroadcastService.INTENT_ACTIONS.MESSAGE_READ_AND_DELIVERED.toString().equals(action)) {
applozicUIListener.onMessageDelivered(message, userId);
} else if (BroadcastService.INTENT_ACTIONS.MESSAGE_DELIVERY_FOR_CONTACT.toString().equals(action)) {
applozicUIListener.onAllMessagesDelivered(intent.getStringExtra("contactId"));
} else if (BroadcastService.INTENT_ACTIONS.MESSAGE_READ_AND_DELIVERED_FOR_CONTECT.toString().equals(action)) {
applozicUIListener.onAllMessagesRead(intent.getStringExtra("contactId"));
} else if (BroadcastService.INTENT_ACTIONS.DELETE_CONVERSATION.toString().equals(action)) {
String contactNumber = intent.getStringExtra("contactNumber");
Integer channelKey = intent.getIntExtra("channelKey", 0);
String response = intent.getStringExtra("response");
/* Contact contact = null;
if (contactNumber != null) {
contact = baseContactService.getContactById(contactNumber);
}*/
applozicUIListener.onConversationDeleted(contactNumber, channelKey, response);
} else if (BroadcastService.INTENT_ACTIONS.UPLOAD_ATTACHMENT_FAILED.toString().equals(action) && message != null) {
// applozicUIListener.updateUploadFailedStatus(message);
} else if (BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_DONE.toString().equals(action) && message != null) {
// applozicUIListener.updateDownloadStatus(message);
} else if (BroadcastService.INTENT_ACTIONS.MESSAGE_ATTACHMENT_DOWNLOAD_FAILD.toString().equals(action) && message != null) {
// applozicUIListener.updateDownloadFailed(message);
} else if (BroadcastService.INTENT_ACTIONS.UPDATE_TYPING_STATUS.toString().equals(action)) {
String currentUserId = intent.getStringExtra("userId");
String isTyping = intent.getStringExtra("isTyping");
applozicUIListener.onUpdateTypingStatus(currentUserId, isTyping);
} else if (BroadcastService.INTENT_ACTIONS.UPDATE_LAST_SEEN_AT_TIME.toString().equals(action)) {
applozicUIListener.onUpdateLastSeen(intent.getStringExtra("contactId"));
} else if (BroadcastService.INTENT_ACTIONS.MQTT_DISCONNECTED.toString().equals(action)) {
applozicUIListener.onMqttDisconnected();
} else if (BroadcastService.INTENT_ACTIONS.CHANNEL_SYNC.toString().equals(action)) {
applozicUIListener.onChannelUpdated();
} else if (BroadcastService.INTENT_ACTIONS.UPDATE_TITLE_SUBTITLE.toString().equals(action)) {
// applozicUIListener.onChannelTitleUpdated();
} else if (BroadcastService.INTENT_ACTIONS.CONVERSATION_READ.toString().equals(action)) {
String currentId = intent.getStringExtra("currentId");
boolean isGroup = intent.getBooleanExtra("isGroup", false);
applozicUIListener.onConversationRead(currentId, isGroup);
} else if (BroadcastService.INTENT_ACTIONS.UPDATE_USER_DETAIL.toString().equals(action)) {
applozicUIListener.onUserDetailUpdated(intent.getStringExtra("contactId"));
} else if (BroadcastService.INTENT_ACTIONS.MESSAGE_METADATA_UPDATE.toString().equals(action)) {
applozicUIListener.onMessageMetadataUpdated(keyString);
}
}
use of com.applozic.mobicomkit.api.conversation.Message 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.mobicomkit.api.conversation.Message in project Applozic-Android-SDK by AppLozic.
the class AttachmentDownloader method loadAttachmentImage.
public void loadAttachmentImage(Message message, Context context) {
File file = null;
try {
InputStream inputStream = null;
FileMeta fileMeta = message.getFileMetas();
String contentType = fileMeta.getContentType();
String fileKey = fileMeta.getKeyString();
HttpURLConnection connection = null;
String fileName = null;
if (message.getContentType() == Message.ContentType.AUDIO_MSG.getValue()) {
fileName = fileMeta.getName();
} else {
fileName = FileUtils.getName(fileMeta.getName()) + message.getCreatedAtTime() + "." + FileUtils.getFileFormat(fileMeta.getName());
}
file = FileClientService.getFilePath(fileName, context.getApplicationContext(), contentType);
if (!file.exists()) {
if (ApplozicClient.getInstance(context).isCustomStorageServiceEnabled() && !TextUtils.isEmpty(message.getFileMetas().getUrl())) {
connection = openHttpConnection(fileMeta.getUrl());
} else {
connection = openHttpConnection(new MobiComKitClientService(context).getFileUrl() + fileMeta.getBlobKeyString());
}
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = connection.getInputStream();
} else {
// TODO: Error Handling...
Utils.printLog(context, TAG, "Got Error response while uploading file : " + connection.getResponseCode());
return;
}
OutputStream output = new FileOutputStream(file);
byte[] data = new byte[1024];
long totalSize = fileMeta.getSize();
long progressCount = 0;
int count = 0;
int prevPrecentage = 0;
while ((count = inputStream.read(data)) != -1) {
output.write(data, 0, count);
progressCount = progressCount + count;
long percentage = progressCount * 100 / totalSize;
android.os.Message msg = new android.os.Message();
// Message code 2 represents image is successfully downloaded....
if (percentage + 1 != prevPrecentage) {
mPhotoTask.handleDownloadState(5);
mPhotoTask.downloadProgress((int) percentage + 1);
msg.what = 5;
msg.arg1 = (int) percentage + 1;
msg.obj = this;
// msg.sendToTarget();
prevPrecentage = (int) percentage + 1;
}
if ((percentage % 10 == 0)) {
msg.what = 1;
msg.obj = this;
}
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
output.flush();
output.close();
inputStream.close();
}
// Todo: Fix this, so that attach package can be moved to mobicom mobicom.
new MessageDatabaseService(context).updateInternalFilePath(message.getKeyString(), file.getAbsolutePath());
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add(file.getAbsolutePath());
message.setFilePaths(arrayList);
MediaScannerConnection.scanFile(mPhotoTask.getContext(), new String[] { file.toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
} catch (FileNotFoundException ex) {
ex.printStackTrace();
Utils.printLog(context, TAG, "File not found on server");
} catch (Exception ex) {
// If partial file got created delete it, we try to download it again
if (file != null && file.exists()) {
Utils.printLog(context, TAG, " Exception occured while downloading :" + file.getAbsolutePath());
file.delete();
}
ex.printStackTrace();
Utils.printLog(context, TAG, "Exception fetching file from server");
}
}
Aggregations