pull/1259/head
gedoor 3 years ago
parent 52d3b845cb
commit 6937184ec4
  1. 2
      app/src/main/assets/updateLog.md
  2. 47
      app/src/main/java/io/legado/app/model/ReadBook.kt
  3. 2
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt

@ -14,7 +14,7 @@
**2021/08/18** **2021/08/18**
1. 翻到最后一章时自动更新最新章节 1. 阅读时自动更新最新章节
2. 朗读添加媒体按键配置 2. 朗读添加媒体按键配置
3. 修复rss列表界面分类往回切换时没有数据的bug 3. 修复rss列表界面分类往回切换时没有数据的bug
4. 修复订阅分类往回切换时不显示内容的bug 4. 修复订阅分类往回切换时不显示内容的bug

@ -19,14 +19,13 @@ import io.legado.app.utils.msg
import io.legado.app.utils.toastOnUi 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.delay import kotlinx.coroutines.delay
import splitties.init.appCtx import splitties.init.appCtx
import kotlin.math.max
import kotlin.math.min
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
object ReadBook { object ReadBook : CoroutineScope by MainScope() {
var titleDate = MutableLiveData<String>() var titleDate = MutableLiveData<String>()
var book: Book? = null var book: Book? = null
var inBookshelf = false var inBookshelf = false
@ -145,27 +144,11 @@ object ReadBook {
curPageChanged() curPageChanged()
Coroutine.async { Coroutine.async {
//预下载 //预下载
val maxChapterIndex = val maxChapterIndex = durChapterIndex + AppConfig.preDownloadNum
min(chapterSize - 1, durChapterIndex + AppConfig.preDownloadNum)
for (i in durChapterIndex.plus(2)..maxChapterIndex) { for (i in durChapterIndex.plus(2)..maxChapterIndex) {
delay(1000) delay(1000)
download(i) download(i)
} }
book?.let { book ->
//最后一章时检查更新
if (durChapterPos == 0 && durChapterIndex == chapterSize - 1) {
webBook?.getChapterList(this, book)
?.onSuccess(IO) { cList ->
if (book.bookUrl == ReadBook.book?.bookUrl
&& cList.size > chapterSize
) {
appDb.bookChapterDao.insert(*cList.toTypedArray())
chapterSize = cList.size
nextTextChapter ?: loadContent(1)
}
}
}
}
} }
return true return true
} else { } else {
@ -194,7 +177,7 @@ object ReadBook {
curPageChanged() curPageChanged()
Coroutine.async { Coroutine.async {
//预下载 //预下载
val minChapterIndex = max(0, durChapterIndex - 5) val minChapterIndex = durChapterIndex - 5
for (i in durChapterIndex.minus(2) downTo minChapterIndex) { for (i in durChapterIndex.minus(2) downTo minChapterIndex) {
delay(1000) delay(1000)
download(i) download(i)
@ -301,6 +284,11 @@ object ReadBook {
} }
private fun download(index: Int) { private fun download(index: Int) {
if (index < 0) return
if (index > chapterSize - 1) {
upToc()
return
}
book?.let { book -> book?.let { book ->
if (book.isLocalBook()) return if (book.isLocalBook()) return
if (addLoading(index)) { if (addLoading(index)) {
@ -404,6 +392,23 @@ object ReadBook {
} }
} }
@Synchronized
fun upToc() {
val webBook = webBook ?: return
val book = book ?: return
if (System.currentTimeMillis() - book.lastCheckTime < 600000) return
book.lastCheckTime = System.currentTimeMillis()
webBook.getChapterList(this, book).onSuccess(IO) { cList ->
if (book.bookUrl == ReadBook.book?.bookUrl
&& cList.size > chapterSize
) {
appDb.bookChapterDao.insert(*cList.toTypedArray())
chapterSize = cList.size
nextTextChapter ?: loadContent(1)
}
}
}
fun pageAnim(): Int { fun pageAnim(): Int {
book?.let { book?.let {
return if (it.getPageAnim() < 0) return if (it.getPageAnim() < 0)

@ -120,8 +120,8 @@ object BookChapterList {
if (book.totalChapterNum < list.size) { if (book.totalChapterNum < list.size) {
book.lastCheckCount = list.size - book.totalChapterNum book.lastCheckCount = list.size - book.totalChapterNum
book.latestChapterTime = System.currentTimeMillis() book.latestChapterTime = System.currentTimeMillis()
book.lastCheckTime = System.currentTimeMillis()
} }
book.lastCheckTime = System.currentTimeMillis()
book.totalChapterNum = list.size book.totalChapterNum = list.size
return list return list
} }

Loading…
Cancel
Save