|
|
|
@ -2,7 +2,6 @@ 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 |
|
|
|
@ -26,7 +25,6 @@ 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,14 +160,20 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun syncBookProgress(book: Book, syncBookProgress: Boolean = AppConfig.syncBookProgress) { |
|
|
|
|
fun syncBookProgress( |
|
|
|
|
book: Book, |
|
|
|
|
syncBookProgress: Boolean = AppConfig.syncBookProgress, |
|
|
|
|
alertSync: ((progress: BookProgress) -> Unit)? = null |
|
|
|
|
) { |
|
|
|
|
if (syncBookProgress) |
|
|
|
|
execute { |
|
|
|
|
BookWebDav.getBookProgress(book)?.let { progress -> |
|
|
|
|
BookWebDav.getBookProgress(book) |
|
|
|
|
}.onSuccess { |
|
|
|
|
it?.let { progress -> |
|
|
|
|
if (progress.durChapterIndex < book.durChapterIndex || |
|
|
|
|
(progress.durChapterIndex == book.durChapterIndex && progress.durChapterPos < book.durChapterPos) |
|
|
|
|
) { |
|
|
|
|
processLiveData.postValue(progress) |
|
|
|
|
alertSync?.invoke(progress) |
|
|
|
|
} else { |
|
|
|
|
ReadBook.setProgress(progress) |
|
|
|
|
} |
|
|
|
|