pull/1705/head
kunfei 3 years ago
parent 08e777b6df
commit 3cd61799b5
  1. 8
      app/src/main/java/io/legado/app/constant/AppConst.kt
  2. 9
      app/src/main/java/io/legado/app/data/dao/KeyboardAssistsDao.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt
  6. 23
      app/src/main/java/io/legado/app/ui/widget/KeyboardToolPop.kt

@ -39,14 +39,6 @@ object AppConst {
SimpleDateFormat("yy-MM-dd-HH-mm-ss")
}
val keyboardToolChars: List<String> by lazy {
arrayListOf(
"@css:", "<js></js>", "{{}}", "##", "&&", "%%", "||", "//", "\\", "$.",
"@", ":", "class", "text", "href", "textNodes", "ownText", "all", "html",
"[", "]", "<", ">", "#", "!", ".", "+", "-", "*", "=", "{'webView': true}"
)
}
const val bookGroupAllId = -1L
const val bookGroupLocalId = -2L
const val bookGroupAudioId = -3L

@ -2,6 +2,7 @@ package io.legado.app.data.dao
import androidx.room.*
import io.legado.app.data.entities.KeyboardAssist
import io.legado.app.help.DefaultData
@Dao
interface KeyboardAssistsDao {
@ -20,4 +21,12 @@ interface KeyboardAssistsDao {
@Delete
fun delete(vararg keyboardAssist: KeyboardAssist)
fun getOrDefault(): List<KeyboardAssist> {
return all.ifEmpty {
insert(*DefaultData.keyboardAssists.toTypedArray())
DefaultData.keyboardAssists
}
}
}

@ -66,7 +66,7 @@ class BookSourceEditActivity :
}
private val mSoftKeyboardTool: PopupWindow by lazy {
KeyboardToolPop(this, this)
KeyboardToolPop(this, this, this)
}
private var mIsSoftKeyBoardShowing = false

@ -55,7 +55,7 @@ class ReplaceEditActivity :
override val viewModel by viewModels<ReplaceEditViewModel>()
private val mSoftKeyboardTool: PopupWindow by lazy {
KeyboardToolPop(this, this)
KeyboardToolPop(this, this, this)
}
private var mIsSoftKeyBoardShowing = false

@ -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, this)
KeyboardToolPop(this, this, this)
}
private var mIsSoftKeyBoardShowing = false
private val adapter by lazy { RssSourceEditAdapter() }

@ -8,9 +8,14 @@ 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.data.appDb
import io.legado.app.data.entities.KeyboardAssist
import io.legado.app.databinding.ItemFilletTextBinding
import io.legado.app.databinding.PopupKeyboardToolBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import splitties.systemservices.layoutInflater
/**
@ -18,6 +23,7 @@ import splitties.systemservices.layoutInflater
*/
class KeyboardToolPop(
context: Context,
private val scope: CoroutineScope,
private val callBack: CallBack
) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
@ -48,11 +54,16 @@ class KeyboardToolPop(
}
}
}
adapter.setItems(AppConst.charsets)
scope.launch {
val items = withContext(IO) {
appDb.keyboardAssistsDao.getOrDefault()
}
adapter.setItems(items)
}
}
inner class Adapter(context: Context) :
RecyclerAdapter<String, ItemFilletTextBinding>(context) {
RecyclerAdapter<KeyboardAssist, ItemFilletTextBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemFilletTextBinding {
return ItemFilletTextBinding.inflate(inflater, parent, false)
@ -61,11 +72,11 @@ class KeyboardToolPop(
override fun convert(
holder: ItemViewHolder,
binding: ItemFilletTextBinding,
item: String,
item: KeyboardAssist,
payloads: MutableList<Any>
) {
binding.run {
textView.text = item
textView.text = item.key
}
}
@ -73,7 +84,7 @@ class KeyboardToolPop(
holder.itemView.apply {
setOnClickListener {
getItemByLayoutPosition(holder.layoutPosition)?.let {
callBack.sendText(it)
callBack.sendText(it.value)
}
}
}

Loading…
Cancel
Save