pull/47/head
kunfei 5 years ago
parent e5f3d2f28a
commit ebd9b09d08
  1. 2
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 54
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  3. 8
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.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)
}

@ -131,32 +131,6 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
viewModel.loadContent(viewModel.durChapterIndex + 1)
}
override fun observeLiveBus() {
observeEvent<Boolean>(Bus.AUDIO_PLAY_BUTTON) {
playButton()
}
observeEvent<Int>(Bus.AUDIO_NEXT) {
viewModel.moveToNext()
}
observeEvent<Int>(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<Int>(Bus.AUDIO_PROGRESS) {
viewModel.durPageIndex = it
if (!adjustProgress) player_progress.progress = it
tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss")
}
observeEvent<Int>(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<AudioPlayViewModel>(R.layout.activity_a
}
}
}
override fun observeLiveBus() {
observeEvent<Boolean>(Bus.AUDIO_PLAY_BUTTON) {
playButton()
}
observeEvent<Int>(Bus.AUDIO_NEXT) {
viewModel.moveToNext()
}
observeEvent<Int>(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<Int>(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<Int>(Bus.AUDIO_SIZE) {
player_progress.max = it
tv_all_time.text = DateFormatUtils.format(it.toLong(), "mm:ss")
}
}
}

@ -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 {

Loading…
Cancel
Save