Bug 1361755 - Allow distributions to specify a homepage option in prefs. r=sebastian
authorMichael Kaply <mozilla@kaply.com>
Wed, 31 May 2017 11:39:41 -0500
changeset 361580 9b8b0f1e0c8043be3a2276fe98c5e5591d537c96
parent 361579 946a0bae3779896e18bfa440876ecd3a0b094974
child 361581 9983ac05d7d1533fc13605ffc17e42d1b7fcbcf7
push id31934
push userryanvm@gmail.com
push dateThu, 01 Jun 2017 00:25:46 +0000
treeherdermozilla-central@7fb3d9dfa8e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1361755
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1361755 - Allow distributions to specify a homepage option in prefs. r=sebastian MozReview-Commit-ID: CNvhkzDyynZ
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
mobile/android/base/java/org/mozilla/gecko/preferences/SetHomepagePreference.java
mobile/android/base/resources/layout/preference_set_homepage.xml
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferences.java
@@ -164,16 +164,18 @@ public class GeckoPreferences
     public static final String PREFS_ACTIVITY_STREAM = NON_PREF_PREFIX + "experiments.activitystream";
     public static final String PREFS_CATEGORY_EXPERIMENTAL_FEATURES = NON_PREF_PREFIX + "category_experimental";
     public static final String PREFS_COMPACT_TABS = NON_PREF_PREFIX + "compact_tabs";
     public static final String PREFS_SHOW_QUIT_MENU = NON_PREF_PREFIX + "distribution.show_quit_menu";
     public static final String PREFS_SEARCH_SUGGESTIONS_ENABLED = "browser.search.suggest.enabled";
     public static final String PREFS_DEFAULT_BROWSER = NON_PREF_PREFIX + "default_browser.link";
     public static final String PREFS_SYSTEM_FONT_SIZE = NON_PREF_PREFIX + "font.size.use_system_font_size";
     public static final String PREFS_SET_AS_HOMEPAGE = NON_PREF_PREFIX + "distribution.set_as_homepage";
+    public static final String PREFS_DIST_HOMEPAGE = NON_PREF_PREFIX + "distribution.homepage";
+    public static final String PREFS_DIST_HOMEPAGE_NAME = NON_PREF_PREFIX + "distribution.homepage.name";
 
     private static final String ACTION_STUMBLER_UPLOAD_PREF = "STUMBLER_PREF";
 
 
     // This isn't a Gecko pref, even if it looks like one.
     private static final String PREFS_BROWSER_LOCALE = "locale";
 
     public static final String PREFS_RESTORE_SESSION = NON_PREF_PREFIX + "restoreSession3";
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/SetHomepagePreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/SetHomepagePreference.java
@@ -15,23 +15,25 @@ import android.preference.DialogPreferen
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.EditText;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
 
+
 public class SetHomepagePreference extends DialogPreference {
     private static final String DEFAULT_HOMEPAGE = AboutPages.HOME;
 
     private final SharedPreferences prefs;
 
     private RadioGroup homepageLayout;
     private RadioButton defaultRadio;
+    private RadioButton distributionRadio;
     private RadioButton userAddressRadio;
     private EditText homepageEditText;
 
     // This is the url that 1) was loaded from prefs or, 2) stored
     // when the user pressed the "default homepage" checkbox.
     private String storedUrl;
 
     public SetHomepagePreference(final Context context, final AttributeSet attrs) {
@@ -46,16 +48,17 @@ public class SetHomepagePreference exten
     }
 
     @Override
     protected void onBindDialogView(final View view) {
         super.onBindDialogView(view);
 
         homepageLayout = (RadioGroup) view.findViewById(R.id.homepage_layout);
         defaultRadio = (RadioButton) view.findViewById(R.id.radio_default);
+        distributionRadio = (RadioButton) view.findViewById(R.id.radio_distribution);
         userAddressRadio = (RadioButton) view.findViewById(R.id.radio_user_address);
         homepageEditText = (EditText) view.findViewById(R.id.edittext_user_address);
 
         storedUrl = prefs.getString(GeckoPreferences.PREFS_HOMEPAGE, DEFAULT_HOMEPAGE);
 
         homepageLayout.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
             @Override
             public void onCheckedChanged(final RadioGroup radioGroup, final int checkedId) {
@@ -66,28 +69,42 @@ public class SetHomepagePreference exten
                     homepageEditText.setVisibility(View.GONE);
                 }
             }
         });
         setUIState(storedUrl);
     }
 
     private void setUIState(final String url) {
+        if (prefs.contains(GeckoPreferences.PREFS_DIST_HOMEPAGE_NAME) &&
+            prefs.contains(GeckoPreferences.PREFS_DIST_HOMEPAGE)) {
+            distributionRadio.setText(prefs.getString(GeckoPreferences.PREFS_DIST_HOMEPAGE_NAME, ""));
+        } else {
+            distributionRadio.setVisibility(View.GONE);
+        }
         if (isUrlDefaultHomepage(url)) {
             defaultRadio.setChecked(true);
+        } else if (distributionRadio.getVisibility() == View.VISIBLE &&
+                   isUrlDistributionHomepage(url)) {
+            distributionRadio.setChecked(true);
         } else {
             userAddressRadio.setChecked(true);
             homepageEditText.setText(url);
         }
     }
 
     private boolean isUrlDefaultHomepage(final String url) {
         return TextUtils.isEmpty(url) || DEFAULT_HOMEPAGE.equals(url);
     }
 
