pull/49/head
kunfei 5 years ago
parent c728fed744
commit 12068318dc
  1. 4
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  2. 30
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  3. 40
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  4. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -36,6 +36,7 @@ abstract class BaseReadAloudService : BaseService(),
companion object {
var isRun = false
var timeMinute: Int = 0
var pause = false
}
private val handler = Handler()
@ -45,7 +46,6 @@ abstract class BaseReadAloudService : BaseService(),
private var mediaSessionCompat: MediaSessionCompat? = null
private var title: String = ""
private var subtitle: String = ""
var pause = false
val contentList = arrayListOf<String>()
var nowSpeak: Int = 0
var readAloudNumber: Int = 0
@ -128,7 +128,7 @@ abstract class BaseReadAloudService : BaseService(),
@CallSuper
open fun pauseReadAloud(pause: Boolean) {
postEvent(Bus.ALOUD_STATE, Status.PAUSE)
this.pause = pause
BaseReadAloudService.pause = pause
upNotification()
upMediaSessionPlaybackState(PlaybackStateCompat.STATE_PAUSED)
}

@ -6,8 +6,10 @@ import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.WebBook
import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.book.read.ReadBookViewModel
import io.legado.app.ui.widget.page.TextChapter
import kotlinx.coroutines.Dispatchers
@ -56,6 +58,7 @@ object ReadBook {
}
saveRead()
callBack?.curChapterChanged()
curPageChanged()
return true
} else {
return false
@ -85,12 +88,39 @@ object ReadBook {
}
saveRead()
callBack?.curChapterChanged()
curPageChanged()
return true
} else {
return false
}
}
fun curPageChanged() {
callBack?.upPageProgress()
if (BaseReadAloudService.isRun) {
readAloud(!BaseReadAloudService.pause)
}
}
/**
* 朗读
*/
fun readAloud(play: Boolean = true) {
val book = book
val textChapter = curTextChapter
if (book != null && textChapter != null) {
val key = IntentDataHelp.putData(textChapter)
ReadAloud.play(
App.INSTANCE,
book.name,
textChapter.title,
durPageIndex,
key,
play
)
}
}
fun loadContent(index: Int) {
book?.let { book ->
if (addLoading(index)) {

@ -17,7 +17,6 @@ import io.legado.app.constant.Bus
import io.legado.app.constant.Status
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ReadBookConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.noButton
@ -275,9 +274,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
.getTextChapter(bookChapter, content, ReadBook.chapterSize)
page_view.upContent()
curChapterChanged()
ReadBook.curPageChanged()
if (intent.getBooleanExtra("readAloud", false)) {
intent.removeExtra("readAloud")
readAloud()
ReadBook.readAloud()
}
}
ReadBook.durChapterIndex - 1 -> launch {
@ -308,18 +308,11 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
seek_read_page.max = it.pageSize().minus(1)
tv_pre.isEnabled = ReadBook.durChapterIndex != 0
tv_next.isEnabled = ReadBook.durChapterIndex != ReadBook.chapterSize - 1
curPageChanged()
}
}
private fun curPageChanged() {
override fun upPageProgress() {
seek_read_page.progress = ReadBook.durPageIndex
when (readAloudStatus) {
Status.PLAY -> readAloud()
Status.PAUSE -> {
readAloud(false)
}
}
}
override fun showMenu() {
@ -354,7 +347,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun setPageIndex(pageIndex: Int) {
ReadBook.durPageIndex = pageIndex
ReadBook.saveRead()
curPageChanged()
ReadBook.curPageChanged()
}
/**
@ -402,7 +395,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun skipToPage(page: Int) {
ReadBook.durPageIndex = page
page_view.upContent()
curPageChanged()
ReadBook.curPageChanged()
ReadBook.saveRead()
}
@ -440,31 +433,12 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
SystemUtils.ignoreBatteryOptimization(this)
}
when (readAloudStatus) {
Status.STOP -> readAloud()
Status.STOP -> ReadBook.readAloud()
Status.PLAY -> ReadAloud.pause(this)
Status.PAUSE -> ReadAloud.resume(this)
}
}
/**
* 朗读
*/
private fun readAloud(play: Boolean = true) {
val book = ReadBook.book
val textChapter = ReadBook.curTextChapter
if (book != null && textChapter != null) {
val key = IntentDataHelp.putData(textChapter)
ReadAloud.play(
this,
book.name,
textChapter.title,
ReadBook.durPageIndex,
key,
play
)
}
}
override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.getConfig()) {
when (dialogId) {
TEXT_COLOR -> {
@ -535,7 +509,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
if (it) {
onClickReadAloud()
} else {
readAloud(readAloudStatus == Status.PLAY)
ReadBook.readAloud(readAloudStatus == Status.PLAY)
}
}
observeEvent<Boolean>(Bus.UP_CONFIG) {

@ -195,5 +195,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun contentLoadFinish(bookChapter: BookChapter, content: String)
fun upContent()
fun curChapterChanged()
fun upPageProgress()
}
}
Loading…
Cancel
Save