Skip to content

Commit 540c553

Browse files
committed
Update to reflect Live Updates new eligibility criteria
Change-Id: If5f7d557d31bb54f8ffccf2cc03ea3d7bdffad43
1 parent 46c27be commit 540c553

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
agp = "8.9.1"
1818
fragmentCompose = "1.8.6"
1919
kotlin = "2.1.10"
20-
coreKtx = "1.15.0"
20+
coreKtx = "1.17.0-alpha01"
2121
junit = "4.13.2"
2222
junitVersion = "1.2.1"
2323
espressoCore = "3.6.1"

samples/user-interface/live-updates/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
<!--Permission for posting notifications-->
2020
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
2121
<!--Permission for live update eligibility-->
22-
<uses-permission android:name="POST_PROMOTED_NOTIFICATIONS" />
22+
<uses-permission android:name="android.permission.POST_PROMOTED_NOTIFICATIONS" />
2323
</manifest>

samples/user-interface/live-updates/src/main/java/com/example/platform/ui/live_updates/SnackbarNotificationManager.kt

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616

1717
package com.example.platform.ui.live_updates
1818

19-
import android.app.Notification
20-
import android.app.Notification.ProgressStyle
2119
import android.app.NotificationChannel
2220
import android.app.NotificationManager
2321
import android.app.NotificationManager.IMPORTANCE_DEFAULT
2422
import android.content.Context
23+
import androidx.core.app.NotificationCompat.ProgressStyle
2524
import android.graphics.Color
2625
import android.os.Build
27-
import android.os.Bundle
2826
import android.os.Handler
2927
import android.os.Looper
3028
import androidx.annotation.RequiresApi
29+
import androidx.core.app.NotificationCompat
3130
import androidx.core.graphics.drawable.IconCompat
31+
import java.util.logging.Level
32+
import java.util.logging.Logger
3233

