优化
This commit is contained in:
@@ -63,20 +63,8 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
var isLocalBook = true
|
var isLocalBook = true
|
||||||
var chapterChanged = false
|
var chapterChanged = false
|
||||||
var prevTextChapter: TextChapter? = null
|
var prevTextChapter: TextChapter? = null
|
||||||
set(value) {
|
|
||||||
field?.cancelLayout()
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
var curTextChapter: TextChapter? = null
|
var curTextChapter: TextChapter? = null
|
||||||
set(value) {
|
|
||||||
field?.cancelLayout()
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
var nextTextChapter: TextChapter? = null
|
var nextTextChapter: TextChapter? = null
|
||||||
set(value) {
|
|
||||||
field?.cancelLayout()
|
|
||||||
field = value
|
|
||||||
}
|
|
||||||
var bookSource: BookSource? = null
|
var bookSource: BookSource? = null
|
||||||
var msg: String? = null
|
var msg: String? = null
|
||||||
private val loadingChapters = arrayListOf<Int>()
|
private val loadingChapters = arrayListOf<Int>()
|
||||||
@@ -222,6 +210,9 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun clearTextChapter() {
|
fun clearTextChapter() {
|
||||||
|
prevTextChapter?.cancelLayout()
|
||||||
|
curTextChapter?.cancelLayout()
|
||||||
|
nextTextChapter?.cancelLayout()
|
||||||
prevTextChapter = null
|
prevTextChapter = null
|
||||||
curTextChapter = null
|
curTextChapter = null
|
||||||
nextTextChapter = null
|
nextTextChapter = null
|
||||||
@@ -333,6 +324,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
if (durChapterIndex < simulatedChapterSize - 1) {
|
if (durChapterIndex < simulatedChapterSize - 1) {
|
||||||
durChapterPos = 0
|
durChapterPos = 0
|
||||||
durChapterIndex++
|
durChapterIndex++
|
||||||
|
prevTextChapter?.cancelLayout()
|
||||||
prevTextChapter = curTextChapter
|
prevTextChapter = curTextChapter
|
||||||
curTextChapter = nextTextChapter
|
curTextChapter = nextTextChapter
|
||||||
nextTextChapter = null
|
nextTextChapter = null
|
||||||
@@ -363,6 +355,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
if (durChapterIndex < simulatedChapterSize - 1) {
|
if (durChapterIndex < simulatedChapterSize - 1) {
|
||||||
durChapterPos = 0
|
durChapterPos = 0
|
||||||
durChapterIndex++
|
durChapterIndex++
|
||||||
|
prevTextChapter?.cancelLayout()
|
||||||
prevTextChapter = curTextChapter
|
prevTextChapter = curTextChapter
|
||||||
curTextChapter = nextTextChapter
|
curTextChapter = nextTextChapter
|
||||||
nextTextChapter = null
|
nextTextChapter = null
|
||||||
@@ -394,6 +387,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
if (durChapterIndex > 0) {
|
if (durChapterIndex > 0) {
|
||||||
durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: Int.MAX_VALUE else 0
|
durChapterPos = if (toLast) prevTextChapter?.lastReadLength ?: Int.MAX_VALUE else 0
|
||||||
durChapterIndex--
|
durChapterIndex--
|
||||||
|
nextTextChapter?.cancelLayout()
|
||||||
nextTextChapter = curTextChapter
|
nextTextChapter = curTextChapter
|
||||||
curTextChapter = prevTextChapter
|
curTextChapter = prevTextChapter
|
||||||
prevTextChapter = null
|
prevTextChapter = null
|
||||||
@@ -703,6 +697,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
)
|
)
|
||||||
when (val offset = chapter.index - durChapterIndex) {
|
when (val offset = chapter.index - durChapterIndex) {
|
||||||
0 -> {
|
0 -> {
|
||||||
|
curTextChapter?.cancelLayout()
|
||||||
curTextChapter = textChapter
|
curTextChapter = textChapter
|
||||||
callBack?.upMenuView()
|
callBack?.upMenuView()
|
||||||
var available = false
|
var available = false
|
||||||
@@ -727,12 +722,14 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-1 -> {
|
-1 -> {
|
||||||
|
prevTextChapter?.cancelLayout()
|
||||||
prevTextChapter = textChapter
|
prevTextChapter = textChapter
|
||||||
textChapter.layoutChannel.receiveAsFlow().collect()
|
textChapter.layoutChannel.receiveAsFlow().collect()
|
||||||
if (upContent) callBack?.upContent(offset, resetPageOffset)
|
if (upContent) callBack?.upContent(offset, resetPageOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> {
|
1 -> {
|
||||||
|
nextTextChapter?.cancelLayout()
|
||||||
nextTextChapter = textChapter
|
nextTextChapter = textChapter
|
||||||
for (page in textChapter.layoutChannel) {
|
for (page in textChapter.layoutChannel) {
|
||||||
if (page.index > 1) {
|
if (page.index > 1) {
|
||||||
@@ -776,6 +773,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
)
|
)
|
||||||
when (val offset = chapter.index - durChapterIndex) {
|
when (val offset = chapter.index - durChapterIndex) {
|
||||||
0 -> {
|
0 -> {
|
||||||
|
curTextChapter?.cancelLayout()
|
||||||
curTextChapter = textChapter
|
curTextChapter = textChapter
|
||||||
callBack?.upMenuView()
|
callBack?.upMenuView()
|
||||||
var available = false
|
var available = false
|
||||||
@@ -800,12 +798,14 @@ object ReadBook : CoroutineScope by MainScope() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
-1 -> {
|
-1 -> {
|
||||||
|
prevTextChapter?.cancelLayout()
|
||||||
prevTextChapter = textChapter
|
prevTextChapter = textChapter
|
||||||
textChapter.layoutChannel.receiveAsFlow().collect()
|
textChapter.layoutChannel.receiveAsFlow().collect()
|
||||||
if (upContent) callBack?.upContent(offset, resetPageOffset)
|
if (upContent) callBack?.upContent(offset, resetPageOffset)
|
||||||
}
|
}
|
||||||
|
|
||||||
1 -> {
|
1 -> {
|
||||||
|
nextTextChapter?.cancelLayout()
|
||||||
nextTextChapter = textChapter
|
nextTextChapter = textChapter
|
||||||
for (page in textChapter.layoutChannel) {
|
for (page in textChapter.layoutChannel) {
|
||||||
if (page.index > 1) {
|
if (page.index > 1) {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package io.legado.app.ui.book.info.edit
|
package io.legado.app.ui.book.info.edit
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.database.sqlite.SQLiteConstraintException
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import io.legado.app.base.BaseViewModel
|
import io.legado.app.base.BaseViewModel
|
||||||
|
import io.legado.app.constant.AppLog
|
||||||
import io.legado.app.data.appDb
|
import io.legado.app.data.appDb
|
||||||
import io.legado.app.data.entities.Book
|
import io.legado.app.data.entities.Book
|
||||||
import io.legado.app.model.ReadBook
|
import io.legado.app.model.ReadBook
|
||||||
@@ -28,6 +30,12 @@ class BookInfoEditViewModel(application: Application) : BaseViewModel(applicatio
|
|||||||
appDb.bookDao.update(book)
|
appDb.bookDao.update(book)
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
success?.invoke()
|
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