Bug 848267 - Awesomebar loses correct tab selection, r=wesj, f=lucasr

This commit is contained in:
Mark Capella 2013-04-13 08:34:13 -04:00
parent bb863324be
commit 6824a2103c

View File

@ -35,12 +35,8 @@ public class AwesomeBarTabs extends TabHost
private String mTarget;
private ViewPager mViewPager;
private AwesomePagerAdapter mPagerAdapter;
private AwesomeBarTab mTabs[];
// FIXME: This value should probably come from a
// prefs key (just like XUL-based fennec)
private static final int MAX_RESULTS = 100;
private AwesomeBarTab mTabs[];
public interface OnUrlOpenListener {
public void onUrlOpen(String url, String title);
@ -155,7 +151,7 @@ public class AwesomeBarTabs extends TabHost
mViewPager = (ViewPager) findViewById(R.id.tabviewpager);
mPagerAdapter = new AwesomePagerAdapter();
mViewPager.setAdapter(mPagerAdapter);
mViewPager.setCurrentItem(0);
mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrollStateChanged(int state) { }
@ -176,10 +172,6 @@ public class AwesomeBarTabs extends TabHost
i);
}
tabWidget.setCurrentTab(0);
styleSelectedTab();
// Initialize "All Pages" list with no filter
filter("");
}
@ -207,12 +199,16 @@ public class AwesomeBarTabs extends TabHost
}
public void setCurrentItemByTag(String tag) {
mViewPager.setCurrentItem(getTabIdByTag(tag));
}
public int getTabIdByTag(String tag) {
for (int i = 0; i < mTabs.length; i++) {
if (tag.equals(mTabs[i].getTag())) {
mViewPager.setCurrentItem(i);
break;
return i;
}
}
return -1;
}
private void styleSelectedTab() {
@ -313,25 +309,23 @@ public class AwesomeBarTabs extends TabHost
}
public void filter(String searchTerm) {
// Don't let the tab's content steal focus on tab switch
setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
// If searching, disable left / right tab swipes
mSearching = searchTerm.length() != 0;
// reset the pager adapter to force repopulating the cache
mViewPager.setAdapter(mPagerAdapter);
// Ensure the 'All Pages' tab is selected
AllPagesTab allPages = getAllPagesTab();
setCurrentTabByTag(allPages.getTag());
// Restore normal focus behavior on tab host
setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
// The tabs should only be visible if there's no on-going search
mSearching = searchTerm.length() != 0;
// reset the pager adapter to force repopulating the cache
mViewPager.setAdapter(mPagerAdapter);
int tabsVisibility = !mSearching ? View.VISIBLE : View.GONE;
findViewById(R.id.tab_widget_container).setVisibility(tabsVisibility);
getTabWidget().setCurrentTab(getTabIdByTag(allPages.getTag()));
styleSelectedTab();
// Perform the actual search
allPages.filter(searchTerm);
// If searching, hide the tabs bar
findViewById(R.id.tab_widget_container).setVisibility(mSearching ? View.GONE : View.VISIBLE);
}
public boolean isInReadingList() {