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) { if (!book.isLocal) {
context.startService<CacheBookService> { context.startService<CacheBookService> {
action = IntentAction.start action = IntentAction.start
putExtra("bookUrl", book.bookUrl) putExtra("bookUrl", book.bookUrl)
putExtra("start", start) putExtra("start", start)
putExtra("end", end) putExtra("end", end)
putExtra("startDownload", startDownload)
} }
} }
} }

View File

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

View File

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