pull/2309/head
kunfei 2 years ago
parent 91188f1b06
commit 26da15e79a
  1. 57
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  2. 6
      app/src/main/java/io/legado/app/model/Debug.kt
  3. 21
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt
  4. 8
      app/src/main/java/io/legado/app/ui/rss/article/RssSortViewModel.kt
  5. 11
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt
  6. 13
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt
  7. 5
      app/src/main/res/menu/rss_articles.xml
  8. 1
      app/src/main/res/values-es-rES/strings.xml
  9. 1
      app/src/main/res/values-ja-rJP/strings.xml
  10. 1
      app/src/main/res/values-pt-rBR/strings.xml
  11. 3
      app/src/main/res/values-zh-rHK/strings.xml
  12. 3
      app/src/main/res/values-zh-rTW/strings.xml
  13. 3
      app/src/main/res/values-zh/strings.xml
  14. 1
      app/src/main/res/values/strings.xml

@ -9,6 +9,8 @@ import androidx.room.PrimaryKey
import com.jayway.jsonpath.DocumentContext import com.jayway.jsonpath.DocumentContext
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
@Parcelize @Parcelize
@ -133,32 +135,41 @@ data class RssSource(
return this return this
} }
fun sortUrls(): List<Pair<String, String>> = arrayListOf<Pair<String, String>>().apply { suspend fun sortUrls(): List<Pair<String, String>> = arrayListOf<Pair<String, String>>().apply {
kotlin.runCatching { withContext(IO) {
var a = sortUrl kotlin.runCatching {
if (sortUrl?.startsWith("<js>", false) == true var a = sortUrl
|| sortUrl?.startsWith("@js:", false) == true if (sortUrl?.startsWith("<js>", false) == true
) { || sortUrl?.startsWith("@js:", false) == true
val aCache = ACache.get("rssSortUrl") ) {
a = aCache.getAsString(sourceUrl) ?: "" val aCache = ACache.get("rssSortUrl")
if (a.isBlank()) { a = aCache.getAsString(sourceUrl) ?: ""
val jsStr = if (sortUrl!!.startsWith("@")) { if (a.isBlank()) {
sortUrl!!.substring(4) val jsStr = if (sortUrl!!.startsWith("@")) {
} else { sortUrl!!.substring(4)
sortUrl!!.substring(4, sortUrl!!.lastIndexOf("<")) } else {
sortUrl!!.substring(4, sortUrl!!.lastIndexOf("<"))
}
a = evalJS(jsStr).toString()
aCache.put(sourceUrl, a)
} }
a = evalJS(jsStr).toString() }
aCache.put(sourceUrl, a) a?.split("(&&|\n)+".toRegex())?.forEach { c ->
val d = c.split("::")
if (d.size > 1)
add(Pair(d[0], d[1]))
}
if (isEmpty()) {
add(Pair("", sourceUrl))
} }
} }
a?.split("(&&|\n)+".toRegex())?.forEach { c -> }
val d = c.split("::") }
if (d.size > 1)
add(Pair(d[0], d[1])) suspend fun removeSortCache() {
} withContext(IO) {
if (isEmpty()) { val aCache = ACache.get("rssSortUrl")
add(Pair("", sourceUrl)) aCache.remove(sourceUrl)
}
} }
} }

