diff --git a/litho-core/src/main/java/com/facebook/litho/Border.java b/litho-core/src/main/java/com/facebook/litho/Border.java index 4b9f5117736..b3145739a02 100644 --- a/litho-core/src/main/java/com/facebook/litho/Border.java +++ b/litho-core/src/main/java/com/facebook/litho/Border.java @@ -48,9 +48,8 @@ public class Border { @Retention(RetentionPolicy.SOURCE) @IntDef( - flag = true, - value = {Corner.TOP_LEFT, Corner.TOP_RIGHT, Corner.BOTTOM_RIGHT, Corner.BOTTOM_LEFT} - ) + flag = true, + value = {Corner.TOP_LEFT, Corner.TOP_RIGHT, Corner.BOTTOM_RIGHT, Corner.BOTTOM_LEFT}) public @interface Corner { int TOP_LEFT = 0; int TOP_RIGHT = 1; @@ -446,7 +445,6 @@ public Builder pathDashEffect( public Border build() { checkNotBuilt(); - mResourceResolver.release(); mResourceResolver = null; if (mNumPathEffects == MAX_PATH_EFFECTS) { diff --git a/litho-core/src/main/java/com/facebook/litho/ResourceResolver.java b/litho-core/src/main/java/com/facebook/litho/ResourceResolver.java index 64e06fed367..2ac64be45af 100644 --- a/litho-core/src/main/java/com/facebook/litho/ResourceResolver.java +++ b/litho-core/src/main/java/com/facebook/litho/ResourceResolver.java @@ -30,20 +30,11 @@ import androidx.annotation.StringRes; public class ResourceResolver { - private Resources mResources; - private Resources.Theme mTheme; - private ResourceCache mResourceCache; - - // Use for *Attr methods to retrieve attributes without needing to - // allocate a new int[] for each call. - private final int[] mAttrs = new int[1]; + private final Resources mResources; + private final Resources.Theme mTheme; + private final ResourceCache mResourceCache; public ResourceResolver(ComponentContext context) { - // Only temporary whilst conversion is underway. - init(context); - } - - public void init(ComponentContext context) { mResources = context.getAndroidContext().getResources(); mTheme = context.getAndroidContext().getTheme(); mResourceCache = context.getResourceCache(); @@ -230,8 +221,7 @@ public Drawable resolveDrawableRes(@DrawableRes int resId) { } public String resolveStringAttr(@AttrRes int attrResId, @StringRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { String result = a.getString(0); @@ -247,8 +237,7 @@ public String resolveStringAttr(@AttrRes int attrResId, @StringRes int defResId) @Nullable public String[] resolveStringArrayAttr(@AttrRes int attrResId, @ArrayRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return resolveStringArrayRes(a.getResourceId(0, defResId)); @@ -258,8 +247,7 @@ public String[] resolveStringArrayAttr(@AttrRes int attrResId, @ArrayRes int def } public int resolveIntAttr(@AttrRes int attrResId, @IntegerRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return a.getInt(0, resolveIntRes(defResId)); @@ -270,8 +258,7 @@ public int resolveIntAttr(@AttrRes int attrResId, @IntegerRes int defResId) { @Nullable public int[] resolveIntArrayAttr(@AttrRes int attrResId, @ArrayRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return resolveIntArrayRes(a.getResourceId(0, defResId)); @@ -292,8 +279,7 @@ public Integer[] resolveIntegerArrayAttr(@AttrRes int attrResId, @ArrayRes int d } public boolean resolveBoolAttr(@AttrRes int attrResId, @BoolRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return a.getBoolean(0, resolveBoolRes(defResId)); @@ -303,8 +289,7 @@ public boolean resolveBoolAttr(@AttrRes int attrResId, @BoolRes int defResId) { } public int resolveColorAttr(@AttrRes int attrResId, @ColorRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return a.getColor(0, resolveColorRes(defResId)); @@ -314,8 +299,7 @@ public int resolveColorAttr(@AttrRes int attrResId, @ColorRes int defResId) { } public int resolveDimenSizeAttr(@AttrRes int attrResId, @DimenRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return a.getDimensionPixelSize(0, resolveDimenSizeRes(defResId)); @@ -325,8 +309,7 @@ public int resolveDimenSizeAttr(@AttrRes int attrResId, @DimenRes int defResId) } public int resolveDimenOffsetAttr(@AttrRes int attrResId, @DimenRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return a.getDimensionPixelOffset(0, resolveDimenOffsetRes(defResId)); @@ -336,8 +319,7 @@ public int resolveDimenOffsetAttr(@AttrRes int attrResId, @DimenRes int defResId } public float resolveFloatAttr(@AttrRes int attrResId, @DimenRes int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return a.getDimension(0, resolveFloatRes(defResId)); @@ -352,8 +334,7 @@ public Drawable resolveDrawableAttr(@AttrRes int attrResId, @DrawableRes int def return null; } - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return resolveDrawableRes(a.getResourceId(0, defResId)); @@ -363,8 +344,7 @@ public Drawable resolveDrawableAttr(@AttrRes int attrResId, @DrawableRes int def } final int resolveResIdAttr(@AttrRes int attrResId, int defResId) { - mAttrs[0] = attrResId; - TypedArray a = mTheme.obtainStyledAttributes(mAttrs); + TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return a.getResourceId(0, defResId); @@ -372,10 +352,4 @@ final int resolveResIdAttr(@AttrRes int attrResId, int defResId) { a.recycle(); } } - - public final void release() { - mResources = null; - mTheme = null; - mResourceCache = null; - } } diff --git a/litho-sections-core/src/main/java/com/facebook/litho/sections/Section.java b/litho-sections-core/src/main/java/com/facebook/litho/sections/Section.java index 14e5c0f0c8c..978b77d2f2e 100644 --- a/litho-sections-core/src/main/java/com/facebook/litho/sections/Section.java +++ b/litho-sections-core/src/main/java/com/facebook/litho/sections/Section.java @@ -108,14 +108,11 @@ protected T loadingEventHandler(EventHandler loadingEventHandler) public abstract T getThis(); - /** - * @return The immutable {@link Section}. - */ + /** @return The immutable {@link Section}. */ public abstract Section build(); protected void release() { mSection = null; - mResourceResolver.release(); mResourceResolver = null; } @@ -210,17 +207,15 @@ public Section getParent() { return mParent; } - /** - * Sets the parent of this {@link Section} in the tree. - */ + /** Sets the parent of this {@link Section} in the tree. */ void setParent(Section parent) { mParent = parent; } /** * Invalidates The subtree having its root in this {@link Section}. When a subtree is invalidated, - * the {@link OnDiff} will be invoked - * regardless of whether the {@link com.facebook.litho.annotations.Prop}s changed or not. + * the {@link OnDiff} will be invoked regardless of whether the {@link + * com.facebook.litho.annotations.Prop}s changed or not. */ void invalidate() { invalidateInternal(this); @@ -243,9 +238,8 @@ void setInvalidated(boolean invalidated) { } /** - * @return a clone of this {@link Section}. - * if deepCopy is false the clone won't contain any children or count as it will - * be returned in a pre - ChangeSet generation state. + * @return a clone of this {@link Section}. if deepCopy is false the clone won't contain any + * children or count as it will be returned in a pre - ChangeSet generation state. */ public Section makeShallowCopy(boolean deepCopy) { try { @@ -338,11 +332,9 @@ protected StateContainer getStateContainer() { return null; } - /** - * Called when this {@link Section} is not in use anymore to release its resources. - */ + /** Called when this {@link Section} is not in use anymore to release its resources. */ void release() { - //TODO release list into a pool t11953296 + // TODO release list into a pool t11953296 } void generateKeyAndSet(SectionContext c, String globalKey) { @@ -384,7 +376,7 @@ public String generateUniqueGlobalKeyForChild(Section section, String childKey) static Map> acquireChildrenMap( @Nullable Section currentComponent) { - //TODO use pools instead t11953296 + // TODO use pools instead t11953296 final HashMap> childrenMap = new HashMap<>(); if (currentComponent == null) { return childrenMap; @@ -405,7 +397,7 @@ static Map> acquireChildrenMap( } static void releaseChildrenMap(Map> newChildren) { - //TODO use pools t11953296 + // TODO use pools t11953296 } @VisibleForTesting