From 1c46fc7f23a8d79b406c629921c5681ce3203c38 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 30 Sep 2020 20:36:53 +0300 Subject: [PATCH] Fix manga downloading --- app/build.gradle | 2 +- .../org/koitharu/kotatsu/core/local/WritableCbzFile.kt | 3 +++ .../kotatsu/ui/download/DownloadNotification.kt | 10 +++++++++- .../koitharu/kotatsu/ui/download/DownloadService.kt | 3 +++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 3c4ae917f..f9eae0684 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,7 +16,7 @@ android { minSdkVersion 21 targetSdkVersion 30 versionCode gitCommits - versionName '0.5.3' + versionName '0.5.4' kapt { arguments { diff --git a/app/src/main/java/org/koitharu/kotatsu/core/local/WritableCbzFile.kt b/app/src/main/java/org/koitharu/kotatsu/core/local/WritableCbzFile.kt index 8ddbf6631..7ea9a2523 100644 --- a/app/src/main/java/org/koitharu/kotatsu/core/local/WritableCbzFile.kt +++ b/app/src/main/java/org/koitharu/kotatsu/core/local/WritableCbzFile.kt @@ -22,6 +22,9 @@ class WritableCbzFile(private val file: File) { if (!dir.exists()) { dir.mkdir() } + if (!file.exists()) { + return@withContext + } ZipInputStream(FileInputStream(file)).use { zip -> var entry = zip.nextEntry while (entry != null) { diff --git a/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadNotification.kt b/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadNotification.kt index 502a55b39..7eaf3c515 100644 --- a/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadNotification.kt +++ b/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadNotification.kt @@ -47,6 +47,7 @@ class DownloadNotification(private val context: Context) { builder.setSmallIcon(android.R.drawable.stat_sys_download) builder.setLargeIcon(null) builder.setContentIntent(null) + builder.setStyle(null) } fun setCancelId(startId: Int) { @@ -68,13 +69,15 @@ class DownloadNotification(private val context: Context) { } fun setError(e: Throwable) { + val message = e.getDisplayMessage(context.resources) builder.setProgress(0, 0, false) builder.setSmallIcon(android.R.drawable.stat_notify_error) builder.setSubText(context.getString(R.string.error)) - builder.setContentText(e.getDisplayMessage(context.resources)) + builder.setContentText(message) builder.setAutoCancel(true) builder.setContentIntent(null) builder.setCategory(NotificationCompat.CATEGORY_ERROR) + builder.setStyle(NotificationCompat.BigTextStyle().bigText(message)) } fun setLargeIcon(icon: Drawable?) { @@ -89,16 +92,19 @@ class DownloadNotification(private val context: Context) { builder.setProgress(max, progress, false) builder.setContentText("%d%%".format(percent)) builder.setCategory(NotificationCompat.CATEGORY_PROGRESS) + builder.setStyle(null) } fun setWaitingForNetwork() { builder.setProgress(0, 0, false) builder.setContentText(context.getString(R.string.waiting_for_network)) + builder.setStyle(null) } fun setPostProcessing() { builder.setProgress(1, 0, true) builder.setContentText(context.getString(R.string.processing_)) + builder.setStyle(null) } fun setDone(manga: Manga) { @@ -108,12 +114,14 @@ class DownloadNotification(private val context: Context) { builder.setAutoCancel(true) builder.setSmallIcon(android.R.drawable.stat_sys_download_done) builder.setCategory(null) + builder.setStyle(null) } fun setCancelling() { builder.setProgress(1, 0, true) builder.setContentText(context.getString(R.string.cancelling_)) builder.setContentIntent(null) + builder.setStyle(null) } fun update(id: Int = NOTIFICATION_ID) { diff --git a/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt b/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt index 776af0ee0..d6d03f4fb 100644 --- a/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt +++ b/app/src/main/java/org/koitharu/kotatsu/ui/download/DownloadService.kt @@ -156,6 +156,9 @@ class DownloadService : BaseService() { notification.update() } } catch (e: Throwable) { + if (BuildConfig.DEBUG) { + e.printStackTrace() + } notification.setError(e) notification.setCancelId(0) notification.dismiss()