From 19027427cc3fd74cb7855c52d2dde89286d0f385 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 09:26:15 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../legado/app/ui/book/read/TextActionMenu.kt | 32 +++---------- app/src/main/res/layout/dialog_dict.xml | 3 +- app/src/main/res/layout/popup_action_menu.xml | 47 +++---------------- 4 files changed, 17 insertions(+), 69 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1cf1e1e41..ba28c8557 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -133,8 +133,8 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' - implementation 'com.google.android.material:material:1.3.0' - implementation 'com.google.android:flexbox:1.1.0' + implementation 'com.google.android.material:material:1.4.0' + implementation 'com.google.android.flexbox:flexbox:3.0.0' implementation 'com.google.code.gson:gson:2.8.6' implementation 'androidx.webkit:webkit:1.4.0' diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index 29373ae37..a0ea37e03 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -17,20 +17,23 @@ import androidx.annotation.RequiresApi import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuItemImpl -import androidx.core.view.isVisible import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemTextBinding import io.legado.app.databinding.PopupActionMenuBinding import io.legado.app.service.BaseReadAloudService -import io.legado.app.utils.* +import io.legado.app.utils.isAbsUrl +import io.legado.app.utils.sendToClip +import io.legado.app.utils.share +import io.legado.app.utils.toastOnUi import java.util.* @SuppressLint("RestrictedApi") class TextActionMenu(private val context: Context, private val callBack: CallBack) : PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT), TextToSpeech.OnInitListener { + private val binding = PopupActionMenuBinding.inflate(LayoutInflater.from(context)) private val adapter = Adapter(context) private val menu = MenuBuilder(context) @@ -48,38 +51,15 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac isFocusable = false initRecyclerView() - setOnDismissListener { - binding.ivMenuMore.setImageResource(R.drawable.ic_more_vert) - binding.recyclerViewMore.gone() - adapter.setItems(menu.visibleItems) - binding.recyclerView.visible() - } } private fun initRecyclerView() = with(binding) { recyclerView.adapter = adapter - recyclerViewMore.adapter = adapter SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) - adapter.setItems(menu.visibleItems) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { onInitializeMenu(moreMenu) } - if (moreMenu.size() > 0) { - ivMenuMore.visible() - } - ivMenuMore.setOnClickListener { - if (recyclerView.isVisible) { - ivMenuMore.setImageResource(R.drawable.ic_arrow_back) - adapter.setItems(moreMenu.visibleItems) - recyclerView.gone() - recyclerViewMore.visible() - } else { - ivMenuMore.setImageResource(R.drawable.ic_more_vert) - recyclerViewMore.gone() - adapter.setItems(menu.visibleItems) - recyclerView.visible() - } - } + adapter.setItems(menu.visibleItems + moreMenu.visibleItems) } inner class Adapter(context: Context) : diff --git a/app/src/main/res/layout/dialog_dict.xml b/app/src/main/res/layout/dialog_dict.xml index e04adae59..acd6a42f3 100644 --- a/app/src/main/res/layout/dialog_dict.xml +++ b/app/src/main/res/layout/dialog_dict.xml @@ -1,7 +1,8 @@ + android:layout_height="wrap_content" + android:padding="16dp"> - - - - - - - - - - - + android:orientation="horizontal" + app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager"> - + From 762d63d4b74e738115ec75b786f762631877fe90 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 10:25:13 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/dict/DictDialog.kt | 4 ++++ app/src/main/res/layout/dialog_dict.xml | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt b/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt index 573e708ae..fc140d0c9 100644 --- a/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt +++ b/app/src/main/java/io/legado/app/ui/dict/DictDialog.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.dict import android.os.Bundle import android.text.Html +import android.text.method.LinkMovementMethod import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -10,6 +11,7 @@ import androidx.fragment.app.viewModels import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.databinding.DialogDictBinding +import io.legado.app.utils.invisible import io.legado.app.utils.toastOnUi import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -48,6 +50,7 @@ class DictDialog : BaseDialogFragment() { } override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + binding.tvDict.movementMethod = LinkMovementMethod() val word = arguments?.getString("word") if (word.isNullOrEmpty()) { toastOnUi(R.string.cannot_empty) @@ -55,6 +58,7 @@ class DictDialog : BaseDialogFragment() { return } viewModel.dictHtmlData.observe(viewLifecycleOwner) { + binding.rotateLoading.invisible() binding.tvDict.text = Html.fromHtml(it) } viewModel.dict(word) diff --git a/app/src/main/res/layout/dialog_dict.xml b/app/src/main/res/layout/dialog_dict.xml index acd6a42f3..7eed5f326 100644 --- a/app/src/main/res/layout/dialog_dict.xml +++ b/app/src/main/res/layout/dialog_dict.xml @@ -1,5 +1,5 @@ - @@ -9,4 +9,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> - \ No newline at end of file + + + \ No newline at end of file From 3914b279026701366639785388d90462a7bf4784 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 10:26:14 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index c27a942b7..0f310b2c9 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -20,6 +20,7 @@ 3. 添加Umd格式支持 by ag2s20150909 4. 修复web页面按键重复监听的bug 5. 亮度条往中间移了一点,防止误触 +6. 添加内置字典 **2021/06/29** * 修复html格式化bug From 4a71068f0b31789a76591ac8ac9611884b344681 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 10:27:31 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 43 +------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 0f310b2c9..d39269e03 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -8,7 +8,7 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则出现问题。先关闭替换净化并刷新,再观察是否正常。如果正常说明净化规则存在误杀,如果关闭后仍然出现相关问题,请点击源链接查看原文与正文是否相同,如果不同,再进行反馈。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! -**2021/07/05** +**2021/07/07** 1. 默认规则新增类似`jsonPath`的索引写法 by bushixuanqi * 格式形如 `[index,index, ...]` 或 `[!index,index, ...]` 其中`[!`开头表示筛选方式为排除,`index`可以是单个索引,也可以是区间。 * 区间格式为 `start:end` 或 `start:end:step`,其中`start`为`0`可省略,`end`为`-1`可省略。 @@ -429,44 +429,3 @@ getTxtInFolder(unzipPath: String): String ``` * 增加type字段,返回16进制字符串,例:`https://www.baidu.com,{"type":"zip"}` * 底部操作栏阴影跟随设置调节 - -**2020/09/24** -* 修复规则解析bug - -**2020/09/21** -* 修复规则解析bug -* 换源时无最新章节信息时可加载详情页来获取(默认关闭) - -**2020/09/20** -* 优化正文搜索 -* 阅读界面信息添加书名 - -**2020/09/18** -* 解决正文替换{{title}}问题 -* 修复共用布局配置不能读取的问题 -* 添加自定义源分组功能 by KKL369 -* 解决跨进程调用ReaderProvider出现CursorIndexOutOfBoundsException问题 - -**2020/09/17** -* 优化正文搜索文字颜色 -* 优化书源校验 by KKL369 -* 缓存导出到webDav by 10bits -* 导入的字体在字体选择界面显示 - -**2020/09/15** -* 修复导入排版字体重复报错的bug -* 添加正文搜索 by [h11128](https://github.com/h11128) - -**2020/09/12** -* web看书同步最新章 -* web写源增加图片样式等规则 -* 正文规则可以使用@get:{title}获取目录标题,js里使用title - -**2020/09/11** -* 修复一些bug -* 背景配置自由添加 - -**2020/09/10** -* 修复自动换源的bug -* 修复保存主题的bug -* 书源排序,分享,注释优化 by [h11128](https://github.com/h11128) From 0aba2edceeb34a25054d7fa9b1cf9ca4cf83bc39 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 11:21:41 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E5=A2=9E=E5=8A=A0webdav=E8=AE=A2?= =?UTF-8?q?=E9=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/assets/defaultData/rssSources.json | 25 ++++++------------- .../java/io/legado/app/help/LocalConfig.kt | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/assets/defaultData/rssSources.json b/app/src/main/assets/defaultData/rssSources.json index cb6140a93..0537719fa 100644 --- a/app/src/main/assets/defaultData/rssSources.json +++ b/app/src/main/assets/defaultData/rssSources.json @@ -9,31 +9,22 @@ "sourceUrl": "https://www.yuque.com/legado" }, { - "articleStyle": 0, "customOrder": 2, "enableJs": true, "enabled": true, - "loadWithBaseUrl": false, - "ruleArticles": "class.release-main-section||tbody@tr", - "ruleContent": "@js:\nif(baseUrl.match(\/90pan\/)){\nresult=result.replace(\/true\\||<.*?>([^<]+)<\\\/span><\\\/a>\/g,'

$2<\/a><\/h4>

$1<\/p>\\n\\n')}\nelse{\nhtml=String(java.getString(\"@@class.markdown-body@html\",false)+java.getString(\"@@class.flex-justify-between.-1@html\",false));\nhref='https:\/\/github.com'+String(java.getString(\"@@class.flex-justify-between.-1@class.Box-body.0@a@href\",false))\nhtml+'

