pull/1344/head
gedoor 3 years ago
parent 9cdc769c2b
commit 714dd7bd03
  1. 43
      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) {
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())
}
}
}

@ -97,11 +97,11 @@ object DocumentUtils {
fun listFiles(context: Context, uri: Uri): ArrayList<DocItem> {
val docList = arrayListOf<DocItem>()
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
}

@ -882,5 +882,10 @@
<string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_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>

@ -886,5 +886,10 @@
<string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_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>

@ -886,5 +886,10 @@
<string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_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>

@ -883,5 +883,10 @@
<string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_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>

@ -885,5 +885,10 @@
<string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_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>

@ -885,5 +885,10 @@
<string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_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>

@ -886,5 +886,10 @@
<string name="cover_show_author_summary">封面上显示作者</string>
<string name="read_aloud_prev_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>

Loading…
Cancel
Save