Skip to content

Commit

Permalink
Add throttle for offline plugin notification update (#1200)
Browse files Browse the repository at this point in the history
* Add throttle for offline plugin notification update

* Update changelog for offline 0.10.0
  • Loading branch information
Kevin Li authored Aug 24, 2021
1 parent c1440a9 commit ec1e8b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions plugin-offline/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Mapbox welcomes participation and contributions from everyone.

### mapbox-android-plugin-offline-v9:0.10.0 - August 24, 2021
- Add throttle for offline plugin notification update [#1200](https://github.com/mapbox/mapbox-plugins-android/pull/1200)

### mapbox-android-plugin-offline-v9:0.9.0 - August 18, 2021
- Update compatibility for Android 12 [#1194](https://github.com/mapbox/mapbox-plugins-android/pull/1194)
- Bump maps sdk to 9.6.2 [#1194](https://github.com/mapbox/mapbox-plugins-android/pull/1194)
Expand Down
2 changes: 1 addition & 1 deletion plugin-offline/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=0.9.0-SNAPSHOT
VERSION_NAME=0.10.0-SNAPSHOT
POM_ARTIFACT_ID=mapbox-android-plugin-offline-v9
POM_NAME=Mapbox Android Offline Plugin
POM_DESCRIPTION=Mapbox Android Offline Plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class OfflineDownloadService extends Service {
// map offline regions to requests, ids are received with onStartCommand, these match serviceId
// in OfflineDownloadOptions
final LongSparseArray<OfflineRegion> regionLongSparseArray = new LongSparseArray<>();
final LongSparseArray<Integer> regionProgressSparseArray = new LongSparseArray<>();

@Override
public void onCreate() {
Expand Down Expand Up @@ -130,7 +131,7 @@ public void onCreate(OfflineRegion offlineRegion) {
= offlineDownload.toBuilder().uuid(offlineRegion.getID()).build();
OfflineDownloadStateReceiver.dispatchStartBroadcast(getApplicationContext(), options);
regionLongSparseArray.put(options.uuid(), offlineRegion);

regionProgressSparseArray.put(options.uuid(), 0);
launchDownload(options, offlineRegion);
showNotification(options);
}
Expand Down Expand Up @@ -209,6 +210,7 @@ private synchronized void removeOfflineRegion(int regionId) {
notificationManager.cancel(regionId);
}
regionLongSparseArray.remove(regionId);
regionProgressSparseArray.remove(regionId);
if (regionLongSparseArray.size() == 0) {
stopForeground(true);
}
Expand Down Expand Up @@ -266,11 +268,15 @@ void progressDownload(OfflineDownloadOptions offlineDownload, OfflineRegionStatu

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

if (percentage % 2 == 0 && regionLongSparseArray.get(offlineDownload.uuid().intValue()) != null) {
int uuid = offlineDownload.uuid().intValue();
Integer lastPercent = regionProgressSparseArray.get(uuid);
if (percentage % 2 == 0 && regionLongSparseArray.get(uuid) != null
&& lastPercent != null && percentage != lastPercent) {
regionProgressSparseArray.put(uuid, percentage);
OfflineDownloadStateReceiver.dispatchProgressChanged(this, offlineDownload, percentage);
if (notificationBuilder != null) {
notificationBuilder.setProgress(100, percentage, false);
notificationManager.notify(offlineDownload.uuid().intValue(), notificationBuilder.build());
notificationManager.notify(uuid, notificationBuilder.build());
}
}
}
Expand Down

0 comments on commit ec1e8b9

Please sign in to comment.