Bug 1361755 - Allow distributions to specify a homepage option in prefs. r=sebastian
☠☠ backed out by 2645d067b1e3 ☠ ☠
authorMichael Kaply <mozilla@kaply.com>
Wed, 03 May 2017 15:47:09 -0500
changeset 361505 970698e1bb620df117a6da3964b9e4d9a7e7f7c2
parent 361504 703fc5a4a92c63151f7d1d070ec1c765ee610830
child 361506 9bce19249d9b7fd841f8c85c7974b0e08d0f4440
push id43799
push usermozilla@kaply.com
push dateWed, 31 May 2017 13:30:28 +0000
treeherderautoland@970698e1bb62 [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: KjdZvHNG6VR
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
@@ -12,16 +12,23 @@
 
     <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.