优化
This commit is contained in:
@@ -308,7 +308,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
|||||||
|
|
||||||
fun getItem(position: Int): ITEM? = items.getOrNull(position)
|
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
|
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 {
|
final override fun getItemViewType(position: Int) = when {
|
||||||
isHeader(position) -> TYPE_HEADER_VIEW + position
|
isHeader(position) -> TYPE_HEADER_VIEW + position
|
||||||
isFooter(position) -> TYPE_FOOTER_VIEW + position - getActualItemCount() - getHeaderCount()
|
isFooter(position) -> TYPE_FOOTER_VIEW + position - getActualItemCount() - getHeaderCount()
|
||||||
else -> getItem(getActualPosition(position))?.let {
|
else -> getItemByLayoutPosition(position)?.let {
|
||||||
getItemViewType(it, getActualPosition(position))
|
getItemViewType(it, getActualPosition(position))
|
||||||
} ?: 0
|
} ?: 0
|
||||||
}
|
}
|
||||||
@@ -350,7 +350,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
|||||||
|
|
||||||
if (itemClickListener != null) {
|
if (itemClickListener != null) {
|
||||||
holder.itemView.setOnClickListener {
|
holder.itemView.setOnClickListener {
|
||||||
getItem(holder.layoutPosition)?.let {
|
getItemByLayoutPosition(holder.layoutPosition)?.let {
|
||||||
itemClickListener?.invoke(holder, it)
|
itemClickListener?.invoke(holder, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -358,7 +358,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
|||||||
|
|
||||||
if (itemLongClickListener != null) {
|
if (itemLongClickListener != null) {
|
||||||
holder.itemView.onLongClick {
|
holder.itemView.onLongClick {
|
||||||
getItem(holder.layoutPosition)?.let {
|
getItemByLayoutPosition(holder.layoutPosition)?.let {
|
||||||
itemLongClickListener?.invoke(holder, it)
|
itemLongClickListener?.invoke(holder, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,7 @@ abstract class RecyclerAdapter<ITEM, VB : ViewBinding>(protected val context: Co
|
|||||||
payloads: MutableList<Any>
|
payloads: MutableList<Any>
|
||||||
) {
|
) {
|
||||||
if (!isHeader(holder.layoutPosition) && !isFooter(holder.layoutPosition)) {
|
if (!isHeader(holder.layoutPosition) && !isFooter(holder.layoutPosition)) {
|
||||||
getItem(holder.layoutPosition - getHeaderCount())?.let {
|
getItemByLayoutPosition(holder.layoutPosition)?.let {
|
||||||
convert(holder, (holder.binding as VB), it, payloads)
|
convert(holder, (holder.binding as VB), it, payloads)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ object AppConst {
|
|||||||
|
|
||||||
val keyboardToolChars: List<String> by lazy {
|
val keyboardToolChars: List<String> by lazy {
|
||||||
arrayListOf(
|
arrayListOf(
|
||||||
"❓", "@css:", "<js></js>", "{{}}", "##", "&&", "%%", "||", "//", "\\", "$.",
|
"@css:", "<js></js>", "{{}}", "##", "&&", "%%", "||", "//", "\\", "$.",
|
||||||
"@", ":", "class", "text", "href", "textNodes", "ownText", "all", "html",
|
"@", ":", "class", "text", "href", "textNodes", "ownText", "all", "html",
|
||||||
"[", "]", "<", ">", "#", "!", ".", "+", "-", "*", "=", "{'webView': true}"
|
"[", "]", "<", ">", "#", "!", ".", "+", "-", "*", "=", "{'webView': true}"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class BookSourceEditActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val mSoftKeyboardTool: PopupWindow by lazy {
|
private val mSoftKeyboardTool: PopupWindow by lazy {
|
||||||
KeyboardToolPop(this, AppConst.keyboardToolChars, this)
|
KeyboardToolPop(this, this)
|
||||||
}
|
}
|
||||||
private var mIsSoftKeyBoardShowing = false
|
private var mIsSoftKeyBoardShowing = false
|
||||||
|
|
||||||
@@ -441,7 +441,22 @@ class BookSourceEditActivity :
|
|||||||
return true
|
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
|
if (text.isBlank()) return
|
||||||
val view = window.decorView.findFocus()
|
val view = window.decorView.findFocus()
|
||||||
if (view is EditText) {
|
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) {
|
private fun showHelp(fileName: String) {
|
||||||
//显示目录help下的帮助文档
|
//显示目录help下的帮助文档
|
||||||
val mdText = String(assets.open("help/${fileName}.md").readBytes())
|
val mdText = String(assets.open("help/${fileName}.md").readBytes())
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import android.widget.PopupWindow
|
|||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import io.legado.app.R
|
import io.legado.app.R
|
||||||
import io.legado.app.base.VMBaseActivity
|
import io.legado.app.base.VMBaseActivity
|
||||||
import io.legado.app.constant.AppConst
|
|
||||||
import io.legado.app.data.entities.ReplaceRule
|
import io.legado.app.data.entities.ReplaceRule
|
||||||
import io.legado.app.databinding.ActivityReplaceEditBinding
|
import io.legado.app.databinding.ActivityReplaceEditBinding
|
||||||
import io.legado.app.lib.dialogs.selector
|
import io.legado.app.lib.dialogs.selector
|
||||||
@@ -56,7 +55,7 @@ class ReplaceEditActivity :
|
|||||||
override val viewModel by viewModels<ReplaceEditViewModel>()
|
override val viewModel by viewModels<ReplaceEditViewModel>()
|
||||||
|
|
||||||
private val mSoftKeyboardTool: PopupWindow by lazy {
|
private val mSoftKeyboardTool: PopupWindow by lazy {
|
||||||
KeyboardToolPop(this, AppConst.keyboardToolChars, this)
|
KeyboardToolPop(this, this)
|
||||||
}
|
}
|
||||||
private var mIsSoftKeyBoardShowing = false
|
private var mIsSoftKeyBoardShowing = false
|
||||||
|
|
||||||
@@ -116,7 +115,16 @@ class ReplaceEditActivity :
|
|||||||
return replaceRule
|
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
|
if (text.isBlank()) return
|
||||||
val view = window?.decorView?.findFocus()
|
val view = window?.decorView?.findFocus()
|
||||||
if (view is EditText) {
|
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() {
|
private fun showRegexHelp() {
|
||||||
val mdText = String(assets.open("help/regexHelp.md").readBytes())
|
val mdText = String(assets.open("help/regexHelp.md").readBytes())
|
||||||
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
|
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class RssSourceEditActivity :
|
|||||||
override val binding by viewBinding(ActivityRssSourceEditBinding::inflate)
|
override val binding by viewBinding(ActivityRssSourceEditBinding::inflate)
|
||||||
override val viewModel by viewModels<RssSourceEditViewModel>()
|
override val viewModel by viewModels<RssSourceEditViewModel>()
|
||||||
private val mSoftKeyboardTool: PopupWindow by lazy {
|
private val mSoftKeyboardTool: PopupWindow by lazy {
|
||||||
KeyboardToolPop(this, AppConst.keyboardToolChars, this)
|
KeyboardToolPop(this, this)
|
||||||
}
|
}
|
||||||
private var mIsSoftKeyBoardShowing = false
|
private var mIsSoftKeyBoardShowing = false
|
||||||
private val adapter by lazy { RssSourceEditAdapter() }
|
private val adapter by lazy { RssSourceEditAdapter() }
|
||||||
@@ -232,7 +232,18 @@ class RssSourceEditActivity :
|
|||||||
return true
|
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
|
if (text.isBlank()) return
|
||||||
val view = window.decorView.findFocus()
|
val view = window.decorView.findFocus()
|
||||||
if (view is EditText) {
|
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() {
|
private fun showRuleHelp() {
|
||||||
val mdText = String(assets.open("help/ruleHelp.md").readBytes())
|
val mdText = String(assets.open("help/ruleHelp.md").readBytes())
|
||||||
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
|
showDialogFragment(TextDialog(mdText, TextDialog.Mode.MD))
|
||||||
|
|||||||
@@ -8,18 +8,21 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import io.legado.app.base.adapter.ItemViewHolder
|
import io.legado.app.base.adapter.ItemViewHolder
|
||||||
import io.legado.app.base.adapter.RecyclerAdapter
|
import io.legado.app.base.adapter.RecyclerAdapter
|
||||||
|
import io.legado.app.constant.AppConst
|
||||||
import io.legado.app.databinding.ItemFilletTextBinding
|
import io.legado.app.databinding.ItemFilletTextBinding
|
||||||
import io.legado.app.databinding.PopupKeyboardToolBinding
|
import io.legado.app.databinding.PopupKeyboardToolBinding
|
||||||
|
import splitties.systemservices.layoutInflater
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 键盘帮助浮窗
|
* 键盘帮助浮窗
|
||||||
*/
|
*/
|
||||||
class KeyboardToolPop(
|
class KeyboardToolPop(
|
||||||
context: Context,
|
context: Context,
|
||||||
private val chars: List<String>,
|
private val callBack: CallBack
|
||||||
val callBack: CallBack?
|
|
||||||
) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
|
) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
|
||||||
|
|
||||||
|
private val helpChar = "❓"
|
||||||
|
|
||||||
private val binding = PopupKeyboardToolBinding.inflate(LayoutInflater.from(context))
|
private val binding = PopupKeyboardToolBinding.inflate(LayoutInflater.from(context))
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -37,7 +40,15 @@ class KeyboardToolPop(
|
|||||||
binding.recyclerView.layoutManager =
|
binding.recyclerView.layoutManager =
|
||||||
LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
|
LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
|
||||||
binding.recyclerView.adapter = adapter
|
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) :
|
inner class Adapter(context: Context) :
|
||||||
@@ -61,8 +72,8 @@ class KeyboardToolPop(
|
|||||||
override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) {
|
override fun registerListener(holder: ItemViewHolder, binding: ItemFilletTextBinding) {
|
||||||
holder.itemView.apply {
|
holder.itemView.apply {
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
getItem(holder.layoutPosition)?.let {
|
getItemByLayoutPosition(holder.layoutPosition)?.let {
|
||||||
callBack?.sendText(it)
|
callBack.sendText(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +81,11 @@ class KeyboardToolPop(
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface CallBack {
|
interface CallBack {
|
||||||
|
|
||||||
|
fun keyboardHelp()
|
||||||
|
|
||||||
fun sendText(text: String)
|
fun sendText(text: String)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user