|
|
@ -23,6 +23,7 @@ class DownloadService : BaseService() { |
|
|
|
private var tasks: ArrayList<Coroutine<*>> = arrayListOf() |
|
|
|
private var tasks: ArrayList<Coroutine<*>> = arrayListOf() |
|
|
|
private val handler = Handler() |
|
|
|
private val handler = Handler() |
|
|
|
private var runnable: Runnable = Runnable { upDownload() } |
|
|
|
private var runnable: Runnable = Runnable { upDownload() } |
|
|
|
|
|
|
|
private var notificationContent = "正在启动下载" |
|
|
|
private val notificationBuilder by lazy { |
|
|
|
private val notificationBuilder by lazy { |
|
|
|
val builder = NotificationCompat.Builder(this, AppConst.channelIdDownload) |
|
|
|
val builder = NotificationCompat.Builder(this, AppConst.channelIdDownload) |
|
|
|
.setSmallIcon(R.drawable.ic_download) |
|
|
|
.setSmallIcon(R.drawable.ic_download) |
|
|
@ -38,7 +39,7 @@ class DownloadService : BaseService() { |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate() { |
|
|
|
override fun onCreate() { |
|
|
|
super.onCreate() |
|
|
|
super.onCreate() |
|
|
|
updateNotification("正在启动下载") |
|
|
|
updateNotification(notificationContent) |
|
|
|
handler.postDelayed(runnable, 1000) |
|
|
|
handler.postDelayed(runnable, 1000) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -74,7 +75,7 @@ class DownloadService : BaseService() { |
|
|
|
if (!BookHelp.hasContent(book, chapter)) { |
|
|
|
if (!BookHelp.hasContent(book, chapter)) { |
|
|
|
webBook.getContent(book, chapter, scope = this, context = searchPool) |
|
|
|
webBook.getContent(book, chapter, scope = this, context = searchPool) |
|
|
|
.onStart { |
|
|
|
.onStart { |
|
|
|
updateNotification(chapter.title) |
|
|
|
notificationContent = chapter.title |
|
|
|
} |
|
|
|
} |
|
|
|
.onSuccess(IO) { content -> |
|
|
|
.onSuccess(IO) { content -> |
|
|
|
content?.let { |
|
|
|
content?.let { |
|
|
@ -100,6 +101,7 @@ class DownloadService : BaseService() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun upDownload() { |
|
|
|
private fun upDownload() { |
|
|
|
|
|
|
|
updateNotification(notificationContent) |
|
|
|
postEvent(Bus.UP_DOWNLOAD, true) |
|
|
|
postEvent(Bus.UP_DOWNLOAD, true) |
|
|
|
handler.removeCallbacks(runnable) |
|
|
|
handler.removeCallbacks(runnable) |
|
|
|
handler.postDelayed(runnable, 1000) |
|
|
|
handler.postDelayed(runnable, 1000) |
|
|
|