Skip to content

Commit

Permalink
Merge pull request #5567 from brave/android_new_autocomplete_options
Browse files Browse the repository at this point in the history
Added new autocomplete options to privacy settings
  • Loading branch information
samartnik authored May 16, 2020
2 parents cd82124 + 67cd8e1 commit 4c820aa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.BravePref;
import org.chromium.chrome.browser.preferences.BravePrefServiceBridge;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
Expand All @@ -27,12 +28,16 @@ public class BravePrivacySettings extends PrivacySettings {
private static final String PREF_CLOSE_TABS_ON_EXIT = "close_tabs_on_exit";
private static final String PREF_SYNC_AND_SERVICES_LINK = "sync_and_services_link";
private static final String PREF_SEARCH_SUGGESTIONS = "search_suggestions";
private static final String PREF_AUTOCOMPLETE_TOP_SITES = "autocomplete_top_sites";
private static final String PREF_AUTOCOMPLETE_BRAVE_SUGGESTED_SITES = "autocomplete_brave_suggested_sites";
private static final String PREF_CLEAR_BROWSING_DATA = "clear_browsing_data";

private final PrefServiceBridge mPrefServiceBridge = PrefServiceBridge.getInstance();
private final ManagedPreferenceDelegate mManagedPreferenceDelegate =
createManagedPreferenceDelegate();
private ChromeSwitchPreference mSearchSuggestions;
private ChromeSwitchPreference mAutocompleteTopSites;
private ChromeSwitchPreference mAutocompleteBraveSuggestedSites;

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Expand Down Expand Up @@ -60,6 +65,12 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
mSearchSuggestions.setOnPreferenceChangeListener(this);
mSearchSuggestions.setManagedPreferenceDelegate(mManagedPreferenceDelegate);

mAutocompleteTopSites = (ChromeSwitchPreference) findPreference(PREF_AUTOCOMPLETE_TOP_SITES);
mAutocompleteTopSites.setOnPreferenceChangeListener(this);

mAutocompleteBraveSuggestedSites = (ChromeSwitchPreference) findPreference(PREF_AUTOCOMPLETE_BRAVE_SUGGESTED_SITES);
mAutocompleteBraveSuggestedSites.setOnPreferenceChangeListener(this);

updatePreferences();
}

Expand All @@ -82,6 +93,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
sharedPreferencesEditor.apply();
} else if (PREF_SEARCH_SUGGESTIONS.equals(key)) {
mPrefServiceBridge.setBoolean(Pref.SEARCH_SUGGEST_ENABLED, (boolean) newValue);
} else if (PREF_AUTOCOMPLETE_TOP_SITES.equals(key)) {
BravePrefServiceBridge.getInstance().setBoolean(BravePref.TOP_SITE_SUGGESTIONS_ENABLED, (boolean) newValue);
} else if (PREF_AUTOCOMPLETE_BRAVE_SUGGESTED_SITES.equals(key)) {
BravePrefServiceBridge.getInstance().setBoolean(BravePref.BRAVE_SUGGESTED_SITE_SUGGESTIONS_ENABLED,
(boolean) newValue);
}

return true;
Expand All @@ -97,6 +113,12 @@ private void updatePreferences() {
removePreferenceIfPresent(PREF_SYNC_AND_SERVICES_LINK);
mSearchSuggestions.setChecked(mPrefServiceBridge.getBoolean(Pref.SEARCH_SUGGEST_ENABLED));
mSearchSuggestions.setOrder(findPreference(PREF_CLEAR_BROWSING_DATA).getOrder() + 1);
mAutocompleteTopSites
.setChecked(BravePrefServiceBridge.getInstance().getBoolean(BravePref.TOP_SITE_SUGGESTIONS_ENABLED));
mAutocompleteTopSites.setOrder(findPreference(PREF_CLEAR_BROWSING_DATA).getOrder() + 2);
mAutocompleteBraveSuggestedSites.setChecked(
BravePrefServiceBridge.getInstance().getBoolean(BravePref.BRAVE_SUGGESTED_SITE_SUGGESTIONS_ENABLED));
mAutocompleteBraveSuggestedSites.setOrder(findPreference(PREF_CLEAR_BROWSING_DATA).getOrder() + 3);
}

private void removePreferenceIfPresent(String key) {
Expand Down
8 changes: 8 additions & 0 deletions android/java/res/xml/brave_privacy_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@
android:title="@string/autocomplete_searches_and_urls_title"
android:summary="@string/autocomplete_searches_and_urls_summary"
android:persistent="false"/>
<org.chromium.chrome.browser.settings.ChromeSwitchPreference
android:key="autocomplete_top_sites"
android:title="@string/autocomplete_top_sites_title"
android:persistent="false"/>
<org.chromium.chrome.browser.settings.ChromeSwitchPreference
android:key="autocomplete_brave_suggested_sites"
android:title="@string/autocomplete_brave_suggested_sites_title"
android:persistent="false"/>
</android.support.v7.preference.PreferenceScreen>
5 changes: 5 additions & 0 deletions browser/android/preferences/brave_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cstddef>

#include "brave/common/pref_names.h"
#include "brave/components/ntp_background_images/common/pref_names.h"
#include "build/build_config.h"

Expand All @@ -17,6 +18,8 @@ enum BravePref {
NTP_SHOW_SPONSORED_IMAGES_BACKGROUND_IMAGE = 10000,
NTP_SHOW_SUPER_REFERRAL_THEMES_OPTION,
NTP_SHOW_BACKGROUND_IMAGE,
TOP_SITE_SUGGESTIONS_ENABLED,
BRAVE_SUGGESTED_SITE_SUGGESTIONS_ENABLED,
// BRAVE_PREF_NUM_PREFS must be the last entry.
BRAVE_PREF_NUM_PREFS
};
Expand All @@ -26,6 +29,8 @@ const char* const kBravePrefsExposedToJava[] = {
ntp_background_images::prefs::kNewTabPageShowSponsoredImagesBackgroundImage,
ntp_background_images::prefs::kNewTabPageSuperReferralThemesOption,
ntp_background_images::prefs::kNewTabPageShowBackgroundImage,
kTopSiteSuggestionsEnabled,
kBraveSuggestedSiteSuggestionsEnabled
};

static const int kBravePrefOffset = 10000;
Expand Down
7 changes: 7 additions & 0 deletions browser/ui/android/strings/android_chrome_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -4004,6 +4004,13 @@ Only you can see what your camera is looking at. The site can't see your camera'
<message name="IDS_ANDROID_NFC_OFF_GLOBALLY" desc="The message to show when NFC has been turned off globally in Android. Contains a link to the settings menu to enable NFC.">
NFC is off for this device. Turn it on in <ph name="BEGIN_LINK">&lt;link&gt;</ph>Android Settings<ph name="END_LINK">&lt;/link&gt;</ph>.
</message>

<message name="IDS_AUTOCOMPLETE_TOP_SITES_TITLE" desc="The label for settings switch controlling whether or not top sites show up in autocomplete">
Show top sites in autocomplete
</message>
<message name="IDS_AUTOCOMPLETE_BRAVE_SUGGESTED_SITES_TITLE" desc="The label for settings switch controlling whether or not Brave suggested sites show up in autocomplete">
Show suggested sites in autocomplete
</message>
</messages>
</release>
</grit>

0 comments on commit 4c820aa

Please sign in to comment.