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