@ -11,6 +11,8 @@ import io.legado.app.utils.HtmlFormatter
import io.legado.app.utils.isAbsUrl import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.stackTraceStr import io.legado.app.utils.stackTraceStr
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -101,11 +103,11 @@ object Debug {
} }
} }
fun startDebug(scope: CoroutineScope, rssSource: RssSource) { suspend fun startDebug(scope: CoroutineScope, rssSource: RssSource) {
cancelDebug() cancelDebug()
debugSource = rssSource.sourceUrl debugSource = rssSource.sourceUrl
log(debugSource, "︾开始解析") log(debugSource, "︾开始解析")
val sort = rssSource.sortUrls().first() val sort = withContext(IO) { rssSource.sortUrls().first() }
Rss.getArticles(scope, sort.first, sort.second, rssSource, 1) Rss.getArticles(scope, sort.first, sort.second, rssSource, 1)
.onSuccess { .onSuccess {
if (it.first.isEmpty()) { if (it.first.isEmpty()) {

@ -69,6 +69,7 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
putExtra("type", "rssSource") putExtra("type", "rssSource")
putExtra("key", viewModel.rssSource?.sourceUrl) putExtra("key", viewModel.rssSource?.sourceUrl)
} }
R.id.menu_refresh_sort -> viewModel.clearSortCache { upFragments() }
R.id.menu_set_source_variable -> setSourceVariable() R.id.menu_set_source_variable -> setSourceVariable()
R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let { R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let {
editSourceResult.launch { editSourceResult.launch {
@ -89,16 +90,18 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
} }
private fun upFragments() { private fun upFragments() {
viewModel.rssSource?.sortUrls()?.let { launch {
sortList.clear() viewModel.rssSource?.sortUrls()?.let {
sortList.addAll(it) sortList.clear()
} sortList.addAll(it)
if (sortList.size == 1) { }
binding.tabLayout.gone() if (sortList.size == 1) {
} else { binding.tabLayout.gone()
binding.tabLayout.visible() } else {
binding.tabLayout.visible()
}
adapter.notifyDataSetChanged()
} }
adapter.notifyDataSetChanged()
} }
private fun setSourceVariable() { private fun setSourceVariable() {

@ -63,4 +63,12 @@ class RssSortViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun clearSortCache(onFinally: () -> Unit) {
execute {
rssSource?.removeSortCache()
}.onFinally {
onFinally.invoke()
}
}
} }

@ -38,7 +38,7 @@ class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSou
} }
} }
viewModel.initData(intent.getStringExtra("key")) { viewModel.initData(intent.getStringExtra("key")) {
startSearch() startDebug()
} }
} }
@ -65,12 +65,11 @@ class RssSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, RssSou
binding.titleBar.findViewById<SearchView>(R.id.search_view).gone() binding.titleBar.findViewById<SearchView>(R.id.search_view).gone()
} }
private fun startSearch() { private fun startDebug() {
adapter.clearItems() adapter.clearItems()
viewModel.startDebug({ viewModel.rssSource?.let {
binding.rotateLoading.show() binding.rotateLoading.show()
}, { viewModel.startDebug(it)
toastOnUi("未获取到源") } ?: toastOnUi(R.string.error_no_source)
})
} }
} }

