pull/32/head
kunfei 5 years ago
parent 9190eb8edd
commit 60075bfd85
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 13
      app/src/main/java/io/legado/app/service/ReadAloudService.kt
  3. 5
      app/src/main/java/io/legado/app/service/notification/ReadAloudNotification.kt
  4. 7
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt

@ -6,6 +6,7 @@ object Bus {
const val ALOUD_STATE = "aloud_state" const val ALOUD_STATE = "aloud_state"
const val TTS_START = "ttsStart" const val TTS_START = "ttsStart"
const val TTS_NEXT = "ttsNextPage" const val TTS_NEXT = "ttsNextPage"
const val TTS_DS = "ttsDs"
const val BATTERY_CHANGED = "batteryChanged" const val BATTERY_CHANGED = "batteryChanged"
const val TIME_CHANGED = "timeChanged" const val TIME_CHANGED = "timeChanged"
const val READ_ALOUD_BUTTON = "readAloudButton" const val READ_ALOUD_BUTTON = "readAloudButton"

@ -34,6 +34,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
var textToSpeech: TextToSpeech? = null var textToSpeech: TextToSpeech? = null
var timeMinute: Int = 0
fun play( fun play(
context: Context, context: Context,
@ -101,6 +102,15 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
} }
} }
fun setTimer(context: Context, minute: Int) {
if (isRun) {
val intent = Intent(context, ReadAloudService::class.java)
intent.action = Action.setTimer
intent.putExtra("minute", minute)
context.startService(intent)
}
}
fun clearTTS() { fun clearTTS() {
textToSpeech?.stop() textToSpeech?.stop()
textToSpeech?.shutdown() textToSpeech?.shutdown()
@ -124,7 +134,6 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
var pause = false var pause = false
var title: String = "" var title: String = ""
var subtitle: String = "" var subtitle: String = ""
var timeMinute: Int = 0
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@ -243,6 +252,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
handler.removeCallbacks(dsRunnable) handler.removeCallbacks(dsRunnable)
handler.postDelayed(dsRunnable, 6000) handler.postDelayed(dsRunnable, 6000)
} }
postEvent(Bus.TTS_DS, timeMinute)
ReadAloudNotification.upNotification(this) ReadAloudNotification.upNotification(this)
} }
@ -255,6 +265,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
handler.postDelayed(dsRunnable, 6000) handler.postDelayed(dsRunnable, 6000)
} }
} }
postEvent(Bus.TTS_DS, timeMinute)
ReadAloudNotification.upNotification(this) ReadAloudNotification.upNotification(this)
} }

@ -16,7 +16,10 @@ object ReadAloudNotification {
fun upNotification(service: ReadAloudService) { fun upNotification(service: ReadAloudService) {
var nTitle: String = when { var nTitle: String = when {
service.pause -> service.getString(R.string.read_aloud_pause) service.pause -> service.getString(R.string.read_aloud_pause)
service.timeMinute in 1..60 -> service.getString(R.string.read_aloud_timer, service.timeMinute) ReadAloudService.timeMinute in 1..60 -> service.getString(
R.string.read_aloud_timer,
ReadAloudService.timeMinute
)
else -> service.getString(R.string.read_aloud_t) else -> service.getString(R.string.read_aloud_t)
} }
nTitle += ": ${service.title}" nTitle += ": ${service.title}"

@ -54,10 +54,12 @@ class ReadAloudDialog : DialogFragment() {
private fun initData() { private fun initData() {
observeEvent<Int>(Bus.ALOUD_STATE) { upPlayState(it) } observeEvent<Int>(Bus.ALOUD_STATE) { upPlayState(it) }
observeEvent<Int>(Bus.TTS_DS) { seek_timer.progress = it }
val activity = activity val activity = activity
if (activity is ReadBookActivity) { if (activity is ReadBookActivity) {
upPlayState(activity.readAloudStatus) upPlayState(activity.readAloudStatus)
} }
tv_timer.text = requireContext().getString(R.string.timer_m, ReadAloudService.timeMinute)
cb_by_page.isChecked = requireContext().getPrefBoolean("readAloudByPage") cb_by_page.isChecked = requireContext().getPrefBoolean("readAloudByPage")
cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true) cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true)
seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked
@ -92,15 +94,14 @@ class ReadAloudDialog : DialogFragment() {
}) })
seek_timer.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { seek_timer.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
tv_timer.text = requireContext().getString(R.string.timer_m, progress)
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) {
} }
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
ReadAloudService.setTimer(requireContext(), seek_timer.progress)
} }
}) })
} }

Loading…
Cancel
Save