@@ -209,12 +209,12 @@ public boolean onStartJob(JobParameters params) {
209
209
String destinationDirectoryPath = separateDownloadFolder ? destinationDirectory .getAbsolutePath () + "/Infinity/" + subredditName + "/" : destinationDirectory .getAbsolutePath () + "/Infinity/" ;
210
210
File infinityDir = new File (destinationDirectoryPath );
211
211
if (!infinityDir .exists () && !infinityDir .mkdir ()) {
212
- downloadFinished (null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
212
+ downloadFinished (params , null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
213
213
return ;
214
214
}
215
215
destinationFileUriString = destinationDirectoryPath + destinationFileName ;
216
216
} else {
217
- downloadFinished (null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
217
+ downloadFinished (params , null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
218
218
return ;
219
219
}
220
220
} else {
@@ -228,21 +228,21 @@ public boolean onStartJob(JobParameters params) {
228
228
if (separateDownloadFolder ) {
229
229
dir = DocumentFile .fromTreeUri (DownloadRedditVideoService .this , Uri .parse (destinationFileDirectory ));
230
230
if (dir == null ) {
231
- downloadFinished (null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
231
+ downloadFinished (params , null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
232
232
return ;
233
233
}
234
234
dir = dir .findFile (subredditName );
235
235
if (dir == null ) {
236
236
dir = DocumentFile .fromTreeUri (DownloadRedditVideoService .this , Uri .parse (destinationFileDirectory )).createDirectory (subredditName );
237
237
if (dir == null ) {
238
- downloadFinished (null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
238
+ downloadFinished (params , null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
239
239
return ;
240
240
}
241
241
}
242
242
} else {
243
243
dir = DocumentFile .fromTreeUri (DownloadRedditVideoService .this , Uri .parse (destinationFileDirectory ));
244
244
if (dir == null ) {
245
- downloadFinished (null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
245
+ downloadFinished (params , null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
246
246
return ;
247
247
}
248
248
}
@@ -255,7 +255,7 @@ public boolean onStartJob(JobParameters params) {
255
255
}
256
256
picFile = dir .createFile ("video/mp4" , finalFileNameWithoutExtension + ".mp4" );
257
257
if (picFile == null ) {
258
- downloadFinished (null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
258
+ downloadFinished (params , null , ERROR_CANNOT_GET_DESTINATION_DIRECTORY , randomNotificationIdOffset );
259
259
return ;
260
260
}
261
261
destinationFileUriString = picFile .getUri ().toString ();
@@ -267,7 +267,7 @@ public boolean onStartJob(JobParameters params) {
267
267
String videoFilePath = externalCacheDirectoryPath + finalFileNameWithoutExtension + "-cache.mp4" ;
268
268
String savedVideoFilePath = writeResponseBodyToDisk (videoResponse .body (), videoFilePath );
269
269
if (savedVideoFilePath == null ) {
270
- downloadFinished (null , ERROR_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
270
+ downloadFinished (params , null , ERROR_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
271
271
return ;
272
272
}
273
273
@@ -279,14 +279,14 @@ public boolean onStartJob(JobParameters params) {
279
279
280
280
String savedAudioFilePath = writeResponseBodyToDisk (audioResponse , audioFilePath );
281
281
if (savedAudioFilePath == null ) {
282
- downloadFinished (null , ERROR_AUDIO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
282
+ downloadFinished (params , null , ERROR_AUDIO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
283
283
return ;
284
284
}
285
285
286
286
updateNotification (R .string .downloading_reddit_video_muxing , -1 ,
287
287
randomNotificationIdOffset , null );
288
288
if (!muxVideoAndAudio (videoFilePath , audioFilePath , outputFilePath )) {
289
- downloadFinished (null , ERROR_MUX_FAILED , randomNotificationIdOffset );
289
+ downloadFinished (params , null , ERROR_MUX_FAILED , randomNotificationIdOffset );
290
290
return ;
291
291
}
292
292
@@ -299,16 +299,16 @@ public boolean onStartJob(JobParameters params) {
299
299
new File (audioFilePath ).delete ();
300
300
new File (outputFilePath ).delete ();
301
301
302
- downloadFinished (destinationFileUri , NO_ERROR , randomNotificationIdOffset );
302
+ downloadFinished (params , destinationFileUri , NO_ERROR , randomNotificationIdOffset );
303
303
} catch (IOException e ) {
304
304
e .printStackTrace ();
305
- downloadFinished (null , ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
305
+ downloadFinished (params , null , ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
306
306
}
307
307
} else {
308
308
updateNotification (R .string .downloading_reddit_video_muxing , -1 ,
309
309
randomNotificationIdOffset , null );
310
310
if (!muxVideoAndAudio (videoFilePath , null , outputFilePath )) {
311
- downloadFinished (null , ERROR_MUX_FAILED , randomNotificationIdOffset );
311
+ downloadFinished (params , null , ERROR_MUX_FAILED , randomNotificationIdOffset );
312
312
return ;
313
313
}
314
314
@@ -320,10 +320,10 @@ public boolean onStartJob(JobParameters params) {
320
320
new File (videoFilePath ).delete ();
321
321
new File (outputFilePath ).delete ();
322
322
323
- downloadFinished (destinationFileUri , NO_ERROR , randomNotificationIdOffset );
323
+ downloadFinished (params , destinationFileUri , NO_ERROR , randomNotificationIdOffset );
324
324
} catch (IOException e ) {
325
325
e .printStackTrace ();
326
- downloadFinished (null , ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
326
+ downloadFinished (params , null , ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
327
327
}
328
328
}
329
329
} else {
@@ -333,21 +333,21 @@ public boolean onStartJob(JobParameters params) {
333
333
try {
334
334
Uri destinationFileUri = copyToDestination (videoFilePath , destinationFileUriString , destinationFileName , isDefaultDestination );
335
335
new File (videoFilePath ).delete ();
336
- downloadFinished (destinationFileUri , NO_ERROR , randomNotificationIdOffset );
336
+ downloadFinished (params , destinationFileUri , NO_ERROR , randomNotificationIdOffset );
337
337
} catch (IOException e ) {
338
338
e .printStackTrace ();
339
- downloadFinished (null , ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
339
+ downloadFinished (params , null , ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE , randomNotificationIdOffset );
340
340
}
341
341
}
342
342
} else {
343
- downloadFinished (null , ERROR_VIDEO_FILE_CANNOT_DOWNLOAD , randomNotificationIdOffset );
343
+ downloadFinished (params , null , ERROR_VIDEO_FILE_CANNOT_DOWNLOAD , randomNotificationIdOffset );
344
344
}
345
345
} catch (IOException e ) {
346
346
e .printStackTrace ();
347
- downloadFinished (null , ERROR_VIDEO_FILE_CANNOT_DOWNLOAD , randomNotificationIdOffset );
347
+ downloadFinished (params , null , ERROR_VIDEO_FILE_CANNOT_DOWNLOAD , randomNotificationIdOffset );
348
348
}
349
349
} else {
350
- downloadFinished (null , ERROR_CANNOT_GET_CACHE_DIRECTORY , randomNotificationIdOffset );
350
+ downloadFinished (params , null , ERROR_CANNOT_GET_CACHE_DIRECTORY , randomNotificationIdOffset );
351
351
}
352
352
});
353
353
@@ -583,7 +583,7 @@ private Uri copyToDestination(String srcPath, String destinationFileUriString, S
583
583
return Uri .parse (destinationFileUriString );
584
584
}
585
585
586
- private void downloadFinished (Uri destinationFileUri , int errorCode , int randomNotificationIdOffset ) {
586
+ private void downloadFinished (JobParameters parameters , Uri destinationFileUri , int errorCode , int randomNotificationIdOffset ) {
587
587
if (errorCode != NO_ERROR ) {
588
588
switch (errorCode ) {
589
589
case ERROR_CANNOT_GET_CACHE_DIRECTORY :
@@ -623,7 +623,7 @@ private void downloadFinished(Uri destinationFileUri, int errorCode, int randomN
623
623
}
624
624
);
625
625
}
626
- stopForeground ( false );
626
+ jobFinished ( parameters , false );
627
627
}
628
628
629
629
private Notification createNotification (String fileName ) {
0 commit comments