|
|
|
@ -60,7 +60,7 @@ class CacheBookService : BaseService() { |
|
|
|
|
|
|
|
|
|
override fun onCreate() { |
|
|
|
|
super.onCreate() |
|
|
|
|
updateNotification(notificationContent) |
|
|
|
|
upNotification() |
|
|
|
|
handler.postDelayed(runnable, 1000) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -126,8 +126,9 @@ class CacheBookService : BaseService() { |
|
|
|
|
private fun addDownloadData(bookUrl: String?, start: Int, end: Int) { |
|
|
|
|
bookUrl ?: return |
|
|
|
|
if (downloadMap.containsKey(bookUrl)) { |
|
|
|
|
updateNotification(getString(R.string.already_in_download)) |
|
|
|
|
toast(R.string.already_in_download) |
|
|
|
|
notificationContent = getString(R.string.already_in_download) |
|
|
|
|
upNotification() |
|
|
|
|
toast(notificationContent) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
downloadCount[bookUrl] = DownloadCount() |
|
|
|
@ -193,15 +194,15 @@ class CacheBookService : BaseService() { |
|
|
|
|
synchronized(this) { |
|
|
|
|
downloadingList.remove(bookChapter.url) |
|
|
|
|
} |
|
|
|
|
CacheBook.addLog("getContentError${it.localizedMessage}") |
|
|
|
|
updateNotification("getContentError${it.localizedMessage}") |
|
|
|
|
notificationContent = "getContentError${it.localizedMessage}" |
|
|
|
|
upNotification() |
|
|
|
|
} |
|
|
|
|
.onSuccess { |
|
|
|
|
synchronized(this@CacheBookService) { |
|
|
|
|
downloadCount[book.bookUrl]?.increaseSuccess() |
|
|
|
|
downloadCount[book.bookUrl]?.increaseFinished() |
|
|
|
|
downloadCount[book.bookUrl]?.let { |
|
|
|
|
updateNotification( |
|
|
|
|
upNotification( |
|
|
|
|
it, |
|
|
|
|
downloadMap[book.bookUrl]?.size, |
|
|
|
|
bookChapter.title |
|
|
|
@ -230,8 +231,9 @@ class CacheBookService : BaseService() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onError { |
|
|
|
|
CacheBook.addLog("ERROR:${it.localizedMessage}") |
|
|
|
|
updateNotification("ERROR:${it.localizedMessage}") |
|
|
|
|
notificationContent = "ERROR:${it.localizedMessage}" |
|
|
|
|
CacheBook.addLog(notificationContent) |
|
|
|
|
upNotification() |
|
|
|
|
} |
|
|
|
|
tasks.add(task) |
|
|
|
|
} |
|
|
|
@ -253,13 +255,13 @@ class CacheBookService : BaseService() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upDownload() { |
|
|
|
|
updateNotification(notificationContent) |
|
|
|
|
upNotification() |
|
|
|
|
postEvent(EventBus.UP_DOWNLOAD, downloadMap) |
|
|
|
|
handler.removeCallbacks(runnable) |
|
|
|
|
handler.postDelayed(runnable, 1000) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun updateNotification( |
|
|
|
|
private fun upNotification( |
|
|
|
|
downloadCount: DownloadCount, |
|
|
|
|
totalCount: Int?, |
|
|
|
|
content: String |
|
|
|
@ -271,8 +273,8 @@ class CacheBookService : BaseService() { |
|
|
|
|
/** |
|
|
|
|
* 更新通知 |
|
|
|
|
*/ |
|
|
|
|
private fun updateNotification(content: String) { |
|
|
|
|
notificationBuilder.setContentText(content) |
|
|
|
|
private fun upNotification() { |
|
|
|
|
notificationBuilder.setContentText(notificationContent) |
|
|
|
|
val notification = notificationBuilder.build() |
|
|
|
|
startForeground(AppConst.notificationIdDownload, notification) |
|
|
|
|
} |
|
|
|
|