pull/48/head
kunfei 5 years ago
parent e3cce8cafd
commit 66a1f7dca2
  1. 6
      app/src/main/java/io/legado/app/model/WebBook.kt
  2. 10
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  3. 14
      app/src/main/java/io/legado/app/service/help/AudioPlay.kt
  4. 27
      app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt
  5. 21
      app/src/main/java/io/legado/app/ui/audio/AudioPlayViewModel.kt

@ -180,7 +180,11 @@ class WebBook(val bookSource: BookSource) {
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
if (analyzeUrl.useWebView) { if (analyzeUrl.useWebView) {
analyzeUrl.getResultByWebView(bookSource.bookSourceUrl).content analyzeUrl.getResultByWebView(
bookSource.bookSourceUrl,
jsStr = bookSource.getContentRule().webJs,
sourceRegex = bookSource.getContentRule().sourceRegex
).content
} else { } else {
analyzeUrl.getResponseAwait().body() analyzeUrl.getResponseAwait().body()
} }

@ -175,10 +175,12 @@ class AnalyzeUrl(
} }
when (method) { when (method) {
RequestMethod.GET -> { RequestMethod.GET -> {
urlArray = url.split("?") if (!useWebView) {
url = urlArray[0] urlArray = url.split("?")
if (urlArray.size > 1) { url = urlArray[0]
analyzeFields(urlArray[1]) if (urlArray.size > 1) {
analyzeFields(urlArray[1])
}
} }
} }
RequestMethod.POST -> { RequestMethod.POST -> {

@ -2,10 +2,24 @@ package io.legado.app.service.help
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.constant.Action import io.legado.app.constant.Action
import io.legado.app.data.entities.Book
import io.legado.app.model.WebBook
import io.legado.app.service.AudioPlayService import io.legado.app.service.AudioPlayService
import io.legado.app.ui.audio.AudioPlayViewModel
object AudioPlay { object AudioPlay {
var titleData = MutableLiveData<String>()
var coverData = MutableLiveData<String>()
var book: Book? = null
var inBookshelf = false
var chapterSize = 0
var callBack: AudioPlayViewModel.CallBack? = null
var durChapterIndex = 0
var durPageIndex = 0
var webBook: WebBook? = null
val loadingChapters = arrayListOf<Int>()
fun play(context: Context, title: String?, subtitle: String, url: String, position: Int) { fun play(context: Context, title: String?, subtitle: String, url: String, position: Int) {
val intent = Intent(context, AudioPlayService::class.java) val intent = Intent(context, AudioPlayService::class.java)

@ -47,9 +47,8 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
viewModel.callBack = this AudioPlay.titleData.observe(this, Observer { title_bar.title = it })
viewModel.titleData.observe(this, Observer { title_bar.title = it }) AudioPlay.coverData.observe(this, Observer { upCover(it) })
viewModel.coverData.observe(this, Observer { upCover(it) })
viewModel.initData(intent) viewModel.initData(intent)
initView() initView()
} }
@ -83,7 +82,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
} }
}) })
iv_chapter.onClick { iv_chapter.onClick {
viewModel.book?.let { AudioPlay.book?.let {
startActivityForResult<ChapterListActivity>( startActivityForResult<ChapterListActivity>(
requestCodeChapter, requestCodeChapter,
Pair("bookUrl", it.bookUrl) Pair("bookUrl", it.bookUrl)
@ -114,27 +113,27 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
when (status) { when (status) {
Status.PLAY -> AudioPlay.pause(this) Status.PLAY -> AudioPlay.pause(this)
Status.PAUSE -> AudioPlay.resume(this) Status.PAUSE -> AudioPlay.resume(this)
else -> viewModel.loadContent(viewModel.durChapterIndex) else -> viewModel.loadContent(AudioPlay.durChapterIndex)
} }
} }
override fun contentLoadFinish(bookChapter: BookChapter, content: String) { override fun contentLoadFinish(bookChapter: BookChapter, content: String) {
AudioPlay.play( AudioPlay.play(
this, this,
viewModel.book?.name, AudioPlay.book?.name,
bookChapter.title, bookChapter.title,
content, content,
viewModel.durPageIndex AudioPlay.durPageIndex
) )
viewModel.loadContent(viewModel.durChapterIndex + 1) viewModel.loadContent(AudioPlay.durChapterIndex + 1)
} }
override fun finish() { override fun finish() {
viewModel.book?.let { AudioPlay.book?.let {
if (!viewModel.inBookshelf) { if (!AudioPlay.inBookshelf) {
this.alert(title = getString(R.string.add_to_shelf)) { this.alert(title = getString(R.string.add_to_shelf)) {
message = getString(R.string.check_add_bookshelf, it.name) message = getString(R.string.check_add_bookshelf, it.name)
okButton { viewModel.inBookshelf = true } okButton { AudioPlay.inBookshelf = true }
noButton { viewModel.removeFromBookshelf { super.finish() } } noButton { viewModel.removeFromBookshelf { super.finish() } }
}.show().applyTint() }.show().applyTint()
} else { } else {
@ -159,8 +158,8 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
when (requestCode) { when (requestCode) {
requestCodeChapter -> data?.getIntExtra("index", viewModel.durChapterIndex)?.let { requestCodeChapter -> data?.getIntExtra("index", AudioPlay.durChapterIndex)?.let {
if (it != viewModel.durChapterIndex) { if (it != AudioPlay.durChapterIndex) {
viewModel.loadContent(it) viewModel.loadContent(it)
} }
} }
@ -184,7 +183,7 @@ class AudioPlayActivity : VMBaseActivity<AudioPlayViewModel>(R.layout.activity_a
} }
} }
observeEventSticky<Int>(Bus.AUDIO_PROGRESS) { observeEventSticky<Int>(Bus.AUDIO_PROGRESS) {
viewModel.durPageIndex = it AudioPlay.durPageIndex = it
if (!adjustProgress) player_progress.progress = it if (!adjustProgress) player_progress.progress = it
tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss") tv_dur_time.text = DateFormatUtils.format(it.toLong(), "mm:ss")
viewModel.saveProgress() viewModel.saveProgress()

@ -2,7 +2,6 @@ package io.legado.app.ui.audio
import android.app.Application import android.app.Application
import android.content.Intent import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
@ -11,20 +10,20 @@ import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.service.help.AudioPlay import io.legado.app.service.help.AudioPlay
import io.legado.app.service.help.AudioPlay.book
import io.legado.app.service.help.AudioPlay.callBack
import io.legado.app.service.help.AudioPlay.chapterSize
import io.legado.app.service.help.AudioPlay.coverData
import io.legado.app.service.help.AudioPlay.durChapterIndex
import io.legado.app.service.help.AudioPlay.durPageIndex
import io.legado.app.service.help.AudioPlay.inBookshelf
import io.legado.app.service.help.AudioPlay.loadingChapters
import io.legado.app.service.help.AudioPlay.titleData
import io.legado.app.service.help.AudioPlay.webBook
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
class AudioPlayViewModel(application: Application) : BaseViewModel(application) { class AudioPlayViewModel(application: Application) : BaseViewModel(application) {
var titleData = MutableLiveData<String>()
var coverData = MutableLiveData<String>()
var book: Book? = null
var inBookshelf = false
private var chapterSize = 0
var callBack: CallBack? = null
var durChapterIndex = 0
var durPageIndex = 0
var webBook: WebBook? = null
private val loadingChapters = arrayListOf<Int>()
fun initData(intent: Intent) { fun initData(intent: Intent) {
execute { execute {

Loading…
Cancel
Save