修复代码表搜索的的错误

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

View File

@ -2,10 +2,8 @@ package com.coldmint.rust.pro.adapters
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.coldmint.rust.core.database.code.CodeInfo import com.coldmint.rust.core.database.code.CodeInfo
import com.coldmint.rust.core.database.code.SectionInfo import com.coldmint.rust.core.database.code.SectionInfo
@ -205,32 +203,32 @@ class CodeTableAdapter(
lineParser.symbol = "," lineParser.symbol = ","
} }
@SuppressLint("StringFormatInvalid") @SuppressLint("NotifyDataSetChanged", "StringFormatInvalid")
override fun onBindViewHolder(holder: VH<ItemCodetableBinding>, position: Int) { override fun onBindViewHolder(holder: VH<ItemCodetableBinding>, position: Int) {
holder.binging.title.text = group[position].translate holder.binging.title.text = group[position].translate
val format = String.format( val format = String.format(
context.getString(R.string.filenum), context.getString(R.string.filenum),
itemList[position].size itemList[position].size
) )
holder.binging.message.text = format holder.binging.message.text = format
holder.itemView.setOnClickListener { holder.itemView.setOnClickListener {
i = group[position].translate i = group[position].translate
pick = 0
pickString = ""
picklist.clear()
if (item != null) { if (item != null) {
item!!.list = itemList[position] item!!.list = itemList[position]
binding.codeRecyclerB.adapter = item binding.codeRecyclerB.adapter = item
notifyDataSetChanged() notifyDataSetChanged()
} }
if (!binding.edittext.text.isNullOrEmpty())
binding.edittext.setText("")
// notifyItemChanged(p) // notifyItemChanged(p)
} }
if (Objects.equal(group[position].translate, i)) { if (Objects.equal(group[position].translate, i)) {
//背景高亮 //背景高亮
holder.binging.root.setCardBackgroundColor(GlobalMethod.getThemeColor(context,R.attr.colorPrimaryContainer)) holder.binging.root.setCardBackgroundColor(GlobalMethod.getThemeColor(context, R.attr.colorPrimaryContainer))
} else { } else {
//背景恢复 //背景恢复
holder.binging.root.setCardBackgroundColor(GlobalMethod.getThemeColor(context,R.attr.colorSurface)) holder.binging.root.setCardBackgroundColor(GlobalMethod.getThemeColor(context, R.attr.colorSurface))
} }
} }

View File

@ -52,6 +52,8 @@ class CodeTableItemAdapter(val recyclerView: RecyclerView,
//在list查找是否有这个关键字 //在list查找是否有这个关键字
fun search(keyword: String) { fun search(keyword: String) {
CodeTableAdapter.pickString = keyword CodeTableAdapter.pickString = keyword
CodeTableAdapter.pick = 0
CodeTableAdapter.picklist.clear()
for (i in list.indices) { for (i in list.indices) {
if (list[i].translate.contains(keyword) || list[i].description.contains(keyword) || list[i].code.contains(keyword)) { if (list[i].translate.contains(keyword) || list[i].description.contains(keyword) || list[i].code.contains(keyword)) {
CodeTableAdapter.picklist.add(i) CodeTableAdapter.picklist.add(i)