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 5eb9ece5c..e265239a4 100644
--- a/app/src/main/java/io/legado/app/model/ReadBook.kt
+++ b/app/src/main/java/io/legado/app/model/ReadBook.kt
@@ -153,6 +153,8 @@ object ReadBook : CoroutineScope by MainScope() {
upWebBook(book)
synchronized(this) {
loadingChapters.clear()
+ downloadedChapters.clear()
+ downloadFailChapters.clear()
}
}
@@ -615,7 +617,7 @@ object ReadBook : CoroutineScope by MainScope() {
val book = book ?: return
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, index) ?: return
if (BookHelp.hasContent(book, chapter)) {
- addDownloadedChapter(chapter.index)
+ downloadedChapters.add(chapter.index)
} else {
delay(1000)
if (addLoading(index)) {
@@ -673,11 +675,6 @@ object ReadBook : CoroutineScope by MainScope() {
loadingChapters.remove(index)
}
- @Synchronized
- fun addDownloadedChapter(index: Int) {
- downloadedChapters.add(index)
- }
-
/**
* 内容加载完成
*/
diff --git a/app/src/main/java/io/legado/app/model/ReadManga.kt b/app/src/main/java/io/legado/app/model/ReadManga.kt
index 67eedbf96..3c24e5e0b 100644
--- a/app/src/main/java/io/legado/app/model/ReadManga.kt
+++ b/app/src/main/java/io/legado/app/model/ReadManga.kt
@@ -13,6 +13,7 @@ import io.legado.app.help.ConcurrentRateLimiter
import io.legado.app.help.book.BookHelp
import io.legado.app.help.book.ContentProcessor
import io.legado.app.help.book.isLocal
+import io.legado.app.help.book.isSameNameAuthor
import io.legado.app.help.book.readSimulating
import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.book.update
@@ -108,6 +109,8 @@ object ReadManga : CoroutineScope by MainScope() {
upWebBook(book)
synchronized(this) {
loadingChapters.clear()
+ downloadedChapters.clear()
+ downloadFailChapters.clear()
}
}
@@ -151,11 +154,6 @@ object ReadManga : CoroutineScope by MainScope() {
loadingChapters.remove(index)
}
- @Synchronized
- fun addDownloadedChapter(index: Int) {
- downloadedChapters.add(index)
- }
-
fun loadContent() {
clearMangaChapter()
loadContent(durChapterIndex)
@@ -403,7 +401,7 @@ object ReadManga : CoroutineScope by MainScope() {
val book = book ?: return
val chapter = appDb.bookChapterDao.getChapter(book.bookUrl, index) ?: return
if (BookHelp.hasContent(book, chapter)) {
- addDownloadedChapter(chapter.index)
+ downloadedChapters.add(chapter.index)
} else {
delay(1000)
if (addLoading(index)) {
@@ -530,6 +528,18 @@ object ReadManga : CoroutineScope by MainScope() {
mCallback?.showLoading()
}
+ fun onChapterListUpdated(newBook: Book) {
+ if (newBook.isSameNameAuthor(book)) {
+ book = newBook
+ chapterSize = newBook.totalChapterNum
+ simulatedChapterSize = newBook.simulatedTotalChapterNum()
+ if (simulatedChapterSize > 0 && durChapterIndex > simulatedChapterSize - 1) {
+ durChapterIndex = simulatedChapterSize - 1
+ }
+ clearMangaChapter()
+ }
+ }
+
/**
* 注册回调
*/
diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
index 46c5e5139..b91d1c011 100644
--- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
+++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
@@ -32,6 +32,7 @@ import io.legado.app.lib.webdav.ObjectNotFoundException
import io.legado.app.model.AudioPlay
import io.legado.app.model.BookCover
import io.legado.app.model.ReadBook
+import io.legado.app.model.ReadManga
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook
@@ -483,6 +484,9 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
if (ReadBook.book?.bookUrl == bookData.value!!.bookUrl) {
ReadBook.clearTextChapter()
}
+ if (ReadManga.book?.bookUrl == bookData.value!!.bookUrl) {
+ ReadManga.clearMangaChapter()
+ }
}.onSuccess {
context.toastOnUi(R.string.clear_cache_success)
}.onError {
diff --git a/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt b/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt
index 3463e293e..94decfe26 100644
--- a/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt
+++ b/app/src/main/java/io/legado/app/ui/book/manga/ReadMangaViewModel.kt
@@ -15,7 +15,6 @@ import io.legado.app.help.book.BookHelp
import io.legado.app.help.book.isLocal
import io.legado.app.help.book.isLocalModified
import io.legado.app.help.book.removeType
-import io.legado.app.help.book.simulatedTotalChapterNum
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.ReadManga
@@ -81,7 +80,6 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
if ((ReadManga.chapterSize == 0 || book.isLocalModified()) && !loadChapterListAwait(book)) {
return
}
- ensureChapterExist()
//开始加载内容
if (!isSameBook) {
@@ -110,8 +108,7 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
}
appDb.bookChapterDao.delByBook(oldBook.bookUrl)
appDb.bookChapterDao.insert(*cList.toTypedArray())
- ReadManga.chapterSize = cList.size
- ReadManga.simulatedChapterSize = book.simulatedTotalChapterNum()
+ ReadManga.onChapterListUpdated(book)
return true
}.onFailure {
//加载章节出错
@@ -139,12 +136,6 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
}
}
- private fun ensureChapterExist() {
- if (ReadManga.simulatedChapterSize > 0 && ReadManga.durChapterIndex > ReadManga.simulatedChapterSize - 1) {
- ReadManga.durChapterIndex = ReadManga.simulatedChapterSize - 1
- }
- }
-
/**
* 自动换源
*/
diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
index d3fa85fa5..2eeec34eb 100644
--- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
+++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
@@ -9,7 +9,6 @@ import android.widget.EditText
import androidx.activity.viewModels
import androidx.core.view.ViewCompat
import androidx.lifecycle.lifecycleScope
-import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.tabs.TabLayout
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
import io.legado.app.R
@@ -39,6 +38,7 @@ import io.legado.app.ui.qrcode.QrCodeResult
import io.legado.app.ui.widget.dialog.UrlOptionDialog
import io.legado.app.ui.widget.dialog.VariableDialog
import io.legado.app.ui.widget.keyboard.KeyboardToolPop
+import io.legado.app.ui.widget.recycler.NoChildScrollLinearLayoutManager
import io.legado.app.ui.widget.text.EditEntity
import io.legado.app.utils.GSON
import io.legado.app.utils.imeHeight
@@ -184,7 +184,7 @@ class BookSourceEditActivity :
setText(R.string.source_tab_content)
})
binding.recyclerView.setEdgeEffectColor(primaryColor)
- binding.recyclerView.layoutManager = LinearLayoutManager(this)
+ binding.recyclerView.layoutManager = NoChildScrollLinearLayoutManager(this)
binding.recyclerView.adapter = adapter
binding.tabLayout.setBackgroundColor(backgroundColor)
binding.tabLayout.setSelectedTabIndicatorColor(accentColor)
diff --git a/app/src/main/java/io/legado/app/ui/widget/NoChildScrollNestedScrollView.kt b/app/src/main/java/io/legado/app/ui/widget/NoChildScrollNestedScrollView.kt
new file mode 100644
index 000000000..31a28d066
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/widget/NoChildScrollNestedScrollView.kt
@@ -0,0 +1,26 @@
+package io.legado.app.ui.widget
+
+import android.content.Context
+import android.graphics.Rect
+import android.util.AttributeSet
+import android.view.View
+import androidx.core.widget.NestedScrollView
+
+class NoChildScrollNestedScrollView @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+) : NestedScrollView(context, attrs) {
+
+ override fun requestChildFocus(child: View?, focused: View?) {
+ // do nothing
+ }
+
+ override fun requestChildRectangleOnScreen(
+ child: View,
+ rectangle: Rect?,
+ immediate: Boolean
+ ): Boolean {
+ return false
+ }
+
+}
diff --git a/app/src/main/java/io/legado/app/ui/widget/recycler/NoChildScrollLinearLayoutManager.kt b/app/src/main/java/io/legado/app/ui/widget/recycler/NoChildScrollLinearLayoutManager.kt
new file mode 100644
index 000000000..e9e8e1e69
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/widget/recycler/NoChildScrollLinearLayoutManager.kt
@@ -0,0 +1,39 @@
+package io.legado.app.ui.widget.recycler
+
+import android.content.Context
+import android.graphics.Rect
+import android.view.View
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+
+class NoChildScrollLinearLayoutManager(context: Context) : LinearLayoutManager(context) {
+
+ override fun onRequestChildFocus(
+ parent: RecyclerView,
+ state: RecyclerView.State,
+ child: View,
+ focused: View?
+ ): Boolean {
+ return true
+ }
+
+ override fun requestChildRectangleOnScreen(
+ parent: RecyclerView,
+ child: View,
+ rect: Rect,
+ immediate: Boolean,
+ focusedChildVisible: Boolean
+ ): Boolean {
+ return false
+ }
+
+ override fun requestChildRectangleOnScreen(
+ parent: RecyclerView,
+ child: View,
+ rect: Rect,
+ immediate: Boolean
+ ): Boolean {
+ return false
+ }
+
+}
diff --git a/app/src/main/res/layout/activity_book_info.xml b/app/src/main/res/layout/activity_book_info.xml
index 9b3d90a16..2515362a1 100644
--- a/app/src/main/res/layout/activity_book_info.xml
+++ b/app/src/main/res/layout/activity_book_info.xml
@@ -35,7 +35,7 @@
android:layout_height="0dp"
android:layout_weight="1">
-
-
+
diff --git a/app/src/main/res/layout/activity_replace_edit.xml b/app/src/main/res/layout/activity_replace_edit.xml
index ef0553e3c..5e136534c 100644
--- a/app/src/main/res/layout/activity_replace_edit.xml
+++ b/app/src/main/res/layout/activity_replace_edit.xml
@@ -15,7 +15,7 @@
app:displayHomeAsUp="true"
app:title="@string/replace_rule_edit" />
-
@@ -166,6 +166,6 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_source_debug.xml b/app/src/main/res/layout/activity_source_debug.xml
index 0df2ee495..be146cfca 100644
--- a/app/src/main/res/layout/activity_source_debug.xml
+++ b/app/src/main/res/layout/activity_source_debug.xml
@@ -36,7 +36,7 @@
app:layout_constraintTop_toBottomOf="@+id/title_bar"
app:loading_width="2dp" />
-
-
+
\ No newline at end of file