From 9df1e2f982a5da39371154e940960f68b1db932a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 19 Mar 2022 18:23:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/App.kt | 21 +++------------ .../io/legado/app/help/storage/AppWebDav.kt | 26 +++++++++++++++++-- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index 679abf150..7a5592006 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -48,8 +48,8 @@ class App : MultiDexApplication() { //清除过期数据 appDb.cacheDao.clearDeadline(System.currentTimeMillis()) if (getPrefBoolean(PreferKey.autoClearExpired, true)) { - appDb.searchBookDao - .clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) + val clearTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1) + appDb.searchBookDao.clearExpired(clearTime) } RuleBigDataHelp.clearInvalid() //初始化简繁转换引擎 @@ -58,21 +58,8 @@ class App : MultiDexApplication() { 2 -> ChineseUtils.s2t("初始化") } //同步阅读记录 - if (!AppConfig.syncBookProgress) return@async - val books = appDb.bookDao.all - books.forEach { book -> - AppWebDav.getBookProgress(book)?.let { bookProgress -> - if (bookProgress.durChapterIndex > book.durChapterIndex || - (bookProgress.durChapterIndex == book.durChapterIndex && - bookProgress.durChapterPos > book.durChapterPos) - ) { - book.durChapterIndex = bookProgress.durChapterIndex - book.durChapterPos = bookProgress.durChapterPos - book.durChapterTitle = bookProgress.durChapterTitle - book.durChapterTime = bookProgress.durChapterTime - appDb.bookDao.update(book) - } - } + if (AppConfig.syncBookProgress) { + AppWebDav.downloadAllBookProgress() } } } diff --git a/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt b/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt index f7685d21d..1a7dd0768 100644 --- a/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt +++ b/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt @@ -5,6 +5,7 @@ import android.os.Handler import android.os.Looper import io.legado.app.R import io.legado.app.constant.PreferKey +import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookProgress import io.legado.app.exception.NoStackTraceException @@ -166,6 +167,13 @@ object AppWebDav { } } + private fun getProgressUrl(book: Book): String { + return bookProgressUrl + book.name + "_" + book.author + ".json" + } + + /** + * 获取书籍进度 + */ suspend fun getBookProgress(book: Book): BookProgress? { if (initWebDav() && NetworkUtils.isAvailable()) { val url = getProgressUrl(book) @@ -179,7 +187,21 @@ object AppWebDav { return null } - private fun getProgressUrl(book: Book): String { - return bookProgressUrl + book.name + "_" + book.author + ".json" + suspend fun downloadAllBookProgress() { + appDb.bookDao.all.forEach { book -> + getBookProgress(book)?.let { bookProgress -> + if (bookProgress.durChapterIndex > book.durChapterIndex || + (bookProgress.durChapterIndex == book.durChapterIndex && + bookProgress.durChapterPos > book.durChapterPos) + ) { + book.durChapterIndex = bookProgress.durChapterIndex + book.durChapterPos = bookProgress.durChapterPos + book.durChapterTitle = bookProgress.durChapterTitle + book.durChapterTime = bookProgress.durChapterTime + appDb.bookDao.update(book) + } + } + } } + } \ No newline at end of file