Bug 1403347: Set dialog titles in createDialogItems. r=liuche draft
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 26 Sep 2017 16:22:21 -0700
changeset 670852 3cc0d80e9fa5d569320b8ebbf583204dbb7dd467
parent 670851 fcc731dd0c24bc2472fe014b3b7495a2070b7989
child 670853 337fcaec7eafeaa872173eb50b14b3dbb9067b90
push id81740
push usermichael.l.comella@gmail.com
push dateTue, 26 Sep 2017 23:57:01 +0000
reviewersliuche
bugs1403347
milestone58.0a1
Bug 1403347: Set dialog titles in createDialogItems. r=liuche We manipulate the data before the dialog is shown, rather than manipulating the Views after the dialog is shown: this is more stable. One question is what is the value of isHidden, which we branch on, when we're manipulating the data. isHidden is set: - When the preference is constructed (previous commit) - When the preference is set as the default (e.g. the default panel was hidden) - When "Hide" or "Show" is clicked in the preference Thus the preference (and hidden state) outlives the dialog and each time we reread the value of isHidden to set the dialog items. This would fix the bug but the dialog values are actually cached so we'll need to fix/remove that cache: coming up in the next changeset. MozReview-Commit-ID: 86v1RDNFZHZ
mobile/android/base/java/org/mozilla/gecko/preferences/PanelsPreference.java
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/PanelsPreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/PanelsPreference.java
@@ -35,19 +35,16 @@ public class PanelsPreference extends Cu
      */
     private static final int INDEX_DISPLAY_BUTTON = 1;
     private static final int INDEX_REORDER_BUTTON = 2;
 
     // Indices of buttons in context menu for reordering.
     private static final int INDEX_MOVE_UP_BUTTON = 0;
     private static final int INDEX_MOVE_DOWN_BUTTON = 1;
 
-    private String LABEL_HIDE;
-    private String LABEL_SHOW;
-
     private View preferenceView;
     protected boolean mIsHidden;
     private final boolean mIsRemovable;
 
     private boolean mAnimate;
     private static final int ANIMATION_DURATION_MS = 400;
 
     // State for reordering.
@@ -101,20 +98,19 @@ public class PanelsPreference extends Cu
         final Resources res = getContext().getResources();
         final String labelReorder = res.getString(R.string.pref_panels_reorder);
 
         if (mIsRemovable) {
             return new String[] { LABEL_SET_AS_DEFAULT, LABEL_REMOVE, labelReorder };
         }
 
         // Built-in panels can't be removed, so use show/hide options.
-        LABEL_HIDE = res.getString(R.string.pref_panels_hide);
-        LABEL_SHOW = res.getString(R.string.pref_panels_show);
+        final String labelShowHide = res.getString(mIsHidden ? R.string.pref_panels_show : R.string.pref_panels_hide);
 
-        return new String[] { LABEL_SET_AS_DEFAULT, LABEL_HIDE, labelReorder };
+        return new String[] { LABEL_SET_AS_DEFAULT, labelShowHide, labelReorder };
     }
 
     @Override
     public void setIsDefault(boolean isDefault) {
         mIsDefault = isDefault;
         if (isDefault) {
             setSummary(LABEL_IS_DEFAULT);
             if (mIsHidden) {
@@ -150,28 +146,16 @@ public class PanelsPreference extends Cu
                 orderDialog.show();
                 break;
 
             default:
                 Log.w(LOGTAG, "Selected index out of range: " + index);
         }
     }
 
-    @Override
-    protected void configureShownDialog() {
-        super.configureShownDialog();
-
-        // Handle Show/Hide buttons.
-        if (!mIsRemovable) {
-            final TextView hideButton = (TextView) mDialog.getListView().getChildAt(INDEX_DISPLAY_BUTTON);
-            hideButton.setText(mIsHidden ? LABEL_SHOW : LABEL_HIDE);
-        }
-    }
-
-
     private Dialog makeReorderDialog() {
         final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
 
         final Resources res = getContext().getResources();
         final String labelUp = res.getString(R.string.pref_panels_move_up);
         final String labelDown = res.getString(R.string.pref_panels_move_down);
 
         builder.setTitle(getTitle());