diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt | 55 |
1 files changed, 38 insertions, 17 deletions
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 f15df482..4ede5163 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationService.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.services import android.app.job.JobParameters @@ -31,10 +47,12 @@ class NotificationService : JobService() { override fun onStopJob(params: JobParameters?): Boolean { val time = System.currentTimeMillis() - startTime L.d { "Notification service has finished abruptly in $time ms" } - frostEvent("NotificationTime", - "Type" to "Service force stop", - "IM Included" to Prefs.notificationsInstantMessages, - "Duration" to time) + frostEvent( + "NotificationTime", + "Type" to "Service force stop", + "IM Included" to Prefs.notificationsInstantMessages, + "Duration" to time + ) future?.cancel(true) future = null return false @@ -43,10 +61,12 @@ class NotificationService : JobService() { fun finish(params: JobParameters?) { val time = System.currentTimeMillis() - startTime L.i { "Notification service has finished in $time ms" } - frostEvent("NotificationTime", - "Type" to "Service", - "IM Included" to Prefs.notificationsInstantMessages, - "Duration" to time) + frostEvent( + "NotificationTime", + "Type" to "Service", + "IM Included" to Prefs.notificationsInstantMessages, + "Duration" to time + ) jobFinished(params, false) future?.cancel(true) future = null @@ -61,11 +81,13 @@ class NotificationService : JobService() { var notifCount = 0 cookies.forEach { val current = it.id == currentId - if (Prefs.notificationsGeneral - && (current || Prefs.notificationAllAccounts)) + if (Prefs.notificationsGeneral && + (current || Prefs.notificationAllAccounts) + ) notifCount += fetch(jobId, NotificationType.GENERAL, it) - if (Prefs.notificationsInstantMessages - && (current || Prefs.notificationsImAllAccounts)) + if (Prefs.notificationsInstantMessages && + (current || Prefs.notificationsImAllAccounts) + ) notifCount += fetch(jobId, NotificationType.MESSAGE, it) } @@ -99,10 +121,9 @@ class NotificationService : JobService() { private fun generalNotification(id: Int, textRes: Int, withDefaults: Boolean) { val notifBuilder = frostNotification(NOTIF_CHANNEL_GENERAL) - .setFrostAlert(withDefaults, Prefs.notificationRingtone) - .setContentTitle(string(R.string.frost_name)) - .setContentText(string(textRes)) + .setFrostAlert(withDefaults, Prefs.notificationRingtone) + .setContentTitle(string(R.string.frost_name)) + .setContentText(string(textRes)) NotificationManagerCompat.from(this).notify(id, notifBuilder.build()) } - -}
\ No newline at end of file +} |