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() {
pause = false
mediaPlayer.start()
mediaPlayer.seekTo(position)
if (!mediaPlayer.isPlaying) {
mediaPlayer.start()
mediaPlayer.seekTo(position)
}
handler.removeCallbacks(mpRunnable)
handler.postDelayed(mpRunnable, 1000)
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PLAYING)
@ -337,7 +339,7 @@ class AudioPlayService : BaseService(),
AudioPlay.durChapterIndex--
AudioPlay.durPageIndex = 0
AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex
saveRead()
AudioPlay.saveRead()
position = 0
loadContent(AudioPlay.durChapterIndex)
}
@ -349,7 +351,7 @@ class AudioPlayService : BaseService(),
AudioPlay.durChapterIndex++
AudioPlay.durPageIndex = 0
AudioPlay.book?.durChapterIndex = AudioPlay.durChapterIndex
saveRead()
AudioPlay.saveRead()
position = 0
loadContent(AudioPlay.durChapterIndex)
} 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() {
launch(IO) {
AudioPlay.book?.let {

@ -3,9 +3,11 @@ package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.constant.IntentAction
import io.legado.app.constant.Status
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.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) {
if (AudioPlayService.isRun) {
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.ImageLoader
import io.legado.app.lib.dialogs.alert
import io.legado.app.service.AudioPlayService
import io.legado.app.service.help.AudioPlay
import io.legado.app.ui.book.changesource.ChangeSourceDialog
import io.legado.app.ui.book.toc.ChapterListActivity
@ -175,16 +174,7 @@ class AudioPlayActivity :
when (requestCode) {
requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let {
if (it != AudioPlay.durChapterIndex) {
val isPlay = !AudioPlayService.pause
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)
}
AudioPlay.skipTo(this, it)
}
}
}

@ -47,7 +47,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
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)?) {
execute {
AudioPlay.book?.let {

Loading…
Cancel
Save