From 544cae4fb410d382e06180cbcd1d4504e1266d29 Mon Sep 17 00:00:00 2001 From: Mauricio Colli Date: Sat, 19 Oct 2019 21:31:19 -0300 Subject: [PATCH] Use tab position from parameters instead of relying on the view pager --- .../org/schabi/newpipe/fragments/MainFragment.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 79199a14d..720e0f216 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -147,7 +147,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte viewPager.setOffscreenPageLimit(tabsList.size()); updateTabsIconAndDescription(); - updateCurrentTitle(); + updateTitleForTab(viewPager.getCurrentItem()); hasTabsChanged = false; } @@ -163,14 +163,14 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } } - private void updateCurrentTitle() { - setTitle(tabsList.get(viewPager.getCurrentItem()).getTabName(requireContext())); + private void updateTitleForTab(int tabPosition) { + setTitle(tabsList.get(tabPosition).getTabName(requireContext())); } @Override public void onTabSelected(TabLayout.Tab selectedTab) { if (DEBUG) Log.d(TAG, "onTabSelected() called with: selectedTab = [" + selectedTab + "]"); - updateCurrentTitle(); + updateTitleForTab(selectedTab.getPosition()); } @Override @@ -180,7 +180,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte @Override public void onTabReselected(TabLayout.Tab tab) { if (DEBUG) Log.d(TAG, "onTabReselected() called with: tab = [" + tab + "]"); - updateCurrentTitle(); + updateTitleForTab(tab.getPosition()); } private static class SelectedTabsPagerAdapter extends FragmentStatePagerAdapter {