diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 158e1e4b4..6cda954e8 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -1,8 +1,6 @@ package io.legado.app.constant import android.annotation.SuppressLint -import com.google.gson.Gson -import com.google.gson.GsonBuilder import io.legado.app.App import io.legado.app.R import java.text.SimpleDateFormat @@ -29,11 +27,32 @@ object AppConst { SimpleDateFormat("HH:mm") } - val GSON_CONVERTER: Gson by lazy { - GsonBuilder() - .disableHtmlEscaping() - .setPrettyPrinting() - .setDateFormat("yyyy-MM-dd HH:mm:ssZ") - .create() - } + val keyboardToolChars = arrayListOf( + "@", + "&", + "|", + "%", + "/", + ":", + "[", + "]", + "{", + "}", + "<", + ">", + "\\", + "$", + "#", + "!", + ".", + "href", + "src", + "textNodes", + "xpath", + "json", + "css", + "id", + "class", + "tag" + ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt index b49db48bc..8a2db83d6 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt @@ -17,6 +17,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.tabs.TabLayout import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppConst import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.rule.* import io.legado.app.lib.theme.ATH @@ -107,7 +108,7 @@ class SourceEditActivity : private fun initView() { ATH.applyEdgeEffectColor(recycler_view) - mSoftKeyboardTool = KeyboardToolPop(this, this) + mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this) window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener()) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt new file mode 100644 index 000000000..de8bf27dc --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt @@ -0,0 +1,2 @@ +package io.legado.app.ui.rss.source.debug + 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 076fac6b9..e31afbc0f 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 @@ -4,34 +4,47 @@ import android.annotation.SuppressLint import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup -import android.widget.LinearLayout import android.widget.PopupWindow -import android.widget.TextView +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter +import kotlinx.android.synthetic.main.item_text.view.* +import kotlinx.android.synthetic.main.popup_keyboard_tool.view.* +import org.jetbrains.anko.sdk27.listeners.onClick -class KeyboardToolPop(context: Context, onClickListener: OnClickListener?) : - PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { +class KeyboardToolPop( + context: Context, + private val chars: List, + val onClickListener: OnClickListener? +) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { init { @SuppressLint("InflateParams") - val view = LayoutInflater.from(context).inflate(R.layout.popup_keyboard_tool, null) - this.contentView = view + this.contentView = LayoutInflater.from(context).inflate(R.layout.popup_keyboard_tool, null) isTouchable = true isOutsideTouchable = false isFocusable = false inputMethodMode = INPUT_METHOD_NEEDED //解决遮盖输入法 + initRecyclerView() + } + + private fun initRecyclerView() = with(contentView) { + val adapter = Adapter(context) + recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) + recycler_view.adapter = adapter + adapter.setItems(chars) + } - val linearLayout = contentView.findViewById(R.id.ll_content) + inner class Adapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_text) { - for (i in 0 until linearLayout.childCount) { - val tv = linearLayout.getChildAt(i) as TextView - tv.setOnClickListener { v -> - (v as? TextView)?.text.toString().let { - onClickListener?.click(it) - } - } + override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + holder.itemView.text_view.text = item + holder.itemView.onClick { onClickListener?.click(item) } } } diff --git a/app/src/main/res/layout/popup_keyboard_tool.xml b/app/src/main/res/layout/popup_keyboard_tool.xml index 9a00a80c4..649534d76 100644 --- a/app/src/main/res/layout/popup_keyboard_tool.xml +++ b/app/src/main/res/layout/popup_keyboard_tool.xml @@ -1,240 +1,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:padding="5dp" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aa63506be..e7c886555 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -392,8 +392,6 @@ 调试书源 二维码导入 扫描二维码 - \@ - 选中时点击可弹出菜单 主题 默认主题