Skip to content

Commit

Permalink
Merge pull request #139 from SecUSo/enh/137-startpage-as-a-search-engine
Browse files Browse the repository at this point in the history
Add Startpage and Brave search engines
  • Loading branch information
udenr authored Aug 18, 2022
2 parents 1014ae6 + 0f3d4cb commit 53bd825
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.secuso.privacyfriendlycodescanner.qrscanner.util

import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.preference.PreferenceManager
Expand All @@ -22,7 +21,8 @@ object WebSearchUtil {
)
.setIcon(R.drawable.ic_warning)
.setTitle(R.string.fragment_result_text_dialog_title)
.setPositiveButton(R.string.fragment_result_text_dialog_positive_button
.setPositiveButton(
R.string.fragment_result_text_dialog_positive_button
) { _, _ ->
val uri =
Uri.parse(String.format(searchEngineURI, content))
Expand All @@ -35,22 +35,7 @@ object WebSearchUtil {
dialog.show()
}

private fun getSearchEngineURI(context: Context): String {
val duckDuckGo =
context.resources
.getStringArray(R.array.pref_search_engine_values)[0]
val pref = PreferenceManager.getDefaultSharedPreferences(context)
val searchEngineType = pref.getString("pref_search_engine", duckDuckGo)
return if (duckDuckGo == searchEngineType) {
context.resources.getString(R.string.pref_search_engine_uri_duckduckgo)
} else {
context.resources.getString(
R.string.pref_search_engine_uri_google
)
}
}

private fun getSearchEngineName(context: Context): String {
private fun getPrefSearchEngineIndex(context: Context): Int {
val searchEngines: Array<String> =
context.resources.getStringArray(R.array.pref_search_engine_values)
val pref = PreferenceManager.getDefaultSharedPreferences(context)
Expand All @@ -62,10 +47,22 @@ object WebSearchUtil {
}
i++
}
return if (i < searchEngines.size) {
i
} else 0
}

private fun getSearchEngineURI(context: Context): String {
val searchEngineIndex = getPrefSearchEngineIndex(context)
val searchEngineUris: Array<String> =
context.resources.getStringArray(R.array.pref_search_engine_uris)
return searchEngineUris[searchEngineIndex]
}

private fun getSearchEngineName(context: Context): String {
val searchEngineIndex = getPrefSearchEngineIndex(context)
val searchEnginesEntries: Array<String> =
context.resources.getStringArray(R.array.pref_search_engine_entries)
return if (i < searchEnginesEntries.size) {
searchEnginesEntries[i]
} else context.resources.getString(R.string.none)
return searchEnginesEntries[searchEngineIndex]
}
}
4 changes: 0 additions & 4 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,6 @@
<string name="fragment_result_product_label">Identificatore:</string>
<string name="activity_result_toast_error_cant_load">Qualcosa è andato storto durante il caricamento del risultato.</string>
<string name="activity_enter_toast_missing_data">Nessun dato</string>
<string-array name="pref_search_engine_entries">
<item>DuckDuckGo</item>
<item>Google</item>
</string-array>

<string name="text_enter">Il testo che vuoi codificare</string>
<string name="hello_world">Ciao mondo</string>
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,6 @@

<!--Settings for Default Search Engine-->
<string name="pref_search_engine_title">Default Search Engine</string>
<string name="pref_search_engine_uri_duckduckgo" translatable="false">
"https://duckduckgo.com/?q=%s"
</string>
<string name="pref_search_engine_uri_google" translatable="false">
"https://www.google.com/search?q=%s"
</string>
<string name="pref_enable_beep_on_scan_title">Beep on scan</string>
<string name="pref_enable_beep_on_scan_summary">Play a confirmation tone when scanning</string>
<string name="activity_history_list_item_qr_image_descriptor" translatable="false">QR Code</string>
Expand Down Expand Up @@ -361,10 +355,20 @@
<string-array name="pref_search_engine_entries">
<item>DuckDuckGo</item>
<item>Google</item>
<item>Startpage</item>
<item>Brave</item>
</string-array>
<string-array name="pref_search_engine_values">
<string-array name="pref_search_engine_values" translatable="false">
<item>DUCK_DUCK_GO</item>
<item>GOOGLE</item>
<item>STARTPAGE</item>
<item>BRAVE</item>
</string-array>
<string-array name="pref_search_engine_uris" translatable="false">
<item>"https://duckduckgo.com/?q=%s"</item>
<item>"https://www.google.com/search?q=%s"</item>
<item>"https://www.startpage.com/search?query=%s"</item>
<item>"https://search.brave.com/search?q=%s"</item>
</string-array>

</resources>

0 comments on commit 53bd825

Please sign in to comment.