Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -60,6 +60,8 @@ jobs:
|
|||||||
VERSIONL: ${{ needs.prepare.outputs.versionL }}
|
VERSIONL: ${{ needs.prepare.outputs.versionL }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
- name: Clear 18PlusList.txt
|
- name: Clear 18PlusList.txt
|
||||||
run: |
|
run: |
|
||||||
echo "清空18PlusList.txt"
|
echo "清空18PlusList.txt"
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ object BookInfo {
|
|||||||
coroutineContext.ensureActive()
|
coroutineContext.ensureActive()
|
||||||
Debug.log(bookSource.bookSourceUrl, "┌获取文件下载链接")
|
Debug.log(bookSource.bookSourceUrl, "┌获取文件下载链接")
|
||||||
book.downloadUrls = analyzeRule.getStringList(infoRule.downloadUrls, isUrl = true)
|
book.downloadUrls = analyzeRule.getStringList(infoRule.downloadUrls, isUrl = true)
|
||||||
if (book.downloadUrls == null) {
|
if (book.downloadUrls.isNullOrEmpty()) {
|
||||||
Debug.log(bookSource.bookSourceUrl, "└")
|
Debug.log(bookSource.bookSourceUrl, "└")
|
||||||
throw NoStackTraceException("下载链接为空")
|
throw NoStackTraceException("下载链接为空")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ class BookInfoActivity :
|
|||||||
VMBaseActivity<ActivityBookInfoBinding, BookInfoViewModel>(toolBarTheme = Theme.Dark),
|
VMBaseActivity<ActivityBookInfoBinding, BookInfoViewModel>(toolBarTheme = Theme.Dark),
|
||||||
GroupSelectDialog.CallBack,
|
GroupSelectDialog.CallBack,
|
||||||
ChangeBookSourceDialog.CallBack,
|
ChangeBookSourceDialog.CallBack,
|
||||||
ChangeCoverDialog.CallBack,
|
ChangeCoverDialog.CallBack {
|
||||||
BookInfoViewModel.CallBack {
|
|
||||||
|
|
||||||
private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
|
private val tocActivityResult = registerForActivityResult(TocActivityResult()) {
|
||||||
it?.let {
|
it?.let {
|
||||||
@@ -108,10 +107,9 @@ class BookInfoActivity :
|
|||||||
binding.flAction.setBackgroundColor(bottomBackground)
|
binding.flAction.setBackgroundColor(bottomBackground)
|
||||||
binding.tvShelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground)))
|
binding.tvShelf.setTextColor(getPrimaryTextColor(ColorUtils.isColorLight(bottomBackground)))
|
||||||
binding.tvToc.text = getString(R.string.toc_s, getString(R.string.loading))
|
binding.tvToc.text = getString(R.string.toc_s, getString(R.string.loading))
|
||||||
viewModel.callBack = this
|
|
||||||
viewModel.bookData.observe(this) { showBook(it) }
|
viewModel.bookData.observe(this) { showBook(it) }
|
||||||
viewModel.chapterListData.observe(this) { upLoading(false, it) }
|
viewModel.chapterListData.observe(this) { upLoading(false, it) }
|
||||||
//viewModel.webFileData.observe(this) { showWebFileDownloadAlert() }
|
viewModel.waitDialogData.observe(this) { upWaitDialogStatus(it) }
|
||||||
viewModel.initData(intent)
|
viewModel.initData(intent)
|
||||||
initViewEvent()
|
initViewEvent()
|
||||||
}
|
}
|
||||||
@@ -499,9 +497,13 @@ class BookInfoActivity :
|
|||||||
private fun showWebFileDownloadAlert(
|
private fun showWebFileDownloadAlert(
|
||||||
onClick: ((Book) -> Unit)? = null
|
onClick: ((Book) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
viewModel.webFileData.value?.let {
|
val webFiles = viewModel.webFiles
|
||||||
|
if (webFiles.isEmpty()) {
|
||||||
|
toastOnUi("Unexpected webFileData")
|
||||||
|
return
|
||||||
|
}
|
||||||
alert(titleResource = R.string.download_and_import_file) {
|
alert(titleResource = R.string.download_and_import_file) {
|
||||||
items<BookInfoViewModel.WebFile>(it) { _, webFile, _ ->
|
items<BookInfoViewModel.WebFile>(webFiles) { _, webFile, _ ->
|
||||||
if (webFile.isSupported) {
|
if (webFile.isSupported) {
|
||||||
/* import */
|
/* import */
|
||||||
viewModel.importOrDownloadWebFile<Book>(webFile) {
|
viewModel.importOrDownloadWebFile<Book>(webFile) {
|
||||||
@@ -523,7 +525,6 @@ class BookInfoActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ?: toastOnUi("Unexpected webFileData")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readBook(book: Book) {
|
private fun readBook(book: Book) {
|
||||||
@@ -588,15 +589,16 @@ class BookInfoActivity :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWebFileProcessFinally() {
|
private fun upWaitDialogStatus(isShow: Boolean) {
|
||||||
waitDialog.dismiss()
|
val showText = "Loading....."
|
||||||
}
|
if (isShow) {
|
||||||
|
|
||||||
override fun onWebFileProcessStart() {
|
|
||||||
waitDialog.run {
|
waitDialog.run {
|
||||||
setText("Loading.....")
|
setText(showText)
|
||||||
show()
|
show()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
waitDialog.dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,8 +21,6 @@ import io.legado.app.help.AppWebDav
|
|||||||
import io.legado.app.help.book.*
|
import io.legado.app.help.book.*
|
||||||
import io.legado.app.help.coroutine.Coroutine
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
import io.legado.app.lib.webdav.ObjectNotFoundException
|
import io.legado.app.lib.webdav.ObjectNotFoundException
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeRule
|
|
||||||
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
|
||||||
import io.legado.app.model.BookCover
|
import io.legado.app.model.BookCover
|
||||||
import io.legado.app.model.ReadBook
|
import io.legado.app.model.ReadBook
|
||||||
import io.legado.app.model.localBook.LocalBook
|
import io.legado.app.model.localBook.LocalBook
|
||||||
@@ -30,18 +28,17 @@ import io.legado.app.model.webBook.WebBook
|
|||||||
import io.legado.app.utils.isContentScheme
|
import io.legado.app.utils.isContentScheme
|
||||||
import io.legado.app.utils.postEvent
|
import io.legado.app.utils.postEvent
|
||||||
import io.legado.app.utils.toastOnUi
|
import io.legado.app.utils.toastOnUi
|
||||||
import io.legado.app.utils.runOnUI
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
|
||||||
class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||||
val bookData = MutableLiveData<Book>()
|
val bookData = MutableLiveData<Book>()
|
||||||
val chapterListData = MutableLiveData<List<BookChapter>>()
|
val chapterListData = MutableLiveData<List<BookChapter>>()
|
||||||
val webFileData = MutableLiveData<List<WebFile>>()
|
val webFiles = mutableListOf<WebFile>()
|
||||||
var inBookshelf = false
|
var inBookshelf = false
|
||||||
var bookSource: BookSource? = null
|
var bookSource: BookSource? = null
|
||||||
private var changeSourceCoroutine: Coroutine<*>? = null
|
private var changeSourceCoroutine: Coroutine<*>? = null
|
||||||
var callBack: CallBack? = null
|
val waitDialogData = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
fun initData(intent: Intent) {
|
fun initData(intent: Intent) {
|
||||||
execute {
|
execute {
|
||||||
@@ -241,45 +238,24 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
scope: CoroutineScope = viewModelScope
|
scope: CoroutineScope = viewModelScope
|
||||||
) {
|
) {
|
||||||
execute(scope) {
|
execute(scope) {
|
||||||
|
webFiles.clear()
|
||||||
val fileName = "${book.name} 作者:${book.author}"
|
val fileName = "${book.name} 作者:${book.author}"
|
||||||
if (book.downloadUrls.isNullOrEmpty()) {
|
book.downloadUrls!!.map {
|
||||||
val ruleDownloadUrls = bookSource.getBookInfoRule().downloadUrls
|
val mFileName = "${fileName}.${LocalBook.parseFileSuffix(it)}"
|
||||||
val content = AnalyzeUrl(book.bookUrl, source = bookSource).getStrResponse().body
|
val isSupportedFile = AppPattern.bookFileRegex.matches(mFileName)
|
||||||
val analyzeRule = AnalyzeRule(book, bookSource)
|
WebFile(it, mFileName, isSupportedFile)
|
||||||
analyzeRule.setContent(content).setBaseUrl(book.bookUrl)
|
|
||||||
analyzeRule.getStringList(ruleDownloadUrls, isUrl = true)?.let {
|
|
||||||
parseDownloadUrls(it, fileName)
|
|
||||||
} ?: throw NoStackTraceException("Unexpected ruleDownloadUrls")
|
|
||||||
} else {
|
|
||||||
parseDownloadUrls(book.downloadUrls, fileName)
|
|
||||||
}
|
}
|
||||||
}.onError {
|
}.onError {
|
||||||
context.toastOnUi("LoadWebFileError\n${it.localizedMessage}")
|
context.toastOnUi("LoadWebFileError\n${it.localizedMessage}")
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
webFileData.postValue(it)
|
webFiles.addAll(it)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseDownloadUrls(
|
|
||||||
downloadUrls: List<String>?,
|
|
||||||
fileName: String
|
|
||||||
): List<WebFile>? {
|
|
||||||
val urls = downloadUrls
|
|
||||||
return urls?.map {
|
|
||||||
val mFileName = "${fileName}.${LocalBook.parseFileSuffix(it)}"
|
|
||||||
val isSupportedFile = AppPattern.bookFileRegex.matches(mFileName)
|
|
||||||
WebFile(it, mFileName, isSupportedFile)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> importOrDownloadWebFile(webFile: WebFile, success: ((T) -> Unit)?) {
|
fun <T> importOrDownloadWebFile(webFile: WebFile, success: ((T) -> Unit)?) {
|
||||||
bookSource ?: return
|
bookSource ?: return
|
||||||
execute {
|
execute {
|
||||||
callBack?.run {
|
waitDialogData.postValue(true)
|
||||||
runOnUI {
|
|
||||||
onWebFileProcessStart()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (webFile.isSupported) {
|
if (webFile.isSupported) {
|
||||||
val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource)
|
val book = LocalBook.importFileOnLine(webFile.url, webFile.name, bookSource)
|
||||||
changeToLocalBook(book)
|
changeToLocalBook(book)
|
||||||
@@ -291,12 +267,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}.onError {
|
}.onError {
|
||||||
context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
|
context.toastOnUi("ImportWebFileError\n${it.localizedMessage}")
|
||||||
}.onFinally {
|
}.onFinally {
|
||||||
callBack?.run {
|
waitDialogData.postValue(false)
|
||||||
runOnUI {
|
|
||||||
onWebFileProcessFinally()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,9 +404,4 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CallBack {
|
|
||||||
fun onWebFileProcessStart()
|
|
||||||
fun onWebFileProcessFinally()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ import java.net.URLDecoder
|
|||||||
/**
|
/**
|
||||||
* rss阅读界面
|
* rss阅读界面
|
||||||
*/
|
*/
|
||||||
class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>(false),
|
class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>(false) {
|
||||||
ReadRssViewModel.CallBack {
|
|
||||||
|
|
||||||
override val binding by viewBinding(ActivityRssReadBinding::inflate)
|
override val binding by viewBinding(ActivityRssReadBinding::inflate)
|
||||||
override val viewModel by viewModels<ReadRssViewModel>()
|
override val viewModel by viewModels<ReadRssViewModel>()
|
||||||
@@ -50,7 +49,8 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
viewModel.callBack = this
|
viewModel.upStarMenuData.observe(this) { upStarMenu() }
|
||||||
|
viewModel.upTtsMenuData.observe(this) { upTtsMenu(it) }
|
||||||
binding.titleBar.title = intent.getStringExtra("title")
|
binding.titleBar.title = intent.getStringExtra("title")
|
||||||
initWebView()
|
initWebView()
|
||||||
initLiveData()
|
initLiveData()
|
||||||
@@ -223,7 +223,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun upStarMenu() {
|
private fun upStarMenu() {
|
||||||
starMenuItem?.isVisible = viewModel.rssArticle != null
|
starMenuItem?.isVisible = viewModel.rssArticle != null
|
||||||
if (viewModel.rssStar != null) {
|
if (viewModel.rssStar != null) {
|
||||||
starMenuItem?.setIcon(R.drawable.ic_star)
|
starMenuItem?.setIcon(R.drawable.ic_star)
|
||||||
@@ -235,7 +235,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
starMenuItem?.icon?.setTintMutate(primaryTextColor)
|
starMenuItem?.icon?.setTintMutate(primaryTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun upTtsMenu(isPlaying: Boolean) {
|
private fun upTtsMenu(isPlaying: Boolean) {
|
||||||
launch {
|
launch {
|
||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp)
|
ttsMenuItem?.setIcon(R.drawable.ic_stop_black_24dp)
|
||||||
|
|||||||
@@ -27,13 +27,14 @@ import java.util.*
|
|||||||
|
|
||||||
|
|
||||||
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
||||||
var callBack: CallBack? = null
|
|
||||||
var rssSource: RssSource? = null
|
var rssSource: RssSource? = null
|
||||||
var rssArticle: RssArticle? = null
|
var rssArticle: RssArticle? = null
|
||||||
var tts: TTS? = null
|
var tts: TTS? = null
|
||||||
val contentLiveData = MutableLiveData<String>()
|
val contentLiveData = MutableLiveData<String>()
|
||||||
val urlLiveData = MutableLiveData<AnalyzeUrl>()
|
val urlLiveData = MutableLiveData<AnalyzeUrl>()
|
||||||
var rssStar: RssStar? = null
|
var rssStar: RssStar? = null
|
||||||
|
val upTtsMenuData = MutableLiveData<Boolean>()
|
||||||
|
val upStarMenuData = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
fun initData(intent: Intent) {
|
fun initData(intent: Intent) {
|
||||||
execute {
|
execute {
|
||||||
@@ -72,7 +73,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.onFinally {
|
}.onFinally {
|
||||||
callBack?.upStarMenu()
|
upStarMenuData.postValue(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +127,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
rssStar = it
|
rssStar = it
|
||||||
}
|
}
|
||||||
}.onSuccess {
|
}.onSuccess {
|
||||||
callBack?.upStarMenu()
|
upStarMenuData.postValue(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,11 +197,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
tts = TTS().apply {
|
tts = TTS().apply {
|
||||||
setSpeakStateListener(object : TTS.SpeakStateListener {
|
setSpeakStateListener(object : TTS.SpeakStateListener {
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
callBack?.upTtsMenu(true)
|
upTtsMenuData.postValue(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDone() {
|
override fun onDone() {
|
||||||
callBack?.upTtsMenu(false)
|
upTtsMenuData.postValue(false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -213,8 +214,4 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|||||||
tts?.clearTts()
|
tts?.clearTts()
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CallBack {
|
|
||||||
fun upStarMenu()
|
|
||||||
fun upTtsMenu(isPlaying: Boolean)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user