mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 00:20:32 +00:00
Added bottom main-tabs feature
This commit is contained in:
parent
b6bf0ffc40
commit
0821f6463a
@ -3,12 +3,14 @@ package org.schabi.newpipe.fragments;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.TypedValue;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@ -17,6 +19,7 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentStatePagerAdapterMenuWorkaround;
|
import androidx.fragment.app.FragmentStatePagerAdapterMenuWorkaround;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
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.settings.tabs.TabsManager;
|
||||||
import org.schabi.newpipe.util.NavigationHelper;
|
import org.schabi.newpipe.util.NavigationHelper;
|
||||||
import org.schabi.newpipe.util.ServiceHelper;
|
import org.schabi.newpipe.util.ServiceHelper;
|
||||||
|
import org.schabi.newpipe.views.ScrollableTabLayout;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -106,6 +110,7 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||||||
} else if (hasTabsChanged) {
|
} else if (hasTabsChanged) {
|
||||||
setupTabs();
|
setupTabs();
|
||||||
}
|
}
|
||||||
|
updateTabsPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -189,6 +194,38 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte
|
|||||||
private void updateTitleForTab(final int tabPosition) {
|
private void updateTitleForTab(final int tabPosition) {
|
||||||
setTitle(tabsList.get(tabPosition).getTabName(requireContext()));
|
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
|
@Override
|
||||||
public void onTabSelected(final TabLayout.Tab selectedTab) {
|
public void onTabSelected(final TabLayout.Tab selectedTab) {
|
||||||
|
@ -241,6 +241,9 @@
|
|||||||
<string name="caption_settings_key">caption_settings_key</string>
|
<string name="caption_settings_key">caption_settings_key</string>
|
||||||
<string name="caption_user_set_key">caption_user_set_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 -->
|
<!-- Content & History -->
|
||||||
<string name="show_search_suggestions_key">show_search_suggestions</string>
|
<string name="show_search_suggestions_key">show_search_suggestions</string>
|
||||||
<string name="show_local_search_suggestions_key">show_local_search_suggestions</string>
|
<string name="show_local_search_suggestions_key">show_local_search_suggestions</string>
|
||||||
|
@ -213,6 +213,8 @@
|
|||||||
<string name="delete_search_history_alert">Delete entire search history?</string>
|
<string name="delete_search_history_alert">Delete entire search history?</string>
|
||||||
<string name="search_history_deleted">Search history deleted</string>
|
<string name="search_history_deleted">Search history deleted</string>
|
||||||
<string name="fast_mode">Fast mode</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>
|
||||||
<!-- error strings -->
|
<!-- error strings -->
|
||||||
<string name="general_error">Error</string>
|
<string name="general_error">Error</string>
|
||||||
<string name="download_to_sdcard_error_title">External storage unavailable</string>
|
<string name="download_to_sdcard_error_title">External storage unavailable</string>
|
||||||
|
@ -66,4 +66,12 @@
|
|||||||
app:singleLineTitle="false"
|
app:singleLineTitle="false"
|
||||||
app:iconSpaceReserved="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>
|
</PreferenceScreen>
|
||||||
|
Loading…
Reference in New Issue
Block a user