Use tab position from parameters instead of relying on the view pager

This commit is contained in:
Mauricio Colli 2019-10-19 21:31:19 -03:00
parent 38a0395d45
commit 544cae4fb4
No known key found for this signature in database
GPG key ID: F200BFD6F29DDD85

View file

@ -147,7 +147,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
viewPager.setOffscreenPageLimit(tabsList.size()); viewPager.setOffscreenPageLimit(tabsList.size());
updateTabsIconAndDescription(); updateTabsIconAndDescription();
updateCurrentTitle(); updateTitleForTab(viewPager.getCurrentItem());
hasTabsChanged = false; hasTabsChanged = false;
} }
@ -163,14 +163,14 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
} }
} }
private void updateCurrentTitle() { private void updateTitleForTab(int tabPosition) {
setTitle(tabsList.get(viewPager.getCurrentItem()).getTabName(requireContext())); setTitle(tabsList.get(tabPosition).getTabName(requireContext()));
} }
@Override @Override
public void onTabSelected(TabLayout.Tab selectedTab) { public void onTabSelected(TabLayout.Tab selectedTab) {
if (DEBUG) Log.d(TAG, "onTabSelected() called with: selectedTab = [" + selectedTab + "]"); if (DEBUG) Log.d(TAG, "onTabSelected() called with: selectedTab = [" + selectedTab + "]");
updateCurrentTitle(); updateTitleForTab(selectedTab.getPosition());
} }
@Override @Override
@ -180,7 +180,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
@Override @Override
public void onTabReselected(TabLayout.Tab tab) { public void onTabReselected(TabLayout.Tab tab) {
if (DEBUG) Log.d(TAG, "onTabReselected() called with: tab = [" + tab + "]"); if (DEBUG) Log.d(TAG, "onTabReselected() called with: tab = [" + tab + "]");
updateCurrentTitle(); updateTitleForTab(tab.getPosition());
} }
private static class SelectedTabsPagerAdapter extends FragmentStatePagerAdapter { private static class SelectedTabsPagerAdapter extends FragmentStatePagerAdapter {