修复代码表搜索的的错误

This commit is contained in:
muqing 2024-07-22 19:22:11 +08:00
parent 05331665f9
commit e2cef38c2e
3 changed files with 16 additions and 23 deletions

View File

@ -1,5 +1,6 @@
package com.coldmint.rust.pro
import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.text.Editable
@ -21,8 +22,6 @@ 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>() {
@ -48,10 +47,10 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
(viewBinding.codeRecyclerB.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(get, 0)
}
viewBinding.listButtom.setOnClickListener {
val size = CodeTableAdapter.picklist.size
if (CodeTableAdapter.picklist.isEmpty()) {
return@setOnClickListener
}
val size = CodeTableAdapter.picklist.size
if (++CodeTableAdapter.pick == size - 1) {
CodeTableAdapter.pick = 0
@ -72,7 +71,7 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
loadData(a.toString())*/
if (a.isNullOrEmpty()) {
viewBinding.searchPick.isVisible = false
// loadData()
loadData()
}
}
@ -112,14 +111,6 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
*/
private fun ifNeedFinish() {
if (filterMode) {
loadData()
} else {
finish()
}
}
/**
* 加载数据
* @param key String?
@ -215,6 +206,7 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
* 没有找到节
* @param key String?
*/
@SuppressLint("StringFormatInvalid")
private fun notFindKey(key: String?) {
if (!key.isNullOrBlank()) {
val tip = String.format(getString(R.string.not_find_code_name), key)
@ -245,9 +237,10 @@ class CodeTableActivity : BaseActivity<ActivityCodeTableBinding>() {
return true
}
@Deprecated("Deprecated in Java", ReplaceWith("moveTaskToBack(true)"))
override fun onBackPressed() {
//显示桌面
moveTaskToBack(true);
moveTaskToBack(true)
// ifNeedFinish()
}

View File

@ -2,10 +2,8 @@ package com.coldmint.rust.pro.adapters
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.coldmint.rust.core.database.code.CodeInfo
import com.coldmint.rust.core.database.code.SectionInfo
@ -205,7 +203,7 @@ class CodeTableAdapter(
lineParser.symbol = ","
}
@SuppressLint("StringFormatInvalid")
@SuppressLint("NotifyDataSetChanged", "StringFormatInvalid")
override fun onBindViewHolder(holder: VH<ItemCodetableBinding>, position: Int) {
holder.binging.title.text = group[position].translate
val format = String.format(
@ -215,14 +213,14 @@ class CodeTableAdapter(
holder.binging.message.text = format
holder.itemView.setOnClickListener {
i = group[position].translate
pick = 0
pickString = ""
picklist.clear()
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)) {

View File

@ -52,6 +52,8 @@ class CodeTableItemAdapter(val recyclerView: RecyclerView,
//在list查找是否有这个关键字
fun search(keyword: String) {
CodeTableAdapter.pickString = keyword
CodeTableAdapter.pick = 0
CodeTableAdapter.picklist.clear()
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)