Bug 1403347: Move initial setHidden to panel preference constructor. r=liuche
This is a code clean-up. Functionally, this is the same to the previous
implementation.
setHidden was originally called right after the constructor is called and so
should just be called from the constructor. If it's not called from the
constructor, there can be a period of confusion where a developer wonders, "Has
isHidden been initialized by the time this other method I care about has been
called?" This should make those questions disappear.
This commit does not need to be uplifted (to change less in 57 and that the
other code does not depend on it) but I'm placing it first so it's clearer to
my reviewer when isHidden is initialized (which is relevant to my other
patches).
MozReview-Commit-ID: 80KXFDB1poY
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/PanelsPreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/PanelsPreference.java
@@ -49,21 +49,24 @@ public class PanelsPreference extends Cu
private boolean mAnimate;
private static final int ANIMATION_DURATION_MS = 400;
// State for reordering.
private int mPositionState = -1;
private final int mIndex;
- public PanelsPreference(Context context, CustomListCategory parentCategory, boolean isRemovable, int index, boolean animate) {
+ public PanelsPreference(final Context context, final CustomListCategory parentCategory, final boolean isRemovable,
+ final boolean isHidden, final int index, final boolean animate) {
super(context, parentCategory);
mIsRemovable = isRemovable;
mIndex = index;
mAnimate = animate;
+
+ setHidden(isHidden);
}
@Override
protected int getPreferenceLayoutResource() {
return R.layout.preference_panels;
}
@Override
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/PanelsPreferenceCategory.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/PanelsPreferenceCategory.java
@@ -95,36 +95,33 @@ public class PanelsPreferenceCategory ex
displayHomeConfig(state, animatePanelId);
}
}
private void displayHomeConfig(HomeConfig.State configState, String animatePanelId) {
int index = 0;
for (PanelConfig panelConfig : configState) {
final boolean isRemovable = panelConfig.isDynamic();
+ final boolean isHidden = panelConfig.isDisabled();
// Create and add the pref.
final String panelId = panelConfig.getId();
final boolean animate = TextUtils.equals(animatePanelId, panelId);
final PanelsPreference pref;
if (TextUtils.equals(panelId, HomeConfig.getIdForBuiltinPanelType(HomeConfig.PanelType.TOP_SITES))) {
- pref = new TopSitesPanelsPreference(getContext(), PanelsPreferenceCategory.this, isRemovable, index, animate);
+ pref = new TopSitesPanelsPreference(getContext(), PanelsPreferenceCategory.this, isRemovable, isHidden, index, animate);
} else {
- pref = new PanelsPreference(getContext(), PanelsPreferenceCategory.this, isRemovable, index, animate);
+ pref = new PanelsPreference(getContext(), PanelsPreferenceCategory.this, isRemovable, isHidden, index, animate);
}
pref.setTitle(panelConfig.getTitle());
pref.setKey(panelConfig.getId());
// XXX: Pull icon from PanelInfo.
addPreference(pref);
- if (panelConfig.isDisabled()) {
- pref.setHidden(true);
- }
-
index++;
}
setPositionState();
setDefaultFromConfig();
}
private void setPositionState() {
--- a/mobile/android/base/java/org/mozilla/gecko/preferences/TopSitesPanelsPreference.java
+++ b/mobile/android/base/java/org/mozilla/gecko/preferences/TopSitesPanelsPreference.java
@@ -10,18 +10,19 @@ import android.view.LayoutInflater;
import org.mozilla.gecko.R;
/**
* Custom preference that also adds additional options to the dialog of preferences for Top Sites settings.
*/
public class TopSitesPanelsPreference extends PanelsPreference {
- TopSitesPanelsPreference(Context context, CustomListCategory parentCategory, boolean isRemovable, int index, boolean animate) {
- super(context, parentCategory, isRemovable, index, animate);
+ TopSitesPanelsPreference(final Context context, final CustomListCategory parentCategory, final boolean isRemovable,
+ final boolean isHidden, final int index, final boolean animate) {
+ super(context, parentCategory, isRemovable, isHidden, index, animate);
}
@Override
protected void configureDialogBuilder(AlertDialog.Builder builder) {
final LayoutInflater inflater = LayoutInflater.from(getContext());
builder.setView(inflater.inflate(R.layout.preference_topsites_panel_dialog, null));
}
}
\ No newline at end of file