Add possibility to add custom extras to app search actions
This commit is contained in:
+4
-3
@@ -4,11 +4,12 @@ import android.app.SearchManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import de.mm20.launcher2.ktx.tryStartActivity
|
||||
|
||||
data class AppSearchAction(
|
||||
override val label: String,
|
||||
val componentName: ComponentName,
|
||||
val baseIntent: Intent,
|
||||
val query: String,
|
||||
override val icon: SearchActionIcon = SearchActionIcon.Custom,
|
||||
override val iconColor: Int = 1,
|
||||
@@ -16,8 +17,8 @@ data class AppSearchAction(
|
||||
): SearchAction {
|
||||
|
||||
override fun start(context: Context) {
|
||||
val intent = Intent(Intent.ACTION_SEARCH).apply {
|
||||
component = componentName
|
||||
val intent = Intent(baseIntent).apply {
|
||||
action = Intent.ACTION_SEARCH
|
||||
putExtra(SearchManager.QUERY, query)
|
||||
putExtra(SearchManager.USER_QUERY, query)
|
||||
}
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ import de.mm20.launcher2.ktx.tryStartActivity
|
||||
class CustomIntentAction(
|
||||
override val label: String,
|
||||
val query: String,
|
||||
val queryKey: String,
|
||||
val baseIntent: Intent,
|
||||
private val queryKey: String,
|
||||
private val baseIntent: Intent,
|
||||
override val icon: SearchActionIcon = SearchActionIcon.Custom,
|
||||
override val iconColor: Int = 1,
|
||||
override val customIcon: String? = null,
|
||||
|
||||
+6
-4
@@ -2,6 +2,8 @@ package de.mm20.launcher2.searchactions.builders
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import de.mm20.launcher2.searchactions.TextClassificationResult
|
||||
import de.mm20.launcher2.searchactions.TextType
|
||||
import de.mm20.launcher2.searchactions.actions.AppSearchAction
|
||||
@@ -10,18 +12,18 @@ import de.mm20.launcher2.searchactions.actions.SearchActionIcon
|
||||
|
||||
data class AppSearchActionBuilder(
|
||||
override val label: String,
|
||||
val componentName: ComponentName,
|
||||
val baseIntent: Intent,
|
||||
override val icon: SearchActionIcon = SearchActionIcon.Custom,
|
||||
override val iconColor: Int = 0,
|
||||
override val customIcon: String? = null,
|
||||
) : CustomizableSearchActionBuilder {
|
||||
|
||||
override val key: String
|
||||
get() = "app://${componentName.flattenToShortString()}"
|
||||
override fun build(context: Context, classifiedQuery: TextClassificationResult): SearchAction? {
|
||||
get() = "app://${baseIntent.toUri(0)}"
|
||||
override fun build(context: Context, classifiedQuery: TextClassificationResult): SearchAction {
|
||||
return AppSearchAction(
|
||||
label = label,
|
||||
componentName = componentName,
|
||||
baseIntent = baseIntent,
|
||||
query = classifiedQuery.text,
|
||||
icon = icon,
|
||||
iconColor = iconColor,
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ interface SearchActionBuilder {
|
||||
"app" -> {
|
||||
return AppSearchActionBuilder(
|
||||
label = entity.label ?: "",
|
||||
componentName = ComponentName.unflattenFromString(entity.data ?: return null) ?: return null,
|
||||
baseIntent = Intent.parseUri(entity.data, 0),
|
||||
iconColor = entity.color ?: 0,
|
||||
icon = SearchActionIcon.fromInt(entity.icon),
|
||||
customIcon = entity.customIcon,
|
||||
@@ -92,7 +92,7 @@ interface SearchActionBuilder {
|
||||
position = position,
|
||||
type = "app",
|
||||
label = builder.label,
|
||||
data = builder.componentName.flattenToShortString(),
|
||||
data = builder.baseIntent.toUri(0),
|
||||
color = builder.iconColor,
|
||||
icon = builder.icon.toInt(),
|
||||
customIcon = builder.customIcon,
|
||||
|
||||
Reference in New Issue
Block a user