Add package name and class name to custom intent search action

This commit is contained in:
MM20
2025-09-27 13:12:59 +02:00
parent 17cf32e72f
commit 5d022d0a5f
3 changed files with 75 additions and 4 deletions

View File

@@ -789,6 +789,30 @@ fun CustomizeCustomIntent(viewModel: EditSearchActionSheetVM) {
singleLine = true,
)
val packageName = action.baseIntent.component?.packageName ?: action.baseIntent.`package`
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp),
value = packageName ?: "",
onValueChange = { viewModel.setIntentPackage(it) },
label = { Text("Package") },
singleLine = true,
)
AnimatedVisibility(packageName != null) {
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp),
value = action.baseIntent.component?.className ?: "",
onValueChange = { viewModel.setIntentClassName(it) },
label = { Text("Class name") },
singleLine = true,
)
}
var showAdvanced by remember {
mutableStateOf(false)

View File

@@ -521,6 +521,49 @@ class EditSearchActionSheetVM : ViewModel(), KoinComponent {
}
}
fun setIntentPackage(pkg: String) {
val searchAction = searchAction.value ?: return
this.searchAction.value = when (searchAction) {
is CustomIntentActionBuilder -> searchAction.copy(
baseIntent = searchAction.baseIntent.cloneFilter().also {
val extras = searchAction.baseIntent.extras?.deepCopy() ?: Bundle()
it.replaceExtras(extras)
if (pkg.isBlank()) {
it.`package` = null
it.component = null
} else if (it.component != null) {
it.component = ComponentName(pkg, it.component!!.className)
} else {
it.`package` = pkg
}
},
)
else -> searchAction
}
}
fun setIntentClassName(className: String) {
val searchAction = searchAction.value ?: return
this.searchAction.value = when (searchAction) {
is CustomIntentActionBuilder -> searchAction.copy(
baseIntent = searchAction.baseIntent.cloneFilter().also {
val extras = searchAction.baseIntent.extras?.deepCopy() ?: Bundle()
it.replaceExtras(extras)
val pkg = it.component?.packageName ?: it.`package`
if (className.isBlank()) {
it.`package` = pkg
it.component = null
} else if (pkg != null) {
it.`package` = null
it.component = ComponentName(pkg, className)
}
},
)
else -> searchAction
}
}
fun setQueryKey(key: String?) {
val action = searchAction.value ?: return
searchAction.value = when (action) {