pull/1352/head
gedoor 4 years ago
parent 813f45dc05
commit 1d04dea4ac
  1. 34
      app/src/main/java/io/legado/app/service/DownloadService.kt

@ -146,24 +146,26 @@ class DownloadService : BaseService() {
query.setFilterById(*ids.toLongArray()) query.setFilterById(*ids.toLongArray())
downloadManager.query(query).use { cursor -> downloadManager.query(query).use { cursor ->
if (cursor.moveToFirst()) { 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 { do {
val id = cursor.getLong(cursor.getColumnIndex(DownloadManager.COLUMN_ID)) val id = cursor.getLong(idIndex)
val progress = cursor val progress = cursor.getInt(progressIndex)
.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) val max = cursor.getInt(fileSizeIndex)
val max = cursor val status = when (cursor.getInt(statusIndex)) {
.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) DownloadManager.STATUS_PAUSED -> getString(R.string.pause)
val status = DownloadManager.STATUS_PENDING -> getString(R.string.wait_download)
when (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS))) { DownloadManager.STATUS_RUNNING -> getString(R.string.downloading)
DownloadManager.STATUS_PAUSED -> getString(R.string.pause) DownloadManager.STATUS_SUCCESSFUL -> {
DownloadManager.STATUS_PENDING -> getString(R.string.wait_download) successDownload(id)
DownloadManager.STATUS_RUNNING -> getString(R.string.downloading) getString(R.string.download_success)
DownloadManager.STATUS_SUCCESSFUL -> {
successDownload(id)
getString(R.string.download_success)
}
DownloadManager.STATUS_FAILED -> getString(R.string.download_error)
else -> getString(R.string.unknown_state)
} }
DownloadManager.STATUS_FAILED -> getString(R.string.download_error)
else -> getString(R.string.unknown_state)
}
upDownloadNotification(id, "${downloads[id]?.second} $status", max, progress) upDownloadNotification(id, "${downloads[id]?.second} $status", max, progress)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }

Loading…
Cancel
Save