优化
This commit is contained in:
@@ -154,7 +154,8 @@ object BookHelp {
|
|||||||
bookSource: BookSource,
|
bookSource: BookSource,
|
||||||
book: Book,
|
book: Book,
|
||||||
bookChapter: BookChapter,
|
bookChapter: BookChapter,
|
||||||
content: String
|
content: String,
|
||||||
|
concurrency: Int = AppConfig.threadCount
|
||||||
) = coroutineScope {
|
) = coroutineScope {
|
||||||
flow {
|
flow {
|
||||||
val matcher = AppPattern.imgPattern.matcher(content)
|
val matcher = AppPattern.imgPattern.matcher(content)
|
||||||
@@ -163,7 +164,7 @@ object BookHelp {
|
|||||||
val mSrc = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
|
val mSrc = NetworkUtils.getAbsoluteURL(bookChapter.url, src)
|
||||||
emit(mSrc)
|
emit(mSrc)
|
||||||
}
|
}
|
||||||
}.onEachParallel(AppConfig.threadCount) { mSrc ->
|
}.onEachParallel(concurrency) { mSrc ->
|
||||||
saveImage(bookSource, book, mSrc, bookChapter)
|
saveImage(bookSource, book, mSrc, bookChapter)
|
||||||
}.collect()
|
}.collect()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ object CacheBook {
|
|||||||
if (BookHelp.hasContent(book, chapter)) {
|
if (BookHelp.hasContent(book, chapter)) {
|
||||||
Coroutine.async(executeContext = context) {
|
Coroutine.async(executeContext = context) {
|
||||||
BookHelp.getContent(book, chapter)?.let {
|
BookHelp.getContent(book, chapter)?.let {
|
||||||
BookHelp.saveImages(bookSource, book, chapter, it)
|
BookHelp.saveImages(bookSource, book, chapter, it, 1)
|
||||||
}
|
}
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
onSuccess(chapter)
|
onSuccess(chapter)
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import io.legado.app.utils.fastSum
|
|||||||
import io.legado.app.utils.splitNotBlank
|
import io.legado.app.utils.splitNotBlank
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.CoroutineStart
|
||||||
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -83,7 +85,11 @@ class TextChapterLayout(
|
|||||||
var channel = Channel<TextPage>(Int.MAX_VALUE)
|
var channel = Channel<TextPage>(Int.MAX_VALUE)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
job = Coroutine.async(scope) {
|
job = Coroutine.async(
|
||||||
|
scope,
|
||||||
|
start = CoroutineStart.LAZY,
|
||||||
|
executeContext = IO
|
||||||
|
) {
|
||||||
launch {
|
launch {
|
||||||
val bookSource = book.getBookSource() ?: return@launch
|
val bookSource = book.getBookSource() ?: return@launch
|
||||||
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
|
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
|
||||||
@@ -95,6 +101,7 @@ class TextChapterLayout(
|
|||||||
}.onFinally {
|
}.onFinally {
|
||||||
isCompleted = true
|
isCompleted = true
|
||||||
}
|
}
|
||||||
|
job.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setProgressListener(l: LayoutProgressListener?) {
|
fun setProgressListener(l: LayoutProgressListener?) {
|
||||||
|
|||||||
Reference in New Issue
Block a user