pull/737/head
Robot 4 years ago
commit 3a6197bee4
  1. 2
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  2. 10
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -75,6 +75,7 @@ abstract class BaseReadAloudService : BaseService(),
postEvent(EventBus.ALOUD_STATE, Status.STOP) postEvent(EventBus.ALOUD_STATE, Status.STOP)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
mediaSessionCompat.release() mediaSessionCompat.release()
ReadBook.uploadProgress()
} }
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@ -140,6 +141,7 @@ abstract class BaseReadAloudService : BaseService(),
upNotification() upNotification()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
postEvent(EventBus.ALOUD_STATE, Status.PAUSE) postEvent(EventBus.ALOUD_STATE, Status.PAUSE)
ReadBook.uploadProgress()
} }
@CallSuper @CallSuper

@ -7,6 +7,7 @@ import io.legado.app.constant.BookType
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import io.legado.app.help.* import io.legado.app.help.*
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.storage.BookWebDav
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
@ -21,6 +22,7 @@ import org.jetbrains.anko.getStackTraceString
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
@Suppress("MemberVisibilityCanBePrivate")
object ReadBook { object ReadBook {
var titleDate = MutableLiveData<String>() var titleDate = MutableLiveData<String>()
var book: Book? = null var book: Book? = null
@ -75,7 +77,7 @@ object ReadBook {
} }
} }
fun upProgress(progress: BookProgress) { fun setProgress(progress: BookProgress) {
durChapterIndex = progress.durChapterIndex durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos durChapterPos = progress.durChapterPos
clearTextChapter() clearTextChapter()
@ -88,6 +90,12 @@ object ReadBook {
nextTextChapter = null nextTextChapter = null
} }
fun uploadProgress() {
book?.let {
BookWebDav.uploadBookProgress(it)
}
}
fun upReadStartTime() { fun upReadStartTime() {
Coroutine.async { Coroutine.async {
readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime

@ -24,7 +24,6 @@ import io.legado.app.data.entities.BookProgress
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.ReadTipConfig import io.legado.app.help.ReadTipConfig
import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Backup
import io.legado.app.help.storage.BookWebDav
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.accentColor
import io.legado.app.receiver.TimeBatteryReceiver import io.legado.app.receiver.TimeBatteryReceiver
@ -142,9 +141,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
} }
upSystemUiVisibility() upSystemUiVisibility()
if (!BuildConfig.DEBUG) { if (!BuildConfig.DEBUG) {
ReadBook.book?.let { ReadBook.uploadProgress()
BookWebDav.uploadBookProgress(it)
}
Backup.autoBack(this) Backup.autoBack(this)
} }
} }
@ -735,7 +732,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
alert(R.string.get_book_progress) { alert(R.string.get_book_progress) {
message = getString(R.string.current_progress_exceeds_cloud) message = getString(R.string.current_progress_exceeds_cloud)
okButton { okButton {
ReadBook.upProgress(progress) ReadBook.setProgress(progress)
} }
noButton() noButton()
}.show() }.show()

@ -170,7 +170,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
) { ) {
processLiveData.postValue(progress) processLiveData.postValue(progress)
} else { } else {
ReadBook.upProgress(progress) ReadBook.setProgress(progress)
} }
} }
} }

Loading…
Cancel
Save