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 06cd93f7f..14cab7ce3 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -63,20 +63,8 @@ object ReadBook : CoroutineScope by MainScope() { var isLocalBook = true var chapterChanged = false var prevTextChapter: TextChapter? = null - set(value) { - field?.cancelLayout() - field = value - } var curTextChapter: TextChapter? = null - set(value) { - field?.cancelLayout() - field = value - } var nextTextChapter: TextChapter? = null - set(value) { - field?.cancelLayout() - field = value - } var bookSource: BookSource? = null var msg: String? = null private val loadingChapters = arrayListOf() @@ -222,6 +210,9 @@ object ReadBook : CoroutineScope by MainScope() { } fun clearTextChapter() { + prevTextChapter?.cancelLayout() + curTextChapter?.cancelLayout() + nextTextChapter?.cancelLayout() prevTextChapter = null curTextChapter = null nextTextChapter = null @@ -333,6 +324,7 @@ object ReadBook : CoroutineScope by MainScope() { if (durChapterIndex < simulatedChapterSize - 1) { durChapterPos = 0 durChapterIndex++ + prevTextChapter?.cancelLayout() prevTextChapter = curTextChapter curTextChapter = nextTextChapter nextTextChapter = null @@ -363,6 +355,7 @@ object ReadBook : CoroutineScope by MainScope() { if (durChapterIndex < simulatedChapterSize - 1) { durChapterPos = 0 durChapterIndex++ + prevTextChapter?.cancelLayout() prevTextChapter = curTextChapter curTextChapter = nextTextChapter nextTextChapter = null @@ -394,6 +387,7 @@ object ReadBook : CoroutineScope by MainScope() { if (durChapterIndex > 0) { durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: Int.MAX_VALUE else 0 durChapterIndex-- + nextTextChapter?.cancelLayout() nextTextChapter = curTextChapter curTextChapter = prevTextChapter prevTextChapter = null @@ -703,6 +697,7 @@ object ReadBook : CoroutineScope by MainScope() { ) when (val offset = chapter.index - durChapterIndex) { 0 -> { + curTextChapter?.cancelLayout() curTextChapter = textChapter callBack?.upMenuView() var available = false @@ -727,12 +722,14 @@ object ReadBook : CoroutineScope by MainScope() { } -1 -> { + prevTextChapter?.cancelLayout() prevTextChapter = textChapter textChapter.layoutChannel.receiveAsFlow().collect() if (upContent) callBack?.upContent(offset, resetPageOffset) } 1 -> { + nextTextChapter?.cancelLayout() nextTextChapter = textChapter for (page in textChapter.layoutChannel) { if (page.index > 1) { @@ -776,6 +773,7 @@ object ReadBook : CoroutineScope by MainScope() { ) when (val offset = chapter.index - durChapterIndex) { 0 -> { + curTextChapter?.cancelLayout() curTextChapter = textChapter callBack?.upMenuView() var available = false @@ -800,12 +798,14 @@ object ReadBook : CoroutineScope by MainScope() { } -1 -> { + prevTextChapter?.cancelLayout() prevTextChapter = textChapter textChapter.layoutChannel.receiveAsFlow().collect() if (upContent) callBack?.upContent(offset, resetPageOffset) } 1 -> { + nextTextChapter?.cancelLayout() nextTextChapter = textChapter for (page in textChapter.layoutChannel) { if (page.index > 1) { diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt index da9917acc..ebb4e6cec 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditViewModel.kt @@ -1,8 +1,10 @@ package io.legado.app.ui.book.info.edit import android.app.Application +import android.database.sqlite.SQLiteConstraintException import androidx.lifecycle.MutableLiveData import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppLog import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.model.ReadBook @@ -28,6 +30,12 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio appDb.bookDao.update(book) }.onSuccess { success?.invoke() + }.onError { + if (it is SQLiteConstraintException) { + AppLog.put("书籍信息保存失败,存在相同书名作者书籍\n$it", it, true) + } else { + AppLog.put("书籍信息保存失败\n$it", it, true) + } } } } \ No newline at end of file