From d64480fc9b70fa37f1519b34d6113f3141801582 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Tue, 16 May 2017 22:14:07 -0300 Subject: [PATCH] Add option to disable the search suggestions --- .../schabi/newpipe/fragments/search/SearchFragment.java | 9 +++++++++ app/src/main/res/values/settings_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/settings.xml | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/search/SearchFragment.java index 11707c38d..d31addbfb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/search/SearchFragment.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; @@ -68,6 +69,7 @@ public class SearchFragment extends BaseFragment implements SuggestionWorker.OnS private int serviceId = -1; private String searchQuery = ""; private int pageNumber = 0; + private boolean showSuggestions = true; private SearchWorker curSearchWorker; private SuggestionWorker curSuggestionWorker; @@ -135,6 +137,8 @@ public class SearchFragment extends BaseFragment implements SuggestionWorker.OnS if (pageNumber > 0) search(searchQuery, pageNumber); else search(searchQuery, 0, true); } + + showSuggestions = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(getString(R.string.show_search_suggestions_key), true); } @Override @@ -523,6 +527,11 @@ public class SearchFragment extends BaseFragment implements SuggestionWorker.OnS } private void searchSuggestions(String query) { + if (!showSuggestions) { + if (DEBUG) Log.d(TAG, "searchSuggestions() showSuggestions is disabled"); + return; + } + if (DEBUG) Log.d(TAG, "searchSuggestions() called with: query = [" + query + "]"); if (curSuggestionWorker != null && curSuggestionWorker.isRunning()) curSuggestionWorker.cancel(); curSuggestionWorker = SuggestionWorker.startForQuery(activity, serviceId, query, this); diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 2c9362c93..05f08c085 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -44,6 +44,7 @@ 3GPP + show_search_suggestions show_play_with_kodi theme diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 180bb0ef7..a1fc44420 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -64,6 +64,8 @@ Remember the last size and position set to the popup Player gesture controls Use gestures to control the brightness and volume of the player + Search suggestions + Show suggestions when searching Download diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 34a9eed0d..43435dc1d 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -155,6 +155,12 @@ android:summary="@string/autoplay_by_calling_app_summary" android:defaultValue="false" /> + +