Skip to content

Commit 1e834fd

Browse files
Call jobFinished in downloadFinished in DownloadRedditVideoService.
1 parent ccb5d0f commit 1e834fd

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ public boolean onStartJob(JobParameters params) {
209209
String destinationDirectoryPath = separateDownloadFolder ? destinationDirectory.getAbsolutePath() + "/Infinity/" + subredditName + "/" : destinationDirectory.getAbsolutePath() + "/Infinity/";
210210
File infinityDir = new File(destinationDirectoryPath);
211211
if (!infinityDir.exists() && !infinityDir.mkdir()) {
212-
downloadFinished(null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
212+
downloadFinished(params, null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
213213
return;
214214
}
215215
destinationFileUriString = destinationDirectoryPath + destinationFileName;
216216
} else {
217-
downloadFinished(null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
217+
downloadFinished(params, null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
218218
return;
219219
}
220220
} else {
@@ -228,21 +228,21 @@ public boolean onStartJob(JobParameters params) {
228228
if (separateDownloadFolder) {
229229
dir = DocumentFile.fromTreeUri(DownloadRedditVideoService.this, Uri.parse(destinationFileDirectory));
230230
if (dir == null) {
231-
downloadFinished(null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
231+
downloadFinished(params, null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
232232
return;
233233
}
234234
dir = dir.findFile(subredditName);
235235
if (dir == null) {
236236
dir = DocumentFile.fromTreeUri(DownloadRedditVideoService.this, Uri.parse(destinationFileDirectory)).createDirectory(subredditName);
237237
if (dir == null) {
238-
downloadFinished(null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
238+
downloadFinished(params, null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
239239
return;
240240
}
241241
}
242242
} else {
243243
dir = DocumentFile.fromTreeUri(DownloadRedditVideoService.this, Uri.parse(destinationFileDirectory));
244244
if (dir == null) {
245-
downloadFinished(null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
245+
downloadFinished(params, null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
246246
return;
247247
}
248248
}
@@ -255,7 +255,7 @@ public boolean onStartJob(JobParameters params) {
255255
}
256256
picFile = dir.createFile("video/mp4", finalFileNameWithoutExtension + ".mp4");
257257
if (picFile == null) {
258-
downloadFinished(null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
258+
downloadFinished(params, null, ERROR_CANNOT_GET_DESTINATION_DIRECTORY, randomNotificationIdOffset);
259259
return;
260260
}
261261
destinationFileUriString = picFile.getUri().toString();
@@ -267,7 +267,7 @@ public boolean onStartJob(JobParameters params) {
267267
String videoFilePath = externalCacheDirectoryPath + finalFileNameWithoutExtension + "-cache.mp4";
268268
String savedVideoFilePath = writeResponseBodyToDisk(videoResponse.body(), videoFilePath);
269269
if (savedVideoFilePath == null) {
270-
downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
270+
downloadFinished(params, null, ERROR_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
271271
return;
272272
}
273273

@@ -279,14 +279,14 @@ public boolean onStartJob(JobParameters params) {
279279

280280
String savedAudioFilePath = writeResponseBodyToDisk(audioResponse, audioFilePath);
281281
if (savedAudioFilePath == null) {
282-
downloadFinished(null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
282+
downloadFinished(params, null, ERROR_AUDIO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
283283
return;
284284
}
285285

286286
updateNotification(R.string.downloading_reddit_video_muxing, -1,
287287
randomNotificationIdOffset, null);
288288
if (!muxVideoAndAudio(videoFilePath, audioFilePath, outputFilePath)) {
289-
downloadFinished(null, ERROR_MUX_FAILED, randomNotificationIdOffset);
289+
downloadFinished(params, null, ERROR_MUX_FAILED, randomNotificationIdOffset);
290290
return;
291291
}
292292

@@ -299,16 +299,16 @@ public boolean onStartJob(JobParameters params) {
299299
new File(audioFilePath).delete();
300300
new File(outputFilePath).delete();
301301

302-
downloadFinished(destinationFileUri, NO_ERROR, randomNotificationIdOffset);
302+
downloadFinished(params, destinationFileUri, NO_ERROR, randomNotificationIdOffset);
303303
} catch (IOException e) {
304304
e.printStackTrace();
305-
downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
305+
downloadFinished(params, null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
306306
}
307307
} else {
308308
updateNotification(R.string.downloading_reddit_video_muxing, -1,
309309
randomNotificationIdOffset, null);
310310
if (!muxVideoAndAudio(videoFilePath, null, outputFilePath)) {
311-
downloadFinished(null, ERROR_MUX_FAILED, randomNotificationIdOffset);
311+
downloadFinished(params, null, ERROR_MUX_FAILED, randomNotificationIdOffset);
312312
return;
313313
}
314314

@@ -320,10 +320,10 @@ public boolean onStartJob(JobParameters params) {
320320
new File(videoFilePath).delete();
321321
new File(outputFilePath).delete();
322322

323-
downloadFinished(destinationFileUri, NO_ERROR, randomNotificationIdOffset);
323+
downloadFinished(params, destinationFileUri, NO_ERROR, randomNotificationIdOffset);
324324
} catch (IOException e) {
325325
e.printStackTrace();
326-
downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
326+
downloadFinished(params, null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
327327
}
328328
}
329329
} else {
@@ -333,21 +333,21 @@ public boolean onStartJob(JobParameters params) {
333333
try {
334334
Uri destinationFileUri = copyToDestination(videoFilePath, destinationFileUriString, destinationFileName, isDefaultDestination);
335335
new File(videoFilePath).delete();
336-
downloadFinished(destinationFileUri, NO_ERROR, randomNotificationIdOffset);
336+
downloadFinished(params, destinationFileUri, NO_ERROR, randomNotificationIdOffset);
337337
} catch (IOException e) {
338338
e.printStackTrace();
339-
downloadFinished(null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
339+
downloadFinished(params, null, ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE, randomNotificationIdOffset);
340340
}
341341
}
342342
} else {
343-
downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_DOWNLOAD, randomNotificationIdOffset);
343+
downloadFinished(params, null, ERROR_VIDEO_FILE_CANNOT_DOWNLOAD, randomNotificationIdOffset);
344344
}
345345
} catch (IOException e) {
346346
e.printStackTrace();
347-
downloadFinished(null, ERROR_VIDEO_FILE_CANNOT_DOWNLOAD, randomNotificationIdOffset);
347+
downloadFinished(params, null, ERROR_VIDEO_FILE_CANNOT_DOWNLOAD, randomNotificationIdOffset);
348348
}
349349
} else {
350-
downloadFinished(null, ERROR_CANNOT_GET_CACHE_DIRECTORY, randomNotificationIdOffset);
350+
downloadFinished(params, null, ERROR_CANNOT_GET_CACHE_DIRECTORY, randomNotificationIdOffset);
351351
}
352352
});
353353

@@ -583,7 +583,7 @@ private Uri copyToDestination(String srcPath, String destinationFileUriString, S
583583
return Uri.parse(destinationFileUriString);
584584
}
585585

586-
private void downloadFinished(Uri destinationFileUri, int errorCode, int randomNotificationIdOffset) {
586+
private void downloadFinished(JobParameters parameters, Uri destinationFileUri, int errorCode, int randomNotificationIdOffset) {
587587
if (errorCode != NO_ERROR) {
588588
switch (errorCode) {
589589
case ERROR_CANNOT_GET_CACHE_DIRECTORY:
@@ -623,7 +623,7 @@ private void downloadFinished(Uri destinationFileUri, int errorCode, int randomN
623623
}
624624
);
625625
}
626-
stopForeground(false);
626+
jobFinished(parameters, false);
627627
}
628628

629629
private Notification createNotification(String fileName) {

0 commit comments

Comments
 (0)