Merge remote-tracking branch 'origin/master' into master

# Conflicts:
#	app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt
pull/1114/head
bushixuanqi 3 years ago
commit 126f4d3991
  1. 25
      app/src/main/java/io/legado/app/model/analyzeRule/RuleAnalyzer.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 37
      app/src/main/java/io/legado/app/ui/dict/DictDialog.kt
  4. 25
      app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt
  5. 11
      app/src/main/res/layout/dialog_dict.xml
  6. 4
      app/src/main/res/menu/content_select_action.xml
  7. 1
      app/src/main/res/values-ja-rJP/strings.xml
  8. 1
      app/src/main/res/values-pt-rBR/strings.xml
  9. 1
      app/src/main/res/values-zh-rHK/strings.xml
  10. 1
      app/src/main/res/values-zh-rTW/strings.xml
  11. 1
      app/src/main/res/values-zh/strings.xml
  12. 1
      app/src/main/res/values/strings.xml

@ -266,13 +266,13 @@ class RuleAnalyzer(data: String, code:Boolean = false) {
this.pos = pos //同步位置 this.pos = pos //同步位置
true true
} }
} }
/** /**
* 不用正则,不到最后不切片也不用中间变量存储,只在序列中标记当前查找字段的开头结尾,到返回时才切片,高效快速准确切割规则 * 不用正则,不到最后不切片也不用中间变量存储,只在序列中标记当前查找字段的开头结尾,到返回时才切片,高效快速准确切割规则
* 解决jsonPath自带的"&&""||"与阅读的规则冲突,以及规则正则或字符串中包含"&&""||""%%""@"导致的冲突 * 解决jsonPath自带的"&&""||"与阅读的规则冲突,以及规则正则或字符串中包含"&&""||""%%""@"导致的冲突
*/ */
tailrec fun splitRule(vararg split: String): Array<String>{ //首段匹配,elementsType为空 tailrec fun splitRule(vararg split: String): Array<String>{ //首段匹配,elementsType为空
if(split.size == 1) { if(split.size == 1) {
elementsType = split[0] //设置分割字串 elementsType = split[0] //设置分割字串
@ -348,10 +348,10 @@ tailrec fun splitRule(vararg split: String): Array<String>{ //首段匹配,eleme
start = pos //设置开始查找筛选器位置的起始位置 start = pos //设置开始查找筛选器位置的起始位置
return splitRule(* split) //递归调用首段匹配 return splitRule(* split) //递归调用首段匹配
} }
@JvmName("splitRuleNext") @JvmName("splitRuleNext")
private tailrec fun splitRule(): Array<String>{ //二段匹配被调用,elementsType非空(已在首段赋值),直接按elementsType查找,比首段采用的方式更快 private tailrec fun splitRule(): Array<String>{ //二段匹配被调用,elementsType非空(已在首段赋值),直接按elementsType查找,比首段采用的方式更快
val end = pos //记录分隔位置 val end = pos //记录分隔位置
pos = start //重回开始,启动另一种查找 pos = start //重回开始,启动另一种查找
@ -413,10 +413,10 @@ private tailrec fun splitRule(): Array<String>{ //二段匹配被调用,elements
rule rule
}else splitRule() //递归匹配 }else splitRule() //递归匹配
} }
/** /**
* 替换内嵌规则 * 替换内嵌规则
* @param inner 起始标志,{$. {{ * @param inner 起始标志,{$. {{
* @param startStep 不属于规则部分的前置字符长度{$.{不属于规则的组成部分故startStep为1 * @param startStep 不属于规则部分的前置字符长度{$.{不属于规则的组成部分故startStep为1
@ -424,7 +424,7 @@ private tailrec fun splitRule(): Array<String>{ //二段匹配被调用,elements
* @param fr 查找到内嵌规则时用于解析的函数 * @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 //规则匹配前起点 val start0 = pos //规则匹配前起点
@ -450,7 +450,7 @@ fun innerRule( inner:String,startStep:Int = 1,endStep:Int = 1,fr:(String)->Strin
st.append(remainingString()) //压入剩余字符串 st.append(remainingString()) //压入剩余字符串
st.toString() st.toString()
} }
} }
// /** // /**
// * 匹配并返回标签中的属性键字串(字母、数字、-、_、:) // * 匹配并返回标签中的属性键字串(字母、数字、-、_、:)
@ -485,7 +485,7 @@ fun innerRule( inner:String,startStep:Int = 1,endStep:Int = 1,fr:(String)->Strin
// return query // return query
// } // }
companion object { companion object {
/** /**
* 转义字符 * 转义字符
*/ */
@ -564,4 +564,5 @@ companion object {
*/ */
val splitListDefault = arrayOf("-",".","!","@","@@") val splitListDefault = arrayOf("-",".","!","@","@@")
}} }
}

