/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.jessyan.art.base;

import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * ================================================
 * 基类 {@link FragmentStatePagerAdapter}
 * <p>
 * Created by JessYan on 22/03/2016
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
public class AdapterViewPager extends FragmentStatePagerAdapter {
    private List<Fragment> mList;
    private CharSequence[] mTitles;

    public AdapterViewPager(FragmentManager fragmentManager, List<Fragment> list) {
        super(fragmentManager);
        this.mList = list;
    }


    public AdapterViewPager(FragmentManager fragmentManager, List<Fragment> list, CharSequence[] titles) {
        super(fragmentManager);
        this.mList = list;
        this.mTitles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return mList.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mTitles != null) {
            return mTitles[position];
        }
        return super.getPageTitle(position);
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Parcelable saveState() {
        return null;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment f = (Fragment) super.instantiateItem(container, position);
        View view = f.getView();
        if (view != null)
            container.addView(view);
        return f;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        View view = mList.get(position).getView();
        if (view != null)
            container.removeView(view);
    }
}

@@ -636,39 +636,8 @@
 %0D%0A%0D%0A
-import android.os.Parcelable;%0D%0A
 impo
@@ -782,67 +782,8 @@
 er;%0D
-%0Aimport android.view.View;%0D%0Aimport android.view.ViewGroup;%0D
 %0A%0D%0Ai
@@ -1842,21 +1842,50 @@
  != null
+ && position %3C mTitles.length
 ) %7B%0D%0A
-
         
@@ -2021,24 +2021,24 @@
 tCount() %7B%0D%0A
+
         retu
@@ -2065,607 +2065,8 @@
   %7D%0D
-%0A%0D%0A    @Override%0D%0A    public Parcelable saveState() %7B%0D%0A        return null;%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public Object instantiateItem(ViewGroup container, int position) %7B%0D%0A        Fragment f = (Fragment) super.instantiateItem(container, position);%0D%0A        View view = f.getView();%0D%0A        if (view != null)%0D%0A            container.addView(view);%0D%0A        return f;%0D%0A    %7D%0D%0A%0D%0A    @Override%0D%0A    public void destroyItem(ViewGroup container, int position, Object object) %7B%0D%0A        View view = mList.get(position).getView();%0D%0A        if (view != null)%0D%0A            container.removeView(view);%0D%0A    %7D%0D
 %0A%7D%0D%0A

Improve AdapterViewPager