From 55bf3e4b5b4af5baa3c230ca82f74988608971a3 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Tue, 6 Aug 2019 00:49:58 -0700 Subject: Format kotlin --- .../frost/services/NotificationService.kt | 47 +++++++++++----------- .../frost/services/NotificationUtils.kt | 11 ++++- 2 files changed, 33 insertions(+), 25 deletions(-) (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt index 1d983f14..95726974 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -84,32 +84,33 @@ class NotificationService : BaseJobService() { return true } - private suspend fun sendNotifications(params: JobParameters?): Unit = withContext(Dispatchers.Default) { - val currentId = Prefs.userId - val cookies = cookieDao.selectAll() - yield() - val jobId = params?.extras?.getInt(NOTIFICATION_PARAM_ID, -1) ?: -1 - var notifCount = 0 - for (cookie in cookies) { + private suspend fun sendNotifications(params: JobParameters?): Unit = + withContext(Dispatchers.Default) { + val currentId = Prefs.userId + val cookies = cookieDao.selectAll() yield() - val current = cookie.id == currentId - if (Prefs.notificationsGeneral && - (current || Prefs.notificationAllAccounts) - ) - notifCount += fetch(jobId, NotificationType.GENERAL, cookie) - if (Prefs.notificationsInstantMessages && - (current || Prefs.notificationsImAllAccounts) - ) - notifCount += fetch(jobId, NotificationType.MESSAGE, cookie) - } + val jobId = params?.extras?.getInt(NOTIFICATION_PARAM_ID, -1) ?: -1 + var notifCount = 0 + for (cookie in cookies) { + yield() + val current = cookie.id == currentId + if (Prefs.notificationsGeneral && + (current || Prefs.notificationAllAccounts) + ) + notifCount += fetch(jobId, NotificationType.GENERAL, cookie) + if (Prefs.notificationsInstantMessages && + (current || Prefs.notificationsImAllAccounts) + ) + notifCount += fetch(jobId, NotificationType.MESSAGE, cookie) + } - L.i { "Sent $notifCount notifications" } - if (notifCount == 0 && jobId == NOTIFICATION_JOB_NOW) - generalNotification(665, R.string.no_new_notifications, BuildConfig.DEBUG) - if (notifCount > 0) { - NotificationWidget.forceUpdate(this@NotificationService) + L.i { "Sent $notifCount notifications" } + if (notifCount == 0 && jobId == NOTIFICATION_JOB_NOW) + generalNotification(665, R.string.no_new_notifications, BuildConfig.DEBUG) + if (notifCount > 0) { + NotificationWidget.forceUpdate(this@NotificationService) + } } - } /** * Implemented fetch to also notify when an error occurs diff --git a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt index 7327d098..8a8893e5 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt @@ -58,7 +58,10 @@ fun setupNotificationChannels(c: Context) { } @RequiresApi(Build.VERSION_CODES.O) -private fun NotificationManager.createNotificationChannel(id: String, name: String): NotificationChannel { +private fun NotificationManager.createNotificationChannel( + id: String, + name: String +): NotificationChannel { val channel = NotificationChannel( id, name, NotificationManager.IMPORTANCE_DEFAULT @@ -85,7 +88,11 @@ fun Context.frostNotification(id: String) = * Delegates to channels if Android O and up * Otherwise uses our provided preferences */ -fun NotificationCompat.Builder.setFrostAlert(context: Context, enable: Boolean, ringtone: String): NotificationCompat.Builder { +fun NotificationCompat.Builder.setFrostAlert( + context: Context, + enable: Boolean, + ringtone: String +): NotificationCompat.Builder { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setGroupAlertBehavior( if (enable) NotificationCompat.GROUP_ALERT_CHILDREN -- cgit v1.2.3