From 09709d1b28b090d0e5363c717eb3a056bf8521aa Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 10:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=97=E8=AF=BB=E5=81=9C=E6=AD=A2=E6=97=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=BF=9B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/BaseReadAloudService.kt | 2 ++ .../main/java/io/legado/app/service/help/ReadBook.kt | 10 +++++++++- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 7 ++----- .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) 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..797508ee3 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.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 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..08bdb99bf 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 upProgress() { + 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..31500f4a4 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.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() 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) } } }