diff --git a/app/src/main/assets/web/help/md/jsHelp.md b/app/src/main/assets/web/help/md/jsHelp.md index ec213bf08..cab519860 100644 --- a/app/src/main/assets/web/help/md/jsHelp.md +++ b/app/src/main/assets/web/help/md/jsHelp.md @@ -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)| diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 8bc80c3c6..0925c658b 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -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() - 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() 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 { diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index f3e00314e..35202dda1 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -249,7 +249,7 @@ class OtherConfigFragment : PreferenceFragment(), putPrefString(PreferKey.userAgent, userAgent) } } - noButton() + cancelButton() } } diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt index d0458e219..e5db6eec1 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesActivity.kt @@ -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() { override val binding by viewBinding(ActivityRssFavoritesBinding::inflate) private val adapter by lazy { TabFragmentPageAdapter() } private var groupList = mutableListOf() + private var groupsMenu: SubMenu? = null override fun onActivityCreated(savedInstanceState: Bundle?) { initView() @@ -40,6 +45,28 @@ class RssFavoritesActivity : BaseActivity() { 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() { } else { binding.tabLayout.visible() } + if (groupsMenu != null){ + upGroupsMenu() + } adapter.notifyDataSetChanged() } }