Skip to content

Commit

Permalink
Closes #735, code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamantcheese committed Feb 26, 2020
1 parent 8bcf415 commit 4164b5f
Showing 1 changed file with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ public ImageSaver(FileManager fileManager) {
.doOnSuccess((success) -> imageSaveTaskFinished(t, success))
.doOnError((error) -> Logger.e(TAG, "Unhandled exception", error))
.onErrorReturnItem(BundledDownloadResult.Failure);
}, false, CONCURRENT_REQUESTS_COUNT).subscribe((result) -> {
// Do nothing
}, (error) -> {
throw new RuntimeException(TAG + " Uncaught exception!!! " + "workerQueue is in error state now!!! "
+ "This should not happen!!!, original error = " + error.getMessage());
}, () -> {
throw new RuntimeException(TAG + " workerQueue stream has completed!!! This should not happen!!!");
});
}, false, CONCURRENT_REQUESTS_COUNT)
.subscribe((result) -> {
// Do nothing
}, (error) -> {
throw new RuntimeException(TAG + " Uncaught exception!!! " + "workerQueue is in error state now!!! "
+ "This should not happen!!!, original error = " + error.getMessage());
}, () -> {
throw new RuntimeException(TAG + " workerQueue stream has completed!!! This should not happen!!!");
});
}

public void startDownloadTask(Context context, final ImageSaveTask task, DownloadTaskCallbacks callbacks) {
Expand Down Expand Up @@ -236,15 +237,13 @@ public Single<BundledImageSaveResult> startBundledTask(Context context, final Li
}
}

return checkPermission(context)
.flatMap((granted) -> {
if (!granted) {
return Single.just(NoWriteExternalStoragePermission);
}
return checkPermission(context).flatMap((granted) -> {
if (!granted) {
return Single.just(NoWriteExternalStoragePermission);
}

return startBundledTaskInternal(tasks)
.map((result) -> result ? Ok : UnknownError);
});
return startBundledTaskInternal(tasks).map((result) -> result ? Ok : UnknownError);
});
});
}

Expand All @@ -253,8 +252,8 @@ private Single<Boolean> checkPermission(Context context) {
return Single.just(true);
}

return Single.<Boolean>create((emitter) -> requestPermission(context, emitter::onSuccess))
.subscribeOn(AndroidSchedulers.mainThread());
return Single.<Boolean>create((emitter) -> requestPermission(context, emitter::onSuccess)).subscribeOn(
AndroidSchedulers.mainThread());
}

@Nullable
Expand Down Expand Up @@ -295,8 +294,11 @@ private AbstractFile getSaveLocation(ImageSaveTask task) {
AbstractFile innerDirectory = fileManager.create(baseSaveDir, directorySegments);

if (innerDirectory == null) {
Logger.e(TAG, "getSaveLocation() failed to create subdirectory " +
"(" + subFolder + ") for a base dir: " + baseSaveDir.getFullPath());
Logger.e(
TAG,
"getSaveLocation() failed to create subdirectory " + "(" + subFolder + ") for a base dir: "
+ baseSaveDir.getFullPath()
);
}

return innerDirectory;
Expand Down Expand Up @@ -446,9 +448,13 @@ private void updateNotification() {
if (totalTasks.get() == 0) {
getAppContext().stopService(service);
} else {
service.putExtra(SavingNotification.DONE_TASKS_KEY, doneTasks.get());
service.putExtra(SavingNotification.TOTAL_TASKS_KEY, totalTasks.get());
ContextCompat.startForegroundService(getAppContext(), service);
if (BackgroundUtils.isInForeground()) {
service.putExtra(SavingNotification.DONE_TASKS_KEY, doneTasks.get());
service.putExtra(SavingNotification.TOTAL_TASKS_KEY, totalTasks.get());
ContextCompat.startForegroundService(getAppContext(), service);
} else {
getAppContext().stopService(service);
}
}
}

Expand Down

0 comments on commit 4164b5f

Please sign in to comment.