Add custom intent action settings
This commit is contained in:
parent
d5b58df6af
commit
766758a09d
@ -582,9 +582,11 @@ fun CustomizeAppSearch(viewModel: EditSearchActionSheetVM) {
|
|||||||
fun CustomizeCustomIntent(viewModel: EditSearchActionSheetVM) {
|
fun CustomizeCustomIntent(viewModel: EditSearchActionSheetVM) {
|
||||||
val searchAction by viewModel.searchAction
|
val searchAction by viewModel.searchAction
|
||||||
|
|
||||||
if (searchAction != null) {
|
val action = searchAction
|
||||||
|
|
||||||
|
if (action is CustomIntentActionBuilder) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.verticalScroll(rememberScrollState())
|
modifier = Modifier.verticalScroll(rememberScrollState()).fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.Bottom
|
verticalAlignment = Alignment.Bottom
|
||||||
@ -600,11 +602,59 @@ fun CustomizeCustomIntent(viewModel: EditSearchActionSheetVM) {
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(start = 16.dp),
|
.padding(start = 16.dp),
|
||||||
value = searchAction!!.label,
|
value = action.label,
|
||||||
onValueChange = { viewModel.setLabel(it) },
|
onValueChange = { viewModel.setLabel(it) },
|
||||||
label = { Text(stringResource(R.string.search_action_label)) },
|
label = { Text(stringResource(R.string.search_action_label)) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 16.dp),
|
||||||
|
value = action.baseIntent.action ?: "",
|
||||||
|
onValueChange = { viewModel.setIntentAction(it) },
|
||||||
|
label = { Text("Action") },
|
||||||
|
)
|
||||||
|
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 8.dp),
|
||||||
|
value = action.baseIntent.categories?.firstOrNull() ?: "",
|
||||||
|
onValueChange = { viewModel.setIntentCategory(it) },
|
||||||
|
label = { Text("Category") },
|
||||||
|
)
|
||||||
|
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 8.dp),
|
||||||
|
value = action.queryKey,
|
||||||
|
onValueChange = { viewModel.setIntentQueryExtra(it) },
|
||||||
|
label = { Text("Extra key") },
|
||||||
|
supportingText = {
|
||||||
|
Text("The key of the string extra that the search term is passed as.")
|
||||||
|
},
|
||||||
|
isError = viewModel.customIntentKeyError.value
|
||||||
|
)
|
||||||
|
|
||||||
|
var showAdvanced by remember {
|
||||||
|
mutableStateOf(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimatedVisibility(!showAdvanced) {
|
||||||
|
TextButton(
|
||||||
|
modifier = Modifier.padding(top = 16.dp),
|
||||||
|
onClick = { showAdvanced = true }) {
|
||||||
|
Text(stringResource(id = R.string.websearch_dialog_advanced))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimatedVisibility(showAdvanced) {
|
||||||
|
IntentExtrasEditor(viewModel)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import de.mm20.launcher2.searchactions.builders.AppSearchActionBuilder
|
|||||||
import de.mm20.launcher2.searchactions.builders.CustomIntentActionBuilder
|
import de.mm20.launcher2.searchactions.builders.CustomIntentActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.CustomizableSearchActionBuilder
|
import de.mm20.launcher2.searchactions.builders.CustomizableSearchActionBuilder
|
||||||
import de.mm20.launcher2.searchactions.builders.WebsearchActionBuilder
|
import de.mm20.launcher2.searchactions.builders.WebsearchActionBuilder
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -44,6 +43,7 @@ class EditSearchActionSheetVM : ViewModel(), KoinComponent {
|
|||||||
currentPage.value = when (searchAction) {
|
currentPage.value = when (searchAction) {
|
||||||
is AppSearchActionBuilder -> EditSearchActionPage.CustomizeAppSearch
|
is AppSearchActionBuilder -> EditSearchActionPage.CustomizeAppSearch
|
||||||
is WebsearchActionBuilder -> EditSearchActionPage.CustomizeWebSearch
|
is WebsearchActionBuilder -> EditSearchActionPage.CustomizeWebSearch
|
||||||
|
is CustomIntentActionBuilder -> EditSearchActionPage.CustomizeCustomIntent
|
||||||
else -> EditSearchActionPage.SelectType
|
else -> EditSearchActionPage.SelectType
|
||||||
}
|
}
|
||||||
createNew.value = searchAction == null
|
createNew.value = searchAction == null
|
||||||
@ -181,6 +181,7 @@ class EditSearchActionSheetVM : ViewModel(), KoinComponent {
|
|||||||
|
|
||||||
private val invalidWebsearchUrl = mutableStateOf<String?>(null)
|
private val invalidWebsearchUrl = mutableStateOf<String?>(null)
|
||||||
val websearchInvalidUrlError = derivedStateOf { invalidWebsearchUrl.value == (searchAction.value as? WebsearchActionBuilder)?.urlTemplate }
|
val websearchInvalidUrlError = derivedStateOf { invalidWebsearchUrl.value == (searchAction.value as? WebsearchActionBuilder)?.urlTemplate }
|
||||||
|
val customIntentKeyError = mutableStateOf(false)
|
||||||
fun validate() : Boolean {
|
fun validate() : Boolean {
|
||||||
val action = searchAction.value ?: return false
|
val action = searchAction.value ?: return false
|
||||||
|
|
||||||
@ -189,6 +190,11 @@ class EditSearchActionSheetVM : ViewModel(), KoinComponent {
|
|||||||
invalidWebsearchUrl.value = if(valid) null else action.urlTemplate
|
invalidWebsearchUrl.value = if(valid) null else action.urlTemplate
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
|
if (action is CustomIntentActionBuilder) {
|
||||||
|
val valid = action.queryKey.isNotBlank()
|
||||||
|
customIntentKeyError.value = !valid
|
||||||
|
return valid
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,6 +417,46 @@ class EditSearchActionSheetVM : ViewModel(), KoinComponent {
|
|||||||
else -> action
|
else -> action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setIntentAction(action: 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)
|
||||||
|
it.action = action
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else -> searchAction
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setIntentCategory(category: String) {
|
||||||
|
val action = searchAction.value ?: return
|
||||||
|
searchAction.value = when(action) {
|
||||||
|
is CustomIntentActionBuilder -> action.copy(
|
||||||
|
baseIntent = action.baseIntent.cloneFilter().also {
|
||||||
|
val extras = action.baseIntent.extras?.deepCopy() ?: Bundle()
|
||||||
|
it.replaceExtras(extras)
|
||||||
|
val oldCategory = it.categories?.firstOrNull()
|
||||||
|
if (oldCategory != null) it.removeCategory(oldCategory)
|
||||||
|
if (category.isNotBlank()) it.addCategory(category)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else -> action
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setIntentQueryExtra(key: String) {
|
||||||
|
val action = searchAction.value ?: return
|
||||||
|
searchAction.value = when(action) {
|
||||||
|
is CustomIntentActionBuilder -> action.copy(
|
||||||
|
queryKey = key,
|
||||||
|
)
|
||||||
|
else -> action
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class EditSearchActionPage {
|
enum class EditSearchActionPage {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user