pull/32/head
kunfei 5 years ago
parent 0376267e27
commit c3a7f4991f
  1. 13
      app/src/main/java/io/legado/app/service/ReadAloudService.kt
  2. 32
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt

@ -36,7 +36,8 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
title: String,
subtitle: String,
pageIndex: Int,
dataKey: String
dataKey: String,
play: Boolean = true
) {
val readAloudIntent = Intent(context, ReadAloudService::class.java)
readAloudIntent.action = "play"
@ -44,6 +45,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
readAloudIntent.putExtra("subtitle", subtitle)
readAloudIntent.putExtra("pageIndex", pageIndex)
readAloudIntent.putExtra("dataKey", dataKey)
readAloudIntent.putExtra("play", play)
context.startService(readAloudIntent)
}
@ -123,7 +125,10 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
title = intent.getStringExtra("title") ?: ""
subtitle = intent.getStringExtra("subtitle") ?: ""
pageIndex = intent.getIntExtra("pageIndex", 0)
newReadAloud(intent.getStringExtra("dataKey"))
newReadAloud(
intent.getStringExtra("dataKey"),
intent.getBooleanExtra("play", true)
)
}
"pause" -> pauseReadAloud(true)
"resume" -> resumeReadAloud()
@ -153,7 +158,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
}
}
private fun newReadAloud(dataKey: String?) {
private fun newReadAloud(dataKey: String?, paly: Boolean) {
dataKey?.let {
textChapter = IntentDataHelp.getData(dataKey) as? TextChapter
textChapter?.let {
@ -161,7 +166,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
readAloudNumber = it.getReadLength(pageIndex)
contentList.clear()
contentList.addAll(it.getUnRead(pageIndex).split("\n"))
playTTS()
if (paly) playTTS()
} ?: stopSelf()
} ?: stopSelf()
}

@ -120,9 +120,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun skipToPage(page: Int) {
viewModel.durPageIndex = page
page_view.upContent()
if (readAloudStatus == Status.PLAY) {
readAloud()
}
curPageChanged()
}
override fun skipPreChapter() {
@ -236,7 +234,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
viewModel.curTextChapter =
ChapterProvider.getTextChapter(content_text_view, bookChapter, content)
page_view.upContent()
curChapterChange()
curChapterChanged()
}
viewModel.durChapterIndex - 1 -> {
viewModel.prevTextChapter =
@ -250,7 +248,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
}
}
private fun curChapterChange() {
private fun curChapterChanged() {
viewModel.curTextChapter?.let {
tv_chapter_name.text = it.title
tv_chapter_name.visible()
@ -259,8 +257,15 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
tv_chapter_url.visible()
}
read_menu.upReadProgress(it.pageSize(), viewModel.durPageIndex)
if (readAloudStatus == Status.PLAY) {
readAloud()
curPageChanged()
}
}
private fun curPageChanged() {
when (readAloudStatus) {
Status.PLAY -> readAloud()
Status.PAUSE -> {
readAloud(false)
}
}
}
@ -294,9 +299,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun setPageIndex(pageIndex: Int) {
viewModel.durPageIndex = pageIndex
viewModel.saveRead()
if (readAloudStatus == Status.PLAY) {
readAloud()
}
curPageChanged()
}
override fun textChapter(chapterOnDur: Int): TextChapter? {
@ -311,13 +314,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
override fun moveToNextChapter() {
viewModel.durPageIndex = 0
viewModel.moveToNextChapter()
curChapterChange()
curChapterChanged()
}
override fun moveToPrevChapter() {
viewModel.durPageIndex = viewModel.prevTextChapter?.lastIndex() ?: 0
viewModel.moveToPrevChapter()
curChapterChange()
curChapterChanged()
}
override fun clickCenter() {
@ -346,7 +349,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
/**
* 朗读
*/
private fun readAloud() {
private fun readAloud(play: Boolean = true) {
val book = viewModel.bookData.value
val textChapter = viewModel.curTextChapter
if (book != null && textChapter != null) {
@ -357,7 +360,8 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
book.name,
textChapter.title,
viewModel.durPageIndex,
key
key,
play
)
}
}

Loading…
Cancel
Save