mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Revert to deprecated BEHAVIOR_SET_USER_VISIBLE_HINT in TabAdapter
Also added comment explaining why
This commit is contained in:
parent
06d54ef77e
commit
5b631e0387
@ -2,6 +2,7 @@ package org.schabi.newpipe.fragments.detail;
|
|||||||
|
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
@ -10,16 +11,20 @@ import androidx.fragment.app.FragmentPagerAdapter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TabAdaptor extends FragmentPagerAdapter {
|
public class TabAdapter extends FragmentPagerAdapter {
|
||||||
private final List<Fragment> mFragmentList = new ArrayList<>();
|
private final List<Fragment> mFragmentList = new ArrayList<>();
|
||||||
private final List<String> mFragmentTitleList = new ArrayList<>();
|
private final List<String> mFragmentTitleList = new ArrayList<>();
|
||||||
private final FragmentManager fragmentManager;
|
private final FragmentManager fragmentManager;
|
||||||
|
|
||||||
public TabAdaptor(final FragmentManager fm) {
|
public TabAdapter(final FragmentManager fm) {
|
||||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
// if changed to BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT => crash if enqueueing stream in
|
||||||
|
// the background and then clicking on it to open VideoDetailFragment:
|
||||||
|
// "Cannot setMaxLifecycle for Fragment not attached to FragmentManager"
|
||||||
|
super(fm, BEHAVIOR_SET_USER_VISIBLE_HINT);
|
||||||
this.fragmentManager = fm;
|
this.fragmentManager = fm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(final int position) {
|
public Fragment getItem(final int position) {
|
||||||
return mFragmentList.get(position);
|
return mFragmentList.get(position);
|
||||||
@ -57,7 +62,7 @@ public class TabAdaptor extends FragmentPagerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemPosition(final Object object) {
|
public int getItemPosition(@NonNull final Object object) {
|
||||||
if (mFragmentList.contains(object)) {
|
if (mFragmentList.contains(object)) {
|
||||||
return mFragmentList.indexOf(object);
|
return mFragmentList.indexOf(object);
|
||||||
} else {
|
} else {
|
||||||
@ -82,7 +87,9 @@ public class TabAdaptor extends FragmentPagerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyItem(final ViewGroup container, final int position, final Object object) {
|
public void destroyItem(@NonNull final ViewGroup container,
|
||||||
|
final int position,
|
||||||
|
@NonNull final Object object) {
|
||||||
fragmentManager.beginTransaction().remove((Fragment) object).commitNowAllowingStateLoss();
|
fragmentManager.beginTransaction().remove((Fragment) object).commitNowAllowingStateLoss();
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +244,7 @@ public class VideoDetailFragment
|
|||||||
|
|
||||||
private AppBarLayout appBarLayout;
|
private AppBarLayout appBarLayout;
|
||||||
private ViewPager viewPager;
|
private ViewPager viewPager;
|
||||||
private TabAdaptor pageAdapter;
|
private TabAdapter pageAdapter;
|
||||||
private TabLayout tabLayout;
|
private TabLayout tabLayout;
|
||||||
private FrameLayout relatedStreamsLayout;
|
private FrameLayout relatedStreamsLayout;
|
||||||
|
|
||||||
@ -752,7 +752,7 @@ public class VideoDetailFragment
|
|||||||
|
|
||||||
appBarLayout = rootView.findViewById(R.id.appbarlayout);
|
appBarLayout = rootView.findViewById(R.id.appbarlayout);
|
||||||
viewPager = rootView.findViewById(R.id.viewpager);
|
viewPager = rootView.findViewById(R.id.viewpager);
|
||||||
pageAdapter = new TabAdaptor(getChildFragmentManager());
|
pageAdapter = new TabAdapter(getChildFragmentManager());
|
||||||
viewPager.setAdapter(pageAdapter);
|
viewPager.setAdapter(pageAdapter);
|
||||||
tabLayout = rootView.findViewById(R.id.tablayout);
|
tabLayout = rootView.findViewById(R.id.tablayout);
|
||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
|
@ -26,8 +26,6 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||||||
public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
|
public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
|
||||||
private CompositeDisposable disposables = new CompositeDisposable();
|
private CompositeDisposable disposables = new CompositeDisposable();
|
||||||
|
|
||||||
private boolean mIsVisibleToUser = false;
|
|
||||||
|
|
||||||
public static CommentsFragment getInstance(final int serviceId, final String url,
|
public static CommentsFragment getInstance(final int serviceId, final String url,
|
||||||
final String name) {
|
final String name) {
|
||||||
final CommentsFragment instance = new CommentsFragment();
|
final CommentsFragment instance = new CommentsFragment();
|
||||||
@ -39,12 +37,6 @@ public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
|
|||||||
// LifeCycle
|
// LifeCycle
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUserVisibleHint(final boolean isVisibleToUser) {
|
|
||||||
super.setUserVisibleHint(isVisibleToUser);
|
|
||||||
mIsVisibleToUser = isVisibleToUser;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(final Context context) {
|
public void onAttach(final Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
@ -92,7 +84,7 @@ public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
|
|||||||
public void handleResult(@NonNull final CommentsInfo result) {
|
public void handleResult(@NonNull final CommentsInfo result) {
|
||||||
super.handleResult(result);
|
super.handleResult(result);
|
||||||
|
|
||||||
AnimationUtils.slideUp(getView(), 120, 150, 0.06f);
|
AnimationUtils.slideUp(requireView(), 120, 150, 0.06f);
|
||||||
|
|
||||||
if (!result.getErrors().isEmpty()) {
|
if (!result.getErrors().isEmpty()) {
|
||||||
showSnackBarError(result.getErrors(), UserAction.REQUESTED_COMMENTS,
|
showSnackBarError(result.getErrors(), UserAction.REQUESTED_COMMENTS,
|
||||||
|
Loading…
Reference in New Issue
Block a user