mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -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<Int>()
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user