Skip to content

Commit ede2671

Browse files
committed
Rebuild RemoteViews for MapboxNavigationNotification on each update
1 parent 43b0b34 commit ede2671

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/MapboxNavigationNotification.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class MapboxNavigationNotification implements NavigationNotification {
4949
private String etaFormat;
5050
private final Context applicationContext;
5151
private PendingIntent pendingOpenIntent;
52+
private PendingIntent pendingCloseIntent;
5253

5354
private BroadcastReceiver endNavigationBtnReceiver = new BroadcastReceiver() {
5455
@Override
@@ -89,14 +90,8 @@ private void initialize(Context applicationContext, MapboxNavigation mapboxNavig
8990
notificationManager = (NotificationManager) applicationContext.getSystemService(Context.NOTIFICATION_SERVICE);
9091
isTwentyFourHourFormat = DateFormat.is24HourFormat(applicationContext);
9192

92-
collapsedNotificationRemoteViews = new RemoteViews(applicationContext.getPackageName(),
93-
R.layout.collapsed_navigation_notification_layout);
94-
expandedNotificationRemoteViews = new RemoteViews(applicationContext.getPackageName(),
95-
R.layout.expanded_navigation_notification_layout);
96-
9793
pendingOpenIntent = createPendingOpenIntent(applicationContext);
98-
PendingIntent pendingCloseIntent = createPendingCloseIntent(applicationContext);
99-
expandedNotificationRemoteViews.setOnClickPendingIntent(R.id.endNavigationBtn, pendingCloseIntent);
94+
pendingCloseIntent = createPendingCloseIntent(applicationContext);
10095

10196
registerReceiver(applicationContext);
10297
createNotificationChannel(applicationContext);
@@ -138,6 +133,14 @@ private Notification buildNotification(Context applicationContext) {
138133
.build();
139134
}
140135

136+
private void buildRemoteViews() {
137+
collapsedNotificationRemoteViews = new RemoteViews(applicationContext.getPackageName(),
138+
R.layout.collapsed_navigation_notification_layout);
139+
expandedNotificationRemoteViews = new RemoteViews(applicationContext.getPackageName(),
140+
R.layout.expanded_navigation_notification_layout);
141+
expandedNotificationRemoteViews.setOnClickPendingIntent(R.id.endNavigationBtn, pendingCloseIntent);
142+
}
143+
141144
private PendingIntent createPendingOpenIntent(Context applicationContext) {
142145
PackageManager pm = applicationContext.getPackageManager();
143146
Intent intent = pm.getLaunchIntentForPackage(applicationContext.getPackageName());
@@ -157,6 +160,7 @@ private void registerReceiver(Context applicationContext) {
157160
}
158161

159162
private void updateNotificationViews(RouteProgress routeProgress) {
163+
buildRemoteViews();
160164
updateInstructionText(routeProgress.currentLegProgress().currentStep());
161165
updateDistanceText(routeProgress);
162166
updateArrivalTime(routeProgress);

0 commit comments

Comments
 (0)