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 3706d9513..5ad13871b 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -120,7 +120,7 @@ class DownloadService : BaseService() { if (downloadNames[downloadId]?.endsWith(".apk") == true) { installApk(downloadId) } else { - toastOnUi("${downloadNames[downloadId]} 下载完成") + toastOnUi("${downloadNames[downloadId]} ${getString(R.string.download_success)}") } } } @@ -146,25 +146,28 @@ class DownloadService : BaseService() { val query = DownloadManager.Query() query.setFilterById(*ids.toLongArray()) downloadManager.query(query).use { cursor -> - if (!cursor.moveToFirst()) return - val id = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID)) - val progress: Int = cursor - .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) - val max: Int = cursor - .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) - val status = - when (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) { - DownloadManager.STATUS_PAUSED -> "暂停" - DownloadManager.STATUS_PENDING -> "待下载" - DownloadManager.STATUS_RUNNING -> "下载中" - DownloadManager.STATUS_SUCCESSFUL -> { - successDownload(id) - "下载完成" - } - DownloadManager.STATUS_FAILED -> "下载失败" - else -> "未知状态" - } - upDownloadNotification(id, "${downloadNames[id]} $status", max, progress) + if (cursor.moveToFirst()) { + 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) + } + upDownloadNotification(id, "${downloadNames[id]} $status", max, progress) + } while (cursor.moveToNext()) + } } } diff --git a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt index 1c428ea78..0604aaacb 100644 --- a/app/src/main/java/io/legado/app/utils/DocumentUtils.kt +++ b/app/src/main/java/io/legado/app/utils/DocumentUtils.kt @@ -97,11 +97,11 @@ object DocumentUtils { fun listFiles(context: Context, uri: Uri): ArrayList { val docList = arrayListOf() - var c: Cursor? = null + var cursor: Cursor? = null try { val childrenUri = DocumentsContract .buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri)) - c = context.contentResolver.query( + cursor = context.contentResolver.query( childrenUri, arrayOf( DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DISPLAY_NAME, @@ -110,29 +110,30 @@ object DocumentUtils { DocumentsContract.Document.COLUMN_MIME_TYPE ), null, null, DocumentsContract.Document.COLUMN_DISPLAY_NAME ) - c?.let { - val ici = c.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID) - val nci = c.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME) - val sci = c.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE) - val mci = c.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE) - val dci = c.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED) - if (c.moveToFirst()) { + cursor?.let { + val ici = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID) + val nci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME) + val sci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE) + val mci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE) + val dci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED) + if (cursor.moveToFirst()) { do { val item = DocItem( - name = c.getString(nci), - attr = c.getString(mci), - size = c.getLong(sci), - date = Date(c.getLong(dci)), - uri = DocumentsContract.buildDocumentUriUsingTree(uri, c.getString(ici)) + name = cursor.getString(nci), + attr = cursor.getString(mci), + size = cursor.getLong(sci), + date = Date(cursor.getLong(dci)), + uri = DocumentsContract + .buildDocumentUriUsingTree(uri, cursor.getString(ici)) ) docList.add(item) - } while (c.moveToNext()) + } while (cursor.moveToNext()) } } } catch (e: Exception) { e.printOnDebug() } finally { - c?.close() + cursor?.close() } return docList } diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index e85fe74fb..84839d74a 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -882,5 +882,10 @@ 封面上显示作者 朗读上一段 朗读下一段 + 待下载 + 下载完成 + 下载失败 + 下载中 + 未知状态 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 7df284f57..61be18abf 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -886,5 +886,10 @@ 封面上显示作者 朗读上一段 朗读下一段 + 待下载 + 下载完成 + 下载失败 + 下载中 + 未知状态 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index ed0eed38b..907c61534 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -886,5 +886,10 @@ 封面上显示作者 朗读上一段 朗读下一段 + 待下载 + 下载完成 + 下载失败 + 下载中 + 未知状态 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 2ec2fc753..a0222d8bd 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -883,5 +883,10 @@ 封面上显示作者 朗读上一段 朗读下一段 + 待下载 + 下载完成 + 下载失败 + 下载中 + 未知状态 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 5c1a59055..217793329 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -885,5 +885,10 @@ 封面上显示作者 朗读上一段 朗读下一段 + 待下载 + 下载完成 + 下载失败 + 下载中 + 未知状态 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 9016a1e60..05f49bdfd 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -885,5 +885,10 @@ 封面上显示作者 朗读上一段 朗读下一段 + 待下载 + 下载完成 + 下载失败 + 下载中 + 未知状态 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2188da6ce..ab189c6d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -886,5 +886,10 @@ 封面上显示作者 朗读上一段 朗读下一段 + 待下载 + 下载完成 + 下载失败 + 下载中 + 未知状态