This commit is contained in:
Horis 2024-02-29 20:34:54 +08:00
parent a3c3c84ee8
commit 483ed9455a
3 changed files with 5 additions and 9 deletions

View File

@ -68,14 +68,13 @@ object CacheBook {
}
}
fun start(context: Context, book: Book, start: Int, end: Int, startDownload: Boolean = true) {
fun start(context: Context, book: Book, start: Int, end: Int) {
if (!book.isLocal) {
context.startService<CacheBookService> {
action = IntentAction.start
putExtra("bookUrl", book.bookUrl)
putExtra("start", start)
putExtra("end", end)
putExtra("startDownload", startDownload)
}
}
}

View File

@ -80,8 +80,7 @@ class CacheBookService : BaseService() {
IntentAction.start -> addDownloadData(
intent.getStringExtra("bookUrl"),
intent.getIntExtra("start", 0),
intent.getIntExtra("end", 0),
intent.getBooleanExtra("startDownload", true)
intent.getIntExtra("end", 0)
)
IntentAction.remove -> removeDownload(intent.getStringExtra("bookUrl"))
@ -99,7 +98,7 @@ class CacheBookService : BaseService() {
postEvent(EventBus.UP_DOWNLOAD, "")
}
private fun addDownloadData(bookUrl: String?, start: Int, end: Int, startDownload: Boolean) {
private fun addDownloadData(bookUrl: String?, start: Int, end: Int) {
bookUrl ?: return
execute {
val cacheBook = CacheBook.getOrCreate(bookUrl) ?: return@execute

View File

@ -158,14 +158,12 @@ class CacheActivity : VMBaseActivity<ActivityCacheBookBinding, CacheViewModel>()
when (item.itemId) {
R.id.menu_download -> {
if (!CacheBook.isRun) {
val lastIndex = adapter.itemCount - 1
adapter.getItems().forEachIndexed { index, book ->
adapter.getItems().forEach { book ->
CacheBook.start(
this@CacheActivity,
book,
book.durChapterIndex,
book.lastChapterIndex,
index == lastIndex
book.lastChapterIndex
)
}
} else {