pull/1738/head
kunfei 3 years ago
parent 9b751b97b4
commit 9df1e2f982
  1. 21
      app/src/main/java/io/legado/app/App.kt
  2. 26
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt

@ -48,8 +48,8 @@ class App : MultiDexApplication() {
//清除过期数据 //清除过期数据
appDb.cacheDao.clearDeadline(System.currentTimeMillis()) appDb.cacheDao.clearDeadline(System.currentTimeMillis())
if (getPrefBoolean(PreferKey.autoClearExpired, true)) { if (getPrefBoolean(PreferKey.autoClearExpired, true)) {
appDb.searchBookDao val clearTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)
.clearExpired(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) appDb.searchBookDao.clearExpired(clearTime)
} }
RuleBigDataHelp.clearInvalid() RuleBigDataHelp.clearInvalid()
//初始化简繁转换引擎 //初始化简繁转换引擎
@ -58,21 +58,8 @@ class App : MultiDexApplication() {
2 -> ChineseUtils.s2t("初始化") 2 -> ChineseUtils.s2t("初始化")
} }
//同步阅读记录 //同步阅读记录
if (!AppConfig.syncBookProgress) return@async if (AppConfig.syncBookProgress) {
val books = appDb.bookDao.all AppWebDav.downloadAllBookProgress()
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)
}
}
} }
} }
} }

@ -5,6 +5,7 @@ import android.os.Handler
import android.os.Looper import android.os.Looper
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.PreferKey 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.Book
import io.legado.app.data.entities.BookProgress import io.legado.app.data.entities.BookProgress
import io.legado.app.exception.NoStackTraceException 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? { suspend fun getBookProgress(book: Book): BookProgress? {
if (initWebDav() && NetworkUtils.isAvailable()) { if (initWebDav() && NetworkUtils.isAvailable()) {
val url = getProgressUrl(book) val url = getProgressUrl(book)
@ -179,7 +187,21 @@ object AppWebDav {
return null return null
} }
private fun getProgressUrl(book: Book): String { suspend fun downloadAllBookProgress() {
return bookProgressUrl + book.name + "_" + book.author + ".json" 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)
}
}
} }
}
} }
Loading…
Cancel
Save