为下载通知增加进度条
This commit is contained in:
@@ -30,6 +30,20 @@ object CacheBook {
|
|||||||
|
|
||||||
val cacheBookMap = ConcurrentHashMap<String, CacheBookModel>()
|
val cacheBookMap = ConcurrentHashMap<String, CacheBookModel>()
|
||||||
|
|
||||||
|
val totalCount: Int
|
||||||
|
get() {
|
||||||
|
var total = 0
|
||||||
|
cacheBookMap.forEach { (_, model) ->
|
||||||
|
total += model.waitCount + model.onDownloadCount
|
||||||
|
}
|
||||||
|
total += successDownloadSet.size
|
||||||
|
total += errorDownloadMap.size
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
val completedCount: Int
|
||||||
|
get() = successDownloadSet.size + errorDownloadMap.size
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun getOrCreate(bookUrl: String): CacheBookModel? {
|
fun getOrCreate(bookUrl: String): CacheBookModel? {
|
||||||
val book = appDb.bookDao.getBook(bookUrl) ?: return null
|
val book = appDb.bookDao.getBook(bookUrl) ?: return null
|
||||||
|
|||||||
@@ -210,9 +210,20 @@ class CacheBookService : BaseService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun upCacheBookNotification() {
|
private fun upCacheBookNotification() {
|
||||||
notificationBuilder.setContentText(notificationContent)
|
val total = CacheBook.totalCount
|
||||||
val notification = notificationBuilder.build()
|
val progress = CacheBook.completedCount
|
||||||
notificationManager.notify(NotificationId.CacheBookService, notification)
|
val summary = CacheBook.downloadSummary
|
||||||
|
|
||||||
|
notificationBuilder.apply {
|
||||||
|
setContentText(summary)
|
||||||
|
if (total > 0) {
|
||||||
|
setProgress(total, progress, false)
|
||||||
|
} else {
|
||||||
|
setProgress(0, 0, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationManager.notify(NotificationId.CacheBookService, notificationBuilder.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user