@@ -224,8 +224,7 @@ public void queue(Contribution contribution) {
224
224
225
225
@ Override
226
226
public int onStartCommand (Intent intent , int flags , int startId ) {
227
- startForeground (NOTIFICATION_UPLOAD_IN_PROGRESS ,
228
- curNotification .setContentText (getText (R .string .starting_uploads )).build ());
227
+ showUploadNotification ();
229
228
if (ACTION_START_SERVICE .equals (intent .getAction ()) && freshStart ) {
230
229
compositeDisposable .add (contributionDao .updateStates (Contribution .STATE_FAILED ,
231
230
new int []{Contribution .STATE_QUEUED , Contribution .STATE_IN_PROGRESS })
@@ -234,19 +233,32 @@ public int onStartCommand(Intent intent, int flags, int startId) {
234
233
.subscribe ());
235
234
freshStart = false ;
236
235
} else if (PROCESS_PENDING_LIMITED_CONNECTION_MODE_UPLOADS .equals (intent .getAction ())) {
237
- contributionDao .getContribution (Contribution .STATE_QUEUED_LIMITED_CONNECTION_MODE )
238
- .flatMapObservable (
239
- (Function <List <Contribution >, ObservableSource <Contribution >>) contributions -> Observable .fromIterable (contributions ))
240
- .concatMapCompletable (contribution -> Completable .fromAction (() -> queue (contribution )))
241
- .subscribeOn (ioThreadScheduler )
242
- .subscribe ();
243
- }
236
+ contributionDao .getContribution (Contribution .STATE_QUEUED_LIMITED_CONNECTION_MODE )
237
+ .flatMapObservable (
238
+ (Function <List <Contribution >, ObservableSource <Contribution >>) contributions -> Observable
239
+ .fromIterable (contributions ))
240
+ .concatMapCompletable (contribution -> Completable .fromAction (() -> queue (contribution )))
241
+ .subscribeOn (ioThreadScheduler )
242
+ .subscribe ();
243
+ }
244
244
return START_REDELIVER_INTENT ;
245
245
}
246
246
247
+ private void showUploadNotification () {
248
+ compositeDisposable .add (contributionDao
249
+ .getPendingUploads (new int []{Contribution .STATE_IN_PROGRESS , Contribution .STATE_QUEUED })
250
+ .subscribe (count -> {
251
+ if (count > 0 ) {
252
+ startForeground (NOTIFICATION_UPLOAD_IN_PROGRESS ,
253
+ curNotification .setContentText (getText (R .string .starting_uploads )).build ());
254
+ }
255
+ }));
256
+ }
257
+
247
258
@ SuppressLint ("StringFormatInvalid" )
248
259
private NotificationCompat .Builder getNotificationBuilder (String channelId ) {
249
- return new NotificationCompat .Builder (this , channelId ).setAutoCancel (true )
260
+ return new NotificationCompat .Builder (this , channelId )
261
+ .setAutoCancel (true )
250
262
.setSmallIcon (R .drawable .ic_launcher )
251
263
.setLargeIcon (BitmapFactory .decodeResource (getResources (), R .drawable .ic_launcher ))
252
264
.setAutoCancel (true )
0 commit comments