Skip to content

Commit ec1e8b9

Browse files
author
Kevin Li
authored
Add throttle for offline plugin notification update (#1200)
* Add throttle for offline plugin notification update * Update changelog for offline 0.10.0
1 parent c1440a9 commit ec1e8b9

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

plugin-offline/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Mapbox welcomes participation and contributions from everyone.
44

5+
### mapbox-android-plugin-offline-v9:0.10.0 - August 24, 2021
6+
- Add throttle for offline plugin notification update [#1200](https://github.com/mapbox/mapbox-plugins-android/pull/1200)
7+
58
### mapbox-android-plugin-offline-v9:0.9.0 - August 18, 2021
69
- Update compatibility for Android 12 [#1194](https://github.com/mapbox/mapbox-plugins-android/pull/1194)
710
- Bump maps sdk to 9.6.2 [#1194](https://github.com/mapbox/mapbox-plugins-android/pull/1194)

plugin-offline/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION_NAME=0.9.0-SNAPSHOT
1+
VERSION_NAME=0.10.0-SNAPSHOT
22
POM_ARTIFACT_ID=mapbox-android-plugin-offline-v9
33
POM_NAME=Mapbox Android Offline Plugin
44
POM_DESCRIPTION=Mapbox Android Offline Plugin

plugin-offline/src/main/java/com/mapbox/mapboxsdk/plugins/offline/offline/OfflineDownloadService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class OfflineDownloadService extends Service {
5252
// map offline regions to requests, ids are received with onStartCommand, these match serviceId
5353
// in OfflineDownloadOptions
5454
final LongSparseArray<OfflineRegion> regionLongSparseArray = new LongSparseArray<>();
55+
final LongSparseArray<Integer> regionProgressSparseArray = new LongSparseArray<>();
5556

5657
@Override
5758
public void onCreate() {
@@ -130,7 +131,7 @@ public void onCreate(OfflineRegion offlineRegion) {
130131
= offlineDownload.toBuilder().uuid(offlineRegion.getID()).build();
131132
OfflineDownloadStateReceiver.dispatchStartBroadcast(getApplicationContext(), options);
132133
regionLongSparseArray.put(options.uuid(), offlineRegion);
133-
134+
regionProgressSparseArray.put(options.uuid(), 0);
134135
launchDownload(options, offlineRegion);
135136
showNotification(options);
136137
}
@@ -209,6 +210,7 @@ private synchronized void removeOfflineRegion(int regionId) {
209210
notificationManager.cancel(regionId);
210211
}
211212
regionLongSparseArray.remove(regionId);
213+
regionProgressSparseArray.remove(regionId);
212214
if (regionLongSparseArray.size() == 0) {
213215
stopForeground(true);
214216
}
@@ -266,11 +268,15 @@ void progressDownload(OfflineDownloadOptions offlineDownload, OfflineRegionStatu
266268

267269
offlineDownload = offlineDownload.toBuilder().progress(percentage).build();
268270

269-
if (percentage % 2 == 0 && regionLongSparseArray.get(offlineDownload.uuid().intValue()) != null) {
271+
int uuid = offlineDownload.uuid().intValue();
272+
Integer lastPercent = regionProgressSparseArray.get(uuid);
273+
if (percentage % 2 == 0 && regionLongSparseArray.get(uuid) != null
274+
&& lastPercent != null && percentage != lastPercent) {
275+
regionProgressSparseArray.put(uuid, percentage);
270276
OfflineDownloadStateReceiver.dispatchProgressChanged(this, offlineDownload, percentage);
271277
if (notificationBuilder != null) {
272278
notificationBuilder.setProgress(100, percentage, false);
273-
notificationManager.notify(offlineDownload.uuid().intValue(), notificationBuilder.build());
279+
notificationManager.notify(uuid, notificationBuilder.build());
274280
}
275281
}
276282
}

0 commit comments

Comments
 (0)