Skip to content

Commit d6d7736

Browse files
committed
feat: Progress notification support
1 parent 77474a6 commit d6d7736

3 files changed

Lines changed: 52 additions & 12 deletions

File tree

app/src/main/java/com/sameerasw/airsync/service/MediaNotificationListener.kt

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,13 @@ class MediaNotificationListener : NotificationListenerService() {
643643
return@launch
644644
}
645645

646-
// Generate unique notification ID
647-
val notificationId = NotificationDismissalUtil.generateNotificationId(
648-
sbn.packageName,
649-
title,
650-
sbn.postTime
651-
)
646+
// Retrieve existing notification ID or generate a new one
647+
val notificationId = NotificationDismissalUtil.getIdBySystemKey(sbn.key)
648+
?: NotificationDismissalUtil.generateNotificationId(
649+
sbn.packageName,
650+
title,
651+
sbn.postTime
652+
)
652653

653654
// Store notification for potential dismissal or actions
654655
NotificationDismissalUtil.storeNotification(notificationId, sbn)
@@ -670,10 +671,37 @@ class MediaNotificationListener : NotificationListenerService() {
670671
Log.w(TAG, "Failed to extract actions: ${e.message}")
671672
}
672673

674+
// Check for progress bar extras
675+
var progress: Int? = null
676+
var progressMax: Int? = null
677+
var progressIndeterminate: Boolean? = null
678+
val ongoing = (notification.flags and Notification.FLAG_ONGOING_EVENT) != 0
679+
680+
try {
681+
val hasProgress = extras.containsKey(Notification.EXTRA_PROGRESS) ||
682+
extras.containsKey(Notification.EXTRA_PROGRESS_MAX)
683+
if (hasProgress) {
684+
val maxVal = extras.getInt(Notification.EXTRA_PROGRESS_MAX, 0)
685+
val progressVal = extras.getInt(Notification.EXTRA_PROGRESS, 0)
686+
val indeterminateVal = extras.getBoolean(Notification.EXTRA_PROGRESS_INDETERMINATE, false)
687+
688+
if (maxVal > 0 || indeterminateVal) {
689+
progress = progressVal
690+
progressMax = maxVal
691+
progressIndeterminate = indeterminateVal
692+
}
693+
}
694+
} catch (e: Exception) {
695+
Log.w(TAG, "Failed to parse notification progress: ${e.message}")
696+
}
697+
673698
// Get notification priority (alerting vs silent)
674-
val priority = getNotificationPriority(sbn)
699+
var priority = getNotificationPriority(sbn)
700+
if (progressMax != null || progressIndeterminate == true) {
701+
priority = "silent"
702+
}
675703

676-
// Create notification JSON with actions
704+
// Create notification JSON with actions and progress details
677705
val notificationJson = JsonUtil.toSingleLine(
678706
JsonUtil.createNotificationJson(
679707
id = notificationId,
@@ -682,7 +710,11 @@ class MediaNotificationListener : NotificationListenerService() {
682710
app = appName,
683711
packageName = sbn.packageName,
684712
priority = priority,
685-
actions = actions
713+
actions = actions,
714+
progress = progress,
715+
progressMax = progressMax,
716+
progressIndeterminate = progressIndeterminate,
717+
ongoing = ongoing
686718
)
687719
)
688720

app/src/main/java/com/sameerasw/airsync/utils/ClipboardSyncManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ object ClipboardSyncManager {
172172
} catch (_: Exception) {
173173
true
174174
}
175-
if (continueEnabled && isConnected && isLinkOnly(text)) {
175+
if (continueEnabled && WebSocketUtil.isConnected() && isLinkOnly(text)) {
176176
NotificationUtil.showContinueBrowsingLink(context, text.trim(), keepPrevious)
177177
}
178178
}

app/src/main/java/com/sameerasw/airsync/utils/JsonUtil.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ object JsonUtil {
104104
app: String,
105105
packageName: String,
106106
priority: String = "alerting",
107-
actions: List<Pair<String, String>>
107+
actions: List<Pair<String, String>>,
108+
progress: Int? = null,
109+
progressMax: Int? = null,
110+
progressIndeterminate: Boolean? = null,
111+
ongoing: Boolean? = null
108112
): String {
109113
val actionsJson = if (actions.isNotEmpty()) {
110114
val items = actions.joinToString(",") { (name, type) ->
@@ -114,11 +118,15 @@ object JsonUtil {
114118
} else {
115119
""
116120
}
121+
val progressJson = if (progress != null) ",\"progress\":$progress" else ""
122+
val progressMaxJson = if (progressMax != null) ",\"progressMax\":$progressMax" else ""
123+
val progressIndeterminateJson = if (progressIndeterminate != null) ",\"progressIndeterminate\":$progressIndeterminate" else ""
124+
val ongoingJson = if (ongoing != null) ",\"ongoing\":$ongoing" else ""
117125
return """{"type":"notification","data":{"id":"$id","title":"${escape(title)}","body":"${
118126
escape(
119127
body
120128
)
121-
}","app":"${escape(app)}","package":"${escape(packageName)}","priority":"$priority"$actionsJson}}"""
129+
}","app":"${escape(app)}","package":"${escape(packageName)}","priority":"$priority"$actionsJson$progressJson$progressMaxJson$progressIndeterminateJson$ongoingJson}}"""
122130
}
123131

124132
/**

0 commit comments

Comments
 (0)