From ebd9b09d087a2848112df336d67c1240e838e977 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 5 Nov 2019 19:20:38 +0800 Subject: [PATCH] up --- .../java/io/legado/app/data/dao/BookDao.kt | 2 + .../legado/app/ui/audio/AudioPlayActivity.kt | 54 ++++++++++--------- .../legado/app/ui/audio/AudioPlayViewModel.kt | 8 +++ 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index ba1d7e67e..ecd16d6ef 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -53,4 +53,6 @@ interface BookDao { @Query("delete from books where bookUrl = :bookUrl") fun delete(bookUrl: String) + @Query("update books set durChapterIndex = :pos where bookUrl = :bookUrl") + fun upProgress(bookUrl: String, pos: Int) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index 352682664..bd8ea22b0 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -131,32 +131,6 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a viewModel.loadContent(viewModel.durChapterIndex + 1) } - override fun observeLiveBus() { - observeEvent(Bus.AUDIO_PLAY_BUTTON) { - playButton() - } - observeEvent(Bus.AUDIO_NEXT) { - viewModel.moveToNext() - } - observeEvent(Bus.AUDIO_STATE) { - status = it - if (status == Status.PLAY) { - fab_play_stop.setImageResource(R.drawable.ic_pause_24dp) - } else { - fab_play_stop.setImageResource(R.drawable.ic_play_24dp) - } - } - observeEvent(Bus.AUDIO_PROGRESS) { - viewModel.durPageIndex = it - if (!adjustProgress) player_progress.progress = it - tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") - } - observeEvent(Bus.AUDIO_SIZE) { - player_progress.max = it - tv_all_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") - } - } - override fun onKeyLongPress(keyCode: Int, event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_BACK -> { @@ -222,4 +196,32 @@ class AudioPlayActivity : VMBaseActivity(R.layout.activity_a } } } + + override fun observeLiveBus() { + observeEvent(Bus.AUDIO_PLAY_BUTTON) { + playButton() + } + observeEvent(Bus.AUDIO_NEXT) { + viewModel.moveToNext() + } + observeEvent(Bus.AUDIO_STATE) { + status = it + if (status == Status.PLAY) { + fab_play_stop.setImageResource(R.drawable.ic_pause_24dp) + } else { + fab_play_stop.setImageResource(R.drawable.ic_play_24dp) + } + } + observeEvent(Bus.AUDIO_PROGRESS) { + viewModel.durPageIndex = it + if (!adjustProgress) player_progress.progress = it + tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") + viewModel.saveProgress() + } + observeEvent(Bus.AUDIO_SIZE) { + player_progress.max = it + tv_all_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") + } + } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt index 2c9493e29..7831eeda2 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt @@ -222,6 +222,14 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) } } + fun saveProgress() { + execute { + book?.let { + App.db.bookDao().upProgress(it.bookUrl, durPageIndex) + } + } + } + fun removeFromBookshelf(success: (() -> Unit)?) { execute { book?.let {