fixed screen rotation for viewpager
This commit is contained in:
parent
9fc38b5bb8
commit
fa5896ee5b
|
@ -3,6 +3,7 @@ package org.schabi.newpipe.fragments.detail;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -11,10 +12,11 @@ public class TabAdaptor 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<>();
|
||||||
int baseId = 0;
|
private final FragmentManager fragmentManager;
|
||||||
|
|
||||||
public TabAdaptor(FragmentManager fm) {
|
public TabAdaptor(FragmentManager fm) {
|
||||||
super(fm);
|
super(fm);
|
||||||
|
this.fragmentManager = fm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,12 +29,6 @@ public class TabAdaptor extends FragmentPagerAdapter {
|
||||||
return mFragmentList.size();
|
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) {
|
public void addFragment(Fragment fragment, String title) {
|
||||||
mFragmentList.add(fragment);
|
mFragmentList.add(fragment);
|
||||||
mFragmentTitleList.add(title);
|
mFragmentTitleList.add(title);
|
||||||
|
@ -65,19 +61,13 @@ public class TabAdaptor extends FragmentPagerAdapter {
|
||||||
else return POSITION_NONE;
|
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(){
|
public void notifyDataSetUpdate(){
|
||||||
notifyChangeInPosition(1);
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||||
|
fragmentManager.beginTransaction().remove((Fragment) object).commitNowAllowingStateLoss();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,6 @@ public class RelatedVideosFragment extends BaseListInfoFragment<RelatedStreamInf
|
||||||
private View headerRootLayout;
|
private View headerRootLayout;
|
||||||
private Switch aSwitch;
|
private Switch aSwitch;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean mIsVisibleToUser = false;
|
private boolean mIsVisibleToUser = false;
|
||||||
|
|
||||||
public static RelatedVideosFragment getInstance(StreamInfo info) {
|
public static RelatedVideosFragment getInstance(StreamInfo info) {
|
||||||
|
|
Loading…
Reference in New Issue