diff options
author | Allan Wang <me@allanwang.ca> | 2020-02-23 17:50:22 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-23 17:50:22 -0800 |
commit | 654cc6b943177120dc1a0a22a0d68d5cbfde2b5e (patch) | |
tree | 3bba2feb0cf99ae222693a4d564d9acf624322e2 /app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt | |
parent | 4d5aaf541dbfa7d521ebbc5f011a642c83c4b9c5 (diff) | |
parent | 1686de0d71d687990ca6f0d4b621bc4d52dee146 (diff) | |
download | frost-654cc6b943177120dc1a0a22a0d68d5cbfde2b5e.tar.gz frost-654cc6b943177120dc1a0a22a0d68d5cbfde2b5e.tar.bz2 frost-654cc6b943177120dc1a0a22a0d68d5cbfde2b5e.zip |
Merge pull request #1647 from AllanWang/kpref
Remove stateful singletons
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt | 19 |
1 files changed, 11 insertions, 8 deletions
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 7352082d..5f01dfd2 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/services/NotificationUtils.kt @@ -41,13 +41,13 @@ import com.pitchedapps.frost.utils.frostUri const val NOTIF_CHANNEL_GENERAL = "general" const val NOTIF_CHANNEL_MESSAGES = "messages" -fun setupNotificationChannels(c: Context) { +fun setupNotificationChannels(c: Context, prefs: Prefs) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return val manager = c.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val appName = c.string(R.string.frost_name) val msg = c.string(R.string.messages) - manager.createNotificationChannel(NOTIF_CHANNEL_GENERAL, appName) - manager.createNotificationChannel(NOTIF_CHANNEL_MESSAGES, "$appName: $msg") + manager.createNotificationChannel(NOTIF_CHANNEL_GENERAL, appName, prefs) + manager.createNotificationChannel(NOTIF_CHANNEL_MESSAGES, "$appName: $msg", prefs) manager.notificationChannels .filter { it.id != NOTIF_CHANNEL_GENERAL && @@ -60,14 +60,15 @@ fun setupNotificationChannels(c: Context) { @RequiresApi(Build.VERSION_CODES.O) private fun NotificationManager.createNotificationChannel( id: String, - name: String + name: String, + prefs: Prefs ): NotificationChannel { val channel = NotificationChannel( id, name, NotificationManager.IMPORTANCE_DEFAULT ) channel.enableLights(true) - channel.lightColor = Prefs.accentColor + channel.lightColor = prefs.accentColor channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC createNotificationChannel(channel) return channel @@ -93,6 +94,8 @@ fun NotificationCompat.Builder.setFrostAlert( enable: Boolean, ringtone: String ): NotificationCompat.Builder { + val prefs = Prefs.get() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { setGroupAlertBehavior( if (enable) NotificationCompat.GROUP_ALERT_CHILDREN @@ -102,12 +105,12 @@ fun NotificationCompat.Builder.setFrostAlert( setDefaults(0) } else { var defaults = 0 - if (Prefs.notificationVibrate) defaults = defaults or Notification.DEFAULT_VIBRATE - if (Prefs.notificationSound) { + if (prefs.notificationVibrate) defaults = defaults or Notification.DEFAULT_VIBRATE + if (prefs.notificationSound) { if (ringtone.isNotBlank()) setSound(context.frostUri(ringtone)) else defaults = defaults or Notification.DEFAULT_SOUND } - if (Prefs.notificationLights) defaults = defaults or Notification.DEFAULT_LIGHTS + if (prefs.notificationLights) defaults = defaults or Notification.DEFAULT_LIGHTS setDefaults(defaults) } return this |