From 425f4ccf7ca9de92a2396f6884f369a64912eeb5 Mon Sep 17 00:00:00 2001 From: echan0524 Date: Tue, 9 May 2017 15:25:13 -0400 Subject: [PATCH 1/2] added lighlight methods without triggering listener --- .../com/roughike/bottombar/BottomBar.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java index 350cc316..11433b2e 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java @@ -543,6 +543,16 @@ public void selectTabAtPosition(int position) { selectTabAtPosition(position, false); } + public void highlightTabWithId(@IdRes final int tabResId) { + final int tabPosition = findPositionForTabWithId(tabResId); + selectTabAtPosition(tabPosition, false, true); + } + + + public void highlightTabAtPosition(final int position) { + selectTabAtPosition(position, false, true); + } + /** * Select a tab at the specified position. * @@ -550,6 +560,10 @@ public void selectTabAtPosition(int position) { * @param animate should the tab change be animated or not. */ public void selectTabAtPosition(int position, boolean animate) { + selectTabAtPosition(position, animate, false); + } + + private void selectTabAtPosition(final int position, final boolean animate, final boolean highlightOnly) { if (position > getTabCount() - 1 || position < 0) { throw new IndexOutOfBoundsException("Can't select tab at position " + position + ". This BottomBar has no items at that position."); @@ -561,7 +575,7 @@ public void selectTabAtPosition(int position, boolean animate) { oldTab.deselect(animate); newTab.select(animate); - updateSelectedTab(position); + updateSelectedTab(position, highlightOnly); shiftingMagic(oldTab, newTab, animate); handleBackgroundColorChange(newTab, animate); } @@ -941,15 +955,21 @@ private boolean handleLongClick(BottomBarTab longClickedTab) { return true; } - private void updateSelectedTab(int newPosition) { + private void updateSelectedTab(final int newPosition) { + updateSelectedTab(newPosition, false); + } + + private void updateSelectedTab(final int newPosition, final boolean highlightOnly) { int newTabId = getTabAtPosition(newPosition).getId(); - if (newPosition != currentTabPosition) { - if (onTabSelectListener != null) { - onTabSelectListener.onTabSelected(newTabId); + if (!highlightOnly) { + if (newPosition != currentTabPosition) { + if (onTabSelectListener != null) { + onTabSelectListener.onTabSelected(newTabId); + } + } else if (onTabReselectListener != null && !ignoreTabReselectionListener) { + onTabReselectListener.onTabReSelected(newTabId); } - } else if (onTabReselectListener != null && !ignoreTabReselectionListener) { - onTabReselectListener.onTabReSelected(newTabId); } currentTabPosition = newPosition; From 5445af062b58aff56543b40c23f59ae1a6053fcb Mon Sep 17 00:00:00 2001 From: echan0524 Date: Mon, 15 May 2017 13:49:29 -0400 Subject: [PATCH 2/2] methods name change --- .../src/main/java/com/roughike/bottombar/BottomBar.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java index 11433b2e..411e02e2 100644 --- a/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java +++ b/bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java @@ -543,13 +543,13 @@ public void selectTabAtPosition(int position) { selectTabAtPosition(position, false); } - public void highlightTabWithId(@IdRes final int tabResId) { + public void selectOnlyWithId(@IdRes final int tabResId) { final int tabPosition = findPositionForTabWithId(tabResId); selectTabAtPosition(tabPosition, false, true); } - public void highlightTabAtPosition(final int position) { + public void selectOnlyAtPosition(final int position) { selectTabAtPosition(position, false, true); }