pull/32/head
kunfei 5 years ago
parent f06bdf0fe5
commit 0d8b9be12d
  1. 2
      app/src/main/java/io/legado/app/service/ReadAloudService.kt
  2. 19
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  3. 18
      app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt

@ -28,7 +28,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
val tag: String = ReadAloudService::class.java.simpleName val tag: String = ReadAloudService::class.java.simpleName
var isRun = false var isRun = false
fun paly(context: Context, title: String, subtitle: String, body: String) { fun play(context: Context, title: String, subtitle: String, body: String) {
val readAloudIntent = Intent(context, ReadAloudService::class.java) val readAloudIntent = Intent(context, ReadAloudService::class.java)
readAloudIntent.action = "play" readAloudIntent.action = "play"
readAloudIntent.putExtra("title", title) readAloudIntent.putExtra("title", title)

@ -287,16 +287,25 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
SystemUtils.ignoreBatteryOptimization(this) SystemUtils.ignoreBatteryOptimization(this)
} }
when (readAloudStatus) { when (readAloudStatus) {
Status.STOP -> { Status.STOP -> readAloud()
viewModel.bookData.value?.let {
ReadAloudService.paly(this, it.name, "", "")
}
}
Status.PLAY -> ReadAloudService.pause(this) Status.PLAY -> ReadAloudService.pause(this)
Status.PAUSE -> ReadAloudService.resume(this) Status.PAUSE -> ReadAloudService.resume(this)
} }
} }
private fun readAloud() {
val book = viewModel.bookData.value
val textChapter = viewModel.curTextChapter
if (book != null && textChapter != null) {
ReadAloudService.play(
this,
book.name,
textChapter.title,
""
)
}
}
private fun setScreenBrightness(value: Int) { private fun setScreenBrightness(value: Int) {
var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE var brightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
if (this.getPrefBoolean("brightnessAuto").not()) { if (this.getPrefBoolean("brightnessAuto").not()) {

@ -31,5 +31,23 @@ data class TextChapter(
fun pageSize(): Int { fun pageSize(): Int {
return pages.size return pages.size
} }
fun getReadLength(pageIndex: Int): Int {
var length = 0
for (index in 0 until pageIndex) {
length += pageLengths[index]
}
return length
}
fun getUnRead(pageIndex: Int): String {
val stringBuilder = StringBuilder()
if (pageIndex < pages.size) {
for (index in pageIndex..lastIndex()) {
stringBuilder.append(pages[index].text)
}
}
return stringBuilder.toString()
}
} }

Loading…
Cancel
Save