From 57c3703fb5effd0f096e193eb7700ac274afb5ba Mon Sep 17 00:00:00 2001 From: Hamza417 <23103729+Hamza417@users.noreply.github.com> Date: Sun, 22 Dec 2024 13:19:44 +0530 Subject: [PATCH] Option to filter tracker only Dex Classes --- .../viewmodels/viewers/DexDataViewModel.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt b/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt index 03a3c5258..47bb7465f 100644 --- a/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt +++ b/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt @@ -2,7 +2,6 @@ package app.simple.inure.viewmodels.viewers import android.app.Application import android.content.pm.PackageInfo -import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import app.simple.inure.extensions.viewmodels.WrappedViewModel @@ -63,7 +62,6 @@ class DexDataViewModel(application: Application, private val packageInfo: Packag private fun getClassesOfPackage(packageName: String): ArrayList { val appContext = applicationContext().createPackageContext(packageName, 0) val packageCodePath: String = appContext.packageCodePath - Log.d("DexDataViewModel", "Package code path: $packageCodePath") val dexFile = DexFile(packageCodePath) val enumeration = dexFile.entries() @@ -78,20 +76,24 @@ class DexDataViewModel(application: Application, private val packageInfo: Packag fun filterClasses(query: String) { viewModelScope.launch(Dispatchers.Default) { runCatching { - if (query.isEmpty()) { - val filteredClasses = ArrayList() - - for (dexClass in backup) { - if (dexClass.className.lowercase().contains(query.lowercase(), true)) { - filteredClasses.add(dexClass) - } + if (query.isNotEmpty()) { + if (TRACKER.contains(query.lowercase())) { + dexData.postValue(ArrayList(backup.filter { + it.isTracker + })) + } else { + dexData.postValue(ArrayList(backup.filter { + it.className.lowercase().contains(query.lowercase(), true) + })) } - - dexData.postValue(filteredClasses) } else { dexData.postValue(backup) } } } } + + companion object { + private val TRACKER = arrayOf("tracker", "trackers") + } }