diff --git a/app/src/main/java/io/legado/app/constant/AppLog.kt b/app/src/main/java/io/legado/app/constant/AppLog.kt index c20e64dd4..c5c887274 100644 --- a/app/src/main/java/io/legado/app/constant/AppLog.kt +++ b/app/src/main/java/io/legado/app/constant/AppLog.kt @@ -2,15 +2,17 @@ package io.legado.app.constant object AppLog { - val logs = arrayListOf>() + private val mLogs = arrayListOf>() + + val logs get() = mLogs.toList() @Synchronized fun put(message: String?, throwable: Throwable? = null) { message ?: return - if (logs.size > 100) { - logs.removeLastOrNull() + if (mLogs.size > 100) { + mLogs.removeLastOrNull() } - logs.add(0, Triple(System.currentTimeMillis(), message, throwable)) + mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable)) } } \ No newline at end of file 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 fbbda5380..ca254b371 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 @@ -7,6 +7,7 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookProgress +import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.dialogs.selector import io.legado.app.lib.webdav.HttpAuth @@ -143,6 +144,7 @@ object AppWebDav { } fun uploadBookProgress(book: Book) { + if (!AppConfig.syncBookProgress) return if (!NetworkUtils.isAvailable()) return Coroutine.async { val bookProgress = BookProgress(book) @@ -159,8 +161,10 @@ object AppWebDav { val url = getProgressUrl(book) WebDav(url).download()?.let { byteArray -> val json = String(byteArray) - GSON.fromJsonObject(json)?.let { - return it + if (json.isJson()) { + GSON.fromJsonObject(json)?.let { + return it + } } } } diff --git a/app/src/main/java/io/legado/app/model/ReadBook.kt b/app/src/main/java/io/legado/app/model/ReadBook.kt index df0d2014d..e7d105bad 100644 --- a/app/src/main/java/io/legado/app/model/ReadBook.kt +++ b/app/src/main/java/io/legado/app/model/ReadBook.kt @@ -95,11 +95,9 @@ object ReadBook : CoroutineScope by MainScope() { nextTextChapter = null } - fun uploadProgress(syncBookProgress: Boolean = AppConfig.syncBookProgress) { - if (syncBookProgress) { - book?.let { - AppWebDav.uploadBookProgress(it) - } + fun uploadProgress() { + book?.let { + AppWebDav.uploadBookProgress(it) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index d233148f6..d5f016c18 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -148,10 +148,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun syncBookProgress( book: Book, - syncBookProgress: Boolean = AppConfig.syncBookProgress, alertSync: ((progress: BookProgress) -> Unit)? = null ) { - if (syncBookProgress) + if (AppConfig.syncBookProgress) execute { AppWebDav.getBookProgress(book) }.onSuccess { diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 8d5e1224a..b98ba0c66 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -127,7 +127,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) { addDownload(source, book) }.onError(upTocPool) { AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it) - Timber.e(it) + Timber.e(it, "${book.name} 更新目录失败") }.onCancel(upTocPool) { upTocCancel(book.bookUrl) }.onFinally(upTocPool) { diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index be364818e..260de8d44 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -35,6 +35,7 @@ open class WelcomeActivity : BaseActivity() { private fun init() { Coroutine.async { + if (!AppConfig.syncBookProgress) return@async val books = appDb.bookDao.all books.forEach { book -> AppWebDav.getBookProgress(book)?.let { bookProgress ->