|
3 | 3 | import android.content.Context; |
4 | 4 | import android.os.Bundle; |
5 | 5 | import android.util.Log; |
| 6 | +import android.util.TypedValue; |
6 | 7 | import android.view.LayoutInflater; |
7 | 8 | import android.view.Menu; |
8 | 9 | import android.view.MenuInflater; |
9 | 10 | import android.view.MenuItem; |
10 | 11 | import android.view.View; |
11 | 12 | import android.view.ViewGroup; |
| 13 | +import android.widget.RelativeLayout; |
12 | 14 |
|
13 | 15 | import androidx.annotation.NonNull; |
14 | 16 | import androidx.annotation.Nullable; |
|
17 | 19 | import androidx.fragment.app.FragmentManager; |
18 | 20 | import androidx.fragment.app.FragmentStatePagerAdapterMenuWorkaround; |
19 | 21 | import androidx.preference.PreferenceManager; |
| 22 | +import androidx.viewpager.widget.ViewPager; |
20 | 23 |
|
21 | 24 | import com.google.android.material.tabs.TabLayout; |
22 | 25 |
|
|
29 | 32 | import org.schabi.newpipe.settings.tabs.TabsManager; |
30 | 33 | import org.schabi.newpipe.util.NavigationHelper; |
31 | 34 | import org.schabi.newpipe.util.ServiceHelper; |
| 35 | +import org.schabi.newpipe.views.ScrollableTabLayout; |
32 | 36 |
|
33 | 37 | import java.util.ArrayList; |
34 | 38 | import java.util.List; |
@@ -106,6 +110,7 @@ public void onResume() { |
106 | 110 | } else if (hasTabsChanged) { |
107 | 111 | setupTabs(); |
108 | 112 | } |
| 113 | + updateTabsPosition(); |
109 | 114 | } |
110 | 115 |
|
111 | 116 | @Override |
@@ -189,6 +194,38 @@ private void updateTabsIconAndDescription() { |
189 | 194 | private void updateTitleForTab(final int tabPosition) { |
190 | 195 | setTitle(tabsList.get(tabPosition).getTabName(requireContext())); |
191 | 196 | } |
| 197 | + private void updateTabsPosition() { |
| 198 | + final ScrollableTabLayout tabLayout = binding.mainTabLayout; |
| 199 | + final ViewPager viewPager = binding.pager; |
| 200 | + final RelativeLayout.LayoutParams tabParams = (RelativeLayout.LayoutParams) |
| 201 | + tabLayout.getLayoutParams(); |
| 202 | + final RelativeLayout.LayoutParams pagerParams = (RelativeLayout.LayoutParams) |
| 203 | + viewPager.getLayoutParams(); |
| 204 | + if (PreferenceManager.getDefaultSharedPreferences(requireContext()) |
| 205 | + .getBoolean(getString(R.string.main_tabs_position_key), false)) { |
| 206 | + tabParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 207 | + tabParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 208 | + pagerParams.removeRule(RelativeLayout.BELOW); |
| 209 | + pagerParams.addRule(RelativeLayout.ABOVE, R.id.main_tab_layout); |
| 210 | + tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_TOP); |
| 211 | + final TypedValue typedValue = new TypedValue(); |
| 212 | + getContext().getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, |
| 213 | + true); |
| 214 | + getActivity().getWindow().setNavigationBarColor(typedValue.data); |
| 215 | + } else { |
| 216 | + tabParams.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 217 | + tabParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 218 | + pagerParams.removeRule(RelativeLayout.ABOVE); |
| 219 | + pagerParams.addRule(RelativeLayout.BELOW, R.id.main_tab_layout); |
| 220 | + tabLayout.setSelectedTabIndicatorGravity(TabLayout.INDICATOR_GRAVITY_BOTTOM); |
| 221 | + final TypedValue typedValue = new TypedValue(); |
| 222 | + getContext().getTheme().resolveAttribute(R.attr.colorSecondary, typedValue, |
| 223 | + true); |
| 224 | + getActivity().getWindow().setNavigationBarColor(typedValue.data); |
| 225 | + } |
| 226 | + tabLayout.setLayoutParams(tabParams); |
| 227 | + viewPager.setLayoutParams(pagerParams); |
| 228 | + } |
192 | 229 |
|
193 | 230 | @Override |
194 | 231 | public void onTabSelected(final TabLayout.Tab selectedTab) { |
|
0 commit comments