@@ -49,20 +49,22 @@ object LiveUpdateNotification {
4949 context : Context ,
5050 airpodsName : String ,
5151 batteryList : List <Battery >,
52- headsUp : Boolean
52+ headsUp : Boolean ,
53+ currentListeningMode : Int
5354 ) {
5455 val nm = context.getSystemService(NotificationManager ::class .java)
55- val builder = buildMain(context, airpodsName, batteryList, headsUp)
56+ val builder = buildMain(context, airpodsName, batteryList, headsUp, currentListeningMode )
5657 nm.notify(NOTIF_ID_MAIN , builder.build())
5758 }
5859
5960 fun update (
6061 context : Context ,
6162 airpodsName : String ,
62- batteryList : List <Battery >
63+ batteryList : List <Battery >,
64+ currentListeningMode : Int
6365 ) {
6466 val nm = context.getSystemService(NotificationManager ::class .java)
65- val builder = buildMain(context, airpodsName, batteryList, headsUp = false )
67+ val builder = buildMain(context, airpodsName, batteryList, headsUp = false , currentListeningMode )
6668 nm.notify(NOTIF_ID_MAIN , builder.build())
6769 }
6870
@@ -125,7 +127,7 @@ object LiveUpdateNotification {
125127 newMode : Byte
126128 ) {
127129 if (! state.shouldFireListeningModeChange(newMode)) return
128- show(context, airpodsName, batteryList, headsUp = true )
130+ show(context, airpodsName, batteryList, headsUp = true , currentListeningMode = newMode.toInt() )
129131 }
130132
131133 fun cancelAll (context : Context ) {
@@ -141,7 +143,8 @@ object LiveUpdateNotification {
141143 context : Context ,
142144 airpodsName : String ,
143145 batteryList : List <Battery >,
144- headsUp : Boolean
146+ headsUp : Boolean ,
147+ currentListeningMode : Int
145148 ): NotificationCompat .Builder {
146149 val left = batteryList.firstOrNull { it.component == BatteryComponent .LEFT }
147150 val right = batteryList.firstOrNull { it.component == BatteryComponent .RIGHT }
@@ -192,6 +195,27 @@ object LiveUpdateNotification {
192195 .setOnlyAlertOnce(! headsUp)
193196 .setRequestPromotedOngoing(true )
194197 .addExtras(samsungLiveExtras)
198+ .addAction(
199+ listeningModeIconRes(currentListeningMode),
200+ context.getString(listeningModeLabelRes(currentListeningMode)),
201+ listeningModePendingIntent(context)
202+ )
203+ }
204+
205+ private fun listeningModeLabelRes (mode : Int ): Int = when (mode) {
206+ 1 -> R .string.off
207+ 2 -> R .string.noise_cancellation
208+ 3 -> R .string.transparency
209+ 4 -> R .string.adaptive
210+ else -> R .string.noise_control
211+ }
212+
213+ private fun listeningModeIconRes (mode : Int ): Int = when (mode) {
214+ 1 -> R .drawable.close
215+ 2 -> R .drawable.noise_cancellation
216+ 3 -> R .drawable.transparency
217+ 4 -> R .drawable.adaptive
218+ else -> R .drawable.noise_cancellation
195219 }
196220
197221 private fun mainActivityPendingIntent (context : Context ): PendingIntent {
@@ -202,4 +226,16 @@ object LiveUpdateNotification {
202226 PendingIntent .FLAG_UPDATE_CURRENT or PendingIntent .FLAG_IMMUTABLE
203227 )
204228 }
229+
230+ private fun listeningModePendingIntent (context : Context ): PendingIntent {
231+ val intent = Intent (" me.kavishdevar.librepods.SET_ANC_MODE" ).apply {
232+ setPackage(context.packageName)
233+ }
234+ return PendingIntent .getBroadcast(
235+ context,
236+ 2 ,
237+ intent,
238+ PendingIntent .FLAG_UPDATE_CURRENT or PendingIntent .FLAG_IMMUTABLE
239+ )
240+ }
205241}
0 commit comments