+    private boolean isUrlDistributionHomepage(final String url) {
+        String distributionHomepage = prefs.getString(GeckoPreferences.PREFS_DIST_HOMEPAGE, "");
+        return distributionHomepage.equals(url);
+    }
+
     private static void openKeyboardAndSelectAll(final Context context, final View viewToFocus) {
         viewToFocus.requestFocus();
         viewToFocus.post(new Runnable() {
             @Override
             public void run() {
                 InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                 imm.showSoftInput(viewToFocus, InputMethodManager.SHOW_IMPLICIT);
                 // android:selectAllOnFocus doesn't work for the initial focus:
@@ -101,18 +118,21 @@ public class SetHomepagePreference exten
 
     @Override
     protected void onDialogClosed(final boolean positiveResult) {
         super.onDialogClosed(positiveResult);
         if (positiveResult) {
             final SharedPreferences.Editor editor = prefs.edit();
             final String homePageEditTextValue = homepageEditText.getText().toString();
             final String newPrefValue;
-            if (homepageLayout.getCheckedRadioButtonId() == R.id.radio_default ||
-                    isUrlDefaultHomepage(homePageEditTextValue)) {
+            if (homepageLayout.getCheckedRadioButtonId() == R.id.radio_distribution) {
+                newPrefValue = prefs.getString(GeckoPreferences.PREFS_DIST_HOMEPAGE, "");
+                editor.putString(GeckoPreferences.PREFS_HOMEPAGE, newPrefValue);
+            } else if (homepageLayout.getCheckedRadioButtonId() == R.id.radio_default ||
+                       isUrlDefaultHomepage(homePageEditTextValue)) {
                 newPrefValue = "";
                 editor.remove(GeckoPreferences.PREFS_HOMEPAGE);
             } else {
                 newPrefValue = homePageEditTextValue;
                 editor.putString(GeckoPreferences.PREFS_HOMEPAGE, newPrefValue);
             }
             editor.apply();
 
--- a/mobile/android/base/resources/layout/preference_set_homepage.xml
+++ b/mobile/android/base/resources/layout/preference_set_homepage.xml
@@ -1,27 +1,35 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- This Source Code Form is subject to the terms of the Mozilla Public
    - License, v. 2.0. If a copy of the MPL was not distributed with this
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
+            xmlns:tools="http://schemas.android.com/tools"
             android:id="@+id/homepage_layout"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:paddingLeft="20dp"
             android:paddingRight="20dp"
             android:orientation="vertical">
 
     <RadioButton android:id="@+id/radio_default"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="8dp"
                  android:text="@string/home_homepage_radio_default"
                  android:textColor="@color/text_and_tabs_tray_grey"/>
 
+    <RadioButton android:id="@+id/radio_distribution"
+                 android:layout_width="wrap_content"
+                 android:layout_height="wrap_content"
+                 android:layout_marginTop="8dp"
+                 tools:text="Distribution Homepage"
+                 android:textColor="@color/text_and_tabs_tray_grey"/>
+
     <RadioButton android:id="@+id/radio_user_address"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="8dp"
                  android:text="@string/home_homepage_radio_user_address"
                  android:textColor="@color/text_and_tabs_tray_grey"/>
 
     <!-- RadioGroup is a LinearLayout under the hood, so including this View is fine.