diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index ae48ee612666..02169943d72a 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -44,7 +44,7 @@ data class BookChapter( var isVip: Boolean = false, // 是否VIP var isPay: Boolean = false, // 是否已购买 var resourceUrl: String? = null, // 音频真实URL - var tag: String? = null, // + var tag: String? = null, // 更新时间或其他章节附加信息 var start: Long? = null, // 章节起始位置 var end: Long? = null, // 章节终止位置 var startFragmentId: String? = null, //EPUB书籍当前章节的fragmentId diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index 937b5a20b674..f09b358de247 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -303,6 +303,7 @@ object CacheBook { downloadFinish(chapter, content, resetPageOffset) }.onError { onError(chapter, it) + ReadBook.downloadFailChapters.add(chapter.index) downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset) }.onCancel { onCancel(chapter.index) @@ -314,14 +315,12 @@ object CacheBook { private fun downloadFinish( chapter: BookChapter, content: String, - resetPageOffset: Boolean = false, - pageChanged: Boolean = false, + resetPageOffset: Boolean = false ) { if (ReadBook.book?.bookUrl == book.bookUrl) { ReadBook.contentLoadFinish( book, chapter, content, resetPageOffset = resetPageOffset, - pageChanged = pageChanged ) } } diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index e360c7e2ac54..d1da43d9719a 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -55,6 +55,7 @@ object ReadBook : CoroutineScope by MainScope() { var preDownloadTask: Coroutine<*>? = null val downloadedChapters = hashSetOf() + val downloadFailChapters = hashSetOf() var contentProcessor: ContentProcessor? = null val downloadScope = CoroutineScope(SupervisorJob() + IO) @@ -202,7 +203,7 @@ object ReadBook : CoroutineScope by MainScope() { nextTextChapter = null if (curTextChapter == null) { AppLog.putDebug("moveToNextChapter-章节未加载,开始加载") - loadContent(durChapterIndex, upContent, resetPageOffset = false, pageChanged = true) + loadContent(durChapterIndex, upContent, resetPageOffset = false) } else if (upContent) { AppLog.putDebug("moveToNextChapter-章节已加载,刷新视图") callBack?.upContent() @@ -230,7 +231,7 @@ object ReadBook : CoroutineScope by MainScope() { curTextChapter = prevTextChapter prevTextChapter = null if (curTextChapter == null) { - loadContent(durChapterIndex, upContent, resetPageOffset = false, pageChanged = true) + loadContent(durChapterIndex, upContent, resetPageOffset = false) } else if (upContent) { callBack?.upContent() } @@ -312,14 +313,9 @@ object ReadBook : CoroutineScope by MainScope() { */ fun loadContent( resetPageOffset: Boolean, - pageChanged: Boolean = false, success: (() -> Unit)? = null ) { - loadContent( - durChapterIndex, - resetPageOffset = resetPageOffset, - pageChanged = pageChanged - ) { + loadContent(durChapterIndex, resetPageOffset = resetPageOffset) { success?.invoke() } loadContent(durChapterIndex + 1, resetPageOffset = resetPageOffset) @@ -331,14 +327,12 @@ object ReadBook : CoroutineScope by MainScope() { * @param index 章节序号 * @param upContent 是否更新视图 * @param resetPageOffset 滚动阅读是否重置滚动位置 - * @param pageChanged 是否发生了翻页 * @param success 加载完成回调 */ fun loadContent( index: Int, upContent: Boolean = true, resetPageOffset: Boolean = false, - pageChanged: Boolean = false, success: (() -> Unit)? = null ) { if (addLoading(index)) { @@ -351,16 +345,14 @@ object ReadBook : CoroutineScope by MainScope() { chapter, it, upContent, - resetPageOffset, - pageChanged + resetPageOffset ) { success?.invoke() } } ?: download( downloadScope, chapter, - resetPageOffset = resetPageOffset, - pageChanged = pageChanged + resetPageOffset ) } ?: removeLoading(index) }.onError { @@ -388,12 +380,7 @@ object ReadBook : CoroutineScope by MainScope() { downloadedChapters.add(chapter.index) } else { delay(1000) - download( - downloadScope, - chapter, - resetPageOffset = false, - pageChanged = false - ) + download(downloadScope, chapter, false) } } ?: removeLoading(index) } catch (e: Exception) { @@ -409,7 +396,6 @@ object ReadBook : CoroutineScope by MainScope() { scope: CoroutineScope, chapter: BookChapter, resetPageOffset: Boolean, - pageChanged: Boolean, success: (() -> Unit)? = null ) { val book = book ?: return removeLoading(chapter.index) @@ -423,7 +409,6 @@ object ReadBook : CoroutineScope by MainScope() { chapter, "加载正文失败\n$msg", resetPageOffset = resetPageOffset, - pageChanged = pageChanged ) { success?.invoke() } @@ -453,7 +438,6 @@ object ReadBook : CoroutineScope by MainScope() { content: String, upContent: Boolean = true, resetPageOffset: Boolean, - pageChanged: Boolean, success: (() -> Unit)? = null ) { removeLoading(chapter.index) @@ -475,7 +459,7 @@ object ReadBook : CoroutineScope by MainScope() { curTextChapter = textChapter if (upContent) callBack?.upContent(offset, resetPageOffset) callBack?.upMenuView() - if (pageChanged) curPageChanged() + curPageChanged() callBack?.contentLoadFinish() } @@ -561,6 +545,7 @@ object ReadBook : CoroutineScope by MainScope() { val maxChapterIndex = min(durChapterIndex + AppConfig.preDownloadNum, chapterSize) for (i in durChapterIndex.plus(2)..maxChapterIndex) { if (downloadedChapters.contains(i)) continue + if (downloadFailChapters.contains(i)) continue downloadIndex(i) } } @@ -568,6 +553,7 @@ object ReadBook : CoroutineScope by MainScope() { val minChapterIndex = durChapterIndex - min(5, AppConfig.preDownloadNum) for (i in durChapterIndex.minus(2) downTo minChapterIndex) { if (downloadedChapters.contains(i)) continue + if (downloadFailChapters.contains(i)) continue downloadIndex(i) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index ca89af7c57c3..127b9cdc2318 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -1377,6 +1377,7 @@ class ReadBookActivity : BaseReadBookActivity(), ReadBook.downloadScope.coroutineContext.cancelChildren() ReadBook.coroutineContext.cancelChildren() ReadBook.downloadedChapters.clear() + ReadBook.downloadFailChapters.clear() if (!BuildConfig.DEBUG) { Backup.autoBack(this) } @@ -1393,6 +1394,7 @@ class ReadBookActivity : BaseReadBookActivity(), } } observeEvent(EventBus.UP_CONFIG) { + if (!isInitFinish) return@observeEvent upSystemUiVisibility() readView.upPageSlopSquare() readView.upBg() diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index eabf7592a8d5..7bd667c41865 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -228,7 +228,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { appDb.bookChapterDao.insert(*toc.toTypedArray()) ReadBook.resetData(book) ReadBook.upMsg(null) - ReadBook.loadContent(resetPageOffset = true, pageChanged = true) + ReadBook.loadContent(resetPageOffset = true) }.onError { context.toastOnUi("换源失败\n${it.localizedMessage}") ReadBook.upMsg(null) @@ -286,7 +286,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ReadBook.durChapterIndex = index ReadBook.durChapterPos = durChapterPos ReadBook.saveRead() - ReadBook.loadContent(resetPageOffset = true, pageChanged = true) { + ReadBook.loadContent(resetPageOffset = true) { success?.invoke() } } @@ -315,11 +315,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { appDb.bookChapterDao.getChapter(book.bookUrl, ReadBook.durChapterIndex) ?.let { chapter -> BookHelp.delContent(book, chapter) - ReadBook.loadContent( - ReadBook.durChapterIndex, - resetPageOffset = false, - pageChanged = true - ) + ReadBook.loadContent(ReadBook.durChapterIndex, resetPageOffset = false) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index cbf6635fc13d..7d5110f41f06 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -478,7 +478,7 @@ class ReadView(context: Context, attrs: AttributeSet) : /** * 翻页动画完成后事件 - * @param direction 翻页翻页反向 + * @param direction 翻页方向 */ fun fillPage(direction: PageDirection): Boolean { return when (direction) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 0bbe6c06e894..addaaddb207b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -11,7 +11,7 @@ abstract class HorizontalPageDelegate(readView: ReadView) : PageDelegate(readVie protected var curBitmap: Bitmap? = null protected var prevBitmap: Bitmap? = null protected var nextBitmap: Bitmap? = null - protected val slopSquare by lazy { readView.slopSquare * readView.slopSquare } + private val slopSquare by lazy { readView.slopSquare * readView.slopSquare } override fun setDirection(direction: PageDirection) { super.setDirection(direction) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index 120b2e65441b..523ac562147b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -127,7 +127,7 @@ object ChapterProvider { var absStartX = paddingLeft var durY = 0f textPages.add(TextPage()) - if (ReadBookConfig.titleMode != 2) { + if (ReadBookConfig.titleMode != 2 || bookChapter.isVolume) { //标题非隐藏 displayTitle.splitNotBlank("\n").forEach { text -> setTypeText(