pull/1705/head
kunfei 3 years ago
parent e13b333adf
commit 7f2d931238
  1. 17
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt
  2. 5
      app/src/main/res/layout/popup_keyboard_tool.xml

@ -4,8 +4,6 @@ import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.PopupWindow import android.widget.PopupWindow
import androidx.recyclerview.widget.LinearLayoutManager
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.data.appDb import io.legado.app.data.appDb
@ -22,7 +20,7 @@ import splitties.systemservices.layoutInflater
* 键盘帮助浮窗 * 键盘帮助浮窗
*/ */
class KeyboardToolPop( class KeyboardToolPop(
context: Context, private val context: Context,
private val scope: CoroutineScope, private val scope: CoroutineScope,
private val callBack: CallBack private val callBack: CallBack
) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { ) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
@ -30,6 +28,7 @@ class KeyboardToolPop(
private val helpChar = "" private val helpChar = ""
private val binding = PopupKeyboardToolBinding.inflate(LayoutInflater.from(context)) private val binding = PopupKeyboardToolBinding.inflate(LayoutInflater.from(context))
private val adapter = Adapter(context)
init { init {
contentView = binding.root contentView = binding.root
@ -39,21 +38,23 @@ class KeyboardToolPop(
isFocusable = false isFocusable = false
inputMethodMode = INPUT_METHOD_NEEDED //解决遮盖输入法 inputMethodMode = INPUT_METHOD_NEEDED //解决遮盖输入法
initRecyclerView() initRecyclerView()
upAdapterData()
} }
private fun initRecyclerView() = with(contentView) { private fun initRecyclerView() {
val adapter = Adapter(context)
binding.recyclerView.layoutManager =
LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
adapter.addHeaderView { adapter.addHeaderView {
ItemFilletTextBinding.inflate(layoutInflater, it, false).apply { ItemFilletTextBinding.inflate(context.layoutInflater, it, false).apply {
textView.text = helpChar textView.text = helpChar
root.setOnClickListener { root.setOnClickListener {
callBack.keyboardHelp() callBack.keyboardHelp()
} }
} }
} }
}
@Suppress("MemberVisibilityCanBePrivate")
fun upAdapterData() {
scope.launch { scope.launch {
val items = withContext(IO) { val items = withContext(IO) {
appDb.keyboardAssistsDao.getOrDefault() appDb.keyboardAssistsDao.getOrDefault()

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/recycler_view" 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:background="@color/background_card" android:background="@color/background_card"
android:padding="5dp" /> android:orientation="horizontal"
android:padding="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

Loading…
Cancel
Save