From 5b631e0387140a396ce2d1f465a0d04366b004bf Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 6 Sep 2020 14:01:59 +0200 Subject: [PATCH] Revert to deprecated BEHAVIOR_SET_USER_VISIBLE_HINT in TabAdapter Also added comment explaining why --- .../detail/{TabAdaptor.java => TabAdapter.java} | 17 ++++++++++++----- .../fragments/detail/VideoDetailFragment.java | 4 ++-- .../list/comments/CommentsFragment.java | 10 +--------- 3 files changed, 15 insertions(+), 16 deletions(-) rename app/src/main/java/org/schabi/newpipe/fragments/detail/{TabAdaptor.java => TabAdapter.java} (76%) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdaptor.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdapter.java similarity index 76% rename from app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdaptor.java rename to app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdapter.java index c03f79dff..1a11836d4 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdaptor.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/TabAdapter.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.fragments.detail; import android.view.ViewGroup; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -10,16 +11,20 @@ import androidx.fragment.app.FragmentPagerAdapter; import java.util.ArrayList; import java.util.List; -public class TabAdaptor extends FragmentPagerAdapter { +public class TabAdapter extends FragmentPagerAdapter { private final List mFragmentList = new ArrayList<>(); private final List mFragmentTitleList = new ArrayList<>(); private final FragmentManager fragmentManager; - public TabAdaptor(final FragmentManager fm) { - super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); + public TabAdapter(final FragmentManager fm) { + // 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; } + @NonNull @Override public Fragment getItem(final int position) { return mFragmentList.get(position); @@ -57,7 +62,7 @@ public class TabAdaptor extends FragmentPagerAdapter { } @Override - public int getItemPosition(final Object object) { + public int getItemPosition(@NonNull final Object object) { if (mFragmentList.contains(object)) { return mFragmentList.indexOf(object); } else { @@ -82,7 +87,9 @@ public class TabAdaptor extends FragmentPagerAdapter { } @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(); } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 5e202eaa6..42a5cbf02 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -244,7 +244,7 @@ public class VideoDetailFragment private AppBarLayout appBarLayout; private ViewPager viewPager; - private TabAdaptor pageAdapter; + private TabAdapter pageAdapter; private TabLayout tabLayout; private FrameLayout relatedStreamsLayout; @@ -752,7 +752,7 @@ public class VideoDetailFragment appBarLayout = rootView.findViewById(R.id.appbarlayout); viewPager = rootView.findViewById(R.id.viewpager); - pageAdapter = new TabAdaptor(getChildFragmentManager()); + pageAdapter = new TabAdapter(getChildFragmentManager()); viewPager.setAdapter(pageAdapter); tabLayout = rootView.findViewById(R.id.tablayout); tabLayout.setupWithViewPager(viewPager); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java index ff02dd790..fc61a4518 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java @@ -26,8 +26,6 @@ import io.reactivex.disposables.CompositeDisposable; public class CommentsFragment extends BaseListInfoFragment { private CompositeDisposable disposables = new CompositeDisposable(); - private boolean mIsVisibleToUser = false; - public static CommentsFragment getInstance(final int serviceId, final String url, final String name) { final CommentsFragment instance = new CommentsFragment(); @@ -39,12 +37,6 @@ public class CommentsFragment extends BaseListInfoFragment { // LifeCycle //////////////////////////////////////////////////////////////////////////*/ - @Override - public void setUserVisibleHint(final boolean isVisibleToUser) { - super.setUserVisibleHint(isVisibleToUser); - mIsVisibleToUser = isVisibleToUser; - } - @Override public void onAttach(final Context context) { super.onAttach(context); @@ -92,7 +84,7 @@ public class CommentsFragment extends BaseListInfoFragment { public void handleResult(@NonNull final CommentsInfo result) { super.handleResult(result); - AnimationUtils.slideUp(getView(), 120, 150, 0.06f); + AnimationUtils.slideUp(requireView(), 120, 150, 0.06f); if (!result.getErrors().isEmpty()) { showSnackBarError(result.getErrors(), UserAction.REQUESTED_COMMENTS,