|
@@ -182,43 +182,43 @@ object NotificationUtils {
|
|
}
|
|
}
|
|
|
|
|
|
fun cancelAllNotificationsForAccount(context: Context?, conversationUser: UserEntity) {
|
|
fun cancelAllNotificationsForAccount(context: Context?, conversationUser: UserEntity) {
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && conversationUser.id != -1L && context != null) {
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || conversationUser.id == -1L || context == null) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
|
|
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
|
|
- val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
- var notification: Notification?
|
|
|
|
- for (statusBarNotification in statusBarNotifications) {
|
|
|
|
- notification = statusBarNotification.notification
|
|
|
|
|
|
+ val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
+ var notification: Notification?
|
|
|
|
+ for (statusBarNotification in statusBarNotifications) {
|
|
|
|
+ notification = statusBarNotification.notification
|
|
|
|
|
|
- if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
- if (conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID)) {
|
|
|
|
- notificationManager.cancel(statusBarNotification.id)
|
|
|
|
- }
|
|
|
|
|
|
+ if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
+ if (conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID)) {
|
|
|
|
+ notificationManager.cancel(statusBarNotification.id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
fun cancelExistingNotificationWithId(context: Context?, conversationUser: UserEntity, notificationId: Long?) {
|
|
fun cancelExistingNotificationWithId(context: Context?, conversationUser: UserEntity, notificationId: Long?) {
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && conversationUser.id != -1L &&
|
|
|
|
- context != null
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || conversationUser.id == -1L || context == null) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
|
|
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
+
|
|
|
|
+ val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
+ var notification: Notification?
|
|
|
|
+ for (statusBarNotification in statusBarNotifications) {
|
|
|
|
+ notification = statusBarNotification.notification
|
|
|
|
|
|
- val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
- var notification: Notification?
|
|
|
|
- for (statusBarNotification in statusBarNotifications) {
|
|
|
|
- notification = statusBarNotification.notification
|
|
|
|
-
|
|
|
|
- if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
- if (
|
|
|
|
- conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) &&
|
|
|
|
- notificationId == notification.extras.getLong(BundleKeys.KEY_NOTIFICATION_ID)
|
|
|
|
- ) {
|
|
|
|
- notificationManager.cancel(statusBarNotification.id)
|
|
|
|
- }
|
|
|
|
|
|
+ if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
+ if (
|
|
|
|
+ conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) &&
|
|
|
|
+ notificationId == notification.extras.getLong(BundleKeys.KEY_NOTIFICATION_ID)
|
|
|
|
+ ) {
|
|
|
|
+ notificationManager.cancel(statusBarNotification.id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -229,24 +229,23 @@ object NotificationUtils {
|
|
conversationUser: UserEntity,
|
|
conversationUser: UserEntity,
|
|
roomTokenOrId: String
|
|
roomTokenOrId: String
|
|
): StatusBarNotification? {
|
|
): StatusBarNotification? {
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && conversationUser.id != -1L &&
|
|
|
|
- context != null
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || conversationUser.id == -1L || context == null) {
|
|
|
|
+ return null
|
|
|
|
+ }
|
|
|
|
|
|
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
|
|
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
+
|
|
|
|
+ val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
+ var notification: Notification?
|
|
|
|
+ for (statusBarNotification in statusBarNotifications) {
|
|
|
|
+ notification = statusBarNotification.notification
|
|
|
|
|
|
- val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
- var notification: Notification?
|
|
|
|
- for (statusBarNotification in statusBarNotifications) {
|
|
|
|
- notification = statusBarNotification.notification
|
|
|
|
-
|
|
|
|
- if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
- if (
|
|
|
|
- conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) &&
|
|
|
|
- roomTokenOrId == statusBarNotification.notification.extras.getString(BundleKeys.KEY_ROOM_TOKEN)
|
|
|
|
- ) {
|
|
|
|
- return statusBarNotification
|
|
|
|
- }
|
|
|
|
|
|
+ if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
+ if (
|
|
|
|
+ conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) &&
|
|
|
|
+ roomTokenOrId == statusBarNotification.notification.extras.getString(BundleKeys.KEY_ROOM_TOKEN)
|
|
|
|
+ ) {
|
|
|
|
+ return statusBarNotification
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -259,25 +258,22 @@ object NotificationUtils {
|
|
conversationUser: UserEntity,
|
|
conversationUser: UserEntity,
|
|
roomTokenOrId: String
|
|
roomTokenOrId: String
|
|
) {
|
|
) {
|
|
- if (
|
|
|
|
- Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
|
|
|
- conversationUser.id != -1L &&
|
|
|
|
- context != null
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || conversationUser.id == -1L || context == null) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
|
|
- val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
|
|
+ val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
|
|
+
|
|
|
|
+ val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
+ var notification: Notification?
|
|
|
|
+ for (statusBarNotification in statusBarNotifications) {
|
|
|
|
+ notification = statusBarNotification.notification
|
|
|
|
|
|
- val statusBarNotifications = notificationManager.activeNotifications
|
|
|
|
- var notification: Notification?
|
|
|
|
- for (statusBarNotification in statusBarNotifications) {
|
|
|
|
- notification = statusBarNotification.notification
|
|
|
|
-
|
|
|
|
- if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
- if (conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) &&
|
|
|
|
- roomTokenOrId == statusBarNotification.notification.extras.getString(BundleKeys.KEY_ROOM_TOKEN)
|
|
|
|
- ) {
|
|
|
|
- notificationManager.cancel(statusBarNotification.id)
|
|
|
|
- }
|
|
|
|
|
|
+ if (notification != null && !notification.extras.isEmpty) {
|
|
|
|
+ if (conversationUser.id == notification.extras.getLong(BundleKeys.KEY_INTERNAL_USER_ID) &&
|
|
|
|
+ roomTokenOrId == statusBarNotification.notification.extras.getString(BundleKeys.KEY_ROOM_TOKEN)
|
|
|
|
+ ) {
|
|
|
|
+ notificationManager.cancel(statusBarNotification.id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -297,15 +293,15 @@ object NotificationUtils {
|
|
// Notification channel will not be available when starting the application for the first time.
|
|
// Notification channel will not be available when starting the application for the first time.
|
|
// Ringtone uris are required to register the notification channels -> get uri from preferences.
|
|
// Ringtone uris are required to register the notification channels -> get uri from preferences.
|
|
}
|
|
}
|
|
- if (TextUtils.isEmpty(ringtonePreferencesString)) {
|
|
|
|
- return Uri.parse(defaultRingtoneUri)
|
|
|
|
|
|
+ return if (TextUtils.isEmpty(ringtonePreferencesString)) {
|
|
|
|
+ Uri.parse(defaultRingtoneUri)
|
|
} else {
|
|
} else {
|
|
try {
|
|
try {
|
|
val ringtoneSettings =
|
|
val ringtoneSettings =
|
|
LoganSquare.parse(ringtonePreferencesString, RingtoneSettings::class.java)
|
|
LoganSquare.parse(ringtonePreferencesString, RingtoneSettings::class.java)
|
|
- return ringtoneSettings.ringtoneUri
|
|
|
|
|
|
+ ringtoneSettings.ringtoneUri
|
|
} catch (exception: IOException) {
|
|
} catch (exception: IOException) {
|
|
- return Uri.parse(defaultRingtoneUri)
|
|
|
|
|
|
+ Uri.parse(defaultRingtoneUri)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|