@ -46,6 +46,7 @@ import io.legado.app.ui.book.read.page.provider.TextPageFactory
import io.legado.app.ui.book.searchContent.SearchContentActivity import io.legado.app.ui.book.searchContent.SearchContentActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.dict.DictDialog
import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.replace.ReplaceRuleActivity
import io.legado.app.ui.replace.edit.ReplaceEditActivity import io.legado.app.ui.replace.edit.ReplaceEditActivity
@ -531,6 +532,10 @@ class ReadBookActivity : ReadBookBaseActivity(),
openSearchActivity(selectedText) openSearchActivity(selectedText)
return true return true
} }
R.id.menu_dict -> {
DictDialog.dict(supportFragmentManager, selectedText)
return true
}
} }
return false return false
} }

@ -1,11 +1,21 @@
package io.legado.app.ui.dict package io.legado.app.ui.dict
import android.os.Bundle import android.os.Bundle
import android.text.Html
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.databinding.DialogDictBinding
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
/**
* 词典
*/
class DictDialog : BaseDialogFragment() { class DictDialog : BaseDialogFragment() {
companion object { companion object {
@ -21,10 +31,33 @@ class DictDialog : BaseDialogFragment() {
} }
private val viewModel by viewModels<DictViewModel>() private val viewModel by viewModels<DictViewModel>()
private val binding by viewBinding(DialogDictBinding::bind)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onStart() {
viewModel.word = arguments?.getString("word") ?: "" super.onStart()
dialog?.window
?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
return inflater.inflate(R.layout.dialog_dict, container)
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
val word = arguments?.getString("word")
if (word.isNullOrEmpty()) {
toastOnUi(R.string.cannot_empty)
dismiss()
return
}
viewModel.dictHtmlData.observe(viewLifecycleOwner) {
binding.tvDict.text = Html.fromHtml(it)
}
viewModel.dict(word)
} }

@ -1,11 +1,30 @@
package io.legado.app.ui.dict package io.legado.app.ui.dict
import android.app.Application import android.app.Application
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel
import io.legado.app.help.http.get
import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient
import org.jsoup.Jsoup
class DictViewModel(application: Application) : AndroidViewModel(application) { class DictViewModel(application: Application) : BaseViewModel(application) {
var word: String? = null var dictHtmlData: MutableLiveData<String> = MutableLiveData()
fun dict(word: String) {
execute {
val body = okHttpClient.newCallStrResponse {
get("http://apii.dict.cn/mini.php", mapOf(Pair("q", word)))
}.body
val jsoup = Jsoup.parse(body)
jsoup.body()
}.onSuccess {
dictHtmlData.postValue(it.html())
}.onError {
toastOnUi(it.localizedMessage)
}
}
} }

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_dict"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>

@ -17,6 +17,10 @@
android:id="@+id/menu_aloud" android:id="@+id/menu_aloud"
android:title="@string/read_aloud" /> android:title="@string/read_aloud" />
<item
android:id="@+id/menu_dict"
android:title="@string/dict" />
<item <item
android:id="@+id/menu_search_content" android:id="@+id/menu_search_content"
android:title="@string/search_content" /> android:title="@string/search_content" />

@ -846,4 +846,5 @@
<string name="export_file_name">导出文件名</string> <string name="export_file_name">导出文件名</string>
<string name="reset">重置</string> <string name="reset">重置</string>
<string name="null_url">url为空</string> <string name="null_url">url为空</string>
<string name="dict">字典</string>
</resources> </resources>

@ -846,4 +846,5 @@
<string name="export_file_name">Exportar o nome do arquivo</string> <string name="export_file_name">Exportar o nome do arquivo</string>
<string name="reset">重置</string> <string name="reset">重置</string>
<string name="null_url">url为空</string> <string name="null_url">url为空</string>
<string name="dict">字典</string>
</resources> </resources>

@ -844,5 +844,6 @@
<string name="export_file_name">导出文件名</string> <string name="export_file_name">导出文件名</string>
<string name="reset">重置</string> <string name="reset">重置</string>
<string name="null_url">url为空</string> <string name="null_url">url为空</string>
<string name="dict">字典</string>
</resources> </resources>

@ -845,5 +845,6 @@
<string name="export_file_name">匯出檔案名</string> <string name="export_file_name">匯出檔案名</string>
<string name="reset">重設</string> <string name="reset">重設</string>
<string name="null_url">url为空</string> <string name="null_url">url为空</string>
<string name="dict">字典</string>
</resources> </resources>

@ -845,5 +845,6 @@
<string name="export_file_name">导出文件名</string> <string name="export_file_name">导出文件名</string>
<string name="reset">重置</string> <string name="reset">重置</string>
<string name="null_url">url为空</string> <string name="null_url">url为空</string>
<string name="dict">字典</string>
</resources> </resources>

@ -846,5 +846,6 @@
<string name="export_file_name">Export file name</string> <string name="export_file_name">Export file name</string>
<string name="reset">Reset</string> <string name="reset">Reset</string>
<string name="null_url">Null url</string> <string name="null_url">Null url</string>
<string name="dict">字典</string>
</resources> </resources>

Loading…
Cancel
Save