Skip to content

Commit

Permalink
Fix search in Dex Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza417 committed Dec 21, 2024
1 parent b7b07ad commit 7fa21c7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.simple.inure.adapters.viewers

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -92,6 +93,13 @@ class AdapterDexData(private val dexs: ArrayList<String>, val keyword: String) :
return dexs.size
}

@SuppressLint("NotifyDataSetChanged")
fun updateData(it: java.util.ArrayList<String>?) {
dexs.clear()
dexs.addAll(it!!)
notifyDataSetChanged()
}

inner class Holder(itemView: View) : VerticalListViewHolder(itemView) {
val name: CondensedDynamicRippleTextView = itemView.findViewById(R.id.adapter_resources_name)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.simple.inure.ui.viewers
import android.content.SharedPreferences
import android.content.pm.PackageInfo
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -19,7 +20,7 @@ import app.simple.inure.preferences.DexClassesPreferences
import app.simple.inure.util.NullSafety.isNull
import app.simple.inure.viewmodels.viewers.DexDataViewModel

class Dexs : SearchBarScopedFragment() {
class DexClasses : SearchBarScopedFragment() {

private lateinit var dexDataViewModel: DexDataViewModel
private lateinit var packageInfoFactory: PackageInfoFactory
Expand Down Expand Up @@ -61,11 +62,15 @@ class Dexs : SearchBarScopedFragment() {
}

recyclerView.adapter = adapter
} else {
(recyclerView.adapter as AdapterDexData).updateData(it)
}
}

searchBox.doOnTextChanged { text, _, _, _ ->
Log.d("DexClasses", "onViewCreated: $text")
if (searchBox.isFocused) {
Log.d("DexClasses", "Doin it")
dexDataViewModel.filterClasses(text.toString().trim())
}
}
Expand All @@ -92,10 +97,10 @@ class Dexs : SearchBarScopedFragment() {
}

companion object {
fun newInstance(packageInfo: PackageInfo): Dexs {
fun newInstance(packageInfo: PackageInfo): DexClasses {
val args = Bundle()
args.putParcelable(BundleConstants.packageInfo, packageInfo)
val fragment = Dexs()
val fragment = DexClasses()
fragment.arguments = args
return fragment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ class DexDataViewModel(application: Application, private val packageInfo: Packag
}

fun filterClasses(query: String) {
val filteredClasses = ArrayList<String>()
viewModelScope.launch(Dispatchers.Default) {
val filteredClasses = ArrayList<String>()

for (className in classes) {
if (className.contains(query, true)) {
filteredClasses.add(className)
for (className in classes) {
if (className.lowercase().contains(query.lowercase(), true)) {
filteredClasses.add(className)
}
}
}

dexData.postValue(filteredClasses)
dexData.postValue(filteredClasses)
}
}
}

0 comments on commit 7fa21c7

Please sign in to comment.