Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bottom main-tabs feature #9719

Merged
merged 7 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
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;
Expand All @@ -17,6 +19,7 @@
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;

Expand All @@ -29,6 +32,7 @@
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;
Expand Down Expand Up @@ -106,6 +110,7 @@ public void onResume() {
} else if (hasTabsChanged) {
setupTabs();
}
updateTabsPosition();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't you do this only if tab settings were actually changed, to avoid useless recalculations?

}

@Override
Expand Down Expand Up @@ -189,6 +194,38 @@ private void updateTabsIconAndDescription() {
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);
Stypox marked this conversation as resolved.
Show resolved Hide resolved
} 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) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/settings_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@
<string name="caption_settings_key">caption_settings_key</string>
<string name="caption_user_set_key">caption_user_set_key</string>

<!-- Main-Tabs Position -->
<string name="main_tabs_position_key">main_tabs_position</string>

<!-- Content & History -->
<string name="show_search_suggestions_key">show_search_suggestions</string>
<string name="show_local_search_suggestions_key">show_local_search_suggestions</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@
<string name="delete_search_history_alert">Delete entire search history?</string>
<string name="search_history_deleted">Search history deleted</string>
<string name="fast_mode">Fast mode</string>
<string name="main_tabs_position_summary">Change the position of the main tabs</string>
<string name="main_tabs_position_title">Main Tabs Position</string>
Marius1501 marked this conversation as resolved.
Show resolved Hide resolved
<!-- error strings -->
<string name="general_error">Error</string>
<string name="download_to_sdcard_error_title">External storage unavailable</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/appearance_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/main_tabs_position_key"
android:summary="@string/main_tabs_position_summary"
android:title="@string/main_tabs_position_title"
app:singleLineTitle="false"
app:iconSpaceReserved="false" />

</PreferenceScreen>