This commit is contained in:
gedoor 2021-10-20 15:02:04 +08:00
parent 19c8b022ba
commit 199328349d
6 changed files with 18 additions and 14 deletions

View File

@ -2,15 +2,17 @@ package io.legado.app.constant
object AppLog {
val logs = arrayListOf<Triple<Long, String, Throwable?>>()
private val mLogs = arrayListOf<Triple<Long, String, Throwable?>>()
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))
}
}

View File

@ -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<BookProgress>(json)?.let {
return it
if (json.isJson()) {
GSON.fromJsonObject<BookProgress>(json)?.let {
return it
}
}
}
}

View File

@ -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)
}
}

View File

@ -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 {

View File

@ -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) {

View File

@ -35,6 +35,7 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
private fun init() {
Coroutine.async {
if (!AppConfig.syncBookProgress) return@async
val books = appDb.bookDao.all
books.forEach { book ->
AppWebDav.getBookProgress(book)?.let { bookProgress ->