Fix crash on manga downloading
This commit is contained in:
@@ -16,7 +16,7 @@ android {
|
|||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode gitCommits
|
versionCode gitCommits
|
||||||
versionName '0.5-rc1'
|
versionName '0.5-rc2'
|
||||||
|
|
||||||
kapt {
|
kapt {
|
||||||
arguments {
|
arguments {
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ class DownloadService : BaseService() {
|
|||||||
return launch(Dispatchers.IO) {
|
return launch(Dispatchers.IO) {
|
||||||
mutex.lock()
|
mutex.lock()
|
||||||
wakeLock.acquire(TimeUnit.HOURS.toMillis(1))
|
wakeLock.acquire(TimeUnit.HOURS.toMillis(1))
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
notification.fillFrom(manga)
|
notification.fillFrom(manga)
|
||||||
notification.setCancelId(startId)
|
notification.setCancelId(startId)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
startForeground(DownloadNotification.NOTIFICATION_ID, notification())
|
startForeground(DownloadNotification.NOTIFICATION_ID, notification())
|
||||||
}
|
}
|
||||||
val destination = settings.getStorageDir(this@DownloadService)
|
val destination = settings.getStorageDir(this@DownloadService)
|
||||||
@@ -94,10 +94,8 @@ class DownloadService : BaseService() {
|
|||||||
.build()
|
.build()
|
||||||
).drawable
|
).drawable
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
notification.setLargeIcon(cover)
|
notification.setLargeIcon(cover)
|
||||||
notification.update()
|
notification.update()
|
||||||
}
|
|
||||||
val data = if (manga.chapters == null) repo.getDetails(manga) else manga
|
val data = if (manga.chapters == null) repo.getDetails(manga) else manga
|
||||||
output = MangaZip.findInDir(destination, data)
|
output = MangaZip.findInDir(destination, data)
|
||||||
output.prepare(data)
|
output.prepare(data)
|
||||||
@@ -141,31 +139,25 @@ class DownloadService : BaseService() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
notification.setCancelId(0)
|
notification.setCancelId(0)
|
||||||
notification.setPostProcessing()
|
notification.setPostProcessing()
|
||||||
notification.update()
|
notification.update()
|
||||||
}
|
|
||||||
output.compress()
|
output.compress()
|
||||||
val result = MangaProviderFactory.createLocal().getFromFile(output.file)
|
val result = MangaProviderFactory.createLocal().getFromFile(output.file)
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
notification.setDone(result)
|
notification.setDone(result)
|
||||||
notification.dismiss()
|
notification.dismiss()
|
||||||
notification.update(manga.id.toInt().absoluteValue)
|
notification.update(manga.id.toInt().absoluteValue)
|
||||||
}
|
|
||||||
} catch (_: CancellationException) {
|
} catch (_: CancellationException) {
|
||||||
withContext(Dispatchers.Main + NonCancellable) {
|
withContext(NonCancellable) {
|
||||||
notification.setCancelling()
|
notification.setCancelling()
|
||||||
notification.setCancelId(0)
|
notification.setCancelId(0)
|
||||||
notification.update()
|
notification.update()
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
notification.setError(e)
|
notification.setError(e)
|
||||||
notification.setCancelId(0)
|
notification.setCancelId(0)
|
||||||
notification.dismiss()
|
notification.dismiss()
|
||||||
notification.update(manga.id.toInt().absoluteValue)
|
notification.update(manga.id.toInt().absoluteValue)
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
withContext(NonCancellable) {
|
withContext(NonCancellable) {
|
||||||
jobs.remove(startId)
|
jobs.remove(startId)
|
||||||
|
|||||||
Reference in New Issue
Block a user