pull/34/head
kunfei 5 years ago
parent a4f7413ba3
commit 27860a0f98
  1. 37
      app/src/main/java/io/legado/app/constant/AppConst.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/source/edit/SourceEditActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugActivity.kt
  4. 41
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt
  5. 238
      app/src/main/res/layout/popup_keyboard_tool.xml
  6. 2
      app/src/main/res/values/strings.xml

@ -1,8 +1,6 @@
package io.legado.app.constant package io.legado.app.constant
import android.annotation.SuppressLint import android.annotation.SuppressLint
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -29,11 +27,32 @@ object AppConst {
SimpleDateFormat("HH:mm") SimpleDateFormat("HH:mm")
} }
val GSON_CONVERTER: Gson by lazy { val keyboardToolChars = arrayListOf(
GsonBuilder() "@",
.disableHtmlEscaping() "&",
.setPrettyPrinting() "|",
.setDateFormat("yyyy-MM-dd HH:mm:ssZ") "%",
.create() "/",
} ":",
"[",
"]",
"{",
"}",
"<",
">",
"\\",
"$",
"#",
"!",
".",
"href",
"src",
"textNodes",
"xpath",
"json",
"css",
"id",
"class",
"tag"
)
} }

@ -17,6 +17,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout
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.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.* import io.legado.app.data.entities.rule.*
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
@ -107,7 +108,7 @@ class SourceEditActivity :
private fun initView() { private fun initView() {
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(recycler_view)
mSoftKeyboardTool = KeyboardToolPop(this, this) mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this)
window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener()) window.decorView.viewTreeObserver.addOnGlobalLayoutListener(KeyboardOnGlobalChangeListener())
recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.adapter = adapter recycler_view.adapter = adapter

@ -4,34 +4,47 @@ import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.PopupWindow 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.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?) : class KeyboardToolPop(
PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { context: Context,
private val chars: List<String>,
val onClickListener: OnClickListener?
) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
init { init {
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
val view = LayoutInflater.from(context).inflate(R.layout.popup_keyboard_tool, null) this.contentView = LayoutInflater.from(context).inflate(R.layout.popup_keyboard_tool, null)
this.contentView = view
isTouchable = true isTouchable = true
isOutsideTouchable = false isOutsideTouchable = false
isFocusable = false isFocusable = false
inputMethodMode = INPUT_METHOD_NEEDED //解决遮盖输入法 inputMethodMode = INPUT_METHOD_NEEDED //解决遮盖输入法
initRecyclerView()
val linearLayout = contentView.findViewById<LinearLayout>(R.id.ll_content)
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)
} }
private fun initRecyclerView() = with(contentView) {
val adapter = Adapter(context)
recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
recycler_view.adapter = adapter
adapter.setItems(chars)
} }
inner class Adapter(context: Context) :
SimpleRecyclerAdapter<String>(context, R.layout.item_text) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
holder.itemView.text_view.text = item
holder.itemView.onClick { onClickListener?.click(item) }
} }
} }

@ -1,240 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:tools="http://schemas.android.com/tools" <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keyboard_top_view_tip_container" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:padding="5dp"
android:background="@color/background_card" android:background="@color/background_card"
xmlns:android="http://schemas.android.com/apk/res/android"> android:padding="5dp" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="UselessParent">
<LinearLayout
android:id="@+id/ll_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/at_char"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/and_char"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="|"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="%"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="/"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text=":"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="["
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="]"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="{"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="}"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/dsm_start"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/dsm_end"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="\"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="$"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="#"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="!"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="."
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="xpath"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="json"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="css"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="id"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="class"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="tag"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="children"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="href"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="src"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="textNodes"
android:textSize="14sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>

@ -392,8 +392,6 @@
<string name="debug_source">调试书源</string> <string name="debug_source">调试书源</string>
<string name="import_by_qr_code">二维码导入</string> <string name="import_by_qr_code">二维码导入</string>
<string name="scan_qr_code">扫描二维码</string> <string name="scan_qr_code">扫描二维码</string>
<string name="at_char">\@</string>
<string name="and_char"><![CDATA[&]]></string>
<string name="click_on_selected_show_menu">选中时点击可弹出菜单</string> <string name="click_on_selected_show_menu">选中时点击可弹出菜单</string>
<string name="theme">主题</string> <string name="theme">主题</string>
<string name="default_theme">默认主题</string> <string name="default_theme">默认主题</string>

Loading…
Cancel
Save