mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +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) {
|
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user