Bug 1434603 - Settings Header not changed when visiting sub-menus on Oreo; r=mcomella, a=RyanVM
authorPetru Lingurar <petru.lingurar@softvision.ro>
Tue, 15 May 2018 13:03:44 +0300
changeset 473549 3607d8d3561b254246d7a9f7298ee3fafd89c28f
parent 473548 d662fb1625525279cef893c9c6c7286c81a9e723
child 473550 55923d75814212a1e137e17fe90962bdc5bfcd99
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, RyanVM
bugs1434603
milestone61.0
Bug 1434603 - Settings Header not changed when visiting sub-menus on Oreo; r=mcomella, a=RyanVM The ActionBar's title will always be updated with the title of the visiting PreferenceScreen. MozReview-Commit-ID: b5MyrSaWFC
mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferenceFragment.java
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferenceFragment.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/GeckoPreferenceFragment.java
@@ -2,47 +2,42 @@
  * 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/. */
 
 package org.mozilla.gecko.preferences;
 
 import java.util.Locale;
 
-import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.BrowserLocaleManager;
 import org.mozilla.gecko.GeckoApplication;
 import org.mozilla.gecko.GeckoSharedPrefs;
 import org.mozilla.gecko.LocaleManager;
 import org.mozilla.gecko.PrefsHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.TelemetryContract.Method;
 import org.mozilla.gecko.fxa.AccountLoader;
 import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount;
 
 import android.accounts.Account;
-import android.app.ActionBar;
 import android.app.Activity;
 import android.app.LoaderManager;
 import android.content.Context;
 import android.content.Loader;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.os.Bundle;
-import android.preference.PreferenceActivity;
 import android.preference.PreferenceFragment;
 import android.preference.PreferenceScreen;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
 
-import com.squareup.leakcanary.RefWatcher;
-
 /* A simple implementation of PreferenceFragment for large screen devices
  * This will strip category headers (so that they aren't shown to the user twice)
  * as well as initializing Gecko prefs when a fragment is shown.
 */
 public class GeckoPreferenceFragment extends PreferenceFragment {
 
     public static final int ACCOUNT_LOADER_ID = 1;
     private AccountLoaderCallbacks accountLoaderCallbacks;
@@ -92,39 +87,40 @@ public class GeckoPreferenceFragment ext
         setPreferenceScreen(screen);
         mPrefsRequest = ((GeckoPreferences)getActivity()).setupPreferences(screen);
         syncPreference = (SyncPreference) findPreference(GeckoPreferences.PREFS_SYNC);
     }
 
     /**
      * Return the title to use for this preference fragment.
      *
-     * We only return titles for the preference screens that are
-     * launched directly, and thus might need to be redisplayed.
-     *
-     * This method sets the title that you see on non-multi-pane devices.
+     * The result will be used to set the title that you see on non-multi-pane devices.
      */
     private String getTitle() {
         final int res = getResource();
         if (res == R.xml.preferences) {
             return getString(R.string.settings_title);
-        }
-
-        // We can launch this category from the Data Reporting notification.
-        if (res == R.xml.preferences_privacy) {
+        } else if (res == R.xml.preferences_general || res == R.xml.preferences_general_tablet) {
+            return getString(R.string.pref_category_general);
+        } else if (res == R.xml.preferences_home) {
+            return getString(R.string.pref_category_home);
+        } else if (res == R.xml.preferences_locale) {
+            return getString(R.string.pref_category_language);
+        } else if (res == R.xml.preferences_search) {
+            return getString(R.string.pref_category_search);
+        } else if (res == R.xml.preferences_privacy) {
             return getString(R.string.pref_category_privacy_short);
-        }
-
-        // We can launch this category from the the magnifying glass in the quick search bar.
-        if (res == R.xml.preferences_search) {
-            return getString(R.string.pref_category_search);
-        }
-
-        if (res == R.xml.preferences_notifications) {
+        } else if (res == R.xml.preferences_accessibility) {
+            return getString(R.string.pref_category_accessibility);
+        } else if (res == R.xml.preferences_notifications) {
             return getString(R.string.pref_category_notifications);
+        } else if (res == R.xml.preferences_advanced) {
+            return getString(R.string.pref_category_advanced);
+        } else if (res == R.xml.preferences_vendor) {
+            return getString(R.string.pref_category_vendor);
         }
 
         return null;
     }
 
     /**
      * Return the header id for this preference fragment. This allows
      * us to select the correct header when launching a preference
@@ -151,17 +147,17 @@ public class GeckoPreferenceFragment ext
 
         if (res == R.xml.preferences_notifications) {
             return R.id.pref_header_notifications;
         }
 
         return -1;
     }
 
-    private void updateTitle() {
+    private void updateParentTitle() {
         final String newTitle = getTitle();
         if (newTitle == null) {
             Log.d(LOGTAG, "No new title to show.");
             return;
         }
 
         final GeckoPreferences activity = (GeckoPreferences) getActivity();
         if (activity.isMultiPane()) {
@@ -182,16 +178,17 @@ public class GeckoPreferenceFragment ext
         accountLoaderCallbacks = new AccountLoaderCallbacks();
         getLoaderManager().initLoader(ACCOUNT_LOADER_ID, null, accountLoaderCallbacks);
     }
 
     @Override
     public void onResume() {
         // This is a little delicate. Ensure that you do nothing prior to
         // super.onResume that you wouldn't do in onCreate.
+        // This will also set the title in the parent activity's ActionBar to the title of the current PreferenceScreen
         applyLocale(Locale.getDefault());
         super.onResume();
 
         // Force reload as the account may have been deleted while the app was in background.
         getLoaderManager().restartLoader(ACCOUNT_LOADER_ID, null, accountLoaderCallbacks);
     }
 
     private void applyLocale(final Locale currentLocale) {
@@ -205,17 +202,17 @@ public class GeckoPreferenceFragment ext
             this.lastLocale = currentLocale;
 
             // Rebuild the list to reflect the current locale.
             getPreferenceScreen().removeAll();
             addPreferencesFromResource(getResource());
         }
 
         // Fix the parent title regardless.
-        updateTitle();
+        updateParentTitle();
     }
 
     /*
      * Get the resource from Fragment arguments and return it.
      *
      * If no resource can be found, return the resource id of the default preference screen.
      */
     private int getResource() {