pull/1391/head
gedoor 3 years ago
parent 19c8b022ba
commit 199328349d
  1. 10
      app/src/main/java/io/legado/app/constant/AppLog.kt
  2. 8
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt
  3. 8
      app/src/main/java/io/legado/app/model/ReadBook.kt
  4. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  6. 1
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt

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

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

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

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

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

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

Loading…
Cancel
Save