Reduce number of issues reported by detekt

Signed-off-by: Dariusz Olszewski <starypatyk@users.noreply.github.com>
This commit is contained in:
Dariusz Olszewski 2022-04-26 23:00:24 +02:00 committed by Andy Scherzinger
parent a234c178a8
commit b96bba47b5
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B

View File

@ -182,43 +182,43 @@ object NotificationUtils {
}
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?) {
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,
roomTokenOrId: String
): 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,
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.
// 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 {
try {
val ringtoneSettings =
LoganSquare.parse(ringtonePreferencesString, RingtoneSettings::class.java)
return ringtoneSettings.ringtoneUri
ringtoneSettings.ringtoneUri
} catch (exception: IOException) {
return Uri.parse(defaultRingtoneUri)
Uri.parse(defaultRingtoneUri)
}
}
}