Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

<application
android:name=".DebugApp"
tools:replace="android:name" />
tools:replace="android:name"
android:supportsRtl="true" />
</manifest>
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:label="@string/app_name"
android:logo="@mipmap/ic_launcher"
android:theme="@style/OpeningTheme"
android:supportsRtl="true"
tools:ignore="AllowBackup">
<activity
android:name=".MainActivity"
Expand Down
49 changes: 34 additions & 15 deletions app/src/main/java/org/schabi/newpipe/about/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.R;
import org.schabi.newpipe.util.LocalizeLayoutUtils;
import org.schabi.newpipe.util.ThemeHelper;

import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
Expand Down Expand Up @@ -92,16 +93,23 @@ protected void onCreate(final Bundle savedInstanceState) {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

// Set up the ViewPager with the sections adapter.
mViewPager = findViewById(R.id.container);

boolean isRTL = LocalizeLayoutUtils.isRTL(this);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), isRTL);
mViewPager.setAdapter(mSectionsPagerAdapter);


TabLayout tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);

if (isRTL) {
tabLayout.getTabAt(mSectionsPagerAdapter.getCount() - 1).select();
}
}

@Override
Expand All @@ -121,7 +129,8 @@ public boolean onOptionsItemSelected(final MenuItem item) {
* A placeholder fragment containing a simple view.
*/
public static class AboutFragment extends Fragment {
public AboutFragment() { }
public AboutFragment() {
}

/**
* Created a new instance of this fragment for the given section number.
Expand Down Expand Up @@ -172,17 +181,21 @@ private void openWebsite(final String url, final Context context) {
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(final FragmentManager fm) {
private boolean isRTL;

public SectionsPagerAdapter(final FragmentManager fm, final boolean isRTL) {
super(fm);
this.isRTL = isRTL;
}

@Override
public Fragment getItem(final int position) {
switch (position) {
case 0:
return AboutFragment.newInstance();
case 1:
return LicenseFragment.newInstance(SOFTWARE_COMPONENTS);
int newPosition = getLayoutPosition(position);

if (newPosition == 0) {
return AboutFragment.newInstance();
} else if (newPosition == 1) {
return LicenseFragment.newInstance(SOFTWARE_COMPONENTS);
}
return null;
}
Expand All @@ -195,13 +208,19 @@ public int getCount() {

@Override
public CharSequence getPageTitle(final int position) {
switch (position) {
case 0:
return getString(R.string.tab_about);
case 1:
return getString(R.string.tab_licenses);
int newPosition = getLayoutPosition(position);

if (newPosition == 0) {
return getString(R.string.tab_about);
} else if (newPosition == 1) {
return getString(R.string.tab_licenses);
}

return null;
}

private int getLayoutPosition(final int position) {
return LocalizeLayoutUtils.getLayoutPosition(this.isRTL, getCount(), position);
}
}
}
33 changes: 26 additions & 7 deletions app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.settings.tabs.Tab;
import org.schabi.newpipe.settings.tabs.TabsManager;
import org.schabi.newpipe.util.LocalizeLayoutUtils;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.views.ScrollableTabLayout;
Expand Down Expand Up @@ -150,26 +151,35 @@ private void setupTabs() {
tabsList.clear();
tabsList.addAll(tabsManager.getTabs());

boolean isRTL = LocalizeLayoutUtils.isRTL(this.getContext());

if (pagerAdapter == null || !pagerAdapter.sameTabs(tabsList)) {
pagerAdapter = new SelectedTabsPagerAdapter(requireContext(),
getChildFragmentManager(), tabsList);
getChildFragmentManager(), tabsList, isRTL);
}

viewPager.setAdapter(null);
viewPager.setOffscreenPageLimit(tabsList.size());
viewPager.setAdapter(pagerAdapter);

updateTabsIconAndDescription();
if (isRTL) {
tabLayout.getTabAt(pagerAdapter.getCount() - 1).select();
}

updateTabsIconAndDescription(isRTL);
updateTitleForTab(viewPager.getCurrentItem());

hasTabsChanged = false;
}

private void updateTabsIconAndDescription() {
private void updateTabsIconAndDescription(final boolean isRTL) {
for (int i = 0; i < tabsList.size(); i++) {
final TabLayout.Tab tabToSet = tabLayout.getTabAt(i);
if (tabToSet != null) {
final Tab tab = tabsList.get(i);
final Tab tab = isRTL
? tabsList.get(tabsList.size() - 1 - i)
: tabsList.get(i);

tabToSet.setIcon(tab.getTabIconRes(requireContext()));
tabToSet.setContentDescription(tab.getTabName(requireContext()));
}
Expand All @@ -189,7 +199,8 @@ public void onTabSelected(final TabLayout.Tab selectedTab) {
}

@Override
public void onTabUnselected(final TabLayout.Tab tab) { }
public void onTabUnselected(final TabLayout.Tab tab) {
}

@Override
public void onTabReselected(final TabLayout.Tab tab) {
Expand All @@ -203,19 +214,27 @@ private static final class SelectedTabsPagerAdapter
extends FragmentStatePagerAdapterMenuWorkaround {
private final Context context;
private final List<Tab> internalTabsList;
private boolean isRTL;

private SelectedTabsPagerAdapter(final Context context,
final FragmentManager fragmentManager,
final List<Tab> tabsList) {
final List<Tab> tabsList,
final boolean isRTL) {
super(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.context = context;
this.internalTabsList = new ArrayList<>(tabsList);
this.isRTL = isRTL;
}

@NonNull
@Override
public Fragment getItem(final int position) {
final Tab tab = internalTabsList.get(position);
final Tab tab = internalTabsList.get(
LocalizeLayoutUtils.getLayoutPosition(
this.isRTL,
internalTabsList.size(),
position)
);

Throwable throwable = null;
Fragment fragment = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import org.schabi.newpipe.util.LocalizeLayoutUtils;

import java.util.ArrayList;
import java.util.List;

public class TabAdaptor extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
private final FragmentManager fragmentManager;
private boolean isRTL;

public TabAdaptor(final FragmentManager fm) {
public TabAdaptor(final FragmentManager fm, final boolean isRTL) {
super(fm);
this.fragmentManager = fm;
this.isRTL = isRTL;
}

@Override
public Fragment getItem(final int position) {
return mFragmentList.get(position);
return mFragmentList.get(getLayoutPosition(position));
}

@Override
Expand All @@ -41,16 +45,18 @@ public void clearAllItems() {
}

public void removeItem(final int position) {
mFragmentList.remove(position == 0 ? 0 : position - 1);
mFragmentTitleList.remove(position == 0 ? 0 : position - 1);
int newPosition = getLayoutPosition(position);

mFragmentList.remove(newPosition == 0 ? 0 : newPosition - 1);
mFragmentTitleList.remove(newPosition == 0 ? 0 : newPosition - 1);
}

public void updateItem(final int position, final Fragment fragment) {
mFragmentList.set(position, fragment);
mFragmentList.set(getLayoutPosition(position), fragment);
}

public void updateItem(final String title, final Fragment fragment) {
int index = mFragmentTitleList.indexOf(title);
int index = getLayoutPosition(mFragmentTitleList.indexOf(title));
if (index != -1) {
updateItem(index, fragment);
}
Expand All @@ -59,22 +65,23 @@ public void updateItem(final String title, final Fragment fragment) {
@Override
public int getItemPosition(final Object object) {
if (mFragmentList.contains(object)) {
return mFragmentList.indexOf(object);
return getLayoutPosition(mFragmentList.indexOf(object));
} else {
return POSITION_NONE;
}
}

public int getItemPositionByTitle(final String title) {
return mFragmentTitleList.indexOf(title);
return getLayoutPosition(mFragmentTitleList.indexOf(title));
}

@Nullable
public String getItemTitle(final int position) {
if (position < 0 || position >= mFragmentTitleList.size()) {
return null;
}
return mFragmentTitleList.get(position);

return mFragmentTitleList.get(getLayoutPosition(position));
}

public void notifyDataSetUpdate() {
Expand All @@ -86,4 +93,7 @@ public void destroyItem(final ViewGroup container, final int position, final Obj
fragmentManager.beginTransaction().remove((Fragment) object).commitNowAllowingStateLoss();
}

private int getLayoutPosition(final int position) {
return LocalizeLayoutUtils.getLayoutPosition(this.isRTL, mFragmentList.size(), position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import org.schabi.newpipe.util.KoreUtil;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.LocalizeLayoutUtils;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ShareUtils;
Expand Down Expand Up @@ -528,7 +529,10 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {

appBarLayout = rootView.findViewById(R.id.appbarlayout);
viewPager = rootView.findViewById(R.id.viewpager);
pageAdapter = new TabAdaptor(getChildFragmentManager());

boolean isRTL = LocalizeLayoutUtils.isRTL(this.getContext());

pageAdapter = new TabAdaptor(getChildFragmentManager(), isRTL);
viewPager.setAdapter(pageAdapter);
tabLayout = rootView.findViewById(R.id.tablayout);
tabLayout.setupWithViewPager(viewPager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ public int getSuggestionMovementFlags(@NonNull final RecyclerView recyclerView,
final int position = viewHolder.getAdapterPosition();
final SuggestionItem item = suggestionListAdapter.getItem(position);
return item.fromHistory ? makeMovementFlags(0,
ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) : 0;
ItemTouchHelper.START | ItemTouchHelper.END) : 0;
}

public void onSuggestionItemSwiped(@NonNull final RecyclerView.ViewHolder viewHolder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ private void saveImmediate() {
private ItemTouchHelper.SimpleCallback getItemTouchCallback() {
int directions = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
if (isGridLayout()) {
directions |= ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
directions |= ItemTouchHelper.START | ItemTouchHelper.END;
}
return new ItemTouchHelper.SimpleCallback(directions,
ItemTouchHelper.ACTION_STATE_IDLE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,47 @@ import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import org.schabi.newpipe.R
import org.schabi.newpipe.util.LocalizeLayoutUtils

class FeedGroupCarouselDecoration(context: Context) : RecyclerView.ItemDecoration() {

private val marginStartEnd: Int
private val marginTopBottom: Int
private val marginBetweenItems: Int
private val isRTL: Boolean

init {
with(context.resources) {
marginStartEnd = getDimensionPixelOffset(R.dimen.feed_group_carousel_start_end_margin)
marginTopBottom = getDimensionPixelOffset(R.dimen.feed_group_carousel_top_bottom_margin)
marginBetweenItems = getDimensionPixelOffset(R.dimen.feed_group_carousel_between_items_margin)
}

isRTL = LocalizeLayoutUtils.isRTL(context)
}

override fun getItemOffsets(outRect: Rect, child: View, parent: RecyclerView, state: RecyclerView.State) {
val childAdapterPosition = parent.getChildAdapterPosition(child)
val childAdapterCount = parent.adapter?.itemCount ?: 0

outRect.set(marginBetweenItems, marginTopBottom, 0, marginTopBottom)
outRect.set(0, marginTopBottom, 0, marginTopBottom)

if(isRTL) {
outRect.right = marginBetweenItems

if (childAdapterPosition == 0) {
outRect.right = marginStartEnd
} else if (childAdapterPosition == childAdapterCount - 1) {
outRect.left = marginStartEnd
}
} else {
outRect.left = marginBetweenItems

if (childAdapterPosition == 0) {
outRect.left = marginStartEnd
} else if (childAdapterPosition == childAdapterCount - 1) {
outRect.right = marginStartEnd
if (childAdapterPosition == 0) {
outRect.left = marginStartEnd
} else if (childAdapterPosition == childAdapterCount - 1) {
outRect.right = marginStartEnd
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private void initPopup() {
layoutParamType,
IDLE_WINDOW_FLAGS,
PixelFormat.TRANSLUCENT);
popupLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
popupLayoutParams.gravity = Gravity.START | Gravity.TOP;
popupLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;

int centerX = (int) (screenWidth / 2f - popupWidth / 2f);
Expand Down Expand Up @@ -280,7 +280,7 @@ private void initPopupCloseOverlay() {
layoutParamType,
flags,
PixelFormat.TRANSLUCENT);
closeOverlayLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
closeOverlayLayoutParams.gravity = Gravity.START | Gravity.TOP;
closeOverlayLayoutParams.softInputMode = WindowManager
.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;

Expand Down
Loading