优化进度同步

pull/540/head
gedoor 4 years ago
parent e04efe2293
commit 79a3992744
  1. 12
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  2. 14
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 19
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -4,10 +4,7 @@ import androidx.lifecycle.MutableLiveData
import com.hankcs.hanlp.HanLP
import io.legado.app.App
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.ReadRecord
import io.legado.app.data.entities.*
import io.legado.app.help.*
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook
@ -78,6 +75,13 @@ object ReadBook {
}
}
fun upProgress(progress: BookProgress) {
durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos
clearTextChapter()
loadContent(resetPageOffset = true)
}
fun clearTextChapter() {
prevTextChapter = null
curTextChapter = null

@ -20,6 +20,7 @@ import io.legado.app.constant.PreferKey
import io.legado.app.constant.Status
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookProgress
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig
import io.legado.app.help.storage.Backup
@ -108,6 +109,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
upMenu()
upView()
}
viewModel.processLiveData.observe(this) {
sureSyncProgress(it)
}
viewModel.initData(intent)
}
@ -730,6 +734,16 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
}
private fun sureSyncProgress(progress: BookProgress) {
alert(R.string.get_book_progress) {
message = "当前进度超过云端进度,是否同步?"
okButton {
ReadBook.upProgress(progress)
}
noButton()
}.show()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {

@ -2,11 +2,13 @@ package io.legado.app.ui.book.read
import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookProgress
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp
@ -22,9 +24,9 @@ import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.withContext
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var isInitFinish = false
var searchContentQuery = ""
val processLiveData = MutableLiveData<BookProgress>()
fun initData(intent: Intent) {
execute {
@ -162,13 +164,14 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun syncBookProgress(book: Book) {
execute {
BookWebDav.getBookProgress(book)?.let {
book.durChapterIndex = it.durChapterIndex
book.durChapterPos = it.durChapterPos
book.durChapterTime = it.durChapterTime
book.durChapterTitle = it.durChapterTitle
ReadBook.clearTextChapter()
ReadBook.loadContent(resetPageOffset = true)
BookWebDav.getBookProgress(book)?.let { progress ->
if (progress.durChapterIndex < book.durChapterIndex ||
(progress.durChapterIndex == book.durChapterIndex && progress.durChapterPos < book.durChapterPos)
) {
processLiveData.postValue(progress)
} else {
ReadBook.upProgress(progress)
}
}
}
}

Loading…
Cancel
Save