mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Allow changing name of custom web search suggestions
This commit is contained in:
@@ -803,4 +803,5 @@
|
|||||||
<string name="warn_contact_permission_content">To search for contacts, grant contacts and phone permissions to Lawnchair</string>
|
<string name="warn_contact_permission_content">To search for contacts, grant contacts and phone permissions to Lawnchair</string>
|
||||||
<string name="warn_files_permission_content">To search your files, grant storage permissions to Lawnchair</string>
|
<string name="warn_files_permission_content">To search your files, grant storage permissions to Lawnchair</string>
|
||||||
<string name="grant_requested_permissions">Grant permissions</string>
|
<string name="grant_requested_permissions">Grant permissions</string>
|
||||||
|
<string name="custom_search_label">Custom search engine name</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -513,6 +513,11 @@ class PreferenceManager2 private constructor(private val context: Context) :
|
|||||||
defaultValue = "https://google.com/complete/search?client=chrome&q=%s",
|
defaultValue = "https://google.com/complete/search?client=chrome&q=%s",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val webSuggestionProviderName = preference(
|
||||||
|
key = stringPreferencesKey(name = "web_suggestion_provider_name"),
|
||||||
|
defaultValue = context.resources.getString(R.string.custom),
|
||||||
|
)
|
||||||
|
|
||||||
val maxAppSearchResultCount = preference(
|
val maxAppSearchResultCount = preference(
|
||||||
key = intPreferencesKey(name = "max_search_result_count"),
|
key = intPreferencesKey(name = "max_search_result_count"),
|
||||||
defaultValue = resourceProvider.getInt(R.dimen.config_default_search_max_result_count),
|
defaultValue = resourceProvider.getInt(R.dimen.config_default_search_max_result_count),
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import android.os.Process
|
|||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import androidx.core.net.toUri
|
||||||
import androidx.core.os.bundleOf
|
import androidx.core.os.bundleOf
|
||||||
import app.lawnchair.allapps.views.SearchResultView
|
import app.lawnchair.allapps.views.SearchResultView
|
||||||
import app.lawnchair.search.algorithms.data.Calculation
|
import app.lawnchair.search.algorithms.data.Calculation
|
||||||
@@ -73,7 +74,7 @@ class SearchTargetFactory(
|
|||||||
fun createWebSuggestionsTarget(suggestion: String, suggestionProvider: String, suggestionUrl: String = ""): SearchTargetCompat {
|
fun createWebSuggestionsTarget(suggestion: String, suggestionProvider: String, suggestionUrl: String = ""): SearchTargetCompat {
|
||||||
val webSearchProvider = WebSearchProvider.fromString(suggestionProvider)
|
val webSearchProvider = WebSearchProvider.fromString(suggestionProvider)
|
||||||
val url = if (webSearchProvider is CustomWebSearchProvider) webSearchProvider.getCustomSearchUrl(suggestion, suggestionUrl) else webSearchProvider.getSearchUrl(suggestion)
|
val url = if (webSearchProvider is CustomWebSearchProvider) webSearchProvider.getCustomSearchUrl(suggestion, suggestionUrl) else webSearchProvider.getSearchUrl(suggestion)
|
||||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||||
val id = suggestion + url
|
val id = suggestion + url
|
||||||
val action = SearchActionCompat.Builder(id, suggestion).apply {
|
val action = SearchActionCompat.Builder(id, suggestion).apply {
|
||||||
setIcon(
|
setIcon(
|
||||||
@@ -143,7 +144,7 @@ class SearchTargetFactory(
|
|||||||
val value = recentKeyword.getValueByKey("display1") ?: ""
|
val value = recentKeyword.getValueByKey("display1") ?: ""
|
||||||
val webSearchProvider = WebSearchProvider.fromString(suggestionProvider)
|
val webSearchProvider = WebSearchProvider.fromString(suggestionProvider)
|
||||||
val url = if (webSearchProvider is CustomWebSearchProvider) webSearchProvider.getCustomSearchUrl(value, "%s") else webSearchProvider.getSearchUrl(value)
|
val url = if (webSearchProvider is CustomWebSearchProvider) webSearchProvider.getCustomSearchUrl(value, "%s") else webSearchProvider.getSearchUrl(value)
|
||||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||||
val id = recentKeyword.data.toString() + url
|
val id = recentKeyword.data.toString() + url
|
||||||
val action = SearchActionCompat.Builder(id, value)
|
val action = SearchActionCompat.Builder(id, value)
|
||||||
.setIcon(
|
.setIcon(
|
||||||
@@ -239,10 +240,16 @@ class SearchTargetFactory(
|
|||||||
internal fun createWebSearchTarget(
|
internal fun createWebSearchTarget(
|
||||||
query: String,
|
query: String,
|
||||||
suggestionProvider: String,
|
suggestionProvider: String,
|
||||||
|
suggestionName: String,
|
||||||
suggestionUrl: String = "",
|
suggestionUrl: String = "",
|
||||||
): SearchTargetCompat {
|
): SearchTargetCompat {
|
||||||
val webSearchProvider = WebSearchProvider.fromString(suggestionProvider)
|
val webSearchProvider = WebSearchProvider.fromString(suggestionProvider)
|
||||||
val webSearchLabel = context.getString(webSearchProvider.label)
|
val webSearchLabel =
|
||||||
|
if (webSearchProvider is CustomWebSearchProvider) {
|
||||||
|
suggestionName
|
||||||
|
} else {
|
||||||
|
context.getString(webSearchProvider.label)
|
||||||
|
}
|
||||||
val url =
|
val url =
|
||||||
if (webSearchProvider is CustomWebSearchProvider) {
|
if (webSearchProvider is CustomWebSearchProvider) {
|
||||||
webSearchProvider.getCustomSearchUrl(query, suggestionUrl)
|
webSearchProvider.getCustomSearchUrl(query, suggestionUrl)
|
||||||
@@ -250,12 +257,8 @@ class SearchTargetFactory(
|
|||||||
webSearchProvider.getSearchUrl(query)
|
webSearchProvider.getSearchUrl(query)
|
||||||
}
|
}
|
||||||
val id = "browser:$query"
|
val id = "browser:$query"
|
||||||
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
val browserIntent = Intent(Intent.ACTION_VIEW, url.toUri())
|
||||||
val string = if (webSearchProvider is CustomWebSearchProvider) {
|
val string = context.getString(R.string.all_apps_search_on_web_message, webSearchLabel)
|
||||||
context.getString(R.string.all_apps_search_on_web_general)
|
|
||||||
} else {
|
|
||||||
context.getString(R.string.all_apps_search_on_web_message, webSearchLabel)
|
|
||||||
}
|
|
||||||
val action = SearchActionCompat.Builder(id, string)
|
val action = SearchActionCompat.Builder(id, string)
|
||||||
.setIcon(Icon.createWithResource(context, webSearchProvider.iconRes))
|
.setIcon(Icon.createWithResource(context, webSearchProvider.iconRes))
|
||||||
.setIntent(browserIntent)
|
.setIntent(browserIntent)
|
||||||
@@ -275,7 +278,7 @@ class SearchTargetFactory(
|
|||||||
|
|
||||||
val contactIntent = Intent(Intent.ACTION_VIEW, contactUri)
|
val contactIntent = Intent(Intent.ACTION_VIEW, contactUri)
|
||||||
val action = SearchActionCompat.Builder(id, info.name)
|
val action = SearchActionCompat.Builder(id, info.name)
|
||||||
.setIcon(ContactsTarget.displayContactPhoto(context, info.name, Uri.parse(info.uri)))
|
.setIcon(ContactsTarget.displayContactPhoto(context, info.name, info.uri.toUri()))
|
||||||
.setContentDescription(info.contactId)
|
.setContentDescription(info.contactId)
|
||||||
.setSubtitle(info.number)
|
.setSubtitle(info.number)
|
||||||
.setIntent(contactIntent)
|
.setIntent(contactIntent)
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
|
|||||||
private var enableFuzzySearch = false
|
private var enableFuzzySearch = false
|
||||||
private var useWebSuggestions = true
|
private var useWebSuggestions = true
|
||||||
private var webSuggestionsProvider = ""
|
private var webSuggestionsProvider = ""
|
||||||
|
private var webSuggestionsProviderName = ""
|
||||||
private var webSuggestionsProviderUrl = ""
|
private var webSuggestionsProviderUrl = ""
|
||||||
private var webSuggestionProviderSuggestionsUrl = ""
|
private var webSuggestionProviderSuggestionsUrl = ""
|
||||||
|
|
||||||
@@ -108,6 +109,9 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
|
|||||||
pref2.webSuggestionProviderSuggestionsUrl.onEach(launchIn = coroutineScope) {
|
pref2.webSuggestionProviderSuggestionsUrl.onEach(launchIn = coroutineScope) {
|
||||||
webSuggestionProviderSuggestionsUrl = it
|
webSuggestionProviderSuggestionsUrl = it
|
||||||
}
|
}
|
||||||
|
pref2.webSuggestionProviderName.onEach(launchIn = coroutineScope) {
|
||||||
|
webSuggestionsProviderName = it
|
||||||
|
}
|
||||||
|
|
||||||
pref2.maxAppSearchResultCount.onEach(launchIn = coroutineScope) {
|
pref2.maxAppSearchResultCount.onEach(launchIn = coroutineScope) {
|
||||||
maxAppResultsCount = it
|
maxAppResultsCount = it
|
||||||
@@ -215,6 +219,7 @@ class LawnchairLocalSearchAlgorithm(context: Context) : LawnchairSearchAlgorithm
|
|||||||
searchTargetFactory.createWebSearchTarget(
|
searchTargetFactory.createWebSearchTarget(
|
||||||
query,
|
query,
|
||||||
webSuggestionsProvider,
|
webSuggestionsProvider,
|
||||||
|
webSuggestionsProviderName,
|
||||||
suggestionUrl,
|
suggestionUrl,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ private fun LocalSearchSettings(
|
|||||||
)
|
)
|
||||||
WebSearchProvider(
|
WebSearchProvider(
|
||||||
adapter = prefs2.webSuggestionProvider.getAdapter(),
|
adapter = prefs2.webSuggestionProvider.getAdapter(),
|
||||||
|
nameAdapter = prefs2.webSuggestionProviderName.getAdapter(),
|
||||||
urlAdapter = prefs2.webSuggestionProviderUrl.getAdapter(),
|
urlAdapter = prefs2.webSuggestionProviderUrl.getAdapter(),
|
||||||
suggestionsUrlAdapter = prefs2.webSuggestionProviderSuggestionsUrl.getAdapter(),
|
suggestionsUrlAdapter = prefs2.webSuggestionProviderSuggestionsUrl.getAdapter(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import com.android.launcher3.R
|
|||||||
@Composable
|
@Composable
|
||||||
fun WebSearchProvider(
|
fun WebSearchProvider(
|
||||||
adapter: PreferenceAdapter<WebSearchProvider>,
|
adapter: PreferenceAdapter<WebSearchProvider>,
|
||||||
|
nameAdapter: PreferenceAdapter<String>,
|
||||||
urlAdapter: PreferenceAdapter<String>,
|
urlAdapter: PreferenceAdapter<String>,
|
||||||
suggestionsUrlAdapter: PreferenceAdapter<String>,
|
suggestionsUrlAdapter: PreferenceAdapter<String>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
@@ -55,6 +56,13 @@ fun WebSearchProvider(
|
|||||||
label = stringResource(R.string.allapps_web_suggestion_provider_label),
|
label = stringResource(R.string.allapps_web_suggestion_provider_label),
|
||||||
)
|
)
|
||||||
if (adapter.state.value == WebSearchProvider.fromString("custom")) {
|
if (adapter.state.value == WebSearchProvider.fromString("custom")) {
|
||||||
|
SearchPopupPreference(
|
||||||
|
title = stringResource(R.string.custom_search_label),
|
||||||
|
initialValue = nameAdapter.state.value,
|
||||||
|
placeholder = stringResource(R.string.custom),
|
||||||
|
onConfirm = nameAdapter::onChange,
|
||||||
|
isErrorCheck = { it.isEmpty() },
|
||||||
|
)
|
||||||
SearchUrlPreference(
|
SearchUrlPreference(
|
||||||
title = stringResource(R.string.custom_search_url),
|
title = stringResource(R.string.custom_search_url),
|
||||||
initialValue = urlAdapter.state.value,
|
initialValue = urlAdapter.state.value,
|
||||||
@@ -75,6 +83,26 @@ fun SearchUrlPreference(
|
|||||||
initialValue: String,
|
initialValue: String,
|
||||||
onConfirm: (String) -> Unit,
|
onConfirm: (String) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
SearchPopupPreference(
|
||||||
|
title = title,
|
||||||
|
initialValue = initialValue,
|
||||||
|
placeholder = stringResource(R.string.custom_search_input_placeholder),
|
||||||
|
hint = stringResource(R.string.custom_search_input_hint),
|
||||||
|
onConfirm = onConfirm,
|
||||||
|
modifier = modifier,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SearchPopupPreference(
|
||||||
|
title: String,
|
||||||
|
initialValue: String,
|
||||||
|
placeholder: String,
|
||||||
|
onConfirm: (String) -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
hint: String? = null,
|
||||||
|
isErrorCheck: (String) -> Boolean = { it.isEmpty() || !it.contains("%s") },
|
||||||
) {
|
) {
|
||||||
var showPopup by remember { mutableStateOf(false) }
|
var showPopup by remember { mutableStateOf(false) }
|
||||||
var value by remember { mutableStateOf(TextFieldValue(initialValue)) }
|
var value by remember { mutableStateOf(TextFieldValue(initialValue)) }
|
||||||
@@ -111,13 +139,15 @@ fun SearchUrlPreference(
|
|||||||
onValueChange = { value = it },
|
onValueChange = { value = it },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
isError = value.text.isEmpty() || !value.text.contains("%s"),
|
isError = isErrorCheck(value.text),
|
||||||
placeholder = {
|
placeholder = {
|
||||||
Text(stringResource(R.string.custom_search_input_placeholder))
|
Text(placeholder)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
if (hint != null) {
|
||||||
Text(stringResource(R.string.custom_search_input_hint))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
Text(hint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user