mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
a3c3c84ee8
commit
483ed9455a
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user