pull/1344/head
gedoor 3 years ago
parent 9cdc769c2b
commit 714dd7bd03
  1. 23
      app/src/main/java/io/legado/app/service/DownloadService.kt
  2. 33
      app/src/main/java/io/legado/app/utils/DocumentUtils.kt
  3. 5
      app/src/main/res/values-es-rES/strings.xml
  4. 5
      app/src/main/res/values-ja-rJP/strings.xml
  5. 5
      app/src/main/res/values-pt-rBR/strings.xml
  6. 5
      app/src/main/res/values-zh-rHK/strings.xml
  7. 5
      app/src/main/res/values-zh-rTW/strings.xml
  8. 5
      app/src/main/res/values-zh/strings.xml
  9. 5
      app/src/main/res/values/strings.xml

@ -120,7 +120,7 @@ class DownloadService : BaseService() {
if (downloadNames[downloadId]?.endsWith(".apk") == true) { if (downloadNames[downloadId]?.endsWith(".apk") == true) {
installApk(downloadId) installApk(downloadId)
} else { } else {
toastOnUi("${downloadNames[downloadId]} 下载完成") toastOnUi("${downloadNames[downloadId]} ${getString(R.string.download_success)}")
} }
} }
} }
@ -146,25 +146,28 @@ class DownloadService : BaseService() {
val query = DownloadManager.Query() val query = DownloadManager.Query()
query.setFilterById(*ids.toLongArray()) query.setFilterById(*ids.toLongArray())
downloadManager.query(query).use { cursor -> downloadManager.query(query).use { cursor ->
if (!cursor.moveToFirst()) return if (cursor.moveToFirst()) {
do {
val id = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID)) val id = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID))
val progress: Int = cursor val progress = cursor
.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR))
val max: Int = cursor val max = cursor
.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) .getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES))
val status = val status =
when (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) { when (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) {
DownloadManager.STATUS_PAUSED -> "暂停" DownloadManager.STATUS_PAUSED -> getString(R.string.pause)
DownloadManager.STATUS_PENDING -> "待下载" DownloadManager.STATUS_PENDING -> getString(R.string.wait_download)
DownloadManager.STATUS_RUNNING -> "下载中" DownloadManager.STATUS_RUNNING -> getString(R.string.downloading)
DownloadManager.STATUS_SUCCESSFUL -> { DownloadManager.STATUS_SUCCESSFUL -> {
successDownload(id) successDownload(id)
"下载完成" getString(R.string.download_success)
} }
DownloadManager.STATUS_FAILED -> "下载失败" DownloadManager.STATUS_FAILED -> getString(R.string.download_error)
else -> "未知状态" else -> getString(R.string.unknown_state)
} }
upDownloadNotification(id, "${downloadNames[id]} $status", max, progress) upDownloadNotification(id, "${downloadNames[id]} $status", max, progress)
} while (cursor.moveToNext())
}
} }
} }

@ -97,11 +97,11 @@ object DocumentUtils {
fun listFiles(context: Context, uri: Uri): ArrayList<DocItem> { fun listFiles(context: Context, uri: Uri): ArrayList<DocItem> {
val docList = arrayListOf<DocItem>() val docList = arrayListOf<DocItem>()
var c: Cursor? = null var cursor: Cursor? = null
try { try {
val childrenUri = DocumentsContract val childrenUri = DocumentsContract
.buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri)) .buildChildDocumentsUriUsingTree(uri, DocumentsContract.getDocumentId(uri))
c = context.contentResolver.query( cursor = context.contentResolver.query(
childrenUri, arrayOf( childrenUri, arrayOf(
DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_DOCUMENT_ID,
DocumentsContract.Document.COLUMN_DISPLAY_NAME, DocumentsContract.Document.COLUMN_DISPLAY_NAME,
@ -110,29 +110,30 @@ object DocumentUtils {
DocumentsContract.Document.COLUMN_MIME_TYPE DocumentsContract.Document.COLUMN_MIME_TYPE
), null, null, DocumentsContract.Document.COLUMN_DISPLAY_NAME ), null, null, DocumentsContract.Document.COLUMN_DISPLAY_NAME
) )
c?.let { cursor?.let {
val ici = c.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID) val ici = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DOCUMENT_ID)
val nci = c.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME) val nci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME)
val sci = c.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE) val sci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_SIZE)
val mci = c.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE) val mci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_MIME_TYPE)
val dci = c.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED) val dci = cursor.getColumnIndex(DocumentsContract.Document.COLUMN_LAST_MODIFIED)
if (c.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
val item = DocItem( val item = DocItem(
name = c.getString(nci), name = cursor.getString(nci),
attr = c.getString(mci), attr = cursor.getString(mci),
size = c.getLong(sci), size = cursor.getLong(sci),
date = Date(c.getLong(dci)), date = Date(cursor.getLong(dci)),
uri = DocumentsContract.buildDocumentUriUsingTree(uri, c.getString(ici)) uri = DocumentsContract
.buildDocumentUriUsingTree(uri, cursor.getString(ici))
) )
docList.add(item) docList.add(item)
} while (c.moveToNext()) } while (cursor.moveToNext())
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printOnDebug() e.printOnDebug()
} finally { } finally {
c?.close() cursor?.close()
} }
return docList return docList
} }

