mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
Some checks failed
Test Build / prepare (push) Has been cancelled
Test Build / build (app, release) (push) Has been cancelled
Test Build / build (app, releaseA) (push) Has been cancelled
Test Build / prerelease (push) Has been cancelled
Test Build / lanzou (push) Has been cancelled
Test Build / test_Branch (push) Has been cancelled
Test Build / telegram (push) Has been cancelled
update fork / build (push) Has been cancelled
Update Cronet / build (push) Has been cancelled
closeStaleIssue / stale (push) Has been cancelled
Some checks failed
Test Build / prepare (push) Has been cancelled
Test Build / build (app, release) (push) Has been cancelled
Test Build / build (app, releaseA) (push) Has been cancelled
Test Build / prerelease (push) Has been cancelled
Test Build / lanzou (push) Has been cancelled
Test Build / test_Branch (push) Has been cancelled
Test Build / telegram (push) Has been cancelled
update fork / build (push) Has been cancelled
Update Cronet / build (push) Has been cancelled
closeStaleIssue / stale (push) Has been cancelled
This commit is contained in:
@@ -49,6 +49,7 @@ object ReadManga : CoroutineScope by MainScope() {
|
||||
var durChapterIndex = 0 //章节位置
|
||||
var chapterSize = 0//总章节
|
||||
var durChapterPos = 0
|
||||
var chapterChanged = false
|
||||
var prevMangaChapter: MangaChapter? = null
|
||||
var curMangaChapter: MangaChapter? = null
|
||||
var nextMangaChapter: MangaChapter? = null
|
||||
|
||||
@@ -10,11 +10,14 @@ import io.legado.app.constant.EventBus
|
||||
import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.BookChapter
|
||||
import io.legado.app.data.entities.BookProgress
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.AppWebDav
|
||||
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
|
||||
@@ -43,6 +46,7 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
|
||||
fun initData(intent: Intent, success: (() -> Unit)? = null) {
|
||||
execute {
|
||||
ReadManga.inBookshelf = intent.getBooleanExtra("inBookshelf", true)
|
||||
ReadManga.chapterChanged = intent.getBooleanExtra("chapterChanged", false)
|
||||
val bookUrl = intent.getStringExtra("bookUrl")
|
||||
val book = when {
|
||||
bookUrl.isNullOrEmpty() -> appDb.bookDao.lastReadBook
|
||||
@@ -88,6 +92,17 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
|
||||
ReadManga.loadOrUpContent()
|
||||
}
|
||||
|
||||
if (ReadManga.chapterChanged) {
|
||||
// 有章节跳转不同步阅读进度
|
||||
ReadManga.chapterChanged = false
|
||||
} else if (!isSameBook) {
|
||||
if (AppConfig.syncBookProgressPlus) {
|
||||
ReadManga.syncProgress(
|
||||
{ progress -> ReadManga.mCallback?.sureNewProgress(progress) })
|
||||
} else {
|
||||
syncBookProgress(book)
|
||||
}
|
||||
}
|
||||
|
||||
//自动换源
|
||||
if (!book.isLocal && ReadManga.bookSource == null) {
|
||||
@@ -130,8 +145,7 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
|
||||
WebBook.getBookInfoAwait(source, book, canReName = false)
|
||||
return true
|
||||
} catch (e: Throwable) {
|
||||
// 加载详情页失败
|
||||
// ReadBook.upMsg("详情页出错: ${e.localizedMessage}")
|
||||
ReadManga.mCallback?.loadFail("详情页出错: ${e.localizedMessage}")
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -184,6 +198,32 @@ class ReadMangaViewModel(application: Application) : BaseViewModel(application)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步进度
|
||||
*/
|
||||
fun syncBookProgress(
|
||||
book: Book,
|
||||
alertSync: ((progress: BookProgress) -> Unit)? = null
|
||||
) {
|
||||
if (!AppConfig.syncBookProgress) return
|
||||
execute {
|
||||
AppWebDav.getBookProgress(book)
|
||||
}.onError {
|
||||
AppLog.put("拉取阅读进度失败《${book.name}》\n${it.localizedMessage}", it)
|
||||
}.onSuccess { progress ->
|
||||
progress ?: return@onSuccess
|
||||
if (progress.durChapterIndex < book.durChapterIndex ||
|
||||
(progress.durChapterIndex == book.durChapterIndex
|
||||
&& progress.durChapterPos < book.durChapterPos)
|
||||
) {
|
||||
alertSync?.invoke(progress)
|
||||
} else if (progress.durChapterIndex < book.simulatedTotalChapterNum()) {
|
||||
ReadManga.setProgress(progress)
|
||||
AppLog.put("自动同步阅读进度成功《${book.name}》 ${progress.durChapterTitle}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 换源
|
||||
*/
|
||||
|
||||
@@ -78,6 +78,7 @@ object RhinoClassShutter : ClassShutter {
|
||||
"android.app.AppGlobals",
|
||||
"android.os.Looper",
|
||||
"android.os.Process",
|
||||
"android.os.FileUtils",
|
||||
|
||||
"cn.hutool.core.lang.JarClassLoader",
|
||||
"cn.hutool.core.lang.Singleton",
|
||||
|
||||
Reference in New Issue
Block a user