diff --git a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java index a9ce3d9..94b0e7d 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java @@ -26,10 +26,13 @@ import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.download.DownloadHandler; +import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.Utils; +import static acr.browser.lightning.preference.PreferenceManager.*; + public class GeneralSettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { private static final String SETTINGS_PROXY = "proxy"; @@ -42,11 +45,11 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme private static final String SETTINGS_DOWNLOAD = "download"; private static final String SETTINGS_HOME = "home"; private static final String SETTINGS_SEARCHENGINE = "search"; - private static final String SETTINGS_GOOGLESUGGESTIONS = "google_suggestions"; + private static final String SETTINGS_SUGGESTIONS = "suggestions_choice"; private Activity mActivity; private static final int API = android.os.Build.VERSION.SDK_INT; private CharSequence[] mProxyChoices; - private Preference proxy, useragent, downloadloc, home, searchengine; + private Preference proxy, useragent, downloadloc, home, searchengine, searchsSuggestions; private String mDownloadLocation; private int mAgentChoice; private String mHomepage; @@ -68,25 +71,25 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme downloadloc = findPreference(SETTINGS_DOWNLOAD); home = findPreference(SETTINGS_HOME); searchengine = findPreference(SETTINGS_SEARCHENGINE); + searchsSuggestions = findPreference(SETTINGS_SUGGESTIONS); CheckBoxPreference cbFlash = (CheckBoxPreference) findPreference(SETTINGS_FLASH); CheckBoxPreference cbAds = (CheckBoxPreference) findPreference(SETTINGS_ADS); CheckBoxPreference cbImages = (CheckBoxPreference) findPreference(SETTINGS_IMAGES); CheckBoxPreference cbJsScript = (CheckBoxPreference) findPreference(SETTINGS_JAVASCRIPT); CheckBoxPreference cbColorMode = (CheckBoxPreference) findPreference(SETTINGS_COLORMODE); - CheckBoxPreference cbgooglesuggest = (CheckBoxPreference) findPreference(SETTINGS_GOOGLESUGGESTIONS); proxy.setOnPreferenceClickListener(this); useragent.setOnPreferenceClickListener(this); downloadloc.setOnPreferenceClickListener(this); home.setOnPreferenceClickListener(this); + searchsSuggestions.setOnPreferenceClickListener(this); searchengine.setOnPreferenceClickListener(this); cbFlash.setOnPreferenceChangeListener(this); cbAds.setOnPreferenceChangeListener(this); cbImages.setOnPreferenceChangeListener(this); cbJsScript.setOnPreferenceChangeListener(this); cbColorMode.setOnPreferenceChangeListener(this); - cbgooglesuggest.setOnPreferenceChangeListener(this); mAgentChoice = mPreferenceManager.getUserAgentChoice(); mHomepage = mPreferenceManager.getHomepage(); @@ -108,6 +111,19 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme downloadloc.setSummary(mDownloadLocation); + switch (mPreferenceManager.getSearchSuggestionChoice()) { + case SUGGESTION_GOOGLE: + searchsSuggestions.setSummary(R.string.powered_by_google); + break; + case SUGGESTION_DUCK: + searchsSuggestions.setSummary(R.string.powered_by_duck); + break; + case SUGGESTION_NONE: + searchsSuggestions.setSummary(R.string.search_suggestions_off); + break; + } + + if (mHomepage.contains("about:home")) { home.setSummary(getResources().getString(R.string.action_homepage)); } else if (mHomepage.contains("about:blank")) { @@ -144,7 +160,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme cbFlash.setChecked(flashNum > 0); cbAds.setChecked(Constants.FULL_VERSION && mPreferenceManager.getAdBlockEnabled()); cbColorMode.setChecked(mPreferenceManager.getColorModeEnabled()); - cbgooglesuggest.setChecked(mPreferenceManager.getGoogleSearchSuggestionsEnabled()); } private void searchUrlPicker() { @@ -155,15 +170,15 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme getSearchUrl.setText(mSearchUrl); urlPicker.setView(getSearchUrl); urlPicker.setPositiveButton(getResources().getString(R.string.action_ok), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String text = getSearchUrl.getText().toString(); - mPreferenceManager.setSearchUrl(text); - searchengine.setSummary(getResources().getString(R.string.custom_url) + ": " - + text); - } - }); + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getSearchUrl.getText().toString(); + mPreferenceManager.setSearchUrl(text); + searchengine.setSummary(getResources().getString(R.string.custom_url) + ": " + + text); + } + }); Dialog dialog = urlPicker.show(); BrowserDialog.setDialogSize(mActivity, dialog); } @@ -172,22 +187,22 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setTitle(mActivity.getResources().getString(R.string.title_flash)); builder.setMessage(getResources().getString(R.string.flash)) - .setCancelable(true) - .setPositiveButton(getResources().getString(R.string.action_manual), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - mPreferenceManager.setFlashSupport(1); - } - }) - .setNegativeButton(getResources().getString(R.string.action_auto), - new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - mPreferenceManager.setFlashSupport(2); - } - }).setOnCancelListener(new DialogInterface.OnCancelListener() { + .setCancelable(true) + .setPositiveButton(getResources().getString(R.string.action_manual), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + mPreferenceManager.setFlashSupport(1); + } + }) + .setNegativeButton(getResources().getString(R.string.action_auto), + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + mPreferenceManager.setFlashSupport(2); + } + }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { @@ -204,13 +219,13 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); picker.setTitle(getResources().getString(R.string.http_proxy)); picker.setSingleChoiceItems(mProxyChoices, mPreferenceManager.getProxyChoice(), - new DialogInterface.OnClickListener() { + new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - setProxyChoice(which); - } - }); + @Override + public void onClick(DialogInterface dialog, int which) { + setProxyChoice(which); + } + }); picker.setPositiveButton(getResources().getString(R.string.action_ok), null); Dialog dialog = picker.show(); BrowserDialog.setDialogSize(mActivity, dialog); @@ -251,25 +266,25 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme eProxyPort.setText(Integer.toString(mPreferenceManager.getProxyPort())); Dialog dialog = new AlertDialog.Builder(mActivity) - .setTitle(R.string.manual_proxy) - .setView(v) - .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - String proxyHost = eProxyHost.getText().toString(); - int proxyPort; - try { - // Try/Catch in case the user types an empty string or a number - // larger than max integer - proxyPort = Integer.parseInt(eProxyPort.getText().toString()); - } catch (NumberFormatException ignored) { - proxyPort = mPreferenceManager.getProxyPort(); - } - mPreferenceManager.setProxyHost(proxyHost); - mPreferenceManager.setProxyPort(proxyPort); - proxy.setSummary(proxyHost + ':' + proxyPort); + .setTitle(R.string.manual_proxy) + .setView(v) + .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String proxyHost = eProxyHost.getText().toString(); + int proxyPort; + try { + // Try/Catch in case the user types an empty string or a number + // larger than max integer + proxyPort = Integer.parseInt(eProxyPort.getText().toString()); + } catch (NumberFormatException ignored) { + proxyPort = mPreferenceManager.getProxyPort(); } - }).show(); + mPreferenceManager.setProxyHost(proxyHost); + mPreferenceManager.setProxyPort(proxyPort); + proxy.setSummary(proxyHost + ':' + proxyPort); + } + }).show(); BrowserDialog.setDialogSize(mActivity, dialog); } @@ -277,9 +292,9 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); picker.setTitle(getResources().getString(R.string.title_search_engine)); CharSequence[] chars = {getResources().getString(R.string.custom_url), "Google", - "Ask", "Bing", "Yahoo", "StartPage", "StartPage (Mobile)", - "DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)", - "Yandex (Russian)"}; + "Ask", "Bing", "Yahoo", "StartPage", "StartPage (Mobile)", + "DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)", + "Yandex (Russian)"}; int n = mPreferenceManager.getSearchChoice(); @@ -312,28 +327,71 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme } picker.setSingleChoiceItems(R.array.homepage, n - 1, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which + 1) { - case 1: - mPreferenceManager.setHomepage("about:home"); - home.setSummary(getResources().getString(R.string.action_homepage)); - break; - case 2: - mPreferenceManager.setHomepage("about:blank"); - home.setSummary(getResources().getString(R.string.action_blank)); - break; - case 3: - mPreferenceManager.setHomepage("about:bookmarks"); - home.setSummary(getResources().getString(R.string.action_bookmarks)); - break; - case 4: - homePicker(); - break; - } + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which + 1) { + case 1: + mPreferenceManager.setHomepage("about:home"); + home.setSummary(getResources().getString(R.string.action_homepage)); + break; + case 2: + mPreferenceManager.setHomepage("about:blank"); + home.setSummary(getResources().getString(R.string.action_blank)); + break; + case 3: + mPreferenceManager.setHomepage("about:bookmarks"); + home.setSummary(getResources().getString(R.string.action_bookmarks)); + break; + case 4: + homePicker(); + break; } - }); + } + }); + picker.setPositiveButton(getResources().getString(R.string.action_ok), null); + Dialog dialog = picker.show(); + BrowserDialog.setDialogSize(mActivity, dialog); + } + + private void suggestionsDialog() { + AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); + picker.setTitle(getResources().getString(R.string.search_suggestions)); + + int currentChoice = 2; + + switch (mPreferenceManager.getSearchSuggestionChoice()) { + case SUGGESTION_GOOGLE: + currentChoice = 0; + break; + case SUGGESTION_DUCK: + currentChoice = 1; + break; + case SUGGESTION_NONE: + currentChoice = 2; + break; + } + + picker.setSingleChoiceItems(R.array.suggestions, currentChoice, + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case 0: + mPreferenceManager.setSearchSuggestionChoice(Suggestion.SUGGESTION_GOOGLE); + searchsSuggestions.setSummary(R.string.powered_by_google); + break; + case 1: + mPreferenceManager.setSearchSuggestionChoice(Suggestion.SUGGESTION_DUCK); + searchsSuggestions.setSummary(R.string.powered_by_duck); + break; + case 2: + mPreferenceManager.setSearchSuggestionChoice(Suggestion.SUGGESTION_NONE); + searchsSuggestions.setSummary(R.string.search_suggestions_off); + break; + } + } + }); picker.setPositiveButton(getResources().getString(R.string.action_ok), null); Dialog dialog = picker.show(); BrowserDialog.setDialogSize(mActivity, dialog); @@ -352,14 +410,14 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme } homePicker.setView(getHome); homePicker.setPositiveButton(getResources().getString(R.string.action_ok), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String text = getHome.getText().toString(); - mPreferenceManager.setHomepage(text); - home.setSummary(text); - } - }); + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getHome.getText().toString(); + mPreferenceManager.setHomepage(text); + home.setSummary(text); + } + }); Dialog dialog = homePicker.show(); BrowserDialog.setDialogSize(mActivity, dialog); } @@ -376,20 +434,20 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme } picker.setSingleChoiceItems(R.array.download_folder, n, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - switch (which) { - case 0: - mPreferenceManager.setDownloadDirectory(DownloadHandler.DEFAULT_DOWNLOAD_PATH); - downloadloc.setSummary(DownloadHandler.DEFAULT_DOWNLOAD_PATH); - break; - case 1: - downPicker(); - break; - } + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case 0: + mPreferenceManager.setDownloadDirectory(DownloadHandler.DEFAULT_DOWNLOAD_PATH); + downloadloc.setSummary(DownloadHandler.DEFAULT_DOWNLOAD_PATH); + break; + case 1: + downPicker(); + break; } - }); + } + }); picker.setPositiveButton(getResources().getString(R.string.action_ok), null); Dialog dialog = picker.show(); BrowserDialog.setDialogSize(mActivity, dialog); @@ -400,27 +458,27 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme agentPicker.setTitle(getResources().getString(R.string.title_user_agent)); mAgentChoice = mPreferenceManager.getUserAgentChoice(); agentPicker.setSingleChoiceItems(R.array.user_agent, mAgentChoice - 1, - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mPreferenceManager.setUserAgentChoice(which + 1); - switch (which + 1) { - case 1: - useragent.setSummary(getResources().getString(R.string.agent_default)); - break; - case 2: - useragent.setSummary(getResources().getString(R.string.agent_desktop)); - break; - case 3: - useragent.setSummary(getResources().getString(R.string.agent_mobile)); - break; - case 4: - useragent.setSummary(getResources().getString(R.string.agent_custom)); - agentPicker(); - break; - } + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mPreferenceManager.setUserAgentChoice(which + 1); + switch (which + 1) { + case 1: + useragent.setSummary(getResources().getString(R.string.agent_default)); + break; + case 2: + useragent.setSummary(getResources().getString(R.string.agent_desktop)); + break; + case 3: + useragent.setSummary(getResources().getString(R.string.agent_mobile)); + break; + case 4: + useragent.setSummary(getResources().getString(R.string.agent_custom)); + agentPicker(); + break; } - }); + } + }); agentPicker.setPositiveButton(getResources().getString(R.string.action_ok), null); Dialog dialog = agentPicker.show(); BrowserDialog.setDialogSize(mActivity, dialog); @@ -432,14 +490,14 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme final EditText getAgent = new EditText(mActivity); agentStringPicker.setView(getAgent); agentStringPicker.setPositiveButton(getResources().getString(R.string.action_ok), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String text = getAgent.getText().toString(); - mPreferenceManager.setUserAgentString(text); - useragent.setSummary(getResources().getString(R.string.agent_custom)); - } - }); + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getAgent.getText().toString(); + mPreferenceManager.setUserAgentString(text); + useragent.setSummary(getResources().getString(R.string.agent_custom)); + } + }); Dialog dialog = agentStringPicker.show(); BrowserDialog.setDialogSize(mActivity, dialog); } @@ -450,7 +508,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme downLocationPicker.setTitle(getResources().getString(R.string.title_download_location)); final EditText getDownload = new EditText(mActivity); getDownload.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT)); + ViewGroup.LayoutParams.WRAP_CONTENT)); getDownload.setText(mPreferenceManager.getDownloadDirectory()); final int errorColor = ContextCompat.getColor(getActivity(), R.color.error_red); final int regularColor = ThemeUtils.getTextColor(getActivity()); @@ -461,15 +519,15 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme layout.addView(getDownload); downLocationPicker.setView(layout); downLocationPicker.setPositiveButton(getResources().getString(R.string.action_ok), - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - String text = getDownload.getText().toString(); - text = DownloadHandler.addNecessarySlashes(text); - mPreferenceManager.setDownloadDirectory(text); - downloadloc.setSummary(text); - } - }); + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String text = getDownload.getText().toString(); + text = DownloadHandler.addNecessarySlashes(text); + mPreferenceManager.setDownloadDirectory(text); + downloadloc.setSummary(text); + } + }); Dialog dialog = downLocationPicker.show(); BrowserDialog.setDialogSize(mActivity, dialog); } @@ -529,6 +587,9 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme case SETTINGS_SEARCHENGINE: searchDialog(); return true; + case SETTINGS_SUGGESTIONS: + suggestionsDialog(); + return true; default: return false; } @@ -566,9 +627,6 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme case SETTINGS_COLORMODE: mPreferenceManager.setColorModeEnabled(checked); return true; - case SETTINGS_GOOGLESUGGESTIONS: - mPreferenceManager.setGoogleSearchSuggestionsEnabled(checked); - return true; default: return false; } diff --git a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java index fe45442..dbe6082 100644 --- a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java +++ b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java @@ -2,9 +2,14 @@ package acr.browser.lightning.preference; import android.content.Context; import android.content.SharedPreferences; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.util.concurrent.Future; + import javax.inject.Inject; import javax.inject.Singleton; @@ -38,7 +43,6 @@ public class PreferenceManager { public static final String USE_WIDE_VIEWPORT = "wideviewport"; public static final String USER_AGENT = "agentchoose"; public static final String USER_AGENT_STRING = "userAgentString"; - public static final String GOOGLE_SEARCH_SUGGESTIONS = "GoogleSearchSuggestions"; public static final String CLEAR_HISTORY_EXIT = "clearHistoryExit"; public static final String CLEAR_COOKIES_EXIT = "clearCookiesExit"; public static final String SAVE_URL = "saveUrl"; @@ -55,6 +59,7 @@ public class PreferenceManager { public static final String DO_NOT_TRACK = "doNotTrack"; public static final String IDENTIFYING_HEADERS = "removeIdentifyingHeaders"; public static final String SWAP_BOOKMARKS_AND_TABS = "swapBookmarksAndTabs"; + public static final String SEARCH_SUGGESTIONS = "searchSuggestions"; public static final String USE_PROXY = "useProxy"; public static final String PROXY_CHOICE = "proxyChoice"; @@ -66,6 +71,12 @@ public class PreferenceManager { public static final String LEAK_CANARY = "leakCanary"; } + public enum Suggestion { + SUGGESTION_GOOGLE, + SUGGESTION_DUCK, + SUGGESTION_NONE + } + @NonNull private final SharedPreferences mPrefs; private static final String PREFERENCES = "settings"; @@ -75,6 +86,19 @@ public class PreferenceManager { mPrefs = context.getSharedPreferences(PREFERENCES, 0); } + @NonNull + public Suggestion getSearchSuggestionChoice() { + try { + return Suggestion.valueOf(mPrefs.getString(Name.SEARCH_SUGGESTIONS, Suggestion.SUGGESTION_GOOGLE.name())); + } catch (IllegalArgumentException ignored) { + return Suggestion.SUGGESTION_NONE; + } + } + + public void setSearchSuggestionChoice(@NonNull Suggestion suggestion) { + putString(Name.SEARCH_SUGGESTIONS, suggestion.name()); + } + public boolean getBookmarksAndTabsSwapped() { return mPrefs.getBoolean(Name.SWAP_BOOKMARKS_AND_TABS, false); } @@ -140,10 +164,6 @@ public class PreferenceManager { return mPrefs.getBoolean(Name.FULL_SCREEN, false); } - public boolean getGoogleSearchSuggestionsEnabled() { - return mPrefs.getBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, true); - } - public boolean getHideStatusBarEnabled() { return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false); } @@ -354,10 +374,6 @@ public class PreferenceManager { putBoolean(Name.FULL_SCREEN, enable); } - public void setGoogleSearchSuggestionsEnabled(boolean enabled) { - putBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, enabled); - } - public void setHideStatusBarEnabled(boolean enable) { putBoolean(Name.HIDE_STATUS_BAR, enable); } diff --git a/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java b/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java index 34fd4a5..322796c 100644 --- a/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java +++ b/app/src/main/java/acr/browser/lightning/search/DuckSuggestionsTask.java @@ -83,6 +83,11 @@ public final class DuckSuggestionsTask { return sLanguage; } + @NonNull + private static String getQueryUrl(@NonNull String query) { + return "https://duckduckgo.com/ac/?q=" + query; + } + void run() { List filter = new ArrayList<>(5); try { @@ -135,7 +140,8 @@ public final class DuckSuggestionsTask { */ @NonNull private static File downloadSuggestionsForQuery(@NonNull String query, String language, @NonNull Application app) { - File cacheFile = new File(app.getCacheDir(), query.hashCode() + Suggestions.CACHE_FILE_TYPE); + String queryUrl = getQueryUrl(query); + File cacheFile = new File(app.getCacheDir(), queryUrl.hashCode() + Suggestions.CACHE_FILE_TYPE); if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) { return cacheFile; } @@ -145,7 +151,7 @@ public final class DuckSuggestionsTask { InputStream in = null; FileOutputStream fos = null; try { - URL url = new URL("https://duckduckgo.com/ac/?q=" + query); + URL url = new URL(queryUrl); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setDoInput(true); connection.setRequestProperty("Accept-Encoding", "gzip"); diff --git a/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java b/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java index 0f2d144..d6378a0 100644 --- a/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java +++ b/app/src/main/java/acr/browser/lightning/search/GoogleSuggestionsTask.java @@ -70,6 +70,12 @@ public class GoogleSuggestionsTask { return sLanguage; } + @NonNull + private static String getQueryUrl(@NonNull String query, @NonNull String language) { + return "https://suggestqueries.google.com/complete/search?output=toolbar&hl=" + + language + "&q=" + query; + } + @NonNull private static synchronized XmlPullParser getParser() throws XmlPullParserException { if (sXpp == null) { @@ -135,7 +141,8 @@ public class GoogleSuggestionsTask { */ @NonNull private static File downloadSuggestionsForQuery(@NonNull String query, String language, @NonNull Application app) { - File cacheFile = new File(app.getCacheDir(), query.hashCode() + Suggestions.CACHE_FILE_TYPE); + String queryUrl = getQueryUrl(query, language); + File cacheFile = new File(app.getCacheDir(), queryUrl.hashCode() + Suggestions.CACHE_FILE_TYPE); if (System.currentTimeMillis() - INTERVAL_DAY < cacheFile.lastModified()) { return cacheFile; } @@ -147,8 +154,7 @@ public class GoogleSuggestionsTask { try { // Old API that doesn't support HTTPS // http://google.com/complete/search?q= + query + &output=toolbar&hl= + language - URL url = new URL("https://suggestqueries.google.com/complete/search?output=toolbar&hl=" - + language + "&q=" + query); + URL url = new URL(queryUrl); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setDoInput(true); connection.setRequestProperty("Accept-Encoding", "gzip"); diff --git a/app/src/main/java/acr/browser/lightning/search/Suggestions.java b/app/src/main/java/acr/browser/lightning/search/Suggestions.java index 035772e..cf3225d 100644 --- a/app/src/main/java/acr/browser/lightning/search/Suggestions.java +++ b/app/src/main/java/acr/browser/lightning/search/Suggestions.java @@ -70,9 +70,9 @@ public class Suggestions extends BaseAdapter implements Filterable { private final List mAllBookmarks = new ArrayList<>(5); private final boolean mDarkTheme; - private boolean mUseGoogle = true; private boolean mIsIncognito = true; @NonNull private final Context mContext; + PreferenceManager.Suggestion mSuggestionChoice; public Suggestions(@NonNull Context context, boolean dark, boolean incognito) { super(); @@ -81,7 +81,7 @@ public class Suggestions extends BaseAdapter implements Filterable { mDarkTheme = dark || incognito; mIsIncognito = incognito; - mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled(); + refreshPreferences(); refreshBookmarks(); @@ -91,7 +91,7 @@ public class Suggestions extends BaseAdapter implements Filterable { } public void refreshPreferences() { - mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled(); + mSuggestionChoice = mPreferenceManager.getSearchSuggestionChoice(); } public void clearCache() { @@ -286,7 +286,19 @@ public class Suggestions extends BaseAdapter implements Filterable { @NonNull private Observable> getSuggestionsForQuery(@NonNull final String query) { - return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.GOOGLE); + if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_GOOGLE) { + return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.GOOGLE); + } else if (mSuggestionChoice == PreferenceManager.Suggestion.SUGGESTION_DUCK) { + return SuggestionsManager.getObservable(query, mContext, SuggestionsManager.Source.DUCK); + } else { + return Observable.create(new Action>() { + @Override + public void onSubscribe(@NonNull Subscriber> subscriber) { + //TODO add an Observable.empty() method to generate an empty Observable + subscriber.onComplete(); + } + }); + } } @NonNull @@ -302,7 +314,7 @@ public class Suggestions extends BaseAdapter implements Filterable { } private boolean shouldRequestNetwork() { - return mUseGoogle && !mIsIncognito; + return !mIsIncognito && mSuggestionChoice != PreferenceManager.Suggestion.SUGGESTION_NONE; } private static class SearchFilter extends Filter { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 45d66c5..57ce8fb 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -132,7 +132,7 @@ Anmelden Benutzername Passwort - Suchvorschläge + Suchvorschläge Unterstützt durch Google Orbot ist installiert. Soll Tor verwendet werden? Um Tor verwenden zu können, muss Orbot installiert sein! diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 8b474b1..876d8ed 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -115,7 +115,7 @@ Iniciar sesión Usuario Contraseña - Sugerencias de búsqueda + Sugerencias de búsqueda Proporcionadas por Google Parece que tienes Orbot instalado. ¿Quieres usar Tor? Por favor, instala Orbot para usar Tor. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index a4f180e..0ac4949 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -142,7 +142,7 @@ Connexion Nom d\'utilisateur Mot de passe - Suggestions de recherche + Suggestions de recherche Proposé par Google Proxy HTTP diff --git a/app/src/main/res/values-gr/strings.xml b/app/src/main/res/values-gr/strings.xml index bdf439f..8e8e729 100644 --- a/app/src/main/res/values-gr/strings.xml +++ b/app/src/main/res/values-gr/strings.xml @@ -116,7 +116,7 @@ Εγγραφή Όνομα χρήστη Κώδικός - Προτάσεις αναζήτησης + Προτάσεις αναζήτησης Powered by Google Φαίνεται οτι έχετε εγκατεστημένο το Orbot. Θα θέλατε να χρησιμοποιήσετε το Tor? Παρακαλώ εγκαταστήστε το Orbot για να χρησιμοποιήσετε το Tor. diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index cd31452..6364554 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -132,7 +132,7 @@ Bejelentkezés Felhasználónév Jelszó - Keresési javaslatok + Keresési javaslatok A Google támogatásával Úgy tűnik, hogy önnek telepítve van az Orbot.Szeretné használni Tor-t? Kérjük telepítse az Orbot-ot annak érdekében, hogy működjön a proxy a Tor-ral. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index dd4a793..68adb04 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -132,7 +132,7 @@ Registrati Username Password - Suggerimenti di ricerca + Suggerimenti di ricerca Powered by Google HTTP Proxy diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 132e090..ebb59f5 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -129,7 +129,7 @@ サインイン ユーザー名 パスワード - 検索候補を表示する + 検索候補を表示する Powered by Google Orbotがインストールされています。Torを使用しますか? Torでプロキシを有効にするにはOrbotをインストールしてください diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 7d95a0a..75d010c 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -115,7 +115,7 @@ 로그인 사용자 이름 암호 - 검색 제안 + 검색 제안 Google이 제공함 Orbot이 설치되어 있습니다. Tor를 사용할까요? Tor를 사용하려면 Orbot을 설치하세요. diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 3016e75..3a3c32c 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -125,7 +125,7 @@ Zaloguj się Nazwa użytkownika Hasło - Podpowiedzi wyszukiwania + Podpowiedzi wyszukiwania Dostarczane przez Google Konfiguracja serwera proxy diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 68309da..5acdcff 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -131,7 +131,7 @@ Iniciar sessão Utilizador Palavra-passe - Sugestões de pesquisa + Sugestões de pesquisa Disponibilizado por Google Proxy HTTP diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index ccfe11a..93957fe 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -115,7 +115,7 @@ Вход Имя пользователя Пароль - Подсказки поиска + Подсказки поиска Используя Google Похоже, установлен Orbot. Вы хотите использовать Tor? Пожалуйста, установите Orbot для проксирования через Tor. diff --git a/app/src/main/res/values-sr/strings.xml b/app/src/main/res/values-sr/strings.xml index 4d624c7..997be39 100644 --- a/app/src/main/res/values-sr/strings.xml +++ b/app/src/main/res/values-sr/strings.xml @@ -142,7 +142,7 @@ Пријава Корисничко име Лозинка - Предлози претраге + Предлози претраге Погоњено Гуглом ХТТП прокси diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index e383684..d18fdde 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -116,7 +116,7 @@ Giriş Yap Kullanıcı adı Parola - Önerilenleri ara + Önerilenleri ara Powered by Google Cihazında Orbot yüklü görünüyor. Tor kullanmak ister misin? Tor proxy ağı ile gezinmek için Orbot yüklemelisin. diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 8319e5b..420e51f 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -116,7 +116,7 @@ 登录 用户名 密码 - 搜索建议 + 搜索建议 由 Google 提供支持 看起来你已经安装了 Orbot. 你想要使用 Tor 吗? 请安装 Orbot 以便通过 Tor 全使用代理。 diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index b7eee71..2a550a6 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -18,6 +18,12 @@ @string/action_bookmarks @string/action_webpage + + + @string/powered_by_google + @string/powered_by_duck + @string/search_suggestions_off + @string/size_largest diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0fd714e..516ff8a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -144,8 +144,10 @@ Sign In Username Password - Search Suggestions + Search Suggestions Powered by Google + Powered by DuckDuckGo + No search suggestions HTTP Proxy None diff --git a/app/src/main/res/xml/preference_general.xml b/app/src/main/res/xml/preference_general.xml index d2b3d99..e7635a0 100644 --- a/app/src/main/res/xml/preference_general.xml +++ b/app/src/main/res/xml/preference_general.xml @@ -37,10 +37,8 @@ - + \ No newline at end of file