pull/46/head
kunfei 5 years ago
parent b3d55a7f41
commit c686427c70
  1. 44
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  2. 18
      app/src/main/java/io/legado/app/service/help/ReadAloud.kt
  3. 31
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  4. 19
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt
  5. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  6. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  7. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt
  8. 2
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  9. 2
      app/src/main/res/layout/activity_audio_play.xml
  10. 1
      app/src/main/res/values/strings.xml

@ -0,0 +1,44 @@
package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import io.legado.app.constant.Action
import io.legado.app.service.AudioPlayService
object AudioPlay {
fun play(context: Context, title: String?, subtitle: String, url: String, position: Int) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.play
intent.putExtra("title", title)
intent.putExtra("subtitle", subtitle)
intent.putExtra("url", url)
intent.putExtra("dataKey", position)
context.startService(intent)
}
fun pause(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.pause
context.startService(intent)
}
}
fun resume(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.resume
context.startService(intent)
}
}
fun stop(context: Context) {
if (AudioPlayService.isRun) {
val intent = Intent(context, AudioPlayService::class.java)
intent.action = Action.stop
context.startService(intent)
}
}
}

@ -1,4 +1,4 @@
package io.legado.app.help
package io.legado.app.service.help
import android.content.Context
import android.content.Intent
@ -28,14 +28,14 @@ object ReadAloud {
dataKey: String,
play: Boolean = true
) {
val readAloudIntent = Intent(context, aloudClass)
readAloudIntent.action = Action.play
readAloudIntent.putExtra("title", title)
readAloudIntent.putExtra("subtitle", subtitle)
readAloudIntent.putExtra("pageIndex", pageIndex)
readAloudIntent.putExtra("dataKey", dataKey)
readAloudIntent.putExtra("play", play)
context.startService(readAloudIntent)
val intent = Intent(context, aloudClass)
intent.action = Action.play
intent.putExtra("title", title)
intent.putExtra("subtitle", subtitle)
intent.putExtra("pageIndex", pageIndex)
intent.putExtra("dataKey", dataKey)
intent.putExtra("play", play)
context.startService(intent)
}
fun pause(context: Context) {

@ -3,9 +3,14 @@ package io.legado.app.ui.audio
import android.os.Bundle
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.Bus
import io.legado.app.data.entities.BookChapter
import io.legado.app.service.help.AudioPlay
import io.legado.app.utils.getViewModel
import io.legado.app.utils.observeEvent
import kotlinx.android.synthetic.main.activity_audio_play.*
import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.sdk27.listeners.onClick
class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_audio_play),
AudioPlayViewModel.CallBack {
@ -20,19 +25,29 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
}
private fun initView() {
}
override fun loadContent() {
fab_play_stop.onClick {
viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex)
}
}
}
override fun contentLoadFinish(bookChapter: BookChapter, content: String) {
AudioPlay.play(
this,
viewModel.bookData.value?.name,
bookChapter.title,
content,
viewModel.durPageIndex
)
viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex + 1)
}
}
override fun upContent() {
override fun observeLiveBus() {
observeEvent<Int>(Bus.AUDIO_NEXT) {
}
}
}

@ -85,7 +85,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
if (changeDruChapterIndex == null) {
App.db.bookChapterDao().insert(*cList.toTypedArray())
chapterSize = cList.size
callBack?.loadContent()
} else {
changeDruChapterIndex(cList)
}
@ -113,22 +112,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
}
}
private fun download(book: Book, index: Int) {
if (addLoading(index)) {
execute {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter ->
if (BookHelp.hasContent(book, chapter)) {
removeLoading(chapter.index)
} else {
download(book, chapter)
}
} ?: removeLoading(index)
}.onError {
removeLoading(index)
}
}
}
private fun download(book: Book, chapter: BookChapter) {
webBook?.getContent(book, chapter, scope = this)
?.onSuccess(Dispatchers.IO) { content ->
@ -216,8 +199,6 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application)
}
interface CallBack {
fun loadContent()
fun contentLoadFinish(bookChapter: BookChapter, content: String)
fun upContent()
}
}

@ -19,7 +19,6 @@ 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.ReadAloud
import io.legado.app.help.ReadBookConfig
import io.legado.app.help.storage.Backup
import io.legado.app.lib.dialogs.alert
@ -27,6 +26,7 @@ import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.okButton
import io.legado.app.receiver.TimeElectricityReceiver
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.read.config.*
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.BG_COLOR
import io.legado.app.ui.book.read.config.BgTextConfigDialog.Companion.TEXT_COLOR

@ -11,8 +11,8 @@ 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.ReadAloud
import io.legado.app.model.WebBook
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.widget.page.TextChapter
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main

@ -13,9 +13,9 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.help.ReadAloud
import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.read.Help
import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent

@ -11,8 +11,8 @@ import androidx.fragment.app.DialogFragment
import io.legado.app.R
import io.legado.app.constant.Bus
import io.legado.app.constant.Status
import io.legado.app.help.ReadAloud
import io.legado.app.service.BaseReadAloudService
import io.legado.app.service.help.ReadAloud
import io.legado.app.ui.book.read.Help
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.dialog_read_aloud.*

@ -97,7 +97,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:contentDescription="@string/read_aloud"
android:contentDescription="@string/audio_play"
android:src="@drawable/ic_play_24dp"
android:tint="@color/tv_text_default"
app:backgroundTint="@color/background_menu"

@ -125,6 +125,7 @@
<string name="read_aloud">朗读</string>
<string name="read_aloud_t">正在朗读</string>
<string name="read_aloud_s">点击打开阅读界面</string>
<string name="audio_play">播放</string>
<string name="audio_play_t">正在播放</string>
<string name="audio_play_s">点击打开播放界面</string>
<string name="audio_pause">播放暂停</string>

Loading…
Cancel
Save