From 3bd7fdf7c19937dbdccb87977252178757bfe80b Mon Sep 17 00:00:00 2001 From: Jonathan Koren Date: Tue, 14 Mar 2017 23:26:48 +0000 Subject: [PATCH] Make bottom navigation item pool non-static This also fixes a flaky test where items acquired from the pool were still attached to their old parent. Bug: 35422793 Bug: 35395583 Change-Id: I303d49bb4a287856baf997bd85d42fd53131c32b PiperOrigin-RevId: 150129729 --- .../design/internal/BottomNavigationMenuView.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/src/android/support/design/internal/BottomNavigationMenuView.java b/lib/src/android/support/design/internal/BottomNavigationMenuView.java index caf39dfd6..e1a8f69d3 100644 --- a/lib/src/android/support/design/internal/BottomNavigationMenuView.java +++ b/lib/src/android/support/design/internal/BottomNavigationMenuView.java @@ -44,8 +44,7 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView { private final int mItemHeight; private final OnClickListener mOnClickListener; private final BottomNavigationAnimationHelperBase mAnimationHelper; - private static final Pools.Pool sItemPool = - new Pools.SynchronizedPool<>(5); + private final Pools.Pool mItemPool = new Pools.SynchronizedPool<>(5); private boolean mShiftingMode = true; @@ -249,12 +248,12 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView { } public void buildMenuView() { + removeAllViews(); if (mButtons != null) { for (BottomNavigationItemView item : mButtons) { - sItemPool.release(item); + mItemPool.release(item); } } - removeAllViews(); if (mMenu.size() == 0) { mSelectedItemId = 0; mSelectedItemPosition = 0; @@ -306,7 +305,7 @@ public class BottomNavigationMenuView extends ViewGroup implements MenuView { } private BottomNavigationItemView getNewItem() { - BottomNavigationItemView item = sItemPool.acquire(); + BottomNavigationItemView item = mItemPool.acquire(); if (item == null) { item = new BottomNavigationItemView(getContext()); }