Add package name and class name to custom intent search action
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -130,10 +130,8 @@ as data (URI) or as an extra:
|
||||
that
|
||||
is used
|
||||
to store the search term in the intent's extras. For example, you could use the key
|
||||
`android.intent.extra.TEXT` to create an intent that shares the search term as text. You can
|
||||
also
|
||||
provide a template to format the extra value. Again, use the placeholder `${1}` to include the
|
||||
search term in the template.
|
||||
`android.intent.extra.TEXT`. You can also provide a template to format the extra value. Again, use
|
||||
the placeholder `${1}` to include the search term in the template.
|
||||
|
||||
#### Base intent
|
||||
|
||||
@@ -151,6 +149,12 @@ The base intent defines the action.
|
||||
- **Data**:
|
||||
The [data URI](https://developer.android.com/reference/android/content/Intent#setData(android.net.Uri))
|
||||
of the intent. Only used if the search term is not passed as data.
|
||||
- **Package**:
|
||||
The [package](https://developer.android.com/reference/android/content/Intent#setPackage(java.lang.String))
|
||||
of the intent.
|
||||
- **Class name**:
|
||||
The [component class name](https://developer.android.com/reference/android/content/Intent#setClassName(java.lang.String,%20java.lang.String), java.lang.String))
|
||||
of the intent. Requires a package to be set.
|
||||
|
||||
#### Advanced settings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user