优化rss相关 (#4403)

* js变量中增加rssArticle;消除ide警告

* 修改提示按钮

* rss收藏页面增加分组查看和跳转
This commit is contained in:
老牛 2024-12-06 14:50:23 +08:00 committed by GitHub
parent 4d9a8c57d8
commit ad6e61de1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 5 deletions

View File

@ -23,6 +23,7 @@
|baseUrl|当前url,String |
|result|上一步的结果|
|book|[书籍类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/Book.kt)|
|rssArticle|[Article类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/RssArticle.kt)|
|chapter|[章节类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BookChapter.kt)|
|source|[基础书源类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/data/entities/BaseSource.kt)|
|cookie|[cookie操作类](https://github.com/gedoor/legado/blob/master/app/src/main/java/io/legado/app/help/http/CookieStore.kt)|

View File

@ -10,6 +10,7 @@ import io.legado.app.data.entities.BaseSource
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.RssArticle
import io.legado.app.help.CacheManager
import io.legado.app.help.JsExtensions
import io.legado.app.help.http.CookieStore
@ -27,6 +28,7 @@ import org.apache.commons.text.StringEscapeUtils
import org.jsoup.nodes.Node
import org.mozilla.javascript.NativeObject
import java.net.URL
import java.util.Locale
import java.util.regex.Pattern
import kotlin.collections.component1
import kotlin.collections.component2
@ -45,6 +47,7 @@ class AnalyzeRule(
) : JsExtensions {
val book get() = ruleData as? BaseBook
val rssArticle get() = ruleData as? RssArticle
var chapter: BookChapter? = null
var nextChapterUrl: String? = null
@ -199,7 +202,7 @@ class AnalyzeRule(
}
if (sourceRule.replaceRegex.isNotEmpty() && result is List<*>) {
val newList = ArrayList<String>()
for (item in result) {
for (item in result as List<*>) {
newList.add(replaceRegex(item.toString(), sourceRule))
}
result = newList
@ -212,12 +215,12 @@ class AnalyzeRule(
}
if (result == null) return null
if (result is String) {
result = result.split("\n")
result = (result as String).split("\n")
}
if (isUrl) {
val urlList = ArrayList<String>()
if (result is List<*>) {
for (url in result) {
for (url in result as List<*>) {
val absoluteURL = NetworkUtils.getAbsoluteURL(redirectUrl, url.toString())
if (absoluteURL.isNotEmpty() && !urlList.contains(absoluteURL)) {
urlList.add(absoluteURL)
@ -650,7 +653,7 @@ class AnalyzeRule(
jsEval is String -> infoVal.insert(0, jsEval)
jsEval is Double && jsEval % 1.0 == 0.0 -> infoVal.insert(
0,
String.format("%.0f", jsEval)
String.format(Locale.getDefault(), "%.0f", jsEval)
)
else -> infoVal.insert(0, jsEval.toString())
@ -744,6 +747,7 @@ class AnalyzeRule(
bindings["title"] = chapter?.title
bindings["src"] = content
bindings["nextChapterUrl"] = nextChapterUrl
bindings["rssArticle"] = rssArticle
}
val scope = RhinoScriptEngine.getRuntimeScope(bindings)
source?.getShareScope()?.let {

View File

@ -249,7 +249,7 @@ class OtherConfigFragment : PreferenceFragment(),
putPrefString(PreferKey.userAgent, userAgent)
}
}
noButton()
cancelButton()
}
}

View File

@ -3,9 +3,13 @@
package io.legado.app.ui.rss.favorites
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.SubMenu
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.lifecycle.lifecycleScope
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.AppLog
import io.legado.app.data.appDb
@ -28,6 +32,7 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
override val binding by viewBinding(ActivityRssFavoritesBinding::inflate)
private val adapter by lazy { TabFragmentPageAdapter() }
private var groupList = mutableListOf<String>()
private var groupsMenu: SubMenu? = null
override fun onActivityCreated(savedInstanceState: Bundle?) {
initView()
@ -40,6 +45,28 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
binding.tabLayout.setSelectedTabIndicatorColor(accentColor)
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.main_explore, menu)
groupsMenu = menu.findItem(R.id.menu_group)?.subMenu
upGroupsMenu()
return super.onCompatCreateOptionsMenu(menu)
}
private fun upGroupsMenu() = groupsMenu?.let { subMenu ->
subMenu.removeGroup(R.id.menu_group_text)
groupList.forEachIndexed { index, it ->
subMenu.add(R.id.menu_group_text, Menu.NONE, index, it)
}
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
super.onCompatOptionsItemSelected(item)
if (item.groupId == R.id.menu_group_text) {
binding.viewPager.setCurrentItem(item.order)
}
return super.onCompatOptionsItemSelected(item)
}
private fun upFragments() {
lifecycleScope.launch {
appDb.rssStarDao.flowGroups().catch {
@ -52,6 +79,9 @@ class RssFavoritesActivity : BaseActivity<ActivityRssFavoritesBinding>() {
} else {
binding.tabLayout.visible()
}
if (groupsMenu != null){
upGroupsMenu()
}
adapter.notifyDataSetChanged()
}
}