diff --git a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt index a51a7c3dd..9e60ac6b2 100644 --- a/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt +++ b/app/src/main/java/io/legado/app/service/BaseReadAloudService.kt @@ -75,6 +75,7 @@ abstract class BaseReadAloudService : BaseService(), postEvent(EventBus.ALOUD_STATE, Status.STOP) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_STOPPED) mediaSessionCompat.release() + ReadBook.uploadProgress() } 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.uploadProgress() } @CallSuper diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 4724dce6c..b4bf0e7e9 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -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() 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 uploadProgress() { + book?.let { + BookWebDav.uploadBookProgress(it) + } + } + fun upReadStartTime() { Coroutine.async { readRecord.readTime = readRecord.readTime + System.currentTimeMillis() - readStartTime diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index ad9d0e2f4..8d3481550 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -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.uploadProgress() 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() diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 494123cd6..088fe98e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -170,7 +170,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { ) { processLiveData.postValue(progress) } else { - ReadBook.upProgress(progress) + ReadBook.setProgress(progress) } } }