From 93edf72993b7935365154573c1dd7a309e22a39d Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Tue, 22 Oct 2019 16:26:28 +0200 Subject: [PATCH] Rationalize download failure --- .../magisk/model/download/RemoteFileService.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt b/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt index 8070a107e..402266d63 100644 --- a/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/model/download/RemoteFileService.kt @@ -42,11 +42,7 @@ abstract class RemoteFileService : NotificationService() { .doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } } .subscribeK(onError = { Timber.e(it) - finishNotify(subject.hashCode()) { notification -> - notification.setContentText(getString(R.string.download_file_error)) - .setSmallIcon(android.R.drawable.stat_notify_error) - .setOngoing(false) - } + failNotify(subject) }) { val newId = finishNotify(subject) if (get() !is NullActivity) { @@ -76,7 +72,7 @@ abstract class RemoteFileService : NotificationService() { }.doOnComplete { if (subject is Manager) handleAPK(subject) - }.doOnError { send(0f, subject) } + } private fun ResponseBody.toStream(id: Int, subject: DownloadSubject): InputStream { val maxRaw = contentLength() @@ -97,6 +93,13 @@ abstract class RemoteFileService : NotificationService() { } } + private fun failNotify(subject: DownloadSubject) = finishNotify(subject.hashCode()) { + send(0f, subject) + it.setContentText(getString(R.string.download_file_error)) + .setSmallIcon(android.R.drawable.stat_notify_error) + .setOngoing(false) + } + private fun finishNotify(subject: DownloadSubject) = finishNotify(subject.hashCode()) { send(1f, subject) it.addActions(subject)