下载地址:<\/p>'+href+'<\/a>'\n}", - "ruleImage": "@js:if(baseUrl.match(\/legado|704\/g)){\nresult='https:\/\/urlmin.cn\/034'\n}else{result=\"https:\/\/urlmin.cn\/15c\"}", - "ruleLink": "tag.a.0@href\n@js:if(baseUrl.match(\/90pan\/)){\nresult='https:\/\/www.90pan.com\/ajax.php,{\"method\": \"POST\",\"body\": \"action=load_down_addr1&file_id='+result.match(\/b(\\d+)\/)[1]+'\"}'}else{\nresult='https:\/\/github.com'+result\n}", - "ruleNextPage": "text.Next@href", - "rulePubDate": "tag.td!0@text||class.markdown-body@text##\\n##·", - "ruleTitle": "tag.a.0@text", - "sortUrl": "阅读2.0·GitHub::https:\/\/github.com\/gedoor\/MyBookshelf\/releases\n阅读3.0·GitHub::https:\/\/github.com\/gedoor\/legado\/releases\n阅读2.0·90盘::https:\/\/www.90pan.com\/o138703\n阅读3.0·90盘::https:\/\/www.90pan.com\/o138704", - "sourceIcon": "http:\/\/ku.mumuceo.com\/static\/images\/applogo\/yuedu.png", - "sourceName": "阅读下载", - "sourceUrl": "https:\/\/github.com\/gedoor\/legado\/releases", - "style": "" + "singleUrl": true, + "sourceIcon": "http:\/\/mmbiz.qpic.cn\/mmbiz_png\/hpfMV8hEuL2eS6vnCxvTzoOiaCAibV6exBzJWq9xMic9xDg3YXAick87tsfafic0icRwkQ5ibV0bJ84JtSuxhPuEDVquA\/0?wx_fmt=png", + "sourceName": "小说拾遗", + "sourceUrl": "snssdk1128:\/\/user\/profile\/562564899806367" }, { "customOrder": 3, "enableJs": true, "enabled": true, + "loadWithBaseUrl": false, "singleUrl": true, - "sourceIcon": "http:\/\/mmbiz.qpic.cn\/mmbiz_png\/hpfMV8hEuL2eS6vnCxvTzoOiaCAibV6exBzJWq9xMic9xDg3YXAick87tsfafic0icRwkQ5ibV0bJ84JtSuxhPuEDVquA\/0?wx_fmt=png", - "sourceName": "小说拾遗", - "sourceUrl": "snssdk1128:\/\/user\/profile\/562564899806367" + "sourceIcon": "https://Cloud.miaogongzi.net/images/icon.png", + "sourceName": "Meow云", + "sourceUrl": "https://pan.miaogongzi.net" } ] \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/LocalConfig.kt b/app/src/main/java/io/legado/app/help/LocalConfig.kt index b2aa30234..8c90f7498 100644 --- a/app/src/main/java/io/legado/app/help/LocalConfig.kt +++ b/app/src/main/java/io/legado/app/help/LocalConfig.kt @@ -35,7 +35,7 @@ object LocalConfig { get() = !isLastVersion(1, "txtTocRuleVersion") val hasUpRssSources: Boolean - get() = !isLastVersion(3, "rssSourceVersion") + get() = !isLastVersion(4, "rssSourceVersion") var versionCode get() = localConfig.getLong(versionCodeKey, 0) From 8a041009457a6c26ef005023466fd88e7747388e Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 14:02:24 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/ReadBookActivity.kt | 16 ++++++++-------- .../java/io/legado/app/ui/book/read/ReadMenu.kt | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index c5657da1e..ce1f7e710 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -416,7 +416,7 @@ class ReadBookActivity : ReadBookBaseActivity(), * view触摸,文字选择 */ @SuppressLint("ClickableViewAccessibility") - override fun onTouch(v: View, event: MotionEvent): Boolean = with(binding) { + override fun onTouch(v: View, event: MotionEvent): Boolean = binding.run { when (event.action) { MotionEvent.ACTION_DOWN -> textActionMenu.dismiss() MotionEvent.ACTION_MOVE -> { @@ -439,7 +439,7 @@ class ReadBookActivity : ReadBookBaseActivity(), /** * 更新文字选择开始位置 */ - override fun upSelectedStart(x: Float, y: Float, top: Float) = with(binding) { + override fun upSelectedStart(x: Float, y: Float, top: Float) = binding.run { cursorLeft.x = x - cursorLeft.width cursorLeft.y = y cursorLeft.visible(true) @@ -450,7 +450,7 @@ class ReadBookActivity : ReadBookBaseActivity(), /** * 更新文字选择结束位置 */ - override fun upSelectedEnd(x: Float, y: Float) = with(binding) { + override fun upSelectedEnd(x: Float, y: Float) = binding.run { cursorRight.x = x cursorRight.y = y cursorRight.visible(true) @@ -459,7 +459,7 @@ class ReadBookActivity : ReadBookBaseActivity(), /** * 取消文字选择 */ - override fun onCancelSelect() = with(binding) { + override fun onCancelSelect() = binding.run { cursorLeft.invisible() cursorRight.invisible() textActionMenu.dismiss() @@ -468,7 +468,7 @@ class ReadBookActivity : ReadBookBaseActivity(), /** * 显示文本操作菜单 */ - override fun showTextActionMenu() = with(binding) { + override fun showTextActionMenu() = binding.run { textActionMenu.contentView.measure( View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED @@ -543,7 +543,7 @@ class ReadBookActivity : ReadBookBaseActivity(), /** * 文本选择菜单操作完成 */ - override fun onMenuActionFinally() = with(binding) { + override fun onMenuActionFinally() = binding.run { textActionMenu.dismiss() readView.curPage.cancelSelect() readView.isTextSelected = false @@ -796,7 +796,7 @@ class ReadBookActivity : ReadBookBaseActivity(), /** * colorSelectDialog */ - override fun onColorSelected(dialogId: Int, color: Int) = with(ReadBookConfig.durConfig) { + override fun onColorSelected(dialogId: Int, color: Int) = ReadBookConfig.durConfig.run { when (dialogId) { TEXT_COLOR -> { setCurTextColor(color) @@ -899,7 +899,7 @@ class ReadBookActivity : ReadBookBaseActivity(), } } - override fun observeLiveBus() = with(binding) { + override fun observeLiveBus() = binding.run { super.observeLiveBus() observeEvent(EventBus.TIME_CHANGED) { readView.upTime() } observeEvent(EventBus.BATTERY_CHANGED) { readView.upBattery(it) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt index a4e62fbce..671b7ba5d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt @@ -52,7 +52,7 @@ class ReadMenu @JvmOverloads constructor( bindEvent() } - private fun initView() = with(binding) { + private fun initView() = binding.run { if (AppConfig.isNightTheme) { fabNightTheme.setImageResource(R.drawable.ic_daytime) } else { @@ -134,7 +134,7 @@ class ReadMenu @JvmOverloads constructor( return context.getPrefBoolean("brightnessAuto", true) || !showBrightnessView } - private fun bindEvent() = with(binding) { + private fun bindEvent() = binding.run { tvChapterName.setOnClickListener { callBack.openSourceEditActivity() } @@ -304,7 +304,7 @@ class ReadMenu @JvmOverloads constructor( binding.seekReadPage.progress = seek } - fun setAutoPage(autoPage: Boolean) = with(binding) { + fun setAutoPage(autoPage: Boolean) = binding.run { if (autoPage) { fabAutoPage.setImageResource(R.drawable.ic_auto_page_stop) fabAutoPage.contentDescription = context.getString(R.string.auto_next_page_stop) From 279355cf24d393f67bc7e1d9b2e14449658b8730 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 14:16:48 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/about/ReadRecordActivity.kt | 2 +- .../legado/app/ui/book/cache/CacheAdapter.kt | 4 +- .../app/ui/book/changecover/CoverAdapter.kt | 2 +- .../app/ui/book/group/GroupManageDialog.kt | 4 +- .../app/ui/book/group/GroupSelectDialog.kt | 4 +- .../app/ui/book/info/BookInfoActivity.kt | 4 +- .../ui/book/info/edit/BookInfoEditActivity.kt | 6 +- .../app/ui/book/local/ImportBookAdapter.kt | 2 +- .../legado/app/ui/book/read/TextActionMenu.kt | 4 +- .../app/ui/book/read/config/AutoReadDialog.kt | 24 ++--- .../app/ui/book/read/config/BgAdapter.kt | 2 +- .../ui/book/read/config/BgTextConfigDialog.kt | 2 +- .../read/config/ClickActionConfigDialog.kt | 18 ++-- .../book/read/config/PaddingConfigDialog.kt | 88 +++++++++---------- .../book/read/config/ReadAloudConfigDialog.kt | 2 +- .../ui/book/read/config/ReadAloudDialog.kt | 6 +- .../ui/book/read/config/ReadStyleDialog.kt | 6 +- .../ui/book/read/config/SpeakEngineDialog.kt | 4 +- .../ui/book/read/config/TipConfigDialog.kt | 4 +- .../app/ui/book/read/config/TocRegexDialog.kt | 2 +- .../legado/app/ui/book/read/page/PageView.kt | 6 +- .../legado/app/ui/book/search/BookAdapter.kt | 2 +- .../app/ui/book/search/HistoryKeyAdapter.kt | 2 +- .../app/ui/book/search/SearchAdapter.kt | 8 +- .../searchContent/SearchContentAdapter.kt | 2 +- .../book/source/edit/BookSourceEditAdapter.kt | 2 +- .../book/source/manage/BookSourceAdapter.kt | 2 +- .../book/source/manage/GroupManageDialog.kt | 2 +- .../app/ui/book/toc/ChapterListAdapter.kt | 2 +- .../app/ui/book/toc/ChapterListFragment.kt | 4 +- .../legado/app/ui/config/ThemeListDialog.kt | 4 +- .../io/legado/app/ui/main/MainActivity.kt | 2 +- .../style1/books/BooksAdapterGrid.kt | 2 +- .../style1/books/BooksAdapterList.kt | 2 +- .../app/ui/main/explore/ExploreAdapter.kt | 2 +- .../app/ui/replace/GroupManageDialog.kt | 4 +- .../app/ui/replace/ReplaceRuleAdapter.kt | 2 +- .../ui/replace/edit/ReplaceEditActivity.kt | 4 +- .../app/ui/rss/article/RssArticlesAdapter.kt | 2 +- .../app/ui/rss/article/RssArticlesAdapter1.kt | 2 +- .../app/ui/rss/article/RssArticlesAdapter2.kt | 2 +- .../app/ui/rss/article/RssArticlesFragment.kt | 2 +- .../ui/rss/favorites/RssFavoritesAdapter.kt | 2 +- .../rss/source/edit/RssSourceEditAdapter.kt | 2 +- .../ui/rss/source/manage/GroupManageDialog.kt | 4 +- .../ui/rss/source/manage/RssSourceAdapter.kt | 2 +- .../legado/app/ui/widget/KeyboardToolPop.kt | 2 +- .../legado/app/ui/widget/SelectActionBar.kt | 8 +- .../app/ui/widget/dialog/TextListDialog.kt | 2 +- .../legado/app/ui/widget/font/FontAdapter.kt | 2 +- .../app/ui/widget/prefs/IconListPreference.kt | 2 +- 51 files changed, 139 insertions(+), 139 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt index aea9f773d..e34a9f4fe 100644 --- a/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt +++ b/app/src/main/java/io/legado/app/ui/about/ReadRecordActivity.kt @@ -56,7 +56,7 @@ class ReadRecordActivity : BaseActivity() { return super.onCompatOptionsItemSelected(item) } - private fun initView() = with(binding) { + private fun initView() = binding.run { readRecord.tvBookName.setText(R.string.all_read_time) adapter = RecordAdapter(this@ReadRecordActivity) recyclerView.adapter = adapter diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt index 96d20d3df..b1fddc3e8 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheAdapter.kt @@ -31,7 +31,7 @@ class CacheAdapter(context: Context, private val callBack: CallBack) : item: Book, payloads: MutableList ) { - with(binding) { + binding.run { if (payloads.isEmpty()) { tvName.text = item.name tvAuthor.text = context.getString(R.string.author_show, item.getRealAuthor()) @@ -53,7 +53,7 @@ class CacheAdapter(context: Context, private val callBack: CallBack) : } override fun registerListener(holder: ItemViewHolder, binding: ItemDownloadBinding) { - with(binding) { + binding.run { ivDownload.setOnClickListener { getItem(holder.layoutPosition)?.let { if (downloadMap?.containsKey(it.bookUrl) == true) { diff --git a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt index 0f75ed99f..323dbfc05 100644 --- a/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changecover/CoverAdapter.kt @@ -34,7 +34,7 @@ class CoverAdapter(context: Context, val callBack: CallBack) : binding: ItemCoverBinding, item: SearchBook, payloads: MutableList - ) = with(binding) { + ) = binding.run { ivCover.load(item.coverUrl, item.name, item.author) tvSource.text = item.originName } diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt index 6a6498459..33a3d55ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupManageDialog.kt @@ -160,7 +160,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener item: BookGroup, payloads: MutableList ) { - with(binding) { + binding.run { root.setBackgroundColor(context.backgroundColor) tvGroup.text = item.getManageName(context) swShow.isChecked = item.show @@ -168,7 +168,7 @@ class GroupManageDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } override fun registerListener(holder: ItemViewHolder, binding: ItemBookGroupManageBinding) { - with(binding) { + binding.run { tvEdit.setOnClickListener { getItem(holder.layoutPosition)?.let { editGroup(it) } } swShow.setOnCheckedChangeListener { buttonView, isChecked -> if (buttonView.isPressed) { diff --git a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt index 91ed1ab74..fdb1cfd11 100644 --- a/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt @@ -168,7 +168,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener item: BookGroup, payloads: MutableList ) { - with(binding) { + binding.run { root.setBackgroundColor(context.backgroundColor) cbGroup.text = item.groupName cbGroup.isChecked = (groupId and item.groupId) > 0 @@ -176,7 +176,7 @@ class GroupSelectDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } override fun registerListener(holder: ItemViewHolder, binding: ItemGroupSelectBinding) { - with(binding) { + binding.run { cbGroup.setOnCheckedChangeListener { buttonView, isChecked -> if (buttonView.isPressed) { getItem(holder.layoutPosition)?.let { diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index e8d423fdf..cfdf84d02 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -172,7 +172,7 @@ class BookInfoActivity : return super.onCompatOptionsItemSelected(item) } - private fun showBook(book: Book) = with(binding) { + private fun showBook(book: Book) = binding.run { showCover(book) tvName.text = book.name tvAuthor.text = getString(R.string.author_show, book.getRealAuthor()) @@ -243,7 +243,7 @@ class BookInfoActivity : } } - private fun initOnClick() = with(binding) { + private fun initOnClick() = binding.run { ivCover.setOnClickListener { viewModel.bookData.value?.let { ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 2a36e9874..c8e645b11 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -55,7 +55,7 @@ class BookInfoEditActivity : return super.onCompatOptionsItemSelected(item) } - private fun initEvent() = with(binding) { + private fun initEvent() = binding.run { tvChangeCover.setOnClickListener { viewModel.bookData.value?.let { ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) @@ -70,7 +70,7 @@ class BookInfoEditActivity : } } - private fun upView(book: Book) = with(binding) { + private fun upView(book: Book) = binding.run { tieBookName.setText(book.name) tieBookAuthor.setText(book.author) tieCoverUrl.setText(book.getDisplayCover()) @@ -84,7 +84,7 @@ class BookInfoEditActivity : } } - private fun saveData() = with(binding) { + private fun saveData() = binding.run { viewModel.book?.let { book -> book.name = tieBookName.text?.toString() ?: "" book.author = tieBookAuthor.text?.toString() ?: "" diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt index 5e31c9785..86896c35b 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt @@ -31,7 +31,7 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) : item: DocItem, payloads: MutableList ) { - with(binding) { + binding.run { if (payloads.isEmpty()) { if (item.isDir) { ivIcon.setImageResource(R.drawable.ic_folder) diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index a0ea37e03..cefd43b16 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -53,7 +53,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac initRecyclerView() } - private fun initRecyclerView() = with(binding) { + private fun initRecyclerView() = binding.run { recyclerView.adapter = adapter SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -75,7 +75,7 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac item: MenuItemImpl, payloads: MutableList ) { - with(binding) { + binding.run { textView.text = item.title } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt index d4a0d9506..9c9f774ff 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt @@ -52,21 +52,21 @@ class AutoReadDialog : BaseDialogFragment() { return inflater.inflate(R.layout.dialog_auto_read, container) } - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run { val bg = requireContext().bottomBackground val isLight = ColorUtils.isColorLight(bg) val textColor = requireContext().getPrimaryTextColor(isLight) - binding.root.setBackgroundColor(bg) - binding.tvReadSpeedTitle.setTextColor(textColor) - binding.tvReadSpeed.setTextColor(textColor) - binding.ivCatalog.setColorFilter(textColor) - binding.tvCatalog.setTextColor(textColor) - binding.ivMainMenu.setColorFilter(textColor) - binding.tvMainMenu.setTextColor(textColor) - binding.ivAutoPageStop.setColorFilter(textColor) - binding.tvAutoPageStop.setTextColor(textColor) - binding.ivSetting.setColorFilter(textColor) - binding.tvSetting.setTextColor(textColor) + root.setBackgroundColor(bg) + tvReadSpeedTitle.setTextColor(textColor) + tvReadSpeed.setTextColor(textColor) + ivCatalog.setColorFilter(textColor) + tvCatalog.setTextColor(textColor) + ivMainMenu.setColorFilter(textColor) + tvMainMenu.setTextColor(textColor) + ivAutoPageStop.setColorFilter(textColor) + tvAutoPageStop.setTextColor(textColor) + ivSetting.setColorFilter(textColor) + tvSetting.setTextColor(textColor) initOnChange() initData() initEvent() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt index fd0d390e9..f0d8ac752 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt @@ -25,7 +25,7 @@ class BgAdapter(context: Context, val textColor: Int) : item: String, payloads: MutableList ) { - with(binding) { + binding.run { ImageLoader.load( context, context.assets.open("bg${File.separator}$item").readBytes() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 170c51ab4..224d4b93d 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -98,7 +98,7 @@ class BgTextConfigDialog : BaseDialogFragment() { (activity as ReadBookActivity).bottomDialog-- } - private fun initView() = with(binding) { + private fun initView() = binding.run { val bg = requireContext().bottomBackground val isLight = ColorUtils.isColorLight(bg) primaryTextColor = requireContext().getPrimaryTextColor(isLight) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt index 8ade981b6..e351be654 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ClickActionConfigDialog.kt @@ -56,15 +56,15 @@ class ClickActionConfigDialog : BaseDialogFragment() { initViewEvent() } - private fun initData() = with(AppConfig) { - binding.tvTopLeft.text = actions[clickActionTL] - binding.tvTopCenter.text = actions[clickActionTC] - binding.tvTopRight.text = actions[clickActionTR] - binding.tvMiddleLeft.text = actions[clickActionML] - binding.tvMiddleRight.text = actions[clickActionMR] - binding.tvBottomLeft.text = actions[clickActionBL] - binding.tvBottomCenter.text = actions[clickActionBC] - binding.tvBottomRight.text = actions[clickActionBR] + private fun initData() = binding.run { + tvTopLeft.text = actions[AppConfig.clickActionTL] + tvTopCenter.text = actions[AppConfig.clickActionTC] + tvTopRight.text = actions[AppConfig.clickActionTR] + tvMiddleLeft.text = actions[AppConfig.clickActionML] + tvMiddleRight.text = actions[AppConfig.clickActionMR] + tvBottomLeft.text = actions[AppConfig.clickActionBL] + tvBottomCenter.text = actions[AppConfig.clickActionBC] + tvBottomRight.text = actions[AppConfig.clickActionBR] } private fun initViewEvent() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt index 938d0392e..e44eeb8b2 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PaddingConfigDialog.kt @@ -49,84 +49,84 @@ class PaddingConfigDialog : BaseDialogFragment() { ReadBookConfig.save() } - private fun initData() = ReadBookConfig.apply { + private fun initData() = binding.run { //正文 - binding.dsbPaddingTop.progress = paddingTop - binding.dsbPaddingBottom.progress = paddingBottom - binding.dsbPaddingLeft.progress = paddingLeft - binding.dsbPaddingRight.progress = paddingRight + dsbPaddingTop.progress = ReadBookConfig.paddingTop + dsbPaddingBottom.progress = ReadBookConfig.paddingBottom + dsbPaddingLeft.progress = ReadBookConfig.paddingLeft + dsbPaddingRight.progress = ReadBookConfig.paddingRight //页眉 - binding.dsbHeaderPaddingTop.progress = headerPaddingTop - binding.dsbHeaderPaddingBottom.progress = headerPaddingBottom - binding.dsbHeaderPaddingLeft.progress = headerPaddingLeft - binding.dsbHeaderPaddingRight.progress = headerPaddingRight + dsbHeaderPaddingTop.progress = ReadBookConfig.headerPaddingTop + dsbHeaderPaddingBottom.progress = ReadBookConfig.headerPaddingBottom + dsbHeaderPaddingLeft.progress = ReadBookConfig.headerPaddingLeft + dsbHeaderPaddingRight.progress = ReadBookConfig.headerPaddingRight //页脚 - binding.dsbFooterPaddingTop.progress = footerPaddingTop - binding.dsbFooterPaddingBottom.progress = footerPaddingBottom - binding.dsbFooterPaddingLeft.progress = footerPaddingLeft - binding.dsbFooterPaddingRight.progress = footerPaddingRight - binding.cbShowTopLine.isChecked = showHeaderLine - binding.cbShowBottomLine.isChecked = showFooterLine + dsbFooterPaddingTop.progress = ReadBookConfig.footerPaddingTop + dsbFooterPaddingBottom.progress = ReadBookConfig.footerPaddingBottom + dsbFooterPaddingLeft.progress = ReadBookConfig.footerPaddingLeft + dsbFooterPaddingRight.progress = ReadBookConfig.footerPaddingRight + cbShowTopLine.isChecked = ReadBookConfig.showHeaderLine + cbShowBottomLine.isChecked = ReadBookConfig.showFooterLine } - private fun initView() = with(ReadBookConfig) { + private fun initView() = binding.run { //正文 - binding.dsbPaddingTop.onChanged = { - paddingTop = it + dsbPaddingTop.onChanged = { + ReadBookConfig.paddingTop = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbPaddingBottom.onChanged = { - paddingBottom = it + dsbPaddingBottom.onChanged = { + ReadBookConfig.paddingBottom = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbPaddingLeft.onChanged = { - paddingLeft = it + dsbPaddingLeft.onChanged = { + ReadBookConfig.paddingLeft = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbPaddingRight.onChanged = { - paddingRight = it + dsbPaddingRight.onChanged = { + ReadBookConfig.paddingRight = it postEvent(EventBus.UP_CONFIG, true) } //页眉 - binding.dsbHeaderPaddingTop.onChanged = { - headerPaddingTop = it + dsbHeaderPaddingTop.onChanged = { + ReadBookConfig.headerPaddingTop = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbHeaderPaddingBottom.onChanged = { - headerPaddingBottom = it + dsbHeaderPaddingBottom.onChanged = { + ReadBookConfig.headerPaddingBottom = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbHeaderPaddingLeft.onChanged = { - headerPaddingLeft = it + dsbHeaderPaddingLeft.onChanged = { + ReadBookConfig.headerPaddingLeft = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbHeaderPaddingRight.onChanged = { - headerPaddingRight = it + dsbHeaderPaddingRight.onChanged = { + ReadBookConfig.headerPaddingRight = it postEvent(EventBus.UP_CONFIG, true) } //页脚 - binding.dsbFooterPaddingTop.onChanged = { - footerPaddingTop = it + dsbFooterPaddingTop.onChanged = { + ReadBookConfig.footerPaddingTop = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbFooterPaddingBottom.onChanged = { - footerPaddingBottom = it + dsbFooterPaddingBottom.onChanged = { + ReadBookConfig.footerPaddingBottom = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbFooterPaddingLeft.onChanged = { - footerPaddingLeft = it + dsbFooterPaddingLeft.onChanged = { + ReadBookConfig.footerPaddingLeft = it postEvent(EventBus.UP_CONFIG, true) } - binding.dsbFooterPaddingRight.onChanged = { - footerPaddingRight = it + dsbFooterPaddingRight.onChanged = { + ReadBookConfig.footerPaddingRight = it postEvent(EventBus.UP_CONFIG, true) } - binding.cbShowTopLine.onCheckedChangeListener = { _, isChecked -> - showHeaderLine = isChecked + cbShowTopLine.onCheckedChangeListener = { _, isChecked -> + ReadBookConfig.showHeaderLine = isChecked postEvent(EventBus.UP_CONFIG, true) } - binding.cbShowBottomLine.onCheckedChangeListener = { _, isChecked -> - showFooterLine = isChecked + cbShowBottomLine.onCheckedChangeListener = { _, isChecked -> + ReadBookConfig.showFooterLine = isChecked postEvent(EventBus.UP_CONFIG, true) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 1ce1c9179..38bf88920 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -39,7 +39,7 @@ class ReadAloudConfigDialog : DialogFragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View? { + ): View { val view = LinearLayout(requireContext()) view.setBackgroundColor(requireContext().backgroundColor) view.id = R.id.tag1 diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt index 8213c8bee..d1fd5b0bb 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt @@ -60,7 +60,7 @@ class ReadAloudDialog : BaseDialogFragment() { val bg = requireContext().bottomBackground val isLight = ColorUtils.isColorLight(bg) val textColor = requireContext().getPrimaryTextColor(isLight) - with(binding) { + binding.run { rootView.setBackgroundColor(bg) tvPre.setTextColor(textColor) tvNext.setTextColor(textColor) @@ -85,7 +85,7 @@ class ReadAloudDialog : BaseDialogFragment() { initEvent() } - private fun initData() = with(binding) { + private fun initData() = binding.run { upPlayState() upTimerText(BaseReadAloudService.timeMinute) seekTimer.progress = BaseReadAloudService.timeMinute @@ -94,7 +94,7 @@ class ReadAloudDialog : BaseDialogFragment() { seekTtsSpeechRate.progress = AppConfig.ttsSpeechRate } - private fun initEvent() = with(binding) { + private fun initEvent() = binding.run { llMainMenu.setOnClickListener { callBack?.showMenuBar() dismissAllowingStateLoss() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt index a6110a309..7f984491c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt @@ -66,7 +66,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { (activity as ReadBookActivity).bottomDialog-- } - private fun initView() = with(binding) { + private fun initView() = binding.run { val bg = requireContext().bottomBackground val isLight = ColorUtils.isColorLight(bg) val textColor = requireContext().getPrimaryTextColor(isLight) @@ -105,7 +105,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { styleAdapter.setItems(ReadBookConfig.configList) } - private fun initViewEvent() = with(binding) { + private fun initViewEvent() = binding.run { chineseConverter.onChanged { postEvent(EventBus.UP_CONFIG, true) } @@ -178,7 +178,7 @@ class ReadStyleDialog : BaseDialogFragment(), FontSelectDialog.CallBack { return true } - private fun upView() = with(binding) { + private fun upView() = binding.run { ReadBook.pageAnim().let { if (it >= 0 && it < rgPageAnim.childCount) { rgPageAnim.check(rgPageAnim[it].id) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt index 44af2dd45..233eef978 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/SpeakEngineDialog.kt @@ -72,7 +72,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener initData() } - private fun initView() = with(binding) { + private fun initView() = binding.run { toolBar.setBackgroundColor(primaryColor) toolBar.setTitle(R.string.speak_engine) ATH.applyEdgeEffectColor(recyclerView) @@ -96,7 +96,7 @@ class SpeakEngineDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener } } - private fun initMenu() = with(binding) { + private fun initMenu() = binding.run { toolBar.inflateMenu(R.menu.speak_engine) toolBar.menu.applyTint(requireContext()) toolBar.setOnMenuItemClickListener(this@SpeakEngineDialog) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt index f058b2da1..a6540f9c9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TipConfigDialog.kt @@ -46,7 +46,7 @@ class TipConfigDialog : BaseDialogFragment() { } } - private fun initView() = with(binding) { + private fun initView() = binding.run { rgTitleMode.checkByIndex(ReadBookConfig.titleMode) dsbTitleSize.progress = ReadBookConfig.titleSize dsbTitleTop.progress = ReadBookConfig.titleTopSpacing @@ -74,7 +74,7 @@ class TipConfigDialog : BaseDialogFragment() { } } - private fun initEvent() = with(binding) { + private fun initEvent() = binding.run { rgTitleMode.setOnCheckedChangeListener { _, checkedId -> ReadBookConfig.titleMode = rgTitleMode.getIndexById(checkedId) postEvent(EventBus.UP_CONFIG, true) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt index c8d7f2045..136ae587a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt @@ -69,7 +69,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { initData() } - private fun initView() = with(binding) { + private fun initView() = binding.run { adapter = TocRegexAdapter(requireContext()) recyclerView.addItemDecoration(VerticalDivider(requireContext())) recyclerView.adapter = adapter diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt index 7b621735f..cc4399d85 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/PageView.kt @@ -55,7 +55,7 @@ class PageView(context: Context) : FrameLayout(context) { } } - fun upStyle() = with(binding) { + fun upStyle() = binding.run { upTipStyle() ReadBookConfig.let { val tipColor = with(ReadTipConfig) { @@ -102,7 +102,7 @@ class PageView(context: Context) : FrameLayout(context) { ReadBookConfig.hideStatusBar || (activity as? BaseActivity<*>)?.isInMultiWindow == true } - private fun upTipStyle() = with(binding) { + private fun upTipStyle() = binding.run { ReadTipConfig.apply { tvHeaderLeft.isInvisible = tipHeaderLeft != chapterTitle bvHeaderLeft.isInvisible = @@ -173,7 +173,7 @@ class PageView(context: Context) : FrameLayout(context) { } } - private fun getTipView(tip: Int): BatteryView? = with(binding) { + private fun getTipView(tip: Int): BatteryView? = binding.run { return when (tip) { ReadTipConfig.tipHeaderLeft -> if (tip == ReadTipConfig.chapterTitle) tvHeaderLeft else bvHeaderLeft diff --git a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt index 40bcd0ed3..1aa9f0fff 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/BookAdapter.kt @@ -21,7 +21,7 @@ class BookAdapter(context: Context, val callBack: CallBack) : item: Book, payloads: MutableList ) { - with(binding) { + binding.run { textView.text = item.name } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt index 6b377c0ca..660410c44 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/HistoryKeyAdapter.kt @@ -27,7 +27,7 @@ class HistoryKeyAdapter(activity: SearchActivity, val callBack: CallBack) : item: SearchKeyword, payloads: MutableList ) { - with(binding) { + binding.run { textView.text = item.word } } diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index a1c617b08..e36c11fe1 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -74,7 +74,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } private fun bind(binding: ItemSearchBinding, searchBook: SearchBook) { - with(binding) { + binding.run { tvName.text = searchBook.name tvAuthor.text = context.getString(R.string.author_show, searchBook.author) bvOriginCount.setBadgeCount(searchBook.origins.size) @@ -87,7 +87,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } private fun bindChange(binding: ItemSearchBinding, searchBook: SearchBook, bundle: Bundle) { - with(binding) { + binding.run { bundle.keySet().map { when (it) { "origins" -> bvOriginCount.setBadgeCount(searchBook.origins.size) @@ -105,7 +105,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } private fun upLasted(binding: ItemSearchBinding, latestChapterTitle: String?) { - with(binding) { + binding.run { if (latestChapterTitle.isNullOrEmpty()) { tvLasted.gone() } else { @@ -116,7 +116,7 @@ class SearchAdapter(context: Context, val callBack: CallBack) : } } - private fun upKind(binding: ItemSearchBinding, kinds: List) = with(binding) { + private fun upKind(binding: ItemSearchBinding, kinds: List) = binding.run { if (kinds.isEmpty()) { llKind.gone() } else { diff --git a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt index 10a3502df..364e7daaf 100644 --- a/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentAdapter.kt @@ -28,7 +28,7 @@ class SearchContentAdapter(context: Context, val callback: Callback) : item: SearchResult, payloads: MutableList ) { - with(binding) { + binding.run { val isDur = callback.durChapterIndex() == item.chapterIndex if (payloads.isEmpty()) { tvSearchResult.text = item.getHtmlCompat(textColor, accentColor) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt index 63f2da7b8..31ccae918 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditAdapter.kt @@ -33,7 +33,7 @@ class BookSourceEditAdapter : RecyclerView.Adapter ) { - with(binding) { + binding.run { val payload = payloads.getOrNull(0) as? Bundle if (payload == null) { root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt index c3fab473d..c3c4fa80c 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/GroupManageDialog.kt @@ -125,7 +125,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { item: String, payloads: MutableList ) { - with(binding) { + binding.run { root.setBackgroundColor(context.backgroundColor) tvGroup.text = item } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt index 1af21f922..15eebaeb6 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt @@ -27,7 +27,7 @@ class ChapterListAdapter(context: Context, val callback: Callback) : item: BookChapter, payloads: MutableList ) { - with(binding) { + binding.run { val isDur = callback.durChapterIndex() == item.index val cached = callback.isLocalBook || cacheFileNames.contains(item.getFileName()) if (payloads.isEmpty()) { diff --git a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index b13e64c9e..417b740ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -39,7 +39,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt private var tocLiveData: LiveData>? = null private var scrollToDurChapter = false - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = with(binding) { + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run { viewModel.chapterCallBack = this@ChapterListFragment val bbg = bottomBackground val btc = requireContext().getPrimaryTextColor(ColorUtils.isColorLight(bbg)) @@ -62,7 +62,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapt binding.recyclerView.adapter = adapter } - private fun initView() = with(binding) { + private fun initView() = binding.run { ivChapterTop.setOnClickListener { mLayoutManager.scrollToPositionWithOffset(0, 0) } ivChapterBottom.setOnClickListener { if (adapter.itemCount > 0) { diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt index 358b16613..be118d3de 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeListDialog.kt @@ -46,14 +46,14 @@ class ThemeListDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener { initData() } - private fun initView() = with(binding) { + private fun initView() = binding.run { adapter = Adapter() recyclerView.layoutManager = LinearLayoutManager(requireContext()) recyclerView.addItemDecoration(VerticalDivider(requireContext())) recyclerView.adapter = adapter } - private fun initMenu() = with(binding) { + private fun initMenu() = binding.run { toolBar.setOnMenuItemClickListener(this@ThemeListDialog) toolBar.inflateMenu(R.menu.theme_list) toolBar.menu.applyTint(requireContext()) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 7a718bcb9..96197140c 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -82,7 +82,7 @@ class MainActivity : VMBaseActivity(), }, 3000) } - override fun onNavigationItemSelected(item: MenuItem): Boolean = with(binding) { + override fun onNavigationItemSelected(item: MenuItem): Boolean = binding.run { when (item.itemId) { R.id.menu_bookshelf -> viewPagerMain.setCurrentItem(0, false) R.id.menu_discovery -> viewPagerMain.setCurrentItem(1, false) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt index a79155319..b029e5eed 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterGrid.kt @@ -23,7 +23,7 @@ class BooksAdapterGrid(context: Context, private val callBack: CallBack) : binding: ItemBookshelfGridBinding, item: Book, payloads: MutableList - ) = with(binding) { + ) = binding.run { val bundle = payloads.getOrNull(0) as? Bundle if (bundle == null) { tvName.text = item.name diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt index 4cfcb5693..813ead01b 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksAdapterList.kt @@ -23,7 +23,7 @@ class BooksAdapterList(context: Context, private val callBack: CallBack) : binding: ItemBookshelfListBinding, item: Book, payloads: MutableList - ) = with(binding) { + ) = binding.run { val bundle = payloads.getOrNull(0) as? Bundle if (bundle == null) { tvName.text = item.name diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 0944c2a03..e36db00be 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -36,7 +36,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca item: BookSource, payloads: MutableList ) { - with(binding) { + binding.run { if (holder.layoutPosition == itemCount - 1) { root.setPadding(16.dp, 12.dp, 16.dp, 12.dp) } else { diff --git a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index 5917453cf..24bac89bb 100644 --- a/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -53,7 +53,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { initData() } - private fun initData() = with(binding) { + private fun initData() = binding.run { toolBar.title = getString(R.string.group_manage) toolBar.inflateMenu(R.menu.group_manage) toolBar.menu.applyTint(requireContext()) @@ -126,7 +126,7 @@ class GroupManageDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { item: String, payloads: MutableList ) { - with(binding) { + binding.run { root.setBackgroundColor(context.backgroundColor) tvGroup.text = item } diff --git a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt index 1972674b1..bc0badb31 100644 --- a/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt @@ -108,7 +108,7 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : item: ReplaceRule, payloads: MutableList ) { - with(binding) { + binding.run { val bundle = payloads.getOrNull(0) as? Bundle if (bundle == null) { root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) diff --git a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt index 70687727f..8fd22551a 100644 --- a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt @@ -90,7 +90,7 @@ class ReplaceEditActivity : return true } - private fun upReplaceView(replaceRule: ReplaceRule) = with(binding) { + private fun upReplaceView(replaceRule: ReplaceRule) = binding.run { etName.setText(replaceRule.name) etGroup.setText(replaceRule.group) etReplaceRule.setText(replaceRule.pattern) @@ -99,7 +99,7 @@ class ReplaceEditActivity : etScope.setText(replaceRule.scope) } - private fun getReplaceRule(): ReplaceRule = with(binding) { + private fun getReplaceRule(): ReplaceRule = binding.run { val replaceRule: ReplaceRule = viewModel.replaceRule ?: ReplaceRule() replaceRule.name = etName.text.toString() replaceRule.group = etGroup.text.toString() diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt index cabd5b51a..cb5605bc9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter.kt @@ -30,7 +30,7 @@ class RssArticlesAdapter(context: Context, callBack: CallBack) : item: RssArticle, payloads: MutableList ) { - with(binding) { + binding.run { tvTitle.text = item.title tvPubDate.text = item.pubDate if (item.image.isNullOrBlank() && !callBack.isGridLayout) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt index 2c8ff0d8f..574825624 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter1.kt @@ -30,7 +30,7 @@ class RssArticlesAdapter1(context: Context, callBack: CallBack) : item: RssArticle, payloads: MutableList ) { - with(binding) { + binding.run { tvTitle.text = item.title tvPubDate.text = item.pubDate if (item.image.isNullOrBlank() && !callBack.isGridLayout) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt index a82300afe..c4fef291e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesAdapter2.kt @@ -30,7 +30,7 @@ class RssArticlesAdapter2(context: Context, callBack: CallBack) : item: RssArticle, payloads: MutableList ) { - with(binding) { + binding.run { tvTitle.text = item.title tvPubDate.text = item.pubDate if (item.image.isNullOrBlank() && !callBack.isGridLayout) { diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt index 8adcfba95..da784aa0c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesFragment.kt @@ -53,7 +53,7 @@ class RssArticlesFragment : VMBaseFragment(R.layout.fragme initData() } - private fun initView() = with(binding) { + private fun initView() = binding.run { refreshLayout.setColorSchemeColors(accentColor) ATH.applyEdgeEffectColor(recyclerView) recyclerView.layoutManager = if (activityViewModel.isGridLayout) { diff --git a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt index 517c4bb27..71feb0e4d 100644 --- a/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/favorites/RssFavoritesAdapter.kt @@ -29,7 +29,7 @@ class RssFavoritesAdapter(context: Context, val callBack: CallBack) : item: RssStar, payloads: MutableList ) { - with(binding) { + binding.run { tvTitle.text = item.title tvPubDate.text = item.pubDate if (item.image.isNullOrBlank()) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt index 96c71c8e6..a2c80b3e1 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditAdapter.kt @@ -33,7 +33,7 @@ class RssSourceEditAdapter : RecyclerView.Adapter ) { - with(binding) { + binding.run { root.setBackgroundColor(context.backgroundColor) tvGroup.text = item } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt index 3cc2db4bb..152f6a6e3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceAdapter.kt @@ -66,7 +66,7 @@ class RssSourceAdapter(context: Context, val callBack: CallBack) : item: RssSource, payloads: MutableList ) { - with(binding) { + binding.run { val bundle = payloads.getOrNull(0) as? Bundle if (bundle == null) { root.setBackgroundColor(ColorUtils.withAlpha(context.backgroundColor, 0.5f)) diff --git a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt index e0fef5da0..fddb23759 100644 --- a/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt +++ b/app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt @@ -52,7 +52,7 @@ class KeyboardToolPop( item: String, payloads: MutableList ) { - with(binding) { + binding.run { textView.text = item } } diff --git a/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt b/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt index c95a8e493..57b926137 100644 --- a/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/SelectActionBar.kt @@ -46,12 +46,12 @@ class SelectActionBar @JvmOverloads constructor( binding.ivMenuMore.setOnClickListener { selMenu?.show() } } - fun setMainActionText(text: String) = with(binding) { + fun setMainActionText(text: String) = binding.run { btnSelectActionMain.text = text btnSelectActionMain.visible() } - fun setMainActionText(@StringRes id: Int) = with(binding) { + fun setMainActionText(@StringRes id: Int) = binding.run { btnSelectActionMain.setText(id) btnSelectActionMain.visible() } @@ -71,7 +71,7 @@ class SelectActionBar @JvmOverloads constructor( selMenu?.setOnMenuItemClickListener(listener) } - fun upCountView(selectCount: Int, allCount: Int) = with(binding) { + fun upCountView(selectCount: Int, allCount: Int) = binding.run { if (selectCount == 0) { cbSelectedAll.isChecked = false } else { @@ -95,7 +95,7 @@ class SelectActionBar @JvmOverloads constructor( setMenuClickable(selectCount > 0) } - private fun setMenuClickable(isClickable: Boolean) = with(binding) { + private fun setMenuClickable(isClickable: Boolean) = binding.run { btnRevertSelection.isEnabled = isClickable btnRevertSelection.isClickable = isClickable btnSelectActionMain.isEnabled = isClickable diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt index ba356c6e1..cc79dc726 100644 --- a/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt @@ -47,7 +47,7 @@ class TextListDialog : BaseDialogFragment() { return inflater.inflate(R.layout.dialog_recycler_view, container) } - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = with(binding) { + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) = binding.run { arguments?.let { toolBar.title = it.getString("title") values = it.getStringArrayList("values") diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt index 5e9e5b4a9..ddd689a12 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontAdapter.kt @@ -24,7 +24,7 @@ class FontAdapter(context: Context, val callBack: CallBack) : item: DocItem, payloads: MutableList ) { - with(binding) { + binding.run { kotlin.runCatching { val typeface: Typeface? = if (item.isContentPath) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt index fc5ed7291..6ad81165d 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt @@ -168,7 +168,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference item: CharSequence, payloads: MutableList ) { - with(binding) { + binding.run { val index = findIndexOfValue(item.toString()) dialogEntries?.let { label.text = it[index] From 2bb315d4bd56996a5a3500805c8262ea8c6c2024 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 14:47:56 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 11 ++++++----- app/src/main/res/layout/popup_action_menu.xml | 5 +---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index ce1f7e710..d0f138e1f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -105,7 +105,12 @@ class ReadBookActivity : ReadBookBaseActivity(), } private var menu: Menu? = null private val textActionMenu: TextActionMenu by lazy { - TextActionMenu(this, this) + TextActionMenu(this, this).apply { + contentView.measure( + View.MeasureSpec.UNSPECIFIED, + View.MeasureSpec.UNSPECIFIED + ) + } } override val scope: CoroutineScope get() = this @@ -469,10 +474,6 @@ class ReadBookActivity : ReadBookBaseActivity(), * 显示文本操作菜单 */ override fun showTextActionMenu() = binding.run { - textActionMenu.contentView.measure( - View.MeasureSpec.UNSPECIFIED, - View.MeasureSpec.UNSPECIFIED - ) val popupHeight = textActionMenu.contentView.measuredHeight val x = textMenuPosition.x.toInt() var y = textMenuPosition.y.toInt() - popupHeight diff --git a/app/src/main/res/layout/popup_action_menu.xml b/app/src/main/res/layout/popup_action_menu.xml index 12b5ebfc5..238593f51 100644 --- a/app/src/main/res/layout/popup_action_menu.xml +++ b/app/src/main/res/layout/popup_action_menu.xml @@ -7,7 +7,4 @@ android:background="@drawable/shape_card_view" android:padding="5dp" android:orientation="horizontal" - app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager"> - - - + app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager" /> \ No newline at end of file From cf2f0dbf38ac7f59bec76eb1bcae15d46cf3165a Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 16:14:28 +0800 Subject: [PATCH 09/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/dao/BookSourceDao.kt | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 2d2dcff40..a9d113098 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -10,7 +10,16 @@ interface BookSourceDao { @Query("select * from book_sources order by customOrder asc") fun liveDataAll(): LiveData> - @Query("select * from book_sources where bookSourceName like :searchKey or bookSourceGroup like :searchKey or bookSourceUrl like :searchKey or bookSourceComment like :searchKey order by customOrder asc") + @Query( + """ + select * from book_sources + where bookSourceName like :searchKey + or bookSourceGroup like :searchKey + or bookSourceUrl like :searchKey + or bookSourceComment like :searchKey + order by customOrder asc + """ + ) fun liveDataSearch(searchKey: String): LiveData> @Query("select * from book_sources where bookSourceGroup like :searchKey order by customOrder asc") @@ -25,10 +34,26 @@ interface BookSourceDao { @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' order by customOrder asc") fun liveExplore(): LiveData> - @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key or bookSourceName like :key) order by customOrder asc") + @Query( + """ + select * from book_sources + where enabledExplore = 1 + and trim(exploreUrl) <> '' + and (bookSourceGroup like :key or bookSourceName like :key) + order by customOrder asc + """ + ) fun liveExplore(key: String): LiveData> - @Query("select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and (bookSourceGroup like :key) order by customOrder asc") + @Query( + """ + select * from book_sources + where enabledExplore = 1 + and trim(exploreUrl) <> '' + and (bookSourceGroup like :key) + order by customOrder asc + """ + ) fun liveGroupExplore(key: String): LiveData> @Query("select distinct bookSourceGroup from book_sources where trim(bookSourceGroup) <> ''") @@ -37,7 +62,14 @@ interface BookSourceDao { @Query("select distinct bookSourceGroup from book_sources where enabled = 1 and trim(bookSourceGroup) <> ''") fun liveGroupEnabled(): LiveData> - @Query("select distinct bookSourceGroup from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' and trim(bookSourceGroup) <> ''") + @Query( + """ + select distinct bookSourceGroup from book_sources + where enabledExplore = 1 + and trim(exploreUrl) <> '' + and trim(bookSourceGroup) <> '' + """ + ) fun liveExploreGroup(): LiveData> @Query("select * from book_sources where bookSourceGroup like '%' || :group || '%'") From 3da4e43656a50aa7985fc375a29414e93c0e53d9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 7 Jul 2021 17:22:44 +0800 Subject: [PATCH 10/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/service/CheckSourceService.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 6c66be641..448e75414 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -131,11 +131,18 @@ class CheckSourceService : BaseService() { }.timeout(180000L) .onError { source.addGroup("失效") - source.bookSourceComment = - "error:${it.localizedMessage}\n${source.bookSourceComment}" + source.bookSourceComment = """ + "error:${it.localizedMessage} + ${source.bookSourceComment}" + """.trimIndent() appDb.bookSourceDao.update(source) }.onSuccess { source.removeGroup("失效") + source.bookSourceComment = source.bookSourceComment + ?.split("\n") + ?.filterNot { + it.startsWith("error:") + }?.joinToString("\n") appDb.bookSourceDao.update(source) }.onFinally { onNext(source.bookSourceUrl, source.bookSourceName) From 9180a4c40d35e75744d31ed5c9749c5413881da1 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 8 Jul 2021 11:05:13 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/book/read/TextActionMenu.kt | 42 ++++--------------- app/src/main/res/layout/popup_action_menu.xml | 7 ++-- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt index cefd43b16..906fc8ebc 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt @@ -18,8 +18,6 @@ import androidx.appcompat.view.SupportMenuInflater import androidx.appcompat.view.menu.MenuBuilder import androidx.appcompat.view.menu.MenuItemImpl import io.legado.app.R -import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.databinding.ItemTextBinding import io.legado.app.databinding.PopupActionMenuBinding import io.legado.app.service.BaseReadAloudService @@ -27,6 +25,7 @@ import io.legado.app.utils.isAbsUrl import io.legado.app.utils.sendToClip import io.legado.app.utils.share import io.legado.app.utils.toastOnUi +import splitties.views.onClick import java.util.* @SuppressLint("RestrictedApi") @@ -35,7 +34,6 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac TextToSpeech.OnInitListener { private val binding = PopupActionMenuBinding.inflate(LayoutInflater.from(context)) - private val adapter = Adapter(context) private val menu = MenuBuilder(context) private val moreMenu = MenuBuilder(context) private val ttsListener by lazy { @@ -50,45 +48,23 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac isOutsideTouchable = false isFocusable = false - initRecyclerView() - } - - private fun initRecyclerView() = binding.run { - recyclerView.adapter = adapter SupportMenuInflater(context).inflate(R.menu.content_select_action, menu) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { onInitializeMenu(moreMenu) } - adapter.setItems(menu.visibleItems + moreMenu.visibleItems) - } - - inner class Adapter(context: Context) : - RecyclerAdapter(context) { - - override fun getViewBinding(parent: ViewGroup): ItemTextBinding { - return ItemTextBinding.inflate(inflater, parent, false) - } - - override fun convert( - holder: ItemViewHolder, - binding: ItemTextBinding, - item: MenuItemImpl, - payloads: MutableList - ) { - binding.run { - textView.text = item.title - } - } - - override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) { - holder.itemView.setOnClickListener { - getItem(holder.layoutPosition)?.let { + val menuItems = menu.visibleItems + moreMenu.visibleItems + menuItems.forEach { + val textView = ItemTextBinding.inflate(LayoutInflater.from(context)).root.apply { + tag = it + text = it.title + onClick { if (!callBack.onMenuItemSelected(it.itemId)) { onMenuItemSelected(it) } + callBack.onMenuActionFinally() } - callBack.onMenuActionFinally() } + binding.root.addView(textView) } } diff --git a/app/src/main/res/layout/popup_action_menu.xml b/app/src/main/res/layout/popup_action_menu.xml index 238593f51..74b43c301 100644 --- a/app/src/main/res/layout/popup_action_menu.xml +++ b/app/src/main/res/layout/popup_action_menu.xml @@ -1,10 +1,9 @@ - \ No newline at end of file + app:flexDirection="row" + app:flexWrap="wrap" /> \ No newline at end of file From c49e6bae538e9e61cccbb3b2c2b31ac590d71a39 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 8 Jul 2021 20:05:38 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- .../io/legado/app/data/entities/BookSource.kt | 16 +++++++------- .../app/ui/main/explore/ExploreAdapter.kt | 21 ++++++++++++------- .../app/ui/main/explore/ExploreFragment.kt | 3 +++ app/src/main/res/layout/item_find_book.xml | 2 +- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ba28c8557..71aab6b30 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -135,7 +135,7 @@ dependencies { implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.flexbox:flexbox:3.0.0' - implementation 'com.google.code.gson:gson:2.8.6' + implementation 'com.google.code.gson:gson:2.8.7' implementation 'androidx.webkit:webkit:1.4.0' //media diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 8f5adc182..f5843f486 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -101,12 +101,12 @@ data class BookSource( } fun getExploreKinds() = arrayListOf().apply { - exploreUrl?.let { urlRule -> - var a = urlRule + exploreUrl?.let { exploreUrl -> + var a = exploreUrl if (a.isNotBlank()) { kotlin.runCatching { - if (urlRule.startsWith("", false) - || urlRule.startsWith("@js", false) + if (exploreUrl.startsWith("", false) + || exploreUrl.startsWith("@js", false) ) { val aCache = ACache.get(appCtx, "explore") a = aCache.getAsString(bookSourceUrl) ?: "" @@ -116,10 +116,10 @@ data class BookSource( bindings["java"] = this bindings["cookie"] = CookieStore bindings["cache"] = CacheManager - val jsStr = if (urlRule.startsWith("@")) { - urlRule.substring(3) + val jsStr = if (exploreUrl.startsWith("@")) { + exploreUrl.substring(3) } else { - urlRule.substring(4, urlRule.lastIndexOf("<")) + exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) } a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString() aCache.put(bookSourceUrl, a) @@ -173,7 +173,7 @@ data class BookSource( data class ExploreKind( var title: String, - var url: String? = null + var url: String? = null, ) class Converters { diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index e36db00be..dce02afaa 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -5,6 +5,7 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.PopupMenu +import com.google.android.flexbox.FlexboxLayout import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter @@ -56,18 +57,18 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca item.getExploreKinds() }.onSuccess { kindList -> if (!kindList.isNullOrEmpty()) { - glChild.visible() - glChild.removeAllViews() + flexbox.visible() + flexbox.removeAllViews() kindList.map { kind -> val tv = ItemFilletTextBinding.inflate( LayoutInflater.from(context), - glChild, + flexbox, false - ) - glChild.addView(tv.root) - tv.textView.text = kind.title + ).root + flexbox.addView(tv) + tv.text = kind.title if (!kind.url.isNullOrEmpty()) { - tv.textView.setOnClickListener { + tv.setOnClickListener { callBack.openExplore( item.bookSourceUrl, kind.title, @@ -75,6 +76,10 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca ) } } + val lp = tv.layoutParams as FlexboxLayout.LayoutParams + lp.let { + + } } } }.onFinally { @@ -87,7 +92,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } else { binding.ivStatus.setImageResource(R.drawable.ic_arrow_right) binding.rotateLoading.hide() - binding.glChild.gone() + binding.flexbox.gone() } } } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 4660e2ea1..359ec8dea 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -155,6 +155,9 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo } override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) { + if (exploreUrl.isBlank()) { + return + } startActivity { putExtra("exploreName", title) putExtra("sourceUrl", sourceUrl) diff --git a/app/src/main/res/layout/item_find_book.xml b/app/src/main/res/layout/item_find_book.xml index 61ce006c7..b27c04cba 100644 --- a/app/src/main/res/layout/item_find_book.xml +++ b/app/src/main/res/layout/item_find_book.xml @@ -56,7 +56,7 @@ android:layout_gravity="center"> Date: Thu, 8 Jul 2021 20:41:40 +0800 Subject: [PATCH 13/24] Update RuleAnalyzer.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 平衡组区分内嵌{JSONPATH}和非内嵌JSONPATH --- .../java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt index 6a5c674ec..55942b001 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt @@ -10,6 +10,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { private var start = 0 //每次处理字段的开始 private var startX = 0 //规则的开始 + private var innerStr: Boolean = false //true表示以平衡组的起点为规则起始,false表示不这样 private var step:Int = 0 //分割字符的长度 val chompBalanced = if(code) ::chompCodeBalanced else ::chompRuleBalanced //设置平衡组函数,json或JavaScript时设置成chompCodeBalanced,否则为chompRuleBalanced @@ -229,7 +230,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { } while (depth > 0 || otherDepth > 0) //拉出一个平衡字串 return if(depth > 0 || otherDepth > 0) false else { - startX = this.pos //内嵌规则起始 + if(innerStr)startX = this.pos //内嵌规则起始 this.pos = pos //同步位置 true } @@ -428,6 +429,8 @@ class RuleAnalyzer(data: String, code:Boolean = false) { val start0 = pos //规则匹配前起点 + innerStr = true //设置平衡组以平衡组起点为规则起始点 + val st = StringBuilder() while (!isEmpty && consumeTo(inner)) { //拉取成功返回true,ruleAnalyzes里的字符序列索引变量pos后移相应位置,否则返回false,且isEmpty为true From c6c07234f840dc92753ffc6b099ee05a2dcbb3c0 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 8 Jul 2021 22:34:24 +0800 Subject: [PATCH 14/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/model/analyzeRule/RuleAnalyzer.kt | 207 ++++++++---------- 1 file changed, 92 insertions(+), 115 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt index 55942b001..aece2e35c 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt @@ -2,28 +2,32 @@ package io.legado.app.model.analyzeRule //通用的规则切分处理 -class RuleAnalyzer(data: String, code:Boolean = false) { +class RuleAnalyzer(data: String, code: Boolean = false) { private var queue: String = data //被处理字符串 private var pos = 0 //处理到的位置 - private var rule = arrayOf() + private var rule = arrayOf() private var start = 0 //每次处理字段的开始 private var startX = 0 //规则的开始 private var innerStr: Boolean = false //true表示以平衡组的起点为规则起始,false表示不这样 - private var step:Int = 0 //分割字符的长度 + private var step: Int = 0 //分割字符的长度 - val chompBalanced = if(code) ::chompCodeBalanced else ::chompRuleBalanced //设置平衡组函数,json或JavaScript时设置成chompCodeBalanced,否则为chompRuleBalanced + //设置平衡组函数,json或JavaScript时设置成chompCodeBalanced,否则为chompRuleBalanced + val chompBalanced = if (code) ::chompCodeBalanced else ::chompRuleBalanced var elementsType = "" //当前平衡字段 - fun currBalancedString( stepStart:Int = 1 , stepEnd:Int = 1): String { //stepStart平衡字符的起始分隔字串长度,stepEnd平衡字符的结束分隔字串长度 - return queue.substring(startX+stepStart,pos-stepEnd) //当前平衡字段 + fun currBalancedString( + stepStart: Int = 1, + stepEnd: Int = 1 + ): String { //stepStart平衡字符的起始分隔字串长度,stepEnd平衡字符的结束分隔字串长度 + return queue.substring(startX + stepStart, pos - stepEnd) //当前平衡字段 } - fun trim(){ // 修剪当前规则之前的"@"或者空白符 + fun trim() { // 修剪当前规则之前的"@"或者空白符 while (queue[pos] == '@' || queue[pos] < '!') pos++ } @@ -34,7 +38,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { //当前拉取字段 fun currString(): String { - return queue.substring(start,pos) //当前拉取到的字段 + return queue.substring(start, pos) //当前拉取到的字段 } //剩余字串 @@ -49,7 +53,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * @return 若剩余字串中已无字符则返回true */ val isEmpty: Boolean - get() = queue.length - pos == 0 //是否处理到最后 + get() = queue.length - pos == 0 //是否处理到最后 /** * 消耗剩余字串中一个字符。 @@ -73,9 +77,9 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * @param seq 分隔字符 **区分大小写** * @return 是否找到相应字段。 */ - fun consumeTo(seq: String,setStartPos:Boolean = true): Boolean { + fun consumeTo(seq: String, setStartPos: Boolean = true): Boolean { - if(setStartPos)start = pos //将处理到的位置设置为规则起点 + if (setStartPos) start = pos //将处理到的位置设置为规则起点 val offset = queue.indexOf(seq, pos) return if (offset != -1) { pos = offset @@ -89,7 +93,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * @param seq 匹配字符串序列 * @return 成功返回true并设置间隔,失败则直接返回fasle */ - fun consumeToAny(vararg seq:String): Boolean { + fun consumeToAny(vararg seq: String): Boolean { var pos = pos //声明新变量记录匹配位置,不更改类本身的位置 @@ -114,13 +118,13 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * @param seq 匹配字符序列 * @return 返回匹配位置 */ - private fun findToAny(vararg seq:Char): Int { + private fun findToAny(vararg seq: Char): Int { var pos = pos //声明新变量记录匹配位置,不更改类本身的位置 while (pos != queue.length) { - for (s in seq) if(queue[pos] == s) return pos //匹配则返回位置 + for (s in seq) if (queue[pos] == s) return pos //匹配则返回位置 pos++ //逐个试探 @@ -130,13 +134,15 @@ class RuleAnalyzer(data: String, code:Boolean = false) { } //其中js只要符合语法,就不用避开任何阅读关键字,自由发挥 - fun chompJsBalanced(f: ((Char) -> Boolean?) = { - when (it) { - '{' -> true //开始嵌套一层 - '}' -> false //闭合一层嵌套 - else -> null + fun chompJsBalanced( + f: ((Char) -> Boolean?) = { + when (it) { + '{' -> true //开始嵌套一层 + '}' -> false //闭合一层嵌套 + else -> null + } } - } ): Boolean { + ): Boolean { var pos = pos //声明变量记录临时处理位置 var depth = 0 //嵌套深度 var bracketsDepth = 0 //[]嵌套深度 @@ -152,22 +158,23 @@ class RuleAnalyzer(data: String, code:Boolean = false) { if (pos == queue.length) break var c = queue[pos++] if (c != '\\') { //非转义字符 - if (c == '\'' && !commits && !commit && !regex && !inDoubleQuote && !inOtherQuote) inSingleQuote = !inSingleQuote //匹配具有语法功能的单引号 - else if (c == '"' && !commits && !commit && !regex && !inSingleQuote && !inOtherQuote) inDoubleQuote = !inDoubleQuote //匹配具有语法功能的双引号 - else if (c == '`' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote) inOtherQuote = !inOtherQuote //匹配具有语法功能的'`' + if (c == '\'' && !commits && !commit && !regex && !inDoubleQuote && !inOtherQuote) inSingleQuote = + !inSingleQuote //匹配具有语法功能的单引号 + else if (c == '"' && !commits && !commit && !regex && !inSingleQuote && !inOtherQuote) inDoubleQuote = + !inDoubleQuote //匹配具有语法功能的双引号 + else if (c == '`' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote) inOtherQuote = + !inOtherQuote //匹配具有语法功能的'`' else if (c == '/' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote && !inOtherQuote) { //匹配注释或正则起点 c = queue[pos++] - when(c){ - '/'->commit=true //匹配单行注释起点 - '*'->commits=true //匹配多行注释起点 - else ->regex=true //匹配正则起点 + when (c) { + '/' -> commit = true //匹配单行注释起点 + '*' -> commits = true //匹配多行注释起点 + else -> regex = true //匹配正则起点 } - } - else if(commits && c == '*') { //匹配多行注释终点 + } else if (commits && c == '*') { //匹配多行注释终点 c = queue[pos++] - if(c == '/')commits = false - } - else if(regex && c == '/') { //正则的终点或[]平衡 + if (c == '/') commits = false + } else if (regex && c == '/') { //正则的终点或[]平衡 when (c) { '/' -> regex = false//匹配正则终点 @@ -178,18 +185,18 @@ class RuleAnalyzer(data: String, code:Boolean = false) { ']' -> bracketsDepth-- //闭合一层嵌套[] } - }else if(c == '\n') commit = false + } else if (c == '\n') commit = false - if (commits || commit || regex || inSingleQuote || inDoubleQuote || inOtherQuote) continue //语法单元未匹配结束,直接进入下个循环 + if (commits || commit || regex || inSingleQuote || inDoubleQuote || inOtherQuote) continue //语法单元未匹配结束,直接进入下个循环 val fn = f(c) ?: continue if (fn) depth++ else depth-- //嵌套或者闭合 - }else pos++ + } else pos++ - } while (depth > 0 || bracketsDepth >0) //拉出全部符合js语法的字段 + } while (depth > 0 || bracketsDepth > 0) //拉出全部符合js语法的字段 - return if(depth > 0 || bracketsDepth > 0) false else { + return if (depth > 0 || bracketsDepth > 0) false else { this.pos = pos //同步位置 true } @@ -215,22 +222,22 @@ class RuleAnalyzer(data: String, code:Boolean = false) { if (c == '\'' && !inDoubleQuote) inSingleQuote = !inSingleQuote //匹配具有语法功能的单引号 else if (c == '"' && !inSingleQuote) inDoubleQuote = !inDoubleQuote //匹配具有语法功能的双引号 - if (inSingleQuote || inDoubleQuote) continue //语法单元未匹配结束,直接进入下个循环 + if (inSingleQuote || inDoubleQuote) continue //语法单元未匹配结束,直接进入下个循环 - if ( c == '[' )depth++ //开始嵌套一层 - else if ( c== ']') depth-- //闭合一层嵌套 - else if(depth == 0 ) { + if (c == '[') depth++ //开始嵌套一层 + else if (c == ']') depth-- //闭合一层嵌套 + else if (depth == 0) { //处于默认嵌套中的非默认字符不需要平衡,仅depth为0时默认嵌套全部闭合,此字符才进行嵌套 - if(c == open)otherDepth++ - else if(c == close)otherDepth-- + if (c == open) otherDepth++ + else if (c == close) otherDepth-- } - }else pos++ + } else pos++ } while (depth > 0 || otherDepth > 0) //拉出一个平衡字串 - return if(depth > 0 || otherDepth > 0) false else { - if(innerStr)startX = this.pos //内嵌规则起始 + return if (depth > 0 || otherDepth > 0) false else { + if (innerStr) startX = this.pos //内嵌规则起始 this.pos = pos //同步位置 true } @@ -252,18 +259,18 @@ class RuleAnalyzer(data: String, code:Boolean = false) { if (c == '\'' && !inDoubleQuote) inSingleQuote = !inSingleQuote //匹配具有语法功能的单引号 else if (c == '"' && !inSingleQuote) inDoubleQuote = !inDoubleQuote //匹配具有语法功能的双引号 - if (inSingleQuote || inDoubleQuote) continue //语法单元未匹配结束,直接进入下个循环 - else if( c=='\\' ){ //不在引号中的转义字符才将下个字符转义 + if (inSingleQuote || inDoubleQuote) continue //语法单元未匹配结束,直接进入下个循环 + else if (c == '\\') { //不在引号中的转义字符才将下个字符转义 pos++ continue } - if ( c == open )depth++ //开始嵌套一层 - else if ( c== close) depth-- //闭合一层嵌套 + if (c == open) depth++ //开始嵌套一层 + else if (c == close) depth-- //闭合一层嵌套 - } while (depth > 0 ) //拉出一个平衡字串 + } while (depth > 0) //拉出一个平衡字串 - return if(depth > 0) false else { + return if (depth > 0) false else { this.pos = pos //同步位置 true } @@ -273,18 +280,18 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * 不用正则,不到最后不切片也不用中间变量存储,只在序列中标记当前查找字段的开头结尾,到返回时才切片,高效快速准确切割规则 * 解决jsonPath自带的"&&"和"||"与阅读的规则冲突,以及规则正则或字符串中包含"&&"、"||"、"%%"、"@"导致的冲突 */ - tailrec fun splitRule(vararg split: String): Array{ //首段匹配,elementsType为空 + tailrec fun splitRule(vararg split: String): Array { //首段匹配,elementsType为空 - if(split.size == 1) { + if (split.size == 1) { elementsType = split[0] //设置分割字串 - return if(!consumeTo(elementsType)) { + return if (!consumeTo(elementsType)) { rule += queue.substring(startX) rule - }else { + } else { step = elementsType.length //设置分隔符长度 splitRule() } //递归匹配 - }else if (!consumeToAny(* split)) { //未找到分隔符 + } else if (!consumeToAny(* split)) { //未找到分隔符 rule += queue.substring(startX) return rule } @@ -292,7 +299,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { val end = pos //记录分隔位置 pos = start //重回开始,启动另一种查找 - do{ + do { val st = findToAny('[', '(') //查找筛选器位置 if (st == -1) { @@ -324,11 +331,10 @@ class RuleAnalyzer(data: String, code:Boolean = false) { pos += step //跳过分隔符 } - return if(pos > st) { + return if (pos > st) { startX = start splitRule() //首段已匹配,但当前段匹配未完成,调用二段匹配 - } - else { //执行到此,证明后面再无分隔字符 + } else { //执行到此,证明后面再无分隔字符 rule += queue.substring(pos) //将剩余字段压入数组末尾 rule } @@ -344,7 +350,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { ) + "后未平衡" ) //拉出一个筛选器,不平衡则报错 - }while( end > pos ) + } while (end > pos) start = pos //设置开始查找筛选器位置的起始位置 @@ -352,12 +358,12 @@ class RuleAnalyzer(data: String, code:Boolean = false) { } @JvmName("splitRuleNext") - private tailrec fun splitRule(): Array{ //二段匹配被调用,elementsType非空(已在首段赋值),直接按elementsType查找,比首段采用的方式更快 + private tailrec fun splitRule(): Array { //二段匹配被调用,elementsType非空(已在首段赋值),直接按elementsType查找,比首段采用的方式更快 val end = pos //记录分隔位置 pos = start //重回开始,启动另一种查找 - do{ + do { val st = findToAny('[', '(') //查找筛选器位置 if (st == -1) { @@ -385,11 +391,10 @@ class RuleAnalyzer(data: String, code:Boolean = false) { pos += step //跳过分隔符 } - return if(pos > st) { + return if (pos > st) { startX = start splitRule() //首段已匹配,但当前段匹配未完成,调用二段匹配 - } - else { //执行到此,证明后面再无分隔字符 + } else { //执行到此,证明后面再无分隔字符 rule += queue.substring(pos) //将剩余字段压入数组末尾 rule } @@ -405,14 +410,14 @@ class RuleAnalyzer(data: String, code:Boolean = false) { ) + "后未平衡" ) //拉出一个筛选器,不平衡则报错 - }while( end > pos ) + } while (end > pos) start = pos //设置开始查找筛选器位置的起始位置 - return if(!consumeTo(elementsType)) { + return if (!consumeTo(elementsType)) { rule += queue.substring(startX) rule - }else splitRule() //递归匹配 + } else splitRule() //递归匹配 } @@ -425,7 +430,12 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * @param fr 查找到内嵌规则时,用于解析的函数 * * */ - fun innerRule( inner:String,startStep:Int = 1,endStep:Int = 1,fr:(String)->String?): String { + fun innerRule( + inner: String, + startStep: Int = 1, + endStep: Int = 1, + fr: (String) -> String? + ): String { val start0 = pos //规则匹配前起点 @@ -436,9 +446,9 @@ class RuleAnalyzer(data: String, code:Boolean = false) { while (!isEmpty && consumeTo(inner)) { //拉取成功返回true,ruleAnalyzes里的字符序列索引变量pos后移相应位置,否则返回false,且isEmpty为true val posPre = pos //记录上次结束位置 if (chompBalanced('{', '}')) { - val frv= fr(currBalancedString(startStep,endStep)) - if(frv != null) { - st.append(queue.substring(start,posPre)+frv) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 + val frv = fr(currBalancedString(startStep, endStep)) + if (frv != null) { + st.append(queue.substring(start, posPre) + frv) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 continue //获取内容成功,继续选择下个内嵌规则 } @@ -449,45 +459,12 @@ class RuleAnalyzer(data: String, code:Boolean = false) { } //匹配前起点与当前规则起点相同,证明无替换成功的内嵌规则,返回空字符串。否则返回替换后的字符串 - return if(start0 == start) "" else { + return if (start0 == start) "" else { st.append(remainingString()) //压入剩余字符串 st.toString() } } -// /** -// * 匹配并返回标签中的属性键字串(字母、数字、-、_、:) -// * @return 属性键字串 -// */ -// fun consumeAttributeKey(start:Int = pos): String { -// while (!isEmpty && (Character.isLetterOrDigit(queue[pos]) || matchesAny('-', '_', ':'))) pos++ -// return queue.substring(start, pos) -// } - -// fun splitRule(query:String,item:String = "other",listItem:String = "allInOne"):String{ -// -// val cuurItem = item //当前项类型,list->列表项 mulu->章节列表项 url->链接项 search->搜索链接项 find发现链接列表项 other->其他项 -// val cuurList = listItem//当前界面总列表项类型,allInOne,json,xml,kotin,java -// var Reverse = false //是否反转列表 -// -// consumeWhitespace() //消耗开头空白 -// var fisrt = consume() //拉出并消费首字符 -// -// when(item){ -// "search" -> -// "find" -> -// "mulu" -> if(fisrt == '-'){ -// Reverse=true //开启反转 -// consumeWhitespace() //拉出所有空白符 -// fisrt = consume() //首字符后移 -// } -// else -> -// -// } -// -// return query -// } - companion object { /** * 转义字符 @@ -498,7 +475,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * 阅读共有分隔字串起始部分 * "##","@@","{{","{[","", "@js:" */ - val splitList =arrayOf("##","@@","{{","{[","", "@js:") + val splitList = arrayOf("##", "@@", "{{", "{[", "", "@js:") /** * 发现‘名称-链接’分隔字串 @@ -522,7 +499,7 @@ class RuleAnalyzer(data: String, code:Boolean = false) { * 结果为元素列表的项的同规则组合结构 * "||","&&","%%" */ - val splitListReSplit = arrayOf("||","&&","%%") + val splitListReSplit = arrayOf("||", "&&", "%%") /** * js脚本结束字串 @@ -545,27 +522,27 @@ class RuleAnalyzer(data: String, code:Boolean = false) { /** * '[', ']', '(', ')','{','}' */ - val splitListPublic = charArrayOf('[', ']', '(', ')','{','}') + val splitListPublic = charArrayOf('[', ']', '(', ')', '{', '}') /** * '*',"/","//",":","::","@","|","@xpath:" */ - val splitListXpath = arrayOf("*","/","//",":","::","@","|","@xpath:") + val splitListXpath = arrayOf("*", "/", "//", ":", "::", "@", "|", "@xpath:") /** * '*','$',".","..", "@json:" */ - val splitListJson = arrayOf('*','$',".","..", "@json:") + val splitListJson = arrayOf('*', '$', ".", "..", "@json:") /** * '*',"+","~",".",",","|","@","@css:",":" */ - val splitListCss = arrayOf('*',"+","~",".",",","|","@","@css:",":") + val splitListCss = arrayOf('*', "+", "~", ".", ",", "|", "@", "@css:", ":") /** * "-",".","!","@","@@" */ - val splitListDefault = arrayOf("-",".","!","@","@@") + val splitListDefault = arrayOf("-", ".", "!", "@", "@@") } } From 9deda740085dd73e345946cb89c0570cccd5c175 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Jul 2021 10:58:07 +0800 Subject: [PATCH 15/24] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookSource.kt | 5 -- .../legado/app/data/entities/ExploreKind.kt | 31 ++++++++++ .../app/ui/main/explore/ExploreAdapter.kt | 57 ++++++++++--------- .../app/ui/main/explore/ExploreFragment.kt | 6 +- 4 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/ExploreKind.kt diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index f5843f486..fcdb4ee7b 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -171,11 +171,6 @@ data class BookSource( private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) - data class ExploreKind( - var title: String, - var url: String? = null, - ) - class Converters { @TypeConverter fun exploreRuleToString(exploreRule: ExploreRule?): String = GSON.toJson(exploreRule) diff --git a/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt b/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt new file mode 100644 index 000000000..f683a7fef --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt @@ -0,0 +1,31 @@ +package io.legado.app.data.entities + +data class ExploreKind( + val title: String, + val url: String? = null, + val style: Style = Style() +) { + + data class Style( + val layout_flexGrow: Float = 0F, + val layout_flexShrink: Float = 1F, + val layout_alignSelf: String = "auto", + val layout_flexBasisPercent: Float = -1F, + val layout_wrapBefore: Boolean = false, + ) { + + fun alignSelf(): Int { + return when (layout_alignSelf) { + "auto" -> -1 + "flex_start" -> 0 + "flex_end" -> 1 + "center" -> 2 + "baseline" -> 3 + "stretch" -> 4 + else -> -1 + } + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index dce02afaa..85c1a03b2 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -11,6 +11,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource +import io.legado.app.data.entities.ExploreKind import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.ItemFindBookBinding import io.legado.app.help.coroutine.Coroutine @@ -56,32 +57,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca Coroutine.async(scope) { item.getExploreKinds() }.onSuccess { kindList -> - if (!kindList.isNullOrEmpty()) { - flexbox.visible() - flexbox.removeAllViews() - kindList.map { kind -> - val tv = ItemFilletTextBinding.inflate( - LayoutInflater.from(context), - flexbox, - false - ).root - flexbox.addView(tv) - tv.text = kind.title - if (!kind.url.isNullOrEmpty()) { - tv.setOnClickListener { - callBack.openExplore( - item.bookSourceUrl, - kind.title, - kind.url.toString() - ) - } - } - val lp = tv.layoutParams as FlexboxLayout.LayoutParams - lp.let { - - } - } - } + upKindList(flexbox, item.bookSourceUrl, kindList) }.onFinally { rotateLoading.hide() if (scrollTo >= 0) { @@ -97,6 +73,33 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } } + private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List) { + if (!kinds.isNullOrEmpty()) { + flexbox.visible() + flexbox.removeAllViews() + kinds.map { kind -> + val tv = ItemFilletTextBinding.inflate( + LayoutInflater.from(context), + flexbox, + false + ).root + flexbox.addView(tv) + tv.text = kind.title + val lp = tv.layoutParams as FlexboxLayout.LayoutParams + kind.style.let { style -> + lp.flexGrow = style.layout_flexGrow + lp.flexShrink = style.layout_flexShrink + lp.alignSelf = style.alignSelf() + lp.flexBasisPercent = style.layout_flexBasisPercent + lp.isWrapBefore = style.layout_wrapBefore + } + tv.setOnClickListener { + callBack.openExplore(sourceUrl, kind.title, kind.url) + } + } + } + } + override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) { binding.apply { llTitle.setOnClickListener { @@ -151,7 +154,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca interface CallBack { fun scrollTo(pos: Int) - fun openExplore(sourceUrl: String, title: String, exploreUrl: String) + fun openExplore(sourceUrl: String, title: String, exploreUrl: String?) fun editSource(sourceUrl: String) fun toTop(source: BookSource) } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 359ec8dea..8e78d53bb 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -154,10 +154,8 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo (binding.rvFind.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(pos, 0) } - override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) { - if (exploreUrl.isBlank()) { - return - } + override fun openExplore(sourceUrl: String, title: String, exploreUrl: String?) { + if (exploreUrl.isNullOrBlank()) return startActivity { putExtra("exploreName", title) putExtra("sourceUrl", sourceUrl) From d4ee79029d098925b96d67ccf015c5039adc55a2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Jul 2021 12:16:02 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 20 ++++++ .../io/legado/app/data/entities/BookSource.kt | 67 ++++++++++--------- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index d39269e03..2d7ed84c1 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -8,6 +8,26 @@ * 正文出现缺字漏字、内容缺失、排版错乱等情况,有可能是净化规则出现问题。先关闭替换净化并刷新,再观察是否正常。如果正常说明净化规则存在误杀,如果关闭后仍然出现相关问题,请点击源链接查看原文与正文是否相同,如果不同,再进行反馈。 * 漫画源看书显示乱码,**阅读与其他软件的源并不通用**,请导入阅读的支持的漫画源! +**2021/07/09** +1. 发现url添加json格式, 支持设置标签样式 +* 样式属性可以搜索 [FleboxLayout子元素支持的属性介绍](https://www.jianshu.com/p/3c471953e36d) +* 样式属性可省略,有默认值 +```json +[ + { + "title": "xxx", + "url": "", + "style": { + "layout_flexGrow": 0, + "layout_flexShrink": 1, + "layout_alignSelf": "auto", + "layout_flexBasisPercent": -1, + "layout_wrapBefore": false + } + } +] +``` + **2021/07/07** 1. 默认规则新增类似`jsonPath`的索引写法 by bushixuanqi * 格式形如 `[index,index, ...]` 或 `[!index,index, ...]` 其中`[!`开头表示筛选方式为排除,`index`可以是单个索引,也可以是区间。 diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index fcdb4ee7b..2fd84fb93 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -10,10 +10,7 @@ import io.legado.app.help.AppConfig import io.legado.app.help.CacheManager import io.legado.app.help.JsExtensions import io.legado.app.help.http.CookieStore -import io.legado.app.utils.ACache -import io.legado.app.utils.GSON -import io.legado.app.utils.fromJsonObject -import io.legado.app.utils.splitNotBlank +import io.legado.app.utils.* import kotlinx.parcelize.Parcelize import splitties.init.appCtx import javax.script.SimpleBindings @@ -100,42 +97,48 @@ data class BookSource( } } - fun getExploreKinds() = arrayListOf().apply { - exploreUrl?.let { exploreUrl -> - var a = exploreUrl - if (a.isNotBlank()) { - kotlin.runCatching { - if (exploreUrl.startsWith("", false) - || exploreUrl.startsWith("@js", false) - ) { - val aCache = ACache.get(appCtx, "explore") - a = aCache.getAsString(bookSourceUrl) ?: "" - if (a.isBlank()) { - val bindings = SimpleBindings() - bindings["baseUrl"] = bookSourceUrl - bindings["java"] = this - bindings["cookie"] = CookieStore - bindings["cache"] = CacheManager - val jsStr = if (exploreUrl.startsWith("@")) { - exploreUrl.substring(3) - } else { - exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) - } - a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString() - aCache.put(bookSourceUrl, a) + fun getExploreKinds(): List { + val exploreUrl = exploreUrl ?: return emptyList() + val kinds = arrayListOf() + var ruleStr = exploreUrl + if (ruleStr.isNotBlank()) { + kotlin.runCatching { + if (exploreUrl.startsWith("", false) + || exploreUrl.startsWith("@js", false) + ) { + val aCache = ACache.get(appCtx, "explore") + ruleStr = aCache.getAsString(bookSourceUrl) ?: "" + if (ruleStr.isBlank()) { + val bindings = SimpleBindings() + bindings["baseUrl"] = bookSourceUrl + bindings["java"] = this + bindings["cookie"] = CookieStore + bindings["cache"] = CacheManager + val jsStr = if (exploreUrl.startsWith("@")) { + exploreUrl.substring(3) + } else { + exploreUrl.substring(4, exploreUrl.lastIndexOf("<")) } + ruleStr = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString().trim() + aCache.put(bookSourceUrl, ruleStr) } - val b = a.split("(&&|\n)+".toRegex()) - b.forEach { c -> + } + if (ruleStr.isJsonArray()) { + GSON.fromJsonArray(ruleStr)?.let { + kinds.addAll(it) + } + } else { + ruleStr.split("(&&|\n)+".toRegex()).forEach { c -> val d = c.split("::") if (d.size > 1) - add(ExploreKind(d[0], d[1])) + kinds.add(ExploreKind(d[0], d[1])) } - }.onFailure { - add(ExploreKind(it.localizedMessage ?: "")) } + }.onFailure { + kinds.add(ExploreKind(it.localizedMessage ?: "")) } } + return kinds } /** From 1f2684d5a1ce34165f5e064b77b70edcfbebb1e2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Jul 2021 12:21:31 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/help/ruleHelp.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/assets/help/ruleHelp.md b/app/src/main/assets/help/ruleHelp.md index 01eb44eba..abad44a12 100644 --- a/app/src/main/assets/help/ruleHelp.md +++ b/app/src/main/assets/help/ruleHelp.md @@ -11,6 +11,23 @@ : regex规则,不可省略,只可以用在书籍列表和目录列表 ``` +* 发现url格式 +```json +[ + { + "title": "xxx", + "url": "", + "style": { + "layout_flexGrow": 0, + "layout_flexShrink": 1, + "layout_alignSelf": "auto", + "layout_flexBasisPercent": -1, + "layout_wrapBefore": false + } + } +] +``` + * 获取登录后的cookie ``` java.getCookie("http://baidu.com", null) => userid=1234;pwd=adbcd From 4230cca24b5827ac9926db4f87c77a5ff9b85116 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Jul 2021 14:48:20 +0800 Subject: [PATCH 18/24] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/data/entities/ExploreKind.kt | 10 ++++- .../app/ui/main/explore/ExploreAdapter.kt | 41 +++++++++++++------ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt b/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt index f683a7fef..5a44bd419 100644 --- a/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt +++ b/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt @@ -3,9 +3,17 @@ package io.legado.app.data.entities data class ExploreKind( val title: String, val url: String? = null, - val style: Style = Style() + val style: Style? = null ) { + companion object { + val defaultStyle = Style() + } + + fun style(): Style { + return style ?: defaultStyle + } + data class Style( val layout_flexGrow: Float = 0F, val layout_flexShrink: Float = 1F, diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 85c1a03b2..d780b6dd3 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -1,10 +1,11 @@ package io.legado.app.ui.main.explore import android.content.Context -import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.PopupMenu +import android.widget.TextView +import androidx.core.view.children import com.google.android.flexbox.FlexboxLayout import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -25,6 +26,8 @@ import splitties.views.onLongClick class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : RecyclerAdapter(context) { + + private val recycler = arrayListOf() private var exIndex = -1 private var scrollTo = -1 @@ -66,27 +69,24 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } } } else { - binding.ivStatus.setImageResource(R.drawable.ic_arrow_right) - binding.rotateLoading.hide() - binding.flexbox.gone() + ivStatus.setImageResource(R.drawable.ic_arrow_right) + rotateLoading.hide() + recyclerFlexbox(flexbox) + flexbox.gone() } } } private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List) { if (!kinds.isNullOrEmpty()) { + recyclerFlexbox(flexbox) flexbox.visible() - flexbox.removeAllViews() - kinds.map { kind -> - val tv = ItemFilletTextBinding.inflate( - LayoutInflater.from(context), - flexbox, - false - ).root + kinds.forEach { kind -> + val tv = getFlexboxChild(flexbox) flexbox.addView(tv) tv.text = kind.title val lp = tv.layoutParams as FlexboxLayout.LayoutParams - kind.style.let { style -> + kind.style().let { style -> lp.flexGrow = style.layout_flexGrow lp.flexShrink = style.layout_flexShrink lp.alignSelf = style.alignSelf() @@ -100,6 +100,23 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } } + @Synchronized + private fun getFlexboxChild(flexbox: FlexboxLayout): TextView { + return if (recycler.isEmpty()) { + ItemFilletTextBinding.inflate(inflater, flexbox, false).root + } else { + recycler.last().also { + recycler.removeLast() + } as TextView + } + } + + @Synchronized + private fun recyclerFlexbox(flexbox: FlexboxLayout) { + recycler.addAll(flexbox.children) + flexbox.removeAllViews() + } + override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) { binding.apply { llTitle.setOnClickListener { From 9cc1e15864dd9cbff31e382fcf7386fb06ea9245 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Jul 2021 15:37:54 +0800 Subject: [PATCH 19/24] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22a506a7c..e63456b42 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ [![GitHub contributors](https://img.shields.io/github/contributors/gedoor/legado)](https://github.com/gedoor/legado/graphs/contributors) ## 阅读3.0 -* [书源规则](https://alanskycn.gitee.io/teachme/) +* [书源规则](https://alanskycn.gitee.io/teachme) * [更新日志](/app/src/main/assets/updateLog.md) * [帮助文档](/app/src/main/assets/help/appHelp.md) +* [web端](https://github.com/celetor/web-yuedu3) ## 下载 Google Play or CoolApk or [Releases](https://github.com/gedoor/legado/releases/latest) From d567e217bc67f7b5be512ae2c80389d2068f8b10 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 9 Jul 2021 16:15:18 +0800 Subject: [PATCH 20/24] Update RuleAnalyzer.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化 --- .../app/model/analyzeRule/RuleAnalyzer.kt | 101 ++++++++---------- 1 file changed, 42 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt index aece2e35c..c26e817d0 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt @@ -5,25 +5,23 @@ package io.legado.app.model.analyzeRule class RuleAnalyzer(data: String, code: Boolean = false) { private var queue: String = data //被处理字符串 - private var pos = 0 //处理到的位置 - private var rule = arrayOf() + private var pos = 0 //当前处理到的位置 + private var start = 0 //当前处理字段的开始 + private var startX = 0 //当前规则的开始 - private var start = 0 //每次处理字段的开始 - private var startX = 0 //规则的开始 - private var innerStr: Boolean = false //true表示以平衡组的起点为规则起始,false表示不这样 + private var rule = arrayOf() //分割出的规则列表 private var step: Int = 0 //分割字符的长度 + var elementsType = "" //当前分割字符串 //设置平衡组函数,json或JavaScript时设置成chompCodeBalanced,否则为chompRuleBalanced val chompBalanced = if (code) ::chompCodeBalanced else ::chompRuleBalanced - var elementsType = "" - //当前平衡字段 fun currBalancedString( - stepStart: Int = 1, - stepEnd: Int = 1 + stepStart: Int = 1, + stepEnd: Int = 1 ): String { //stepStart平衡字符的起始分隔字串长度,stepEnd平衡字符的结束分隔字串长度 - return queue.substring(startX + stepStart, pos - stepEnd) //当前平衡字段 + return queue.substring(start + stepStart, pos - stepEnd) //当前平衡字段 } @@ -40,14 +38,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) { fun currString(): String { return queue.substring(start, pos) //当前拉取到的字段 } - - //剩余字串 - private fun remainingString(): String { - start = pos - pos = queue.length - return queue.substring(start) - } - + /** * 是否已无剩余字符? * @return 若剩余字串中已无字符则返回true @@ -77,15 +68,13 @@ class RuleAnalyzer(data: String, code: Boolean = false) { * @param seq 分隔字符 **区分大小写** * @return 是否找到相应字段。 */ - fun consumeTo(seq: String, setStartPos: Boolean = true): Boolean { - - if (setStartPos) start = pos //将处理到的位置设置为规则起点 + fun consumeTo(seq: String): Boolean { + start = pos //将处理到的位置设置为规则起点 val offset = queue.indexOf(seq, pos) return if (offset != -1) { pos = offset true } else false - } /** @@ -135,13 +124,13 @@ class RuleAnalyzer(data: String, code: Boolean = false) { //其中js只要符合语法,就不用避开任何阅读关键字,自由发挥 fun chompJsBalanced( - f: ((Char) -> Boolean?) = { - when (it) { - '{' -> true //开始嵌套一层 - '}' -> false //闭合一层嵌套 - else -> null + f: ((Char) -> Boolean?) = { + when (it) { + '{' -> true //开始嵌套一层 + '}' -> false //闭合一层嵌套 + else -> null + } } - } ): Boolean { var pos = pos //声明变量记录临时处理位置 var depth = 0 //嵌套深度 @@ -159,11 +148,11 @@ class RuleAnalyzer(data: String, code: Boolean = false) { var c = queue[pos++] if (c != '\\') { //非转义字符 if (c == '\'' && !commits && !commit && !regex && !inDoubleQuote && !inOtherQuote) inSingleQuote = - !inSingleQuote //匹配具有语法功能的单引号 + !inSingleQuote //匹配具有语法功能的单引号 else if (c == '"' && !commits && !commit && !regex && !inSingleQuote && !inOtherQuote) inDoubleQuote = - !inDoubleQuote //匹配具有语法功能的双引号 + !inDoubleQuote //匹配具有语法功能的双引号 else if (c == '`' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote) inOtherQuote = - !inOtherQuote //匹配具有语法功能的'`' + !inOtherQuote //匹配具有语法功能的'`' else if (c == '/' && !commits && !commit && !regex && !inSingleQuote && !inDoubleQuote && !inOtherQuote) { //匹配注释或正则起点 c = queue[pos++] when (c) { @@ -203,7 +192,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) { } /** - * 拉出一个代码平衡组,存在转义文本,没有实体字符,通常以{}作为模块 + * 拉出一个非内嵌代码平衡组,存在转义文本 */ fun chompCodeBalanced(open: Char, close: Char): Boolean { @@ -237,7 +226,6 @@ class RuleAnalyzer(data: String, code: Boolean = false) { } while (depth > 0 || otherDepth > 0) //拉出一个平衡字串 return if (depth > 0 || otherDepth > 0) false else { - if (innerStr) startX = this.pos //内嵌规则起始 this.pos = pos //同步位置 true } @@ -344,10 +332,10 @@ class RuleAnalyzer(data: String, code: Boolean = false) { val next = if (queue[pos] == '[') ']' else ')' //平衡组末尾字符 if (!chompBalanced(queue[pos], next)) throw Error( - queue.substring( - 0, - start - ) + "后未平衡" + queue.substring( + 0, + start + ) + "后未平衡" ) //拉出一个筛选器,不平衡则报错 } while (end > pos) @@ -404,10 +392,10 @@ class RuleAnalyzer(data: String, code: Boolean = false) { val next = if (queue[pos] == '[') ']' else ')' //平衡组末尾字符 if (!chompBalanced(queue[pos], next)) throw Error( - queue.substring( - 0, - start - ) + "后未平衡" + queue.substring( + 0, + start + ) + "后未平衡" ) //拉出一个筛选器,不平衡则报错 } while (end > pos) @@ -421,7 +409,6 @@ class RuleAnalyzer(data: String, code: Boolean = false) { } - /** * 替换内嵌规则 * @param inner 起始标志,如{$. 或 {{ @@ -431,36 +418,32 @@ class RuleAnalyzer(data: String, code: Boolean = false) { * * */ fun innerRule( - inner: String, - startStep: Int = 1, - endStep: Int = 1, - fr: (String) -> String? + inner: String, + startStep: Int = 1, + endStep: Int = 1, + fr: (String) -> String? ): String { - val start0 = pos //规则匹配前起点 - - innerStr = true //设置平衡组以平衡组起点为规则起始点 + val startXS = pos //设置最初起点 + startX = pos //设置规则起点 val st = StringBuilder() - while (!isEmpty && consumeTo(inner)) { //拉取成功返回true,ruleAnalyzes里的字符序列索引变量pos后移相应位置,否则返回false,且isEmpty为true - val posPre = pos //记录上次结束位置 - if (chompBalanced('{', '}')) { + while (consumeTo(inner)) { //拉取成功返回true,ruleAnalyzes里的字符序列索引变量pos后移相应位置,否则返回false,且isEmpty为true + if (chompCodeBalanced('{', '}')) { val frv = fr(currBalancedString(startStep, endStep)) if (frv != null) { - st.append(queue.substring(start, posPre) + frv) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 + st.append(queue.substring(startX, start) + frv) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 + startX = pos //记录下次规则起点 continue //获取内容成功,继续选择下个内嵌规则 - } } - pos += inner.length //拉出字段不平衡,inner只是个普通字串,跳到此inner后继续匹配 - } - //匹配前起点与当前规则起点相同,证明无替换成功的内嵌规则,返回空字符串。否则返回替换后的字符串 - return if (start0 == start) "" else { - st.append(remainingString()) //压入剩余字符串 + //最初起点与当前规则起点相同,证明无替换成功的内嵌规则,返回空字符串。否则返回替换后的字符串 + return if (startX == startXS) "" else { + st.append(queue.substring(pos)) //压入剩余字符串 st.toString() } } From 3813a7bf10f7f27997ffba74aa318853f616fd92 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 9 Jul 2021 16:28:37 +0800 Subject: [PATCH 21/24] Update RuleAnalyzer.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化 --- .../io/legado/app/model/analyzeRule/RuleAnalyzer.kt | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt index c26e817d0..837a8e554 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt @@ -16,15 +16,6 @@ class RuleAnalyzer(data: String, code: Boolean = false) { //设置平衡组函数,json或JavaScript时设置成chompCodeBalanced,否则为chompRuleBalanced val chompBalanced = if (code) ::chompCodeBalanced else ::chompRuleBalanced - //当前平衡字段 - fun currBalancedString( - stepStart: Int = 1, - stepEnd: Int = 1 - ): String { //stepStart平衡字符的起始分隔字串长度,stepEnd平衡字符的结束分隔字串长度 - return queue.substring(start + stepStart, pos - stepEnd) //当前平衡字段 - } - - fun trim() { // 修剪当前规则之前的"@"或者空白符 while (queue[pos] == '@' || queue[pos] < '!') pos++ } @@ -38,7 +29,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) { fun currString(): String { return queue.substring(start, pos) //当前拉取到的字段 } - + /** * 是否已无剩余字符? * @return 若剩余字串中已无字符则返回true @@ -431,7 +422,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) { while (consumeTo(inner)) { //拉取成功返回true,ruleAnalyzes里的字符序列索引变量pos后移相应位置,否则返回false,且isEmpty为true if (chompCodeBalanced('{', '}')) { - val frv = fr(currBalancedString(startStep, endStep)) + val frv = fr(queue.substring(start + stepStart, pos - stepEnd)) if (frv != null) { st.append(queue.substring(startX, start) + frv) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 startX = pos //记录下次规则起点 From 07143c172d8fdb293fc0eed9a5b6e2aaa45609e5 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 9 Jul 2021 16:35:13 +0800 Subject: [PATCH 22/24] Update RuleAnalyzer.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化 --- .../main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt index 837a8e554..5fd4aa346 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt @@ -422,7 +422,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) { while (consumeTo(inner)) { //拉取成功返回true,ruleAnalyzes里的字符序列索引变量pos后移相应位置,否则返回false,且isEmpty为true if (chompCodeBalanced('{', '}')) { - val frv = fr(queue.substring(start + stepStart, pos - stepEnd)) + val frv = fr(queue.substring(start + startStep, pos - endStep)) if (frv != null) { st.append(queue.substring(startX, start) + frv) //压入内嵌规则前的内容,及内嵌规则解析得到的字符串 startX = pos //记录下次规则起点 From b7e002e1fe53c7253c96a0cfb020fe8c7dd5f147 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 9 Jul 2021 17:04:53 +0800 Subject: [PATCH 23/24] Update RuleAnalyzer.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正与简化 --- .../java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt index 5fd4aa346..aaeda91ab 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt @@ -432,11 +432,8 @@ class RuleAnalyzer(data: String, code: Boolean = false) { pos += inner.length //拉出字段不平衡,inner只是个普通字串,跳到此inner后继续匹配 } - //最初起点与当前规则起点相同,证明无替换成功的内嵌规则,返回空字符串。否则返回替换后的字符串 - return if (startX == startXS) "" else { - st.append(queue.substring(pos)) //压入剩余字符串 - st.toString() - } + st.append(queue.substring(startX)) //压入剩余字符串 + return st.toString() } companion object { From 6dcc556bd1a88833740b2bf482ec2685d87f7806 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 9 Jul 2021 17:06:32 +0800 Subject: [PATCH 24/24] Update RuleAnalyzer.kt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简化 --- .../main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt index aaeda91ab..a464ea746 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt @@ -415,9 +415,7 @@ class RuleAnalyzer(data: String, code: Boolean = false) { fr: (String) -> String? ): String { - val startXS = pos //设置最初起点 startX = pos //设置规则起点 - val st = StringBuilder() while (consumeTo(inner)) { //拉取成功返回true,ruleAnalyzes里的字符序列索引变量pos后移相应位置,否则返回false,且isEmpty为true