pull/1705/head
kunfei 3 years ago
parent 20ca357884
commit ae9c849e50
  1. 10
      app/src/main/java/io/legado/app/base/adapter/RecyclerAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/constant/AppConst.kt
  3. 42
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  4. 31
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  5. 34
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  6. 25
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt

@ -308,7 +308,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
fun getItem(position: Int): ITEM? = items.getOrNull(position)
fun getItemByLayoutPosition(position: Int) = items.getOrNull(position - getHeaderCount())
fun getItemByLayoutPosition(position: Int) = items.getOrNull(getActualPosition(position))
fun getItems(): List<ITEM> = items
@ -324,7 +324,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
final override fun getItemViewType(position: Int) = when {
isHeader(position) -> TYPE_HEADER_VIEW + position
isFooter(position) -> TYPE_FOOTER_VIEW + position - getActualItemCount() - getHeaderCount()
else -> getItem(getActualPosition(position))?.let {
else -> getItemByLayoutPosition(position)?.let {
getItemViewType(it, getActualPosition(position))
} ?: 0
}
@ -350,7 +350,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
if (itemClickListener != null) {
holder.itemView.setOnClickListener {
getItem(holder.layoutPosition)?.let {
getItemByLayoutPosition(holder.layoutPosition)?.let {
itemClickListener?.invoke(holder, it)
}
}
@ -358,7 +358,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
if (itemLongClickListener != null) {
holder.itemView.onLongClick {
getItem(holder.layoutPosition)?.let {
getItemByLayoutPosition(holder.layoutPosition)?.let {
itemLongClickListener?.invoke(holder, it)
}
}
@ -379,7 +379,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
payloads: MutableList<Any>
) {
if (!isHeader(holder.layoutPosition) && !isFooter(holder.layoutPosition)) {
getItem(holder.layoutPosition - getHeaderCount())?.let {
getItemByLayoutPosition(holder.layoutPosition)?.let {
convert(holder, (holder.binding as VB), it, payloads)
}
}

@ -41,7 +41,7 @@ object AppConst {
val keyboardToolChars: List<String> by lazy {
arrayListOf(
"", "@css:", "<js></js>", "{{}}", "##", "&&", "%%", "||", "//", "\\", "$.",
"@css:", "<js></js>", "{{}}", "##", "&&", "%%", "||", "//", "\\", "$.",
"@", ":", "class", "text", "href", "textNodes", "ownText", "all", "html",
"[", "]", "<", ">", "#", "!", ".", "+", "-", "*", "=", "{'webView': true}"
)

@ -66,7 +66,7 @@ class BookSourceEditActivity :
}
private val mSoftKeyboardTool: PopupWindow by lazy {
KeyboardToolPop(this, AppConst.keyboardToolChars, this)
KeyboardToolPop(this, this)
}
private var mIsSoftKeyBoardShowing = false
@ -441,7 +441,22 @@ class BookSourceEditActivity :
return true
}
private fun insertText(text: String) {
override fun keyboardHelp() {
val items = arrayListOf("插入URL参数", "书源教程", "js教程", "正则教程", "选择文件")
selector(getString(R.string.help), items) { _, index ->
when (index) {
0 -> sendText(AppConst.urlOption)
1 -> showHelp("ruleHelp")
2 -> showHelp("jsHelp")
3 -> showHelp("regexHelp")
4 -> selectDoc.launch {
mode = HandleFileContract.FILE
}
}
}
}
override fun sendText(text: String) {
if (text.isBlank()) return
val view = window.decorView.findFocus()
if (view is EditText) {
@ -456,29 +471,6 @@ class BookSourceEditActivity :
}
}
override fun sendText(text: String) {
if (text == AppConst.keyboardToolChars[0]) {
showHelpDialog()
} else {
insertText(text)
}
}
private fun showHelpDialog() {
val items = arrayListOf("插入URL参数", "书源教程", "js教程", "正则教程", "选择文件")
selector(getString(R.string.help), items) { _, index ->
when (index) {
0 -> insertText(AppConst.urlOption)
1 -> showHelp("ruleHelp")
2 -> showHelp("jsHelp")
3 -> showHelp("regexHelp")
4 -> selectDoc.launch {
mode = HandleFileContract.FILE
}
}
}
}
private fun showHelp(fileName: String) {
//显示目录help下的帮助文档
val mdText = String(assets.open("help/${fileName}.md").readBytes())

@ -13,7 +13,6 @@ import android.widget.PopupWindow
import androidx.activity.viewModels
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceEditBinding
import io.legado.app.lib.dialogs.selector
@ -56,7 +55,7 @@ class ReplaceEditActivity :
override val viewModel by viewModels<ReplaceEditViewModel>()
private val mSoftKeyboardTool: PopupWindow by lazy {
KeyboardToolPop(this, AppConst.keyboardToolChars, this)
KeyboardToolPop(this, this)
}
private var mIsSoftKeyBoardShowing = false
@ -116,7 +115,16 @@ class ReplaceEditActivity :
return replaceRule
}
private fun insertText(text: String) {
override fun keyboardHelp() {
val items = arrayListOf("正则教程")
selector(getString(R.string.help), items) { _, index ->
when (index) {
0 -> showRegexHelp()
}
}
}
override fun sendText(text: String) {
if (text.isBlank()) return
val view = window?.decorView?.findFocus()
if (view is EditText) {
@ -133,23 +141,6 @@ class ReplaceEditActivity :
}
}
override fun sendText(text: String) {
if (text == AppConst.keyboardToolChars[0]) {
showHelpDialog()
} else {
insertText(text)
}
}
private fun showHelpDialog() {
val items = arrayListOf("正则教程")
selector(getString(R.string.help), items) { _, index ->
when (index) {
0 -> showRegexHelp()
}
}
}
private fun showRegexHelp() {
val mdText = String(assets.open("help/regexHelp.md").readBytes())
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))

@ -37,7 +37,7 @@ class RssSourceEditActivity :
override val binding by viewBinding(ActivityRssSourceEditBinding::inflate)
override val viewModel by viewModels<RssSourceEditViewModel>()
private val mSoftKeyboardTool: PopupWindow by lazy {
KeyboardToolPop(this, AppConst.keyboardToolChars, this)
KeyboardToolPop(this, this)
}
private var mIsSoftKeyBoardShowing = false
private val adapter by lazy { RssSourceEditAdapter() }
@ -232,7 +232,18 @@ class RssSourceEditActivity :
return true
}
private fun insertText(text: String) {
override fun keyboardHelp() {
val items = arrayListOf("插入URL参数", "订阅源教程", "正则教程")
selector(getString(R.string.help), items) { _, index ->
when (index) {
0 -> sendText(AppConst.urlOption)
1 -> showRuleHelp()
2 -> showRegexHelp()
}
}
}
override fun sendText(text: String) {
if (text.isBlank()) return
val view = window.decorView.findFocus()
if (view is EditText) {
@ -247,25 +258,6 @@ class RssSourceEditActivity :
}
}
override fun sendText(text: String) {
if (text == AppConst.keyboardToolChars[0]) {
showHelpDialog()
} else {
insertText(text)
}
}
private fun showHelpDialog() {
val items = arrayListOf("插入URL参数", "订阅源教程", "正则教程")
selector(getString(R.string.help), items) { _, index ->
when (index) {
0 -> insertText(AppConst.urlOption)
1 -> showRuleHelp()
2 -> showRegexHelp()
}
}
}
private fun showRuleHelp() {
val mdText = String(assets.open("help/ruleHelp.md").readBytes())
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))

@ -8,18 +8,21 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppConst
import io.legado.app.databinding.ItemFilletTextBinding
import io.legado.app.databinding.PopupKeyboardToolBinding
import splitties.systemservices.layoutInflater
/**
* 键盘帮助浮窗
*/
class KeyboardToolPop(
context: Context,
private val chars: List<String>,
val callBack: CallBack?
private val callBack: CallBack
) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
private val helpChar = ""
private val binding = PopupKeyboardToolBinding.inflate(LayoutInflater.from(context))
init {
@ -37,7 +40,15 @@ class KeyboardToolPop(
binding.recyclerView.layoutManager =
LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
binding.recyclerView.adapter = adapter
adapter.setItems(chars)
adapter.addHeaderView {
ItemFilletTextBinding.inflate(layoutInflater, it, false).apply {
textView.text = helpChar
root.setOnClickListener {
callBack.keyboardHelp()
}
}
}
adapter.setItems(AppConst.charsets)
}
inner class Adapter(context: Context) :
@ -61,8 +72,8 @@ class KeyboardToolPop(
override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) {
holder.itemView.apply {
setOnClickListener {
getItem(holder.layoutPosition)?.let {
callBack?.sendText(it)
getItemByLayoutPosition(holder.layoutPosition)?.let {
callBack.sendText(it)
}
}
}
@ -70,7 +81,11 @@ class KeyboardToolPop(
}
interface CallBack {
fun keyboardHelp()
fun sendText(text: String)
}
}

Loading…
Cancel
Save