3334
object SnackbarNotificationManager {
3435
private lateinit var notificationManager: NotificationManager
@@ -49,7 +50,7 @@ object SnackbarNotificationManager {
4950
private enum class OrderState(val delay: Long) {
5051
INITIALIZING(5000) {
5152
@RequiresApi(Build.VERSION_CODES.BAKLAVA)
52-
override fun buildNotification(): Notification.Builder {
53+
override fun buildNotification(): NotificationCompat.Builder {
5354
return buildBaseNotification(appContext, INITIALIZING)
5455
.setSmallIcon(R.drawable.ic_launcher_foreground)
5556
.setContentTitle("You order is being placed")
@@ -59,7 +60,7 @@ object SnackbarNotificationManager {
5960
},
6061
FOOD_PREPARATION(9000) {
6162
@RequiresApi(Build.VERSION_CODES.BAKLAVA)
62-
override fun buildNotification(): Notification.Builder {
63+
override fun buildNotification(): NotificationCompat.Builder {
6364
return buildBaseNotification(appContext, FOOD_PREPARATION)
6465
.setContentTitle("Your order is being prepared")
6566
.setContentText("Next step will be delivery")
@@ -73,7 +74,7 @@ object SnackbarNotificationManager {
7374
},
7475
FOOD_ENROUTE(13000) {
7576
@RequiresApi(Build.VERSION_CODES.BAKLAVA)
76-
override fun buildNotification(): Notification.Builder {
77+
override fun buildNotification(): NotificationCompat.Builder {
7778
return buildBaseNotification(appContext, FOOD_ENROUTE)
7879
.setContentTitle("Your order is on its way")
7980
.setContentText("Enroute to destination")
@@ -82,7 +83,7 @@ object SnackbarNotificationManager {
8283
.setProgressTrackerIcon(
8384
IconCompat.createWithResource(
8485
appContext, R.drawable.shopping_bag
85-
).toIcon(appContext)
86+
)
8687
)
8788
.setProgress(50)
8889
)
@@ -95,7 +96,7 @@ object SnackbarNotificationManager {
9596
},
9697
FOOD_ARRIVING(18000) {
9798
@RequiresApi(Build.VERSION_CODES.BAKLAVA)
98-
override fun buildNotification(): Notification.Builder {
99+
override fun buildNotification(): NotificationCompat.Builder {
99100
return buildBaseNotification(appContext, FOOD_ARRIVING)
100101
.setContentTitle("Your order is arriving and has been dropped off")
101102
.setContentText("Enjoy & don't forget to refrigerate any perishable items.")
@@ -104,7 +105,7 @@ object SnackbarNotificationManager {
104105
.setProgressTrackerIcon(
105106
IconCompat.createWithResource(
106107
appContext, R.drawable.delivery_truck
107-
).toIcon(appContext)
108+
)
108109
)
109110
.setProgress(75)
110111
)
@@ -117,7 +118,7 @@ object SnackbarNotificationManager {
117118
},
118119
ORDER_COMPLETE(21000) {
119120
@RequiresApi(Build.VERSION_CODES.BAKLAVA)
120-
override fun buildNotification(): Notification.Builder {
121+
override fun buildNotification(): NotificationCompat.Builder {
121122
return buildBaseNotification(appContext, ORDER_COMPLETE)
122123
.setContentTitle("Your order is complete.")
123124
.setContentText("Thank you for using JetSnack for your snacking needs.")
@@ -126,7 +127,7 @@ object SnackbarNotificationManager {
126127
.setProgressTrackerIcon(
127128
IconCompat.createWithResource(
128129
appContext, R.drawable.check_circle
129-
).toIcon(appContext)
130+
)
130131
)
131132
.setProgress(100)
132133
)
@@ -143,7 +144,7 @@ object SnackbarNotificationManager {
143144
fun buildBaseProgressStyle(orderState: OrderState): ProgressStyle {
144145
val pointColor = Color.valueOf(236f, 183f, 255f, 1f).toArgb()
145146
val segmentColor = Color.valueOf(134f, 247f, 250f, 1f).toArgb()
146-
var progressStyle = ProgressStyle()
147+
var progressStyle = NotificationCompat.ProgressStyle()
147148
.setProgressPoints(
148149
listOf(
149150
ProgressStyle.Point(25).setColor(pointColor),
@@ -188,14 +189,11 @@ object SnackbarNotificationManager {
188189
}
189190

190191
@RequiresApi(Build.VERSION_CODES.O)
191-
fun buildBaseNotification(appContext: Context, orderState: OrderState): Notification.Builder {
192-
val promotedExtras = Bundle()
193-
promotedExtras.putBoolean("android.requestPromotedOngoing", true)
194-
val notificationBuilder = Notification.Builder(appContext, CHANNEL_ID)
192+
fun buildBaseNotification(appContext: Context, orderState: OrderState): NotificationCompat.Builder {
193+
val notificationBuilder = NotificationCompat.Builder(appContext, CHANNEL_ID)
195194
.setSmallIcon(R.drawable.ic_launcher_foreground)
196195
.setOngoing(true)
197-
.setColorized(true)
198-
.addExtras(promotedExtras)
196+
.setRequestPromotedOngoing(true)
199197

200198
when (orderState) {
201199
INITIALIZING -> {}
@@ -204,27 +202,38 @@ object SnackbarNotificationManager {
204202
FOOD_ARRIVING ->
205203
notificationBuilder
206204
.addAction(
207-
Notification.Action.Builder(null, "Got it", null).build()
205+
NotificationCompat.Action.Builder(null, "Got it", null).build()
208206
)
209207
.addAction(
210-
Notification.Action.Builder(null, "Tip", null).build()
208+
NotificationCompat.Action.Builder(null, "Tip", null).build()
211209
)
212210
ORDER_COMPLETE ->
213211
notificationBuilder
214212
.addAction(
215-
Notification.Action.Builder(
213+
NotificationCompat.Action.Builder(
216214
null, "Rate delivery", null).build()
217215
)
218216
}
219217
return notificationBuilder
220218
}
221219

222-
abstract fun buildNotification(): Notification.Builder
220+
abstract fun buildNotification(): NotificationCompat.Builder
223221
}
224222

223+
@RequiresApi(Build.VERSION_CODES.BAKLAVA)
225224
fun start() {
226225
for (state in OrderState.entries) {
227226
val notification = state.buildNotification().build()
227+
228+
Logger.getLogger("canPostPromotedNotifications")
229+
.log(
230+
Level.INFO,
231+
notificationManager.canPostPromotedNotifications().toString())
232+
Logger.getLogger("hasPromotableCharacteristics")
233+
.log(
234+
Level.INFO,
235+
notification.hasPromotableCharacteristics().toString())
236+
228237
Handler(Looper.getMainLooper()).postDelayed({
229238
notificationManager.notify(NOTIFICATION_ID, notification)
230239
}, state.delay)

0 commit comments

Comments
 (0)