@@ -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