|
@@ -3,8 +3,10 @@ package fr.forum_thalie.tsumugi
|
3
|
3
|
import android.app.PendingIntent
|
4
|
4
|
import android.content.Context
|
5
|
5
|
import android.content.Intent
|
|
6
|
+import android.os.Build
|
6
|
7
|
import android.support.v4.media.session.MediaSessionCompat
|
7
|
8
|
import android.support.v4.media.session.PlaybackStateCompat
|
|
9
|
+import androidx.annotation.RequiresApi
|
8
|
10
|
import androidx.core.app.NotificationCompat
|
9
|
11
|
import fr.forum_thalie.tsumugi.playerstore.PlayerStore
|
10
|
12
|
|
|
@@ -34,7 +36,7 @@ class NowPlayingNotification(
|
34
|
36
|
// got it right
|
35
|
37
|
val delIntent = Intent(c, RadioService::class.java)
|
36
|
38
|
delIntent.putExtra("action", Actions.KILL.name)
|
37
|
|
- val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE)
|
|
39
|
+ val deleteIntent = PendingIntent.getService(c, 0, delIntent, PendingIntent.FLAG_NO_CREATE + PendingIntent.FLAG_IMMUTABLE)
|
38
|
40
|
builder.setDeleteIntent(deleteIntent)
|
39
|
41
|
|
40
|
42
|
mediaStyle = androidx.media.app.NotificationCompat.DecoratedMediaCustomViewStyle().also {
|
|
@@ -46,6 +48,7 @@ class NowPlayingNotification(
|
46
|
48
|
update(c)
|
47
|
49
|
}
|
48
|
50
|
|
|
51
|
+ @RequiresApi(Build.VERSION_CODES.M)
|
49
|
52
|
fun update(c: Context, isUpdatingNotificationButton: Boolean = false, isRinging: Boolean = false) {
|
50
|
53
|
|
51
|
54
|
if (isUpdatingNotificationButton)
|
|
@@ -72,17 +75,17 @@ class NowPlayingNotification(
|
72
|
75
|
|
73
|
76
|
playPauseAction = if (PlayerStore.instance.playbackState.value == PlaybackStateCompat.STATE_PLAYING) {
|
74
|
77
|
intent.putExtra("action", Actions.PAUSE.name)
|
75
|
|
- val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
78
|
+ val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
76
|
79
|
NotificationCompat.Action.Builder(R.drawable.ic_pause, "Pause", pendingButtonIntent).build()
|
77
|
80
|
} else {
|
78
|
81
|
intent.putExtra("action", Actions.PLAY.name)
|
79
|
|
- val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
82
|
+ val pendingButtonIntent = PendingIntent.getService(c, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
80
|
83
|
NotificationCompat.Action.Builder(R.drawable.ic_play,"Play", pendingButtonIntent).build()
|
81
|
84
|
}
|
82
|
85
|
builder.addAction(playPauseAction)
|
83
|
86
|
val intent2 = Intent(c, RadioService::class.java)
|
84
|
87
|
intent2.putExtra("action", Actions.KILL.name)
|
85
|
|
- val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
88
|
+ val pendingButtonIntent = PendingIntent.getService(c, 2, intent2, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
86
|
89
|
val stopAction = NotificationCompat.Action.Builder(R.drawable.ic_close,"Stop", pendingButtonIntent).build()
|
87
|
90
|
builder.addAction(stopAction)
|
88
|
91
|
|
|
@@ -92,7 +95,7 @@ class NowPlayingNotification(
|
92
|
95
|
|
93
|
96
|
val snoozeIntent = Intent(c, RadioService::class.java)
|
94
|
97
|
snoozeIntent.putExtra("action", Actions.SNOOZE.name)
|
95
|
|
- val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
98
|
+ val pendingSnoozeIntent = PendingIntent.getService(c, 5, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT + PendingIntent.FLAG_IMMUTABLE)
|
96
|
99
|
val snoozeAction = NotificationCompat.Action.Builder(R.drawable.ic_alarm, "Snooze ($snoozeMinutes min.)", pendingSnoozeIntent ).build()
|
97
|
100
|
if (snoozeMinutes > 0)
|
98
|
101
|
builder.addAction(snoozeAction)
|