Respect notification badge settings
This commit is contained in:
+6
-7
@@ -21,18 +21,17 @@ class NotificationBadgeProvider : BadgeProvider, KoinComponent {
|
||||
notificationRepository.notifications.map {
|
||||
it.filter { it.packageName == packageName }
|
||||
}.collectLatest {
|
||||
if (it.isEmpty()) {
|
||||
if (it.isEmpty() || it.none { it.canShowBadge }) {
|
||||
send(null)
|
||||
} else {
|
||||
val badge = Badge(
|
||||
number = it.distinctBy { it.notification.shortcutId }.sumOf {
|
||||
if(it.notification.shortcutId == null) 0
|
||||
else it.notification.number
|
||||
number = it.sumOf {
|
||||
if (it.canShowBadge && !it.isGroupSummary) it.number
|
||||
else 0
|
||||
},
|
||||
progress = it.mapNotNull {
|
||||
if (!it.notification.extras.containsKey(Notification.EXTRA_PROGRESS)) return@mapNotNull null
|
||||
val progress = it.notification.extras.getInt(Notification.EXTRA_PROGRESS)
|
||||
val progressMax = it.notification.extras.getInt(Notification.EXTRA_PROGRESS_MAX).takeIf { it > 0 } ?: return@mapNotNull null
|
||||
val progress = it.progress ?: return@mapNotNull null
|
||||
val progressMax = it.progressMax ?: return@mapNotNull null
|
||||
return@mapNotNull progress.toFloat() / progressMax.toFloat()
|
||||
}
|
||||
.takeIf { it.isNotEmpty() }
|
||||
|
||||
@@ -25,6 +25,7 @@ import coil.imageLoader
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Scale
|
||||
import de.mm20.launcher2.crashreporter.CrashReporter
|
||||
import de.mm20.launcher2.notifications.Notification
|
||||
import de.mm20.launcher2.notifications.NotificationRepository
|
||||
import de.mm20.launcher2.preferences.LauncherDataStore
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -114,11 +115,11 @@ internal class MusicServiceImpl(
|
||||
settings.allowListList.toSet(),
|
||||
settings.denyListList.toSet()
|
||||
)
|
||||
val sbn: StatusBarNotification? = notifications.filter {
|
||||
it.notification.extras.getParcelable(NotificationCompat.EXTRA_MEDIA_SESSION) as? MediaSession.Token != null && musicApps.contains(it.packageName)
|
||||
val sbn: Notification? = notifications.filter {
|
||||
it.mediaSessionToken != null && musicApps.contains(it.packageName)
|
||||
}.maxByOrNull { it.postTime }
|
||||
|
||||
return@withContext (sbn?.notification?.extras?.get(NotificationCompat.EXTRA_MEDIA_SESSION) as? MediaSession.Token)
|
||||
return@withContext sbn?.mediaSessionToken
|
||||
}
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
|
||||
Reference in New Issue
Block a user