From 41096e7ca676852b7a94d9050b0a8683ccb5abd4 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Fri, 18 Feb 2022 00:20:26 +0100 Subject: [PATCH] Show progress in notification badges again --- .../providers/NotificationBadgeProvider.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/badges/src/main/java/de/mm20/launcher2/badges/providers/NotificationBadgeProvider.kt b/badges/src/main/java/de/mm20/launcher2/badges/providers/NotificationBadgeProvider.kt index 70b87683..46aab6ad 100644 --- a/badges/src/main/java/de/mm20/launcher2/badges/providers/NotificationBadgeProvider.kt +++ b/badges/src/main/java/de/mm20/launcher2/badges/providers/NotificationBadgeProvider.kt @@ -1,5 +1,6 @@ package de.mm20.launcher2.badges.providers +import android.app.Notification import de.mm20.launcher2.badges.Badge import de.mm20.launcher2.notifications.NotificationRepository import kotlinx.coroutines.flow.Flow @@ -21,9 +22,21 @@ class NotificationBadgeProvider : BadgeProvider, KoinComponent { if (it.isEmpty()) { send(null) } else { - val badge = Badge(number = it.sumOf { - it.notification.number - }) + val badge = Badge( + number = it.sumOf { + it.notification.number + }, + 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 + return@mapNotNull progress.toFloat() / progressMax.toFloat() + } + .takeIf { it.isNotEmpty() } + ?.let { + it.sumOf { it.toDouble() }.toFloat() / it.size + } + ) send(badge) } }