@ -1,7 +1,6 @@
package io.legado.app.ui.rss.source.debug package io.legado.app.ui.rss.source.debug
import android.app.Application import android.app.Application
import androidx.lifecycle.viewModelScope
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
@ -9,7 +8,7 @@ import io.legado.app.model.Debug
class RssSourceDebugModel(application: Application) : BaseViewModel(application), class RssSourceDebugModel(application: Application) : BaseViewModel(application),
Debug.Callback { Debug.Callback {
private var rssSource: RssSource? = null var rssSource: RssSource? = null
private var callback: ((Int, String) -> Unit)? = null private var callback: ((Int, String) -> Unit)? = null
var listSrc: String? = null var listSrc: String? = null
var contentSrc: String? = null var contentSrc: String? = null
@ -28,12 +27,10 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application)
this.callback = callback this.callback = callback
} }
fun startDebug(start: (() -> Unit)? = null, error: (() -> Unit)? = null) { fun startDebug(source: RssSource) {
rssSource?.let { execute {
start?.invoke() Debug.startDebug(this, source)
Debug.callback = this }
Debug.startDebug(viewModelScope, it)
} ?: error?.invoke()
} }
override fun printLog(state: Int, msg: String) { override fun printLog(state: Int, msg: String) {

@ -7,6 +7,11 @@
android:title="@string/login" android:title="@string/login"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_refresh_sort"
android:title="@string/refresh_sort"
app:showAsAction="never" />
<item <item
android:id="@+id/menu_set_source_variable" android:id="@+id/menu_set_source_variable"
android:title="@string/set_source_variable" android:title="@string/set_source_variable"

@ -1031,4 +1031,5 @@
<string name="async_load_image">异步加载图片</string> <string name="async_load_image">异步加载图片</string>
<string name="ignore_audio_focus_title">忽略音频焦点</string> <string name="ignore_audio_focus_title">忽略音频焦点</string>
<string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string> <string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string>
<string name="refresh_sort">刷新分类</string>
</resources> </resources>

@ -1034,4 +1034,5 @@
<string name="async_load_image">异步加载图片</string> <string name="async_load_image">异步加载图片</string>
<string name="ignore_audio_focus_title">忽略音频焦点</string> <string name="ignore_audio_focus_title">忽略音频焦点</string>
<string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string> <string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string>
<string name="refresh_sort">刷新分类</string>
</resources> </resources>

@ -1034,4 +1034,5 @@
<string name="async_load_image">异步加载图片</string> <string name="async_load_image">异步加载图片</string>
<string name="ignore_audio_focus_title">忽略音频焦点</string> <string name="ignore_audio_focus_title">忽略音频焦点</string>
<string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string> <string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string>
<string name="refresh_sort">刷新分类</string>
</resources> </resources>

@ -441,7 +441,7 @@
<!-- source end--> <!-- source end-->
<!--error string start--> <!--error string start-->
<string name="error_no_source">沒有</string> <string name="error_no_source">沒有源</string>
<string name="error_get_book_info">書籍信息獲取失敗</string> <string name="error_get_book_info">書籍信息獲取失敗</string>
<string name="error_get_content">內容獲取失敗</string> <string name="error_get_content">內容獲取失敗</string>
<string name="error_get_chapter_list">目錄獲取失敗</string> <string name="error_get_chapter_list">目錄獲取失敗</string>
@ -1031,4 +1031,5 @@
<string name="async_load_image">异步加载图片</string> <string name="async_load_image">异步加载图片</string>
<string name="ignore_audio_focus_title">忽略音频焦点</string> <string name="ignore_audio_focus_title">忽略音频焦点</string>
<string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string> <string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string>
<string name="refresh_sort">刷新分类</string>
</resources> </resources>

@ -448,7 +448,7 @@
<!-- source end--> <!-- source end-->
<!--error string start--> <!--error string start-->
<string name="error_no_source">沒有</string> <string name="error_no_source">沒有源</string>
<string name="error_get_book_info">書籍訊息獲取失敗</string> <string name="error_get_book_info">書籍訊息獲取失敗</string>
<string name="error_get_content">內容獲取失敗</string> <string name="error_get_content">內容獲取失敗</string>
<string name="error_get_chapter_list">目錄獲取失敗</string> <string name="error_get_chapter_list">目錄獲取失敗</string>
@ -1033,4 +1033,5 @@
<string name="async_load_image">异步加载图片</string> <string name="async_load_image">异步加载图片</string>
<string name="ignore_audio_focus_title">忽略音频焦点</string> <string name="ignore_audio_focus_title">忽略音频焦点</string>
<string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string> <string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string>
<string name="refresh_sort">刷新分类</string>
</resources> </resources>

@ -448,7 +448,7 @@
<!-- source end--> <!-- source end-->
<!--error string start--> <!--error string start-->
<string name="error_no_source">没有</string> <string name="error_no_source">没有源</string>
<string name="error_get_book_info">书籍信息获取失败</string> <string name="error_get_book_info">书籍信息获取失败</string>
<string name="error_get_content">内容获取失败</string> <string name="error_get_content">内容获取失败</string>
<string name="error_get_chapter_list">目录获取失败</string> <string name="error_get_chapter_list">目录获取失败</string>
@ -1033,4 +1033,5 @@
<string name="async_load_image">异步加载图片</string> <string name="async_load_image">异步加载图片</string>
<string name="ignore_audio_focus_title">忽略音频焦点</string> <string name="ignore_audio_focus_title">忽略音频焦点</string>
<string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string> <string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string>
<string name="refresh_sort">刷新分类</string>
</resources> </resources>

@ -1034,4 +1034,5 @@
<string name="async_load_image">异步加载图片</string> <string name="async_load_image">异步加载图片</string>
<string name="ignore_audio_focus_title">忽略音频焦点</string> <string name="ignore_audio_focus_title">忽略音频焦点</string>
<string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string> <string name="ignore_audio_focus_summary">允许与其他应用同时播放音频</string>
<string name="refresh_sort">刷新分类</string>
</resources> </resources>

Loading…
Cancel
Save