pull/508/head
gedoor 4 years ago
parent b0dd5ffa01
commit 940e4c5a97
  1. 23
      app/src/main/java/io/legado/app/service/AudioPlayService.kt
  2. 29
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  3. 12
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  4. 17
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt

@ -161,8 +161,10 @@ class AudioPlayService : BaseService(),
private fun resume() { private fun resume() {
pause = false pause = false
mediaPlayer.start() if (!mediaPlayer.isPlaying) {
mediaPlayer.seekTo(position) mediaPlayer.start()
mediaPlayer.seekTo(position)
}
handler.removeCallbacks(mpRunnable) handler.removeCallbacks(mpRunnable)
handler.postDelayed(mpRunnable, 1000) handler.postDelayed(mpRunnable, 1000)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING) upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
@ -337,7 +339,7 @@ class AudioPlayService : BaseService(),
AudioPlay.durChapterIndex-- AudioPlay.durChapterIndex--
AudioPlay.durPageIndex = 0 AudioPlay.durPageIndex = 0
AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex
saveRead() AudioPlay.saveRead()
position = 0 position = 0
loadContent(AudioPlay.durChapterIndex) loadContent(AudioPlay.durChapterIndex)
} }
@ -349,7 +351,7 @@ class AudioPlayService : BaseService(),
AudioPlay.durChapterIndex++ AudioPlay.durChapterIndex++
AudioPlay.durPageIndex = 0 AudioPlay.durPageIndex = 0
AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex
saveRead() AudioPlay.saveRead()
position = 0 position = 0
loadContent(AudioPlay.durChapterIndex) loadContent(AudioPlay.durChapterIndex)
} else { } else {
@ -357,19 +359,6 @@ class AudioPlayService : BaseService(),
} }
} }
private fun saveRead() {
launch(IO) {
AudioPlay.book?.let { book ->
book.lastCheckCount = 0
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = AudioPlay.durChapterIndex
book.durChapterPos = AudioPlay.durPageIndex
book.durChapterTitle = subtitle
App.db.bookDao().update(book)
}
}
}
private fun saveProgress() { private fun saveProgress() {
launch(IO) { launch(IO) {
AudioPlay.book?.let { AudioPlay.book?.let {

@ -3,9 +3,11 @@ package io.legado.app.service.help
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.constant.IntentAction import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status import io.legado.app.constant.Status
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
@ -73,6 +75,18 @@ object AudioPlay {
} }
} }
fun skipTo(context: Context, chapterIndex: Int) {
val isPlay = !AudioPlayService.pause
pause(context)
status = Status.STOP
durChapterIndex = chapterIndex
durPageIndex = 0
book?.durChapterIndex = durChapterIndex
if (isPlay) {
play(context)
}
}
fun prev(context: Context) { fun prev(context: Context) {
if (AudioPlayService.isRun) { if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java) val intent = Intent(context, AudioPlayService::class.java)
@ -89,4 +103,19 @@ object AudioPlay {
} }
} }
fun saveRead() {
Coroutine.async {
book?.let { book ->
book.lastCheckCount = 0
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = AudioPlay.durChapterIndex
book.durChapterPos = AudioPlay.durPageIndex
App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let {
book.durChapterTitle = it.title
}
App.db.bookDao().update(book)
}
}
}
} }

@ -20,7 +20,6 @@ import io.legado.app.data.entities.Book
import io.legado.app.help.BlurTransformation import io.legado.app.help.BlurTransformation
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.service.AudioPlayService
import io.legado.app.service.help.AudioPlay import io.legado.app.service.help.AudioPlay
import io.legado.app.ui.book.changesource.ChangeSourceDialog import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.toc.ChapterListActivity import io.legado.app.ui.book.toc.ChapterListActivity
@ -175,16 +174,7 @@ class AudioPlayActivity :
when (requestCode) { when (requestCode) {
requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let { requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let {
if (it != AudioPlay.durChapterIndex) { if (it != AudioPlay.durChapterIndex) {
val isPlay = !AudioPlayService.pause AudioPlay.skipTo(this, it)
AudioPlay.pause(this)
AudioPlay.status = Status.STOP
AudioPlay.durChapterIndex = it
AudioPlay.durPageIndex = 0
AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex
viewModel.saveRead()
if (isPlay) {
AudioPlay.play(this)
}
} }
} }
} }

@ -47,7 +47,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
AudioPlay.chapterSize = count AudioPlay.chapterSize = count
} }
} }
saveRead() AudioPlay.saveRead()
} }
} }
} }
@ -128,21 +128,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
} }
} }
fun saveRead() {
execute {
AudioPlay.book?.let { book ->
book.lastCheckCount = 0
book.durChapterTime = System.currentTimeMillis()
book.durChapterIndex = AudioPlay.durChapterIndex
book.durChapterPos = AudioPlay.durPageIndex
App.db.bookChapterDao().getChapter(book.bookUrl, book.durChapterIndex)?.let {
book.durChapterTitle = it.title
}
App.db.bookDao().update(book)
}
}
}
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
execute { execute {
AudioPlay.book?.let { AudioPlay.book?.let {

Loading…
Cancel
Save