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()
)
if (analyzeUrl.useWebView) {
analyzeUrl.getResultByWebView(bookSource.bookSourceUrl).content
analyzeUrl.getResultByWebView(
bookSource.bookSourceUrl,
jsStr = bookSource.getContentRule().webJs,
sourceRegex = bookSource.getContentRule().sourceRegex
).content
} else {
analyzeUrl.getResponseAwait().body()
}

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

@ -2,10 +2,24 @@ package io.legado.app.service.help
import android.content.Context
import android.content.Intent
import androidx.lifecycle.MutableLiveData
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.ui.audio.AudioPlayViewModel
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) {
val intent = Intent(context, AudioPlayService::class.java)

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

@ -2,7 +2,6 @@ package io.legado.app.ui.audio
import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.R
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.model.WebBook
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.withContext
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) {
execute {

Loading…
Cancel
Save