Only show notifications if enabled

This commit is contained in:
Moez Bhatti
2017-12-04 02:56:53 -05:00
parent 0bedf303ef
commit f1ab81f5ee
@@ -22,12 +22,13 @@ import javax.inject.Singleton
@Singleton @Singleton
class NotificationManager @Inject constructor( class NotificationManager @Inject constructor(
private val context: Context, private val context: Context,
private val prefs: Preferences,
private val colors: Colors) { private val colors: Colors) {
private val notificationManager = NotificationManagerCompat.from(context) private val notificationManager = NotificationManagerCompat.from(context)
init { init {
if (Build.VERSION.SDK_INT >= 26) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val id = "channel_1" val id = "channel_1"
@@ -47,6 +48,8 @@ class NotificationManager @Inject constructor(
} }
fun update(messageRepo: MessageRepository) { fun update(messageRepo: MessageRepository) {
if (!prefs.notifications.get()) return
messageRepo.getUnreadUnseenMessages() messageRepo.getUnreadUnseenMessages()
.groupBy { message -> message.threadId } .groupBy { message -> message.threadId }
.forEach { group -> .forEach { group ->