朗读停止时上传进度

pull/736/head
gedoor 4 years ago
parent 18a1ad9a17
commit 09709d1b28
  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)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED)
mediaSessionCompat.release()
ReadBook.upProgress()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@ -140,6 +141,7 @@ abstract class BaseReadAloudService : BaseService(),
upNotification()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
postEvent(EventBus.ALOUD_STATE, Status.PAUSE)
ReadBook.upProgress()
}
@CallSuper

@ -7,6 +7,7 @@ import io.legado.app.constant.BookType
import io.legado.app.data.entities.*
import io.legado.app.help.*
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.service.BaseReadAloudService
import io.legado.app.ui.book.read.page.entities.TextChapter
@ -21,6 +22,7 @@ import org.jetbrains.anko.getStackTraceString
import org.jetbrains.anko.toast
@Suppress("MemberVisibilityCanBePrivate")
object ReadBook {
var titleDate = MutableLiveData<String>()
var book: Book? = null
@ -75,7 +77,7 @@ object ReadBook {
}
}
fun upProgress(progress: BookProgress) {
fun setProgress(progress: BookProgress) {
durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos
clearTextChapter()
@ -88,6 +90,12 @@ object ReadBook {
nextTextChapter = null
}
fun upProgress() {
book?.let {
BookWebDav.uploadBookProgress(it)
}
}
fun upReadStartTime() {
Coroutine.async {
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.ReadTipConfig
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.theme.accentColor
import io.legado.app.receiver.TimeBatteryReceiver
@ -142,9 +141,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
}
upSystemUiVisibility()
if (!BuildConfig.DEBUG) {
ReadBook.book?.let {
BookWebDav.uploadBookProgress(it)
}
ReadBook.upProgress()
Backup.autoBack(this)
}
}
@ -735,7 +732,7 @@ class ReadBookActivity : ReadBookBaseActivity(),
alert(R.string.get_book_progress) {
message = getString(R.string.current_progress_exceeds_cloud)
okButton {
ReadBook.upProgress(progress)
ReadBook.setProgress(progress)
}
noButton()
}.show()

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

Loading…
Cancel
Save