From 0821f6463ac5411cb72afaeb30aff1338d2ac66a Mon Sep 17 00:00:00 2001 From: ge78fug Date: Wed, 25 Jan 2023 19:25:57 +0100 Subject: [PATCH 1/6] Added bottom main-tabs feature --- .../newpipe/fragments/MainFragment.java | 37 +++++++++++++++++++ app/src/main/res/values/settings_keys.xml | 3 ++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/appearance_settings.xml | 8 ++++ 4 files changed, 50 insertions(+) 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 de68269e9..66b2f57b3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -3,12 +3,14 @@ package org.schabi.newpipe.fragments; import android.content.Context; import android.os.Bundle; import android.util.Log; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.RelativeLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -17,6 +19,7 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapterMenuWorkaround; import androidx.preference.PreferenceManager; +import androidx.viewpager.widget.ViewPager; import com.google.android.material.tabs.TabLayout; @@ -29,6 +32,7 @@ import org.schabi.newpipe.settings.tabs.Tab; import org.schabi.newpipe.settings.tabs.TabsManager; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ServiceHelper; +import org.schabi.newpipe.views.ScrollableTabLayout; import java.util.ArrayList; import java.util.List; @@ -106,6 +110,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } else if (hasTabsChanged) { setupTabs(); } + updateTabsPosition(); } @Override @@ -189,6 +194,38 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte private void updateTitleForTab(final int tabPosition) { setTitle(tabsList.get(tabPosition).getTabName(requireContext())); } + private void updateTabsPosition() { + final ScrollableTabLayout tabLayout = binding.mainTabLayout; + final ViewPager viewPager = binding.pager; + final RelativeLayout.LayoutParams tabParams = (RelativeLayout.LayoutParams) + tabLayout.getLayoutParams(); + final RelativeLayout.LayoutParams pagerParams = (RelativeLayout.LayoutParams) + viewPager.getLayoutParams(); + if (PreferenceManager.getDefaultSharedPreferences(requireContext()) + .getBoolean(getString(R.string.main_tabs_position_key), false)) { + tabParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP); + tabParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + pagerParams.removeRule(RelativeLayout.BELOW); + pagerParams.addRule(RelativeLayout.ABOVE, R.id.main_tab_layout); + tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_TOP); + final TypedValue typedValue = new TypedValue(); + getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, + true); + getActivity().getWindow().setNavigationBarColor(typedValue.data); + } else { + tabParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); + tabParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); + pagerParams.removeRule(RelativeLayout.ABOVE); + pagerParams.addRule(RelativeLayout.BELOW, R.id.main_tab_layout); + tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_BOTTOM); + final TypedValue typedValue = new TypedValue(); + getContext().getTheme().resolveAttribute(R.attr.colorSecondary, typedValue, + true); + getActivity().getWindow().setNavigationBarColor(typedValue.data); + } + tabLayout.setLayoutParams(tabParams); + viewPager.setLayoutParams(pagerParams); + } @Override public void onTabSelected(final TabLayout.Tab selectedTab) { diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 126818969..bbd46f7e1 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -241,6 +241,9 @@ caption_settings_key caption_user_set_key + + main_tabs_position + show_search_suggestions show_local_search_suggestions diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5a4ce92f2..654f01e1e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -213,6 +213,8 @@ Delete entire search history? Search history deleted Fast mode + Change the position of the main tabs + Main Tabs Position Error External storage unavailable diff --git a/app/src/main/res/xml/appearance_settings.xml b/app/src/main/res/xml/appearance_settings.xml index d726e26b7..beb46cdf5 100644 --- a/app/src/main/res/xml/appearance_settings.xml +++ b/app/src/main/res/xml/appearance_settings.xml @@ -66,4 +66,12 @@ app:singleLineTitle="false" app:iconSpaceReserved="false" /> + + From 2b37721a6eeb587446063e162e1a0b9cec2e2f87 Mon Sep 17 00:00:00 2001 From: Marius Wagner Date: Sun, 29 Jan 2023 19:37:46 +0100 Subject: [PATCH 2/6] Update app/src/main/res/values/strings.xml Co-authored-by: Stypox --- app/src/main/res/values/strings.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 654f01e1e..2cc1f1caf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -213,8 +213,8 @@ Delete entire search history? Search history deleted Fast mode - Change the position of the main tabs - Main Tabs Position + Move main tab selector to the bottom + Main tabs position Error External storage unavailable From 38db0cc713e2d22770556fc5ac31cdf736053fce Mon Sep 17 00:00:00 2001 From: ge78fug Date: Tue, 31 Jan 2023 16:07:57 +0100 Subject: [PATCH 3/6] Changed the color --- .../newpipe/fragments/MainFragment.java | 20 ++++++++++++++----- 1 file changed, 15 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 66b2f57b3..4a702e0dc 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.fragments; import android.content.Context; +import android.content.res.ColorStateList; import android.os.Bundle; import android.util.Log; import android.util.TypedValue; @@ -15,6 +16,7 @@ import android.widget.RelativeLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapterMenuWorkaround; @@ -208,10 +210,14 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte pagerParams.removeRule(RelativeLayout.BELOW); pagerParams.addRule(RelativeLayout.ABOVE, R.id.main_tab_layout); tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_TOP); - final TypedValue typedValue = new TypedValue(); - getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, + final TypedValue typedValueBackground = new TypedValue(); + getContext().getTheme().resolveAttribute(R.attr.colorSecondary, typedValueBackground, true); - getActivity().getWindow().setNavigationBarColor(typedValue.data); + tabLayout.setBackgroundColor(typedValueBackground.data); + tabLayout.setTabRippleColor(ColorStateList.valueOf( + getResources().getColor(R.color.gray))); + tabLayout.setTabIconTint(ColorStateList.valueOf(getResources().getColor(R.color.gray))); + tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.gray)); } else { tabParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); tabParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); @@ -219,9 +225,13 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte pagerParams.addRule(RelativeLayout.BELOW, R.id.main_tab_layout); tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_BOTTOM); final TypedValue typedValue = new TypedValue(); - getContext().getTheme().resolveAttribute(R.attr.colorSecondary, typedValue, + getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); - getActivity().getWindow().setNavigationBarColor(typedValue.data); + tabLayout.setBackgroundColor(typedValue.data); + tabLayout.setTabRippleColor(binding.mainTabLayout.getTabRippleColor().withAlpha(32)); + tabLayout.setTabIconTint(binding.mainTabLayout.getTabIconTint()); + tabLayout.setSelectedTabIndicatorColor(ContextCompat + .getColor(requireContext(), R.color.white)); } tabLayout.setLayoutParams(tabParams); viewPager.setLayoutParams(pagerParams); From 26b29ca78dc94722b8dfc75130eb723c1258725b Mon Sep 17 00:00:00 2001 From: ge78fug Date: Tue, 7 Feb 2023 18:46:40 +0100 Subject: [PATCH 4/6] Made the requested color changes --- .../newpipe/fragments/MainFragment.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 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 4a702e0dc..44d99cff7 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.res.ColorStateList; import android.os.Bundle; import android.util.Log; -import android.util.TypedValue; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -34,6 +33,7 @@ import org.schabi.newpipe.settings.tabs.Tab; import org.schabi.newpipe.settings.tabs.TabsManager; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ServiceHelper; +import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.views.ScrollableTabLayout; import java.util.ArrayList; @@ -210,26 +210,25 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte pagerParams.removeRule(RelativeLayout.BELOW); pagerParams.addRule(RelativeLayout.ABOVE, R.id.main_tab_layout); tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_TOP); - final TypedValue typedValueBackground = new TypedValue(); - getContext().getTheme().resolveAttribute(R.attr.colorSecondary, typedValueBackground, - true); - tabLayout.setBackgroundColor(typedValueBackground.data); - tabLayout.setTabRippleColor(ColorStateList.valueOf( - getResources().getColor(R.color.gray))); - tabLayout.setTabIconTint(ColorStateList.valueOf(getResources().getColor(R.color.gray))); - tabLayout.setSelectedTabIndicatorColor(getResources().getColor(R.color.gray)); + tabLayout.setBackgroundColor(ThemeHelper + .resolveColorFromAttr(requireContext(), R.attr.colorSecondary)); + final int colorAccent = ThemeHelper.resolveColorFromAttr( + requireContext(), R.attr.colorAccent); + tabLayout.setTabRippleColor(ColorStateList.valueOf(colorAccent).withAlpha(32)); + tabLayout.setTabIconTint(ColorStateList.valueOf(colorAccent)); + tabLayout.setSelectedTabIndicatorColor(colorAccent); } else { tabParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); tabParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); pagerParams.removeRule(RelativeLayout.ABOVE); pagerParams.addRule(RelativeLayout.BELOW, R.id.main_tab_layout); tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_BOTTOM); - final TypedValue typedValue = new TypedValue(); - getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, - true); - tabLayout.setBackgroundColor(typedValue.data); - tabLayout.setTabRippleColor(binding.mainTabLayout.getTabRippleColor().withAlpha(32)); - tabLayout.setTabIconTint(binding.mainTabLayout.getTabIconTint()); + tabLayout.setBackgroundColor(ThemeHelper + .resolveColorFromAttr(requireContext(), R.attr.colorPrimary)); + tabLayout.setTabRippleColor(ColorStateList.valueOf( + getResources().getColor(R.color.white)).withAlpha(32)); + tabLayout.setTabIconTint(ColorStateList.valueOf( + getResources().getColor(R.color.white))); tabLayout.setSelectedTabIndicatorColor(ContextCompat .getColor(requireContext(), R.color.white)); } From c8ffe65acfff3ea12094c1f0b1b8eb12a7126410 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 26 Feb 2023 15:42:49 +0100 Subject: [PATCH 5/6] Simplify code to set tab layout position --- .../newpipe/fragments/MainFragment.java | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 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 44d99cff7..531d7b1cb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -1,7 +1,15 @@ package org.schabi.newpipe.fragments; +import static android.widget.RelativeLayout.ABOVE; +import static android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM; +import static android.widget.RelativeLayout.ALIGN_PARENT_TOP; +import static android.widget.RelativeLayout.BELOW; +import static com.google.android.material.tabs.TabLayout.INDICATOR_GRAVITY_BOTTOM; +import static com.google.android.material.tabs.TabLayout.INDICATOR_GRAVITY_TOP; + import android.content.Context; import android.content.res.ColorStateList; +import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -12,10 +20,10 @@ import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapterMenuWorkaround; @@ -93,8 +101,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte binding.mainTabLayout.setupWithViewPager(binding.pager); binding.mainTabLayout.addOnTabSelectedListener(this); - binding.mainTabLayout.setTabRippleColor(binding.mainTabLayout.getTabRippleColor() - .withAlpha(32)); setupTabs(); } @@ -112,7 +118,8 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } else if (hasTabsChanged) { setupTabs(); } - updateTabsPosition(); + + updateTabLayoutPosition(); } @Override @@ -196,44 +203,38 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte private void updateTitleForTab(final int tabPosition) { setTitle(tabsList.get(tabPosition).getTabName(requireContext())); } - private void updateTabsPosition() { + + private void updateTabLayoutPosition() { final ScrollableTabLayout tabLayout = binding.mainTabLayout; final ViewPager viewPager = binding.pager; - final RelativeLayout.LayoutParams tabParams = (RelativeLayout.LayoutParams) - tabLayout.getLayoutParams(); - final RelativeLayout.LayoutParams pagerParams = (RelativeLayout.LayoutParams) - viewPager.getLayoutParams(); - if (PreferenceManager.getDefaultSharedPreferences(requireContext()) - .getBoolean(getString(R.string.main_tabs_position_key), false)) { - tabParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP); - tabParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); - pagerParams.removeRule(RelativeLayout.BELOW); - pagerParams.addRule(RelativeLayout.ABOVE, R.id.main_tab_layout); - tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_TOP); - tabLayout.setBackgroundColor(ThemeHelper - .resolveColorFromAttr(requireContext(), R.attr.colorSecondary)); - final int colorAccent = ThemeHelper.resolveColorFromAttr( - requireContext(), R.attr.colorAccent); - tabLayout.setTabRippleColor(ColorStateList.valueOf(colorAccent).withAlpha(32)); - tabLayout.setTabIconTint(ColorStateList.valueOf(colorAccent)); - tabLayout.setSelectedTabIndicatorColor(colorAccent); - } else { - tabParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); - tabParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); - pagerParams.removeRule(RelativeLayout.ABOVE); - pagerParams.addRule(RelativeLayout.BELOW, R.id.main_tab_layout); - tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_BOTTOM); - tabLayout.setBackgroundColor(ThemeHelper - .resolveColorFromAttr(requireContext(), R.attr.colorPrimary)); - tabLayout.setTabRippleColor(ColorStateList.valueOf( - getResources().getColor(R.color.white)).withAlpha(32)); - tabLayout.setTabIconTint(ColorStateList.valueOf( - getResources().getColor(R.color.white))); - tabLayout.setSelectedTabIndicatorColor(ContextCompat - .getColor(requireContext(), R.color.white)); - } + final boolean bottom = PreferenceManager.getDefaultSharedPreferences(requireContext()) + .getBoolean(getString(R.string.main_tabs_position_key), false); + + // change layout params to make the tab layout appear either at the top or at the bottom + final var tabParams = (RelativeLayout.LayoutParams) tabLayout.getLayoutParams(); + final var pagerParams = (RelativeLayout.LayoutParams) viewPager.getLayoutParams(); + + tabParams.removeRule(bottom ? ALIGN_PARENT_TOP : ALIGN_PARENT_BOTTOM); + tabParams.addRule(bottom ? ALIGN_PARENT_BOTTOM : ALIGN_PARENT_TOP); + pagerParams.removeRule(bottom ? BELOW : ABOVE); + pagerParams.addRule(bottom ? ABOVE : BELOW, R.id.main_tab_layout); + tabLayout.setSelectedTabIndicatorGravity( + bottom ? INDICATOR_GRAVITY_TOP : INDICATOR_GRAVITY_BOTTOM); + tabLayout.setLayoutParams(tabParams); viewPager.setLayoutParams(pagerParams); + + // change the background and icon color of the tab layout: + // service-colored at the top, app-background-colored at the bottom + tabLayout.setBackgroundColor(ThemeHelper.resolveColorFromAttr(requireContext(), + bottom ? R.attr.colorSecondary : R.attr.colorPrimary)); + + @ColorInt final int iconColor = bottom + ? ThemeHelper.resolveColorFromAttr(requireContext(), R.attr.colorAccent) + : Color.WHITE; + tabLayout.setTabRippleColor(ColorStateList.valueOf(iconColor).withAlpha(32)); + tabLayout.setTabIconTint(ColorStateList.valueOf(iconColor)); + tabLayout.setSelectedTabIndicatorColor(iconColor); } @Override From 65680b2ccfe2c5e15447f257f1bb247b4415a441 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 26 Feb 2023 15:58:09 +0100 Subject: [PATCH 6/6] Only update main tabs position when it changes --- .../newpipe/fragments/MainFragment.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 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 531d7b1cb..e1b61ea7c 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -8,6 +8,7 @@ import static com.google.android.material.tabs.TabLayout.INDICATOR_GRAVITY_BOTTO import static com.google.android.material.tabs.TabLayout.INDICATOR_GRAVITY_TOP; import android.content.Context; +import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.graphics.Color; import android.os.Bundle; @@ -56,8 +57,11 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte private boolean hasTabsChanged = false; - private boolean previousYoutubeRestrictedModeEnabled; + private SharedPreferences prefs; + private boolean youtubeRestrictedModeEnabled; private String youtubeRestrictedModeEnabledKey; + private boolean mainTabsPositionBottom; + private String mainTabsPositionKey; /*////////////////////////////////////////////////////////////////////////// // Fragment's LifeCycle @@ -80,10 +84,11 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte } }); + prefs = PreferenceManager.getDefaultSharedPreferences(requireContext()); youtubeRestrictedModeEnabledKey = getString(R.string.youtube_restricted_mode_enabled); - previousYoutubeRestrictedModeEnabled = - PreferenceManager.getDefaultSharedPreferences(requireContext()) - .getBoolean(youtubeRestrictedModeEnabledKey, false); + youtubeRestrictedModeEnabled = prefs.getBoolean(youtubeRestrictedModeEnabledKey, false); + mainTabsPositionKey = getString(R.string.main_tabs_position_key); + mainTabsPositionBottom = prefs.getBoolean(mainTabsPositionKey, false); } @Override @@ -103,23 +108,25 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte binding.mainTabLayout.addOnTabSelectedListener(this); setupTabs(); + updateTabLayoutPosition(); } @Override public void onResume() { super.onResume(); - final boolean youtubeRestrictedModeEnabled = - PreferenceManager.getDefaultSharedPreferences(requireContext()) - .getBoolean(youtubeRestrictedModeEnabledKey, false); - if (previousYoutubeRestrictedModeEnabled != youtubeRestrictedModeEnabled) { - previousYoutubeRestrictedModeEnabled = youtubeRestrictedModeEnabled; - setupTabs(); - } else if (hasTabsChanged) { + final boolean newYoutubeRestrictedModeEnabled = + prefs.getBoolean(youtubeRestrictedModeEnabledKey, false); + if (youtubeRestrictedModeEnabled != newYoutubeRestrictedModeEnabled || hasTabsChanged) { + youtubeRestrictedModeEnabled = newYoutubeRestrictedModeEnabled; setupTabs(); } - updateTabLayoutPosition(); + final boolean newMainTabsPosition = prefs.getBoolean(mainTabsPositionKey, false); + if (mainTabsPositionBottom != newMainTabsPosition) { + mainTabsPositionBottom = newMainTabsPosition; + updateTabLayoutPosition(); + } } @Override @@ -207,8 +214,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte private void updateTabLayoutPosition() { final ScrollableTabLayout tabLayout = binding.mainTabLayout; final ViewPager viewPager = binding.pager; - final boolean bottom = PreferenceManager.getDefaultSharedPreferences(requireContext()) - .getBoolean(getString(R.string.main_tabs_position_key), false); + final boolean bottom = mainTabsPositionBottom; // change layout params to make the tab layout appear either at the top or at the bottom final var tabParams = (RelativeLayout.LayoutParams) tabLayout.getLayoutParams();