@@ -52,6 +52,7 @@ public class OfflineDownloadService extends Service {
52
52
// map offline regions to requests, ids are received with onStartCommand, these match serviceId
53
53
// in OfflineDownloadOptions
54
54
final LongSparseArray <OfflineRegion > regionLongSparseArray = new LongSparseArray <>();
55
+ final LongSparseArray <Integer > regionProgressSparseArray = new LongSparseArray <>();
55
56
56
57
@ Override
57
58
public void onCreate () {
@@ -130,7 +131,7 @@ public void onCreate(OfflineRegion offlineRegion) {
130
131
= offlineDownload .toBuilder ().uuid (offlineRegion .getID ()).build ();
131
132
OfflineDownloadStateReceiver .dispatchStartBroadcast (getApplicationContext (), options );
132
133
regionLongSparseArray .put (options .uuid (), offlineRegion );
133
-
134
+ regionProgressSparseArray . put ( options . uuid (), 0 );
134
135
launchDownload (options , offlineRegion );
135
136
showNotification (options );
136
137
}
@@ -209,6 +210,7 @@ private synchronized void removeOfflineRegion(int regionId) {
209
210
notificationManager .cancel (regionId );
210
211
}
211
212
regionLongSparseArray .remove (regionId );
213
+ regionProgressSparseArray .remove (regionId );
212
214
if (regionLongSparseArray .size () == 0 ) {
213
215
stopForeground (true );
214
216
}
@@ -266,11 +268,15 @@ void progressDownload(OfflineDownloadOptions offlineDownload, OfflineRegionStatu
266
268
267
269
offlineDownload = offlineDownload .toBuilder ().progress (percentage ).build ();
268
270
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 );
270
276
OfflineDownloadStateReceiver .dispatchProgressChanged (this , offlineDownload , percentage );
271
277
if (notificationBuilder != null ) {
272
278
notificationBuilder .setProgress (100 , percentage , false );
273
- notificationManager .notify (offlineDownload . uuid (). intValue () , notificationBuilder .build ());
279
+ notificationManager .notify (uuid , notificationBuilder .build ());
274
280
}
275
281
}
276
282
}
0 commit comments