fixed screen rotation for viewpager

This commit is contained in:
Ritvik Saraf 2018-10-19 18:44:03 +05:30
parent 9fc38b5bb8
commit fa5896ee5b
2 changed files with 9 additions and 21 deletions

View File

@ -3,6 +3,7 @@ package org.schabi.newpipe.fragments.detail;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
@ -11,10 +12,11 @@ public class TabAdaptor extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
int baseId = 0;
private final FragmentManager fragmentManager;
public TabAdaptor(FragmentManager fm) {
super(fm);
this.fragmentManager = fm;
}
@Override
@ -27,12 +29,6 @@ public class TabAdaptor extends FragmentPagerAdapter {
return mFragmentList.size();
}
@Override
public long getItemId(int position) {
// give an ID different from position when position has been changed
return baseId + position;
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
@ -65,19 +61,13 @@ public class TabAdaptor extends FragmentPagerAdapter {
else return POSITION_NONE;
}
/**
* Notify that the position of a fragment has been changed.
* Create a new ID for each position to force recreation of the fragment
* @param n number of items which have been changed
*/
public void notifyChangeInPosition(int n) {
// shift the ID returned by getItemId outside the range of all previous fragments
// https://stackoverflow.com/questions/10396321/remove-fragment-page-from-viewpager-in-android
baseId += getCount() + n;
}
public void notifyDataSetUpdate(){
notifyChangeInPosition(1);
notifyDataSetChanged();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
fragmentManager.beginTransaction().remove((Fragment) object).commitNowAllowingStateLoss();
}
}

View File

@ -37,8 +37,6 @@ public class RelatedVideosFragment extends BaseListInfoFragment<RelatedStreamInf
private View headerRootLayout;
private Switch aSwitch;
private boolean mIsVisibleToUser = false;
public static RelatedVideosFragment getInstance(StreamInfo info) {