Skip to content

Commit 5d9f91a

Browse files
authored
merge #21 from devnoname120/improve-notification
improve notifications
2 parents 5dbfe69 + 96c4966 commit 5d9f91a

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

android/app/src/main/java/me/kavishdevar/aln/services/AirPodsService.kt

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ class AirPodsService: Service() {
148148
notificationManager.createNotificationChannel(notificationChannel)
149149
val notification = NotificationCompat.Builder(this, "background_service_status")
150150
.setSmallIcon(R.drawable.airpods)
151-
.setContentTitle("AirPods Service")
152-
.setContentText("Service is running in the background")
151+
.setContentTitle("AirPods are not connected")
153152
.setCategory(Notification.CATEGORY_SERVICE)
154153
.setPriority(NotificationCompat.PRIORITY_LOW)
154+
.setOngoing(true)
155155
.build()
156156

157157
try {
@@ -261,36 +261,37 @@ class AirPodsService: Service() {
261261

262262
updatedNotification = NotificationCompat.Builder(this, "background_service_status")
263263
.setSmallIcon(R.drawable.airpods)
264-
.setContentTitle("""L: ${batteryList?.find { it.component == BatteryComponent.LEFT }?.let {
265-
// if (it.status != BatteryStatus.DISCONNECTED) {
266-
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
267-
// } else {
268-
// ""
269-
// }
270-
} ?: ""} R: ${batteryList?.find { it.component == BatteryComponent.RIGHT }?.let {
271-
// if (it.status != BatteryStatus.DISCONNECTED) {
272-
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
273-
// } else {
274-
// ""
275-
// }
276-
} ?: ""} C: ${batteryList?.find { it.component == BatteryComponent.CASE }?.let {
277-
// if (it.status != BatteryStatus.DISCONNECTED) {
278-
"${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
279-
// } else {
280-
// ""
281-
// }
264+
.setContentTitle("""AirPods –${batteryList?.find { it.component == BatteryComponent.LEFT }?.let {
265+
if (it.status != BatteryStatus.DISCONNECTED) {
266+
" L:${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
267+
} else {
268+
""
269+
}
270+
} ?: ""}${batteryList?.find { it.component == BatteryComponent.RIGHT }?.let {
271+
if (it.status != BatteryStatus.DISCONNECTED) {
272+
" R:${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
273+
} else {
274+
""
275+
}
276+
} ?: ""}${batteryList?.find { it.component == BatteryComponent.CASE }?.let {
277+
if (it.status != BatteryStatus.DISCONNECTED) {
278+
" C:${if (it.status == BatteryStatus.CHARGING) "" else ""} ${it.level}%"
279+
} else {
280+
""
281+
}
282282
} ?: ""}""")
283283
.setCategory(Notification.CATEGORY_SERVICE)
284284
.setPriority(NotificationCompat.PRIORITY_LOW)
285+
.setOngoing(true)
285286
.build()
286287

287288
} else {
288289
updatedNotification = NotificationCompat.Builder(this, "background_service_status")
289290
.setSmallIcon(R.drawable.airpods)
290-
.setContentTitle("AirPods Service")
291-
.setContentText("Service is running in the background!")
291+
.setContentTitle("AirPods are not connected")
292292
.setCategory(Notification.CATEGORY_SERVICE)
293293
.setPriority(NotificationCompat.PRIORITY_LOW)
294+
.setOngoing(true)
294295
.build()
295296
}
296297

0 commit comments

Comments
 (0)