From 7ac4b229b68a6533fcb44c5bdf4fa45d6a855a67 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 2 Sep 2022 12:18:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/AudioPlay.kt | 32 ++++++++----------- .../app/ui/book/audio/AudioPlayViewModel.kt | 2 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/AudioPlay.kt b/app/src/main/java/io/legado/app/model/AudioPlay.kt index f224f6d09..b5e7cd87b 100644 --- a/app/src/main/java/io/legado/app/model/AudioPlay.kt +++ b/app/src/main/java/io/legado/app/model/AudioPlay.kt @@ -105,7 +105,7 @@ object AudioPlay { book.durChapterIndex = index book.durChapterPos = 0 durChapter = null - saveRead(book) + saveRead() play(context) } } @@ -120,7 +120,7 @@ object AudioPlay { book.durChapterIndex = book.durChapterIndex - 1 book.durChapterPos = 0 durChapter = null - saveRead(book) + saveRead() play(context) } } @@ -134,17 +134,11 @@ object AudioPlay { book.durChapterIndex = book.durChapterIndex + 1 book.durChapterPos = 0 durChapter = null - saveRead(book) + saveRead() play(context) } } - fun addTimer() { - val intent = Intent(appCtx, AudioPlayService::class.java) - intent.action = IntentAction.addTimer - appCtx.startService(intent) - } - fun setTimer(minute: Int) { val intent = Intent(appCtx, AudioPlayService::class.java) intent.action = IntentAction.setTimer @@ -152,16 +146,18 @@ object AudioPlay { appCtx.startService(intent) } - fun saveRead(book: Book) { - book.lastCheckCount = 0 - book.durChapterTime = System.currentTimeMillis() - Coroutine.async { - appDb.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let { - book.durChapterTitle = it.getDisplayTitle( - ContentProcessor.get(book.name, book.origin).getTitleReplaceRules() - ) + fun saveRead() { + book?.let { book -> + book.lastCheckCount = 0 + book.durChapterTime = System.currentTimeMillis() + Coroutine.async { + appDb.bookChapterDao.getChapter(book.bookUrl, book.durChapterIndex)?.let { + book.durChapterTitle = it.getDisplayTitle( + ContentProcessor.get(book.name, book.origin).getTitleReplaceRules() + ) + } + book.save() } - book.save() } } diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt index 4938728a8..4ad4d49a9 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt @@ -37,9 +37,9 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) loadChapterList(book) } } - saveRead(book) } } + saveRead() } }