From 1d04dea4acd28806b377aab053e130e7d992452d Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 27 Sep 2021 15:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/DownloadService.kt | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index e1fb58efb..254ab0d9f 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -146,24 +146,26 @@ class DownloadService : BaseService() { query.setFilterById(*ids.toLongArray()) downloadManager.query(query).use { cursor -> if (cursor.moveToFirst()) { + val idIndex = cursor.getColumnIndex(DownloadManager.COLUMN_ID) + val progressIndex = + cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR) + val fileSizeIndex = cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES) + val statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS) do { - val id = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID)) - val progress = cursor - .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) - val max = cursor - .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) - val status = - when (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) { - DownloadManager.STATUS_PAUSED -> getString(R.string.pause) - DownloadManager.STATUS_PENDING -> getString(R.string.wait_download) - DownloadManager.STATUS_RUNNING -> getString(R.string.downloading) - DownloadManager.STATUS_SUCCESSFUL -> { - successDownload(id) - getString(R.string.download_success) - } - DownloadManager.STATUS_FAILED -> getString(R.string.download_error) - else -> getString(R.string.unknown_state) + val id = cursor.getLong(idIndex) + val progress = cursor.getInt(progressIndex) + val max = cursor.getInt(fileSizeIndex) + val status = when (cursor.getInt(statusIndex)) { + DownloadManager.STATUS_PAUSED -> getString(R.string.pause) + DownloadManager.STATUS_PENDING -> getString(R.string.wait_download) + DownloadManager.STATUS_RUNNING -> getString(R.string.downloading) + DownloadManager.STATUS_SUCCESSFUL -> { + successDownload(id) + getString(R.string.download_success) } + DownloadManager.STATUS_FAILED -> getString(R.string.download_error) + else -> getString(R.string.unknown_state) + } upDownloadNotification(id, "${downloads[id]?.second} $status", max, progress) } while (cursor.moveToNext()) }