use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseService method getMetadataToUpdateToDatabaseFromGroupInfoUpdate.
// Cleanup: private
@Nullable
public Map<String, String> getMetadataToUpdateToDatabaseFromGroupInfoUpdate(GroupInfoUpdate groupInfoUpdate) {
Map<String, String> updateMetadata = groupInfoUpdate.getMetadata();
if (updateMetadata == null) {
// since no updating required
return null;
}
Channel channel = null;
if (groupInfoUpdate.getGroupId() != null && groupInfoUpdate.getGroupId() != 0) {
channel = getChannelByChannelKey(groupInfoUpdate.getGroupId());
} else if (!TextUtils.isEmpty(groupInfoUpdate.getClientGroupId())) {
channel = getChannelByClientGroupId(groupInfoUpdate.getClientGroupId());
}
if (channel != null) {
Map<String, String> existingChannelMetadata = channel.getMetadata();
if (existingChannelMetadata == null) {
existingChannelMetadata = new HashMap<>();
}
for (String key : updateMetadata.keySet()) {
String value = updateMetadata.get(key);
if (value != null) {
existingChannelMetadata.put(key, value);
}
}
// new and updated now
return existingChannelMetadata;
} else {
Log.d(TAG, "GroupInfoUpdate object doesn't have channelKey or clientGroupId.");
return null;
}
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseService method getChannel.
public Channel getChannel(Cursor cursor) {
Channel channel = new Channel();
channel.setKey(cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.CHANNEL_KEY)));
channel.setParentClientGroupId(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.PARENT_CLIENT_GROUP_ID)));
channel.setClientGroupId(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CLIENT_GROUP_ID)));
channel.setName(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME)));
channel.setAdminKey(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.ADMIN_ID)));
channel.setType(cursor.getShort(cursor.getColumnIndex(MobiComDatabaseHelper.TYPE)));
channel.setImageUrl(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CHANNEL_IMAGE_URL)));
channel.setLocalImageUri(cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CHANNEL_IMAGE_LOCAL_URI)));
int count = cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.UNREAD_COUNT));
channel.setNotificationAfterTime(cursor.getLong(cursor.getColumnIndex(MobiComDatabaseHelper.NOTIFICATION_AFTER_TIME)));
channel.setDeletedAtTime(cursor.getLong(cursor.getColumnIndex(MobiComDatabaseHelper.DELETED_AT)));
channel.setParentKey(cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.PARENT_GROUP_KEY)));
channel.setKmStatus(cursor.getInt(cursor.getColumnIndex(MobiComDatabaseHelper.CONVERSATION_STATUS)));
String metadata = cursor.getString(cursor.getColumnIndex(MobiComDatabaseHelper.CHANNEL_META_DATA));
channel.setMetadata(((Map<String, String>) GsonUtils.getObjectFromJson(metadata, Map.class)));
if (count > 0) {
channel.setUnreadCount(count);
}
return channel;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class ChannelDatabaseService method getAllChannels.
/**
* Get a list of all the channels in the local database.
*
* <p>This will include channels the current logged in user is part of
* or was a part of.
* Note: This will not return all the channels, but simply the ones synced locally.</p>
*
* @return a list of channels, empty if none present, null in case of an exception
*/
public List<Channel> getAllChannels() {
List<Channel> contactList = null;
Cursor cursor = null;
try {
SQLiteDatabase db = dbHelper.getWritableDatabase();
cursor = db.query(CHANNEL, null, null, null, null, null, MobiComDatabaseHelper.CHANNEL_DISPLAY_NAME + " asc");
contactList = getChannelList(cursor);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cursor != null) {
cursor.close();
}
dbHelper.close();
}
return contactList;
}
use of com.applozic.mobicommons.people.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class NotificationService method notifyUser.
// Cleanup: rename to a public api name eg: createApplozicNotification()
public void notifyUser(Contact contact, Channel channel, Message message, int index) {
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 if (Channel.GroupType.SUPPORT_GROUP.getValue().equals(channel.getType())) {
String userId = message.getTo();
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;
int colorResourceId = Utils.getMetaDataValueForResources(context, NOTIFICATION_COLOR_METADATA) != null ? Utils.getMetaDataValueForResources(context, NOTIFICATION_COLOR_METADATA) : -1;
Intent intent;
intent = new Intent(context, activity);
if (count < 2) {
intent.putExtra(MobiComKitConstants.MESSAGE_JSON_INTENT, GsonUtils.getJsonFromObject(message, Message.class));
} else {
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, notificationChannels.getDefaultChannelId(muteNotifications(index))).setSmallIcon(smallIconResourceId).setCategory(NotificationCompat.CATEGORY_MESSAGE).setPriority(muteNotifications(index) ? NotificationCompat.PRIORITY_LOW : NotificationCompat.PRIORITY_HIGH).setWhen(System.currentTimeMillis());
if (colorResourceId > 0) {
mBuilder.setColor(context.getResources().getColor(colorResourceId));
}
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() && !muteNotifications(index)) {
mBuilder.setVibrate(pattern);
}
if (!muteNotifications(index)) {
mBuilder.setSound(TextUtils.isEmpty(notificationFilePath) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(notificationFilePath));
}
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox in expanded layout
inboxStyle.setBigContentTitle(getNotificationTitle(count, contact, channel, message));
// 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(getSpannedText(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(getSpannedText(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, message));
mBuilder.setStyle(inboxStyle);
if (message.hasAttachment()) {
try {
InputStream in;
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 (Throwable 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.channel.Channel in project Applozic-Android-SDK by AppLozic.
the class UserWorker method enqueueWork.
public static void enqueueWork(Context context, String userId, Contact contact, Channel channel, String pairedMessageKeyString, int unreadCount, boolean updateLastSeenStatus) {
Data.Builder dataBuilder = new Data.Builder();
if (!TextUtils.isEmpty(userId)) {
dataBuilder.putString(USER_ID, userId);
}
if (contact != null) {
dataBuilder.putString(CONTACT, GsonUtils.getJsonFromObject(contact, Contact.class));
}
if (channel != null) {
dataBuilder.putString(CHANNEL, GsonUtils.getJsonFromObject(channel, Channel.class));
}
if (!TextUtils.isEmpty(pairedMessageKeyString)) {
dataBuilder.putString(PAIRED_MESSAGE_KEY_STRING, pairedMessageKeyString);
}
dataBuilder.putInt(UNREAD_COUNT, unreadCount);
dataBuilder.putBoolean(USER_LAST_SEEN_AT_STATUS, updateLastSeenStatus);
Data data = dataBuilder.build();
OneTimeWorkRequest messageWorkerRequest = new OneTimeWorkRequest.Builder(UserWorker.class).setInputData(data).build();
WorkManager.getInstance(context).enqueue(messageWorkerRequest);
}
Aggregations