Skip to content

Commit

Permalink
Add basic search
Browse files Browse the repository at this point in the history
  • Loading branch information
felschr authored and soupslurpr committed Jan 30, 2024
1 parent f07f88f commit 12c9b1b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/src/main/kotlin/dev/soupslurpr/appverifier/AppVerifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ fun AppVerifierApp(
}
composable(route = AppVerifierScreens.AppList.name) {
AppListScreen(
verifyAppUiState.value.searchQuery.value,
{ name: String, packageName: String, hashes: Hashes, icon: Drawable, internalDatabaseInfo:
InternalDatabaseInfo ->
verifyAppViewModel.setAppVerificationInfo(
Expand All @@ -152,6 +153,9 @@ fun AppVerifierApp(
navController.navigate(AppVerifierScreens.VerifyApp.name)
},
{ verifyAppViewModel.clearUiState() },
{ verifyAppViewModel.setSearchQuery(it) },
{ },
{ },
{ verifyAppViewModel.getHashesFromPackageInfo(it) },
{ verifyAppViewModel.getInternalDatabaseInfoFromVerificationInfo(it) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ data class VerifyAppUiState(
listOf(Source.NONE)
)
),
val searchQuery: MutableState<String> = mutableStateOf(""),
)


Expand Down
24 changes: 22 additions & 2 deletions app/src/main/kotlin/dev/soupslurpr/appverifier/ui/AppListScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.Verified
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.ListItem
import androidx.compose.material3.SearchBar
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -31,8 +33,10 @@ import dev.soupslurpr.appverifier.data.InternalDatabaseStatus
import dev.soupslurpr.appverifier.data.SimpleVerificationStatus
import dev.soupslurpr.appverifier.data.VerificationInfo

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppListScreen(
searchQuery: String,
onClickAppItem: (
name: String,
packageName: String,
Expand All @@ -41,6 +45,9 @@ fun AppListScreen(
internalDatabaseInfo: InternalDatabaseInfo,
) -> Unit,
onLaunchedEffect: () -> Unit,
onQueryChange: (query: String) -> Unit,
onSearch: (query: String) -> Unit,
onSearchActiveChange: (active: Boolean) -> Unit,
getHashesFromPackageInfo: (packageInfo: PackageInfo) -> Hashes,
getInternalDatabaseInfoFromVerificationInfo: (verification: VerificationInfo) -> InternalDatabaseInfo,
) {
Expand All @@ -63,10 +70,23 @@ fun AppListScreen(
}

LazyColumn {
item {
SearchBar(
modifier = Modifier.padding(horizontal = 24.dp),
query = searchQuery,
onQueryChange = onQueryChange,
onSearch = onSearch,
active = false,
onActiveChange = onSearchActiveChange,
) {}
}
items(userInstalledPackages) {
// Do not show AppVerifier in the list as there is no point in using it to verify itself.
if (it.packageName != context.packageName) {
val packageInfo = packageManager.getPackageInfo(it.packageName, PackageManager.GET_SIGNING_CERTIFICATES)
if (it.packageName != context.packageName &&
(searchQuery == "" || it.packageName.contains(searchQuery))
) {
val packageInfo =
packageManager.getPackageInfo(it.packageName, PackageManager.GET_SIGNING_CERTIFICATES)

val hashes = getHashesFromPackageInfo(packageInfo)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class VerifyAppViewModel(application: Application) : AndroidViewModel(applicatio

return parseVerificationInfoTextToVerificationStatus(getVerificationInfoText(text))
}
fun setSearchQuery(query: String): Unit {
uiState.value.searchQuery.value = query
}

fun getHashesFromPackageInfo(packageInfo: PackageInfo): Hashes {
val signingInfo = packageInfo.signingInfo
Expand Down

0 comments on commit 12c9b1b

Please sign in to comment.