Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added lighlight methods without triggering listener #770

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,27 @@ public void selectTabAtPosition(int position) {
selectTabAtPosition(position, false);
}

public void selectOnlyWithId(@IdRes final int tabResId) {
final int tabPosition = findPositionForTabWithId(tabResId);
selectTabAtPosition(tabPosition, false, true);
}


public void selectOnlyAtPosition(final int position) {
selectTabAtPosition(position, false, true);
}

/**
* Select a tab at the specified position.
*
* @param position the position to select.
* @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.");
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down