|
@@ -20,6 +20,7 @@ import io.legado.app.utils.toastOnUi
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
import kotlinx.coroutines.MainScope
|
|
import kotlinx.coroutines.MainScope
|
|
|
|
|
+import kotlinx.coroutines.SupervisorJob
|
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
import splitties.init.appCtx
|
|
import splitties.init.appCtx
|
|
@@ -55,6 +56,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
var preDownloadTask: Coroutine<*>? = null
|
|
var preDownloadTask: Coroutine<*>? = null
|
|
|
val downloadedChapters = hashSetOf<Int>()
|
|
val downloadedChapters = hashSetOf<Int>()
|
|
|
var contentProcessor: ContentProcessor? = null
|
|
var contentProcessor: ContentProcessor? = null
|
|
|
|
|
+ val downloadScope = CoroutineScope(SupervisorJob() + IO)
|
|
|
|
|
|
|
|
//暂时保存跳转前进度
|
|
//暂时保存跳转前进度
|
|
|
fun saveCurrentBookProcess() {
|
|
fun saveCurrentBookProcess() {
|
|
@@ -347,7 +349,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
success?.invoke()
|
|
success?.invoke()
|
|
|
}
|
|
}
|
|
|
} ?: download(
|
|
} ?: download(
|
|
|
- this,
|
|
|
|
|
|
|
+ downloadScope,
|
|
|
chapter,
|
|
chapter,
|
|
|
resetPageOffset = resetPageOffset,
|
|
resetPageOffset = resetPageOffset,
|
|
|
pageChanged = pageChanged
|
|
pageChanged = pageChanged
|
|
@@ -378,7 +380,12 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
downloadedChapters.add(chapter.index)
|
|
downloadedChapters.add(chapter.index)
|
|
|
} else {
|
|
} else {
|
|
|
delay(1000)
|
|
delay(1000)
|
|
|
- download(this, chapter, resetPageOffset = false, pageChanged = false)
|
|
|
|
|
|
|
+ download(
|
|
|
|
|
+ downloadScope,
|
|
|
|
|
+ chapter,
|
|
|
|
|
+ resetPageOffset = false,
|
|
|
|
|
+ pageChanged = false
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
} ?: removeLoading(index)
|
|
} ?: removeLoading(index)
|
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
@@ -513,16 +520,19 @@ object ReadBook : CoroutineScope by MainScope() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun saveRead() {
|
|
fun saveRead() {
|
|
|
- Coroutine.async {
|
|
|
|
|
|
|
+ Coroutine.async(executeContext = IO) {
|
|
|
val book = book ?: return@async
|
|
val book = book ?: return@async
|
|
|
book.lastCheckCount = 0
|
|
book.lastCheckCount = 0
|
|
|
book.durChapterTime = System.currentTimeMillis()
|
|
book.durChapterTime = System.currentTimeMillis()
|
|
|
|
|
+ val chapterChanged = book.durChapterIndex != durChapterIndex
|
|
|
book.durChapterIndex = durChapterIndex
|
|
book.durChapterIndex = durChapterIndex
|
|
|
book.durChapterPos = durChapterPos
|
|
book.durChapterPos = durChapterPos
|
|
|
- appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
|
|
|
|
|
- book.durChapterTitle = it.getDisplayTitle(
|
|
|
|
|
- ContentProcessor.get(book.name, book.origin).getTitleReplaceRules()
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ if (chapterChanged) {
|
|
|
|
|
+ appDb.bookChapterDao.getChapter(book.bookUrl, durChapterIndex)?.let {
|
|
|
|
|
+ book.durChapterTitle = it.getDisplayTitle(
|
|
|
|
|
+ ContentProcessor.get(book.name, book.origin).getTitleReplaceRules()
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
appDb.bookDao.update(book)
|
|
appDb.bookDao.update(book)
|
|
|
}
|
|
}
|