@ -882,5 +882,10 @@
<string name="cover_show_author_summary">封面上显示作者</string> <string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_paragraph">朗读上一段</string> <string name="read_aloud_prev_paragraph">朗读上一段</string>
<string name="read_aloud_next_paragraph">朗读下一段</string> <string name="read_aloud_next_paragraph">朗读下一段</string>
<string name="wait_download">待下载</string>
<string name="download_success">下载完成</string>
<string name="download_error">下载失败</string>
<string name="downloading">下载中</string>
<string name="unknown_state">未知状态</string>
</resources> </resources>

@ -886,5 +886,10 @@
<string name="cover_show_author_summary">封面上显示作者</string> <string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_paragraph">朗读上一段</string> <string name="read_aloud_prev_paragraph">朗读上一段</string>
<string name="read_aloud_next_paragraph">朗读下一段</string> <string name="read_aloud_next_paragraph">朗读下一段</string>
<string name="wait_download">待下载</string>
<string name="download_success">下载完成</string>
<string name="download_error">下载失败</string>
<string name="downloading">下载中</string>
<string name="unknown_state">未知状态</string>
</resources> </resources>

@ -886,5 +886,10 @@
<string name="cover_show_author_summary">封面上显示作者</string> <string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_paragraph">朗读上一段</string> <string name="read_aloud_prev_paragraph">朗读上一段</string>
<string name="read_aloud_next_paragraph">朗读下一段</string> <string name="read_aloud_next_paragraph">朗读下一段</string>
<string name="wait_download">待下载</string>
<string name="download_success">下载完成</string>
<string name="download_error">下载失败</string>
<string name="downloading">下载中</string>
<string name="unknown_state">未知状态</string>
</resources> </resources>

@ -883,5 +883,10 @@
<string name="cover_show_author_summary">封面上显示作者</string> <string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_paragraph">朗读上一段</string> <string name="read_aloud_prev_paragraph">朗读上一段</string>
<string name="read_aloud_next_paragraph">朗读下一段</string> <string name="read_aloud_next_paragraph">朗读下一段</string>
<string name="wait_download">待下载</string>
<string name="download_success">下载完成</string>
<string name="download_error">下载失败</string>
<string name="downloading">下载中</string>
<string name="unknown_state">未知状态</string>
</resources> </resources>

@ -885,5 +885,10 @@
<string name="cover_show_author_summary">封面上显示作者</string> <string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_paragraph">朗读上一段</string> <string name="read_aloud_prev_paragraph">朗读上一段</string>
<string name="read_aloud_next_paragraph">朗读下一段</string> <string name="read_aloud_next_paragraph">朗读下一段</string>
<string name="wait_download">待下载</string>
<string name="download_success">下载完成</string>
<string name="download_error">下载失败</string>
<string name="downloading">下载中</string>
<string name="unknown_state">未知状态</string>
</resources> </resources>

@ -885,5 +885,10 @@
<string name="cover_show_author_summary">封面上显示作者</string> <string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_paragraph">朗读上一段</string> <string name="read_aloud_prev_paragraph">朗读上一段</string>
<string name="read_aloud_next_paragraph">朗读下一段</string> <string name="read_aloud_next_paragraph">朗读下一段</string>
<string name="wait_download">待下载</string>
<string name="download_success">下载完成</string>
<string name="download_error">下载失败</string>
<string name="downloading">下载中</string>
<string name="unknown_state">未知状态</string>
</resources> </resources>

@ -886,5 +886,10 @@
<string name="cover_show_author_summary">封面上显示作者</string> <string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_paragraph">朗读上一段</string> <string name="read_aloud_prev_paragraph">朗读上一段</string>
<string name="read_aloud_next_paragraph">朗读下一段</string> <string name="read_aloud_next_paragraph">朗读下一段</string>
<string name="wait_download">待下载</string>
<string name="download_success">下载完成</string>
<string name="download_error">下载失败</string>
<string name="downloading">下载中</string>
<string name="unknown_state">未知状态</string>
</resources> </resources>

Loading…
Cancel
Save