Fix manga downloading

This commit is contained in:
Koitharu
2020-09-30 20:36:53 +03:00
parent b7e4c6b8c0
commit 1c46fc7f23
4 changed files with 16 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode gitCommits
versionName '0.5.3'
versionName '0.5.4'
kapt {
arguments {

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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()