修复BUG,添加代码表搜索功能
This commit is contained in:
parent
913cc1a4d7
commit
baf8b01582
|
@ -10,18 +10,19 @@ import android.text.method.LinkMovementMethod
|
|||
import android.text.style.ClickableSpan
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.coldmint.rust.core.database.code.CodeDataBase
|
||||
import com.coldmint.rust.core.database.code.CodeInfo
|
||||
import com.coldmint.rust.core.database.code.SectionInfo
|
||||
import com.coldmint.rust.pro.adapters.CodeTableAdapter
|
||||
import com.coldmint.rust.pro.adapters.CodeTableItemAdapter
|
||||
import com.coldmint.rust.pro.base.BaseActivity
|
||||
import com.coldmint.rust.pro.databinding.ActivityCodeTableBinding
|
||||
import com.google.rpc.Code
|
||||
import com.muqing.gj
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
||||
|
@ -34,20 +35,42 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
|
||||
setReturnButton()
|
||||
loadData()
|
||||
//设置上下选择按钮
|
||||
viewBinding.listTop.setOnClickListener {
|
||||
if (--CodeTableAdapter.pick < 0) {
|
||||
CodeTableAdapter.pick = 0
|
||||
}
|
||||
val get = CodeTableAdapter.picklist[CodeTableAdapter.pick]
|
||||
(viewBinding.codeRecyclerB.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(get, 0)
|
||||
adapter.item?.notifyDataSetChanged()
|
||||
}
|
||||
viewBinding.listButtom.setOnClickListener {
|
||||
val size = CodeTableAdapter.picklist.size
|
||||
|
||||
if (++CodeTableAdapter.pick == size - 1) {
|
||||
CodeTableAdapter.pick = 0
|
||||
}
|
||||
val get = CodeTableAdapter.picklist[CodeTableAdapter.pick]
|
||||
(viewBinding.codeRecyclerB.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(get,
|
||||
0)
|
||||
adapter.item?.notifyDataSetChanged()
|
||||
}
|
||||
viewBinding.edittext.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(a: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
}
|
||||
|
||||
override fun onTextChanged(a: CharSequence?, p1: Int, p2: Int, p3: Int) {
|
||||
/* if (a.isNullOrEmpty()) {
|
||||
loadData()
|
||||
return
|
||||
}
|
||||
loadData(a.toString())*/
|
||||
/* if (a.isNullOrEmpty()) {
|
||||
loadData()
|
||||
return
|
||||
}
|
||||
loadData(a.toString())*/
|
||||
if (a.isNullOrEmpty()) {
|
||||
viewBinding.searchPick.isVisible = false
|
||||
loadData()
|
||||
// loadData()
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(a: Editable?) {
|
||||
}
|
||||
})
|
||||
|
@ -55,12 +78,12 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
if (p1 == EditorInfo.IME_ACTION_SEARCH) {
|
||||
if (v?.text.isNullOrEmpty()) {
|
||||
loadData()
|
||||
}else{
|
||||
} else {
|
||||
var toString = v?.text.toString()
|
||||
if (toString.startsWith("/")) {
|
||||
toString = toString.substring(1)
|
||||
loadData(toString)
|
||||
}else{
|
||||
} else {
|
||||
viewBinding.searchPick.isVisible = true
|
||||
adapter.item?.search(toString)
|
||||
}
|
||||
|
@ -137,7 +160,7 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
codeDataBase.getCodeDao().findCodeBySection(section.code)
|
||||
} else {
|
||||
codeDataBase.getCodeDao()
|
||||
.findCodeByCodeOrTranslateFromSection(key, section.code)
|
||||
.findCodeByCodeOrTranslateFromSection(key, section.code)
|
||||
}
|
||||
if (list.isNullOrEmpty()) {
|
||||
group.remove(section)
|
||||
|
@ -147,25 +170,33 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
}
|
||||
|
||||
if (group.isNotEmpty()) {
|
||||
adapter = CodeTableAdapter(this, group, item, viewBinding.codeRecyclerB)
|
||||
adapter = CodeTableAdapter(this, group, item, viewBinding)
|
||||
adapter.setVersionMap(versionMap)
|
||||
adapter.setTypeNameMap(typeNameMap)
|
||||
adapter.setSectionMap(sectionMap)
|
||||
if (adapter.item == null) {
|
||||
|
||||
adapter.item = CodeTableItemAdapter(viewBinding.codeRecyclerB, item[0])
|
||||
adapter.item!!.versionMap = versionMap
|
||||
adapter.item!!.typeNameMap = typeNameMap
|
||||
adapter.item!!.sectionMap = sectionMap
|
||||
CodeTableAdapter.i = group[0].translate
|
||||
}
|
||||
runOnUiThread {
|
||||
/* adapter.labelFunction = { _, _, string ->
|
||||
// section = string
|
||||
if (string.isEmpty()) {
|
||||
loadData()
|
||||
}
|
||||
loadData(string)
|
||||
}*/
|
||||
viewBinding.codeRecyclerB.adapter = adapter.item
|
||||
/* adapter.labelFunction = { _, _, string ->
|
||||
// section = string
|
||||
if (string.isEmpty()) {
|
||||
loadData()
|
||||
}
|
||||
loadData(string)
|
||||
}*/
|
||||
viewBinding.displayView.isVisible = false
|
||||
viewBinding.progressBar.isVisible = false
|
||||
viewBinding.expandableListView.isVisible = true
|
||||
viewBinding.expandableListView.layoutManager = LinearLayoutManager(this)
|
||||
viewBinding.expandableListView.setAdapter(adapter)
|
||||
viewBinding.expandableListView.adapter = adapter
|
||||
// viewBinding.expandableListView.swapAdapter(adapter, true)
|
||||
|
||||
}
|
||||
} else {
|
||||
notFindKey(key)
|
||||
|
@ -174,6 +205,7 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
}
|
||||
|
||||
lateinit var adapter: CodeTableAdapter
|
||||
|
||||
/**
|
||||
* 没有找到节
|
||||
* @param key String?
|
||||
|
@ -186,11 +218,11 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
val spannableString = SpannableString(tip)
|
||||
if (start > -1) {
|
||||
spannableString.setSpan(
|
||||
object : ClickableSpan() {
|
||||
override fun onClick(p0: View) {
|
||||
loadData()
|
||||
}
|
||||
}, start, start + action.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
object : ClickableSpan() {
|
||||
override fun onClick(p0: View) {
|
||||
loadData()
|
||||
}
|
||||
}, start, start + action.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
viewBinding.displayView.movementMethod = LinkMovementMethod.getInstance()
|
||||
|
@ -202,6 +234,7 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
viewBinding.expandableListView.isVisible = false
|
||||
viewBinding.progressBar.isVisible = false
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_code_table, menu)
|
||||
return true
|
||||
|
@ -212,6 +245,7 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
|
|||
moveTaskToBack(true);
|
||||
// ifNeedFinish()
|
||||
}
|
||||
|
||||
override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityCodeTableBinding {
|
||||
return ActivityCodeTableBinding.inflate(layoutInflater)
|
||||
}
|
||||
|
|
|
@ -3,56 +3,40 @@ package com.coldmint.rust.pro.adapters
|
|||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.Spanned
|
||||
import android.text.style.BackgroundColorSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.coldmint.rust.core.database.code.CodeDataBase
|
||||
import com.coldmint.rust.core.database.code.CodeInfo
|
||||
import com.coldmint.rust.core.database.code.SectionInfo
|
||||
import com.coldmint.rust.core.tool.LineParser
|
||||
import com.coldmint.rust.pro.R
|
||||
import com.coldmint.rust.pro.databinding.CodeTableItemBinding
|
||||
import com.coldmint.rust.pro.databinding.ActivityCodeTableBinding
|
||||
import com.coldmint.rust.pro.databinding.ItemCodetableBinding
|
||||
import com.coldmint.rust.pro.dialog.MaterialBottomDialog
|
||||
import com.coldmint.rust.pro.tool.AppSettings
|
||||
import com.coldmint.rust.pro.tool.GlobalMethod
|
||||
import com.google.android.gms.common.internal.Objects
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.muqing.VH
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class CodeTableAdapter(
|
||||
val context: Context,
|
||||
private val group: List<SectionInfo>,
|
||||
private val itemList: List<List<CodeInfo>>,
|
||||
val recyclerView: RecyclerView
|
||||
private val binding: ActivityCodeTableBinding
|
||||
) : RecyclerView.Adapter<VH<ItemCodetableBinding>>() {
|
||||
private var versionMap: HashMap<Int, String>? = null
|
||||
private var typeNameMap: HashMap<String, String>? = null
|
||||
private var sectionMap: HashMap<String, String>? = null
|
||||
private val executorService by lazy {
|
||||
Executors.newSingleThreadExecutor()
|
||||
}
|
||||
|
||||
/* private val executorService by lazy {
|
||||
Executors.newSingleThreadExecutor()
|
||||
}*/
|
||||
private val lineParser = LineParser()
|
||||
|
||||
//Label点击事件
|
||||
var labelFunction: ((Int, View, String) -> Unit)? = null
|
||||
private val developerMode by lazy {
|
||||
AppSettings
|
||||
.getValue(AppSettings.Setting.DeveloperMode, false)
|
||||
}
|
||||
// var labelFunction: ((Int, View, String) -> Unit)? = null
|
||||
/* private val developerMode by lazy {
|
||||
AppSettings
|
||||
.getValue(AppSettings.Setting.DeveloperMode, false)
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 节名映射
|
||||
|
@ -207,15 +191,17 @@ class CodeTableAdapter(
|
|||
return group.size
|
||||
}
|
||||
|
||||
init {
|
||||
lineParser.symbol = ","
|
||||
}
|
||||
|
||||
companion object {
|
||||
var i: String = null.toString()
|
||||
var pick: Int = -1
|
||||
var pick: Int = 0
|
||||
var pickString: String = ""
|
||||
var picklist: MutableList<Int> = mutableListOf()
|
||||
}
|
||||
|
||||
var item: CodeTableItemAdapter? = null
|
||||
|
||||
init {
|
||||
lineParser.symbol = ","
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
|
@ -228,9 +214,14 @@ class CodeTableAdapter(
|
|||
holder.binging.message.text = format
|
||||
holder.itemView.setOnClickListener {
|
||||
i = group[position].translate
|
||||
item = ITEM(itemList[position])
|
||||
recyclerView.adapter = item
|
||||
notifyDataSetChanged()
|
||||
if (item != null) {
|
||||
item!!.list = itemList[position]
|
||||
binding.codeRecyclerB.adapter = item
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
if (!binding.edittext.text.isNullOrEmpty())
|
||||
binding.edittext.setText("")
|
||||
|
||||
// notifyItemChanged(p)
|
||||
}
|
||||
if (Objects.equal(group[position].translate, i)) {
|
||||
|
@ -242,167 +233,4 @@ class CodeTableAdapter(
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
var item: ITEM? = null
|
||||
|
||||
inner class ITEM(val list: List<CodeInfo>) : RecyclerView.Adapter<VH<CodeTableItemBinding>>() {
|
||||
|
||||
//在list查找是否有这个关键字
|
||||
fun search(keyword: String) {
|
||||
pickString = keyword
|
||||
for (i in list.indices) {
|
||||
if (list[i].translate.contains(keyword) || list[i].description.contains(keyword) || list[i].code.contains(keyword)) {
|
||||
//找到后列表定位 到顶部
|
||||
pick = i
|
||||
(recyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(i, 0)
|
||||
notifyDataSetChanged()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH<CodeTableItemBinding> {
|
||||
return VH(CodeTableItemBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return list.size
|
||||
}
|
||||
|
||||
private fun contains(string: String, textView: TextView) {
|
||||
if (string.contains(pickString)) {
|
||||
val spannableText = SpannableStringBuilder(string)
|
||||
val highlightWord = pickString
|
||||
val start = string.indexOf(highlightWord)
|
||||
val end = start + highlightWord.length
|
||||
if (start != -1) {
|
||||
// 设置文字颜色
|
||||
val colorSpan = ForegroundColorSpan(Color.RED)
|
||||
spannableText.setSpan(colorSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
// 设置背景颜色
|
||||
val backgroundSpan = BackgroundColorSpan(Color.YELLOW)
|
||||
spannableText.setSpan(backgroundSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
textView.text = spannableText
|
||||
} else {
|
||||
textView.text = string
|
||||
}
|
||||
com.muqing.gj.sc(pickString)
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
override fun onBindViewHolder(holder: VH<CodeTableItemBinding>, position: Int) {
|
||||
val resultView: CodeTableItemBinding = holder.binging
|
||||
val codeInfo = list[position]
|
||||
|
||||
contains(codeInfo.description, resultView.descriptionView)
|
||||
resultView.descriptionView.setOnClickListener {
|
||||
GlobalMethod.copyText(it.context, codeInfo.description, it)
|
||||
}
|
||||
|
||||
contains(codeInfo.translate, resultView.titleView)
|
||||
resultView.titleView.setOnClickListener {
|
||||
GlobalMethod.copyText(it.context, codeInfo.translate, it)
|
||||
}
|
||||
val demo = codeInfo.demo
|
||||
resultView.imageView.isVisible = demo.isNotBlank()
|
||||
resultView.imageView.setOnClickListener {
|
||||
val materialBottomDialog = MaterialBottomDialog(it.context)
|
||||
materialBottomDialog.setTitle(R.string.code_demo)
|
||||
materialBottomDialog.setMessage(demo)
|
||||
materialBottomDialog.show()
|
||||
}
|
||||
|
||||
contains(codeInfo.code, resultView.subTitleView)
|
||||
resultView.subTitleView.setOnClickListener {
|
||||
GlobalMethod.copyText(it.context, codeInfo.code, it)
|
||||
}
|
||||
resultView.valueTypeView.text = typeNameMap?.get(codeInfo.type) ?: codeInfo.type
|
||||
lineParser.text = codeInfo.section
|
||||
|
||||
// resultView.chipGroup.removeAllViews()
|
||||
var isNotEmpty = false
|
||||
lineParser.analyse { lineNum, lineData, isEnd ->
|
||||
isNotEmpty = true
|
||||
val text = sectionMap?.get(lineData) ?: lineData
|
||||
val chip = Chip(context)
|
||||
chip.text = text
|
||||
chip.setOnClickListener {
|
||||
labelFunction?.invoke(lineNum, it, text)
|
||||
}
|
||||
// resultView.chipGroup.addView(chip)
|
||||
true
|
||||
}
|
||||
|
||||
// resultView.chipGroup.isVisible = isNotEmpty
|
||||
resultView.valueTypeView.setOnClickListener {
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
executorService.submit {
|
||||
val codeDataBase = CodeDataBase.getInstance(context)
|
||||
val typeInfo = codeDataBase.getValueTypeDao().findTypeByType(codeInfo.type)
|
||||
|
||||
if (typeInfo == null) {
|
||||
handler.post {
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = codeInfo.type).message(
|
||||
text = String.format(
|
||||
context.getString(
|
||||
R.string.unknown_type
|
||||
), codeInfo.type
|
||||
)
|
||||
)
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (developerMode) {
|
||||
val stringBuilder = StringBuilder()
|
||||
stringBuilder.append("介绍:")
|
||||
stringBuilder.append(typeInfo.describe)
|
||||
stringBuilder.append("\n附加信息:")
|
||||
stringBuilder.append(typeInfo.external)
|
||||
stringBuilder.append("\n关联的自动提示:")
|
||||
stringBuilder.append(typeInfo.list)
|
||||
stringBuilder.append("\n光标偏差:")
|
||||
stringBuilder.append(typeInfo.offset)
|
||||
stringBuilder.append("\n标签:")
|
||||
stringBuilder.append(typeInfo.tag)
|
||||
stringBuilder.append("\n数据规则:")
|
||||
stringBuilder.append(typeInfo.rule)
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = typeInfo.name + "(开发者模式)").message(text = stringBuilder.toString())
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (typeInfo.describe == "@search(code)") {
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = typeInfo.name).message(text = codeInfo.description)
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = typeInfo.name).message(text = typeInfo.describe)
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resultView.versionView.text =
|
||||
versionMap?.get(codeInfo.addVersion) ?: codeInfo.addVersion.toString()
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,223 @@
|
|||
package com.coldmint.rust.pro.adapters
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Color
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.Spanned
|
||||
import android.text.style.BackgroundColorSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.coldmint.rust.core.database.code.CodeDataBase
|
||||
import com.coldmint.rust.core.database.code.CodeInfo
|
||||
import com.coldmint.rust.core.tool.LineParser
|
||||
import com.coldmint.rust.pro.R
|
||||
import com.coldmint.rust.pro.databinding.CodeTableItemBinding
|
||||
import com.coldmint.rust.pro.dialog.MaterialBottomDialog
|
||||
import com.coldmint.rust.pro.tool.AppSettings
|
||||
import com.coldmint.rust.pro.tool.GlobalMethod
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.muqing.VH
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class CodeTableItemAdapter(val recyclerView: RecyclerView,
|
||||
var list: List<CodeInfo>) : RecyclerView.Adapter<VH<CodeTableItemBinding>>() {
|
||||
|
||||
private val lineParser = LineParser()
|
||||
|
||||
init {
|
||||
lineParser.symbol = ","
|
||||
}
|
||||
|
||||
var labelFunction: ((Int, View, String) -> Unit)? = null
|
||||
var versionMap: HashMap<Int, String>? = null
|
||||
var typeNameMap: HashMap<String, String>? = null
|
||||
var sectionMap: HashMap<String, String>? = null
|
||||
private val executorService by lazy {
|
||||
Executors.newSingleThreadExecutor()
|
||||
}
|
||||
private val developerMode by lazy {
|
||||
AppSettings
|
||||
.getValue(AppSettings.Setting.DeveloperMode, false)
|
||||
}
|
||||
|
||||
//在list查找是否有这个关键字
|
||||
fun search(keyword: String) {
|
||||
CodeTableAdapter.pickString = keyword
|
||||
for (i in list.indices) {
|
||||
if (list[i].translate.contains(keyword) || list[i].description.contains(keyword) || list[i].code.contains(keyword)) {
|
||||
CodeTableAdapter.picklist.add(i)
|
||||
}
|
||||
}
|
||||
(recyclerView.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(CodeTableAdapter.pick, 0)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH<CodeTableItemBinding> {
|
||||
return VH(CodeTableItemBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return list.size
|
||||
}
|
||||
|
||||
private fun contains(string: String, textView: TextView) {
|
||||
if (string.contains(CodeTableAdapter.pickString)) {
|
||||
val spannableText = SpannableStringBuilder(string)
|
||||
val highlightWord = CodeTableAdapter.pickString
|
||||
val start = string.indexOf(highlightWord)
|
||||
val end = start + highlightWord.length
|
||||
if (start != -1) {
|
||||
// 设置文字颜色
|
||||
val colorSpan = ForegroundColorSpan(Color.RED)
|
||||
spannableText.setSpan(colorSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
// 设置背景颜色
|
||||
val backgroundSpan = BackgroundColorSpan(Color.YELLOW)
|
||||
spannableText.setSpan(backgroundSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
textView.text = spannableText
|
||||
} else {
|
||||
textView.text = string
|
||||
}
|
||||
}
|
||||
|
||||
private fun containsB(string: String, textView: TextView) {
|
||||
if (string.contains(CodeTableAdapter.pickString)) {
|
||||
val spannableText = SpannableStringBuilder(string)
|
||||
val highlightWord = CodeTableAdapter.pickString
|
||||
val start = string.indexOf(highlightWord)
|
||||
val end = start + highlightWord.length
|
||||
if (start != -1) {
|
||||
// 设置文字颜色
|
||||
val colorSpan = ForegroundColorSpan(Color.RED)
|
||||
spannableText.setSpan(colorSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
// 设置背景颜色
|
||||
val backgroundSpan = BackgroundColorSpan(Color.BLUE)
|
||||
spannableText.setSpan(backgroundSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
textView.text = spannableText
|
||||
} else {
|
||||
textView.text = string
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
override fun onBindViewHolder(holder: VH<CodeTableItemBinding>, position: Int) {
|
||||
val context = holder.itemView.context
|
||||
val resultView: CodeTableItemBinding = holder.binging
|
||||
val codeInfo = list[position]
|
||||
|
||||
contains(codeInfo.description, resultView.descriptionView)
|
||||
resultView.descriptionView.setOnClickListener {
|
||||
GlobalMethod.copyText(it.context, codeInfo.description, it)
|
||||
}
|
||||
contains(codeInfo.translate, resultView.titleView)
|
||||
resultView.titleView.setOnClickListener {
|
||||
GlobalMethod.copyText(it.context, codeInfo.translate, it)
|
||||
}
|
||||
val demo = codeInfo.demo
|
||||
resultView.imageView.isVisible = demo.isNotBlank()
|
||||
resultView.imageView.setOnClickListener {
|
||||
val materialBottomDialog = MaterialBottomDialog(it.context)
|
||||
materialBottomDialog.setTitle(R.string.code_demo)
|
||||
materialBottomDialog.setMessage(demo)
|
||||
materialBottomDialog.show()
|
||||
}
|
||||
contains(codeInfo.code, resultView.subTitleView)
|
||||
resultView.subTitleView.setOnClickListener {
|
||||
GlobalMethod.copyText(it.context, codeInfo.code, it)
|
||||
}
|
||||
|
||||
resultView.valueTypeView.text = typeNameMap?.get(codeInfo.type) ?: codeInfo.type
|
||||
lineParser.text = codeInfo.section
|
||||
|
||||
var isNotEmpty = false
|
||||
lineParser.analyse { lineNum, lineData, isEnd ->
|
||||
isNotEmpty = true
|
||||
val text = sectionMap?.get(lineData) ?: lineData
|
||||
val chip = Chip(context)
|
||||
chip.text = text
|
||||
chip.setOnClickListener {
|
||||
labelFunction?.invoke(lineNum, it, text)
|
||||
}
|
||||
// resultView.chipGroup.addView(chip)
|
||||
true
|
||||
}
|
||||
|
||||
// resultView.chipGroup.isVisible = isNotEmpty
|
||||
resultView.valueTypeView.setOnClickListener {
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
executorService.submit {
|
||||
val codeDataBase = CodeDataBase.getInstance(context)
|
||||
val typeInfo = codeDataBase.getValueTypeDao().findTypeByType(codeInfo.type)
|
||||
|
||||
if (typeInfo == null) {
|
||||
handler.post {
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = codeInfo.type).message(
|
||||
text = String.format(
|
||||
context.getString(
|
||||
R.string.unknown_type
|
||||
), codeInfo.type
|
||||
)
|
||||
)
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (developerMode) {
|
||||
val stringBuilder = StringBuilder()
|
||||
stringBuilder.append("介绍:")
|
||||
stringBuilder.append(typeInfo.describe)
|
||||
stringBuilder.append("\n附加信息:")
|
||||
stringBuilder.append(typeInfo.external)
|
||||
stringBuilder.append("\n关联的自动提示:")
|
||||
stringBuilder.append(typeInfo.list)
|
||||
stringBuilder.append("\n光标偏差:")
|
||||
stringBuilder.append(typeInfo.offset)
|
||||
stringBuilder.append("\n标签:")
|
||||
stringBuilder.append(typeInfo.tag)
|
||||
stringBuilder.append("\n数据规则:")
|
||||
stringBuilder.append(typeInfo.rule)
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = typeInfo.name + "(开发者模式)").message(text = stringBuilder.toString())
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (typeInfo.describe == "@search(code)") {
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = typeInfo.name).message(text = codeInfo.description)
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handler.post {
|
||||
MaterialDialog(context).show {
|
||||
title(text = typeInfo.name).message(text = typeInfo.describe)
|
||||
.positiveButton(R.string.dialog_ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resultView.versionView.text =
|
||||
versionMap?.get(codeInfo.addVersion) ?: codeInfo.addVersion.toString()
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.coldmint.rust.pro.databean
|
||||
data class LocaTion(var i: Int, var p: Int,
|
||||
var text: List<String>){
|
||||
lateinit var listInt : List<Int>
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -68,15 +68,19 @@
|
|||
tools:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/listTop"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="3dp"
|
||||
android:padding="9dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:src="@drawable/animator_expand_on" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/listButtom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?selectableItemBackground"
|
||||
android:padding="9dp"
|
||||
android:src="@drawable/animator_expand_off" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue
Block a user