package com.joker.fourfun.ui.fragment;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.joker.fourfun.Constants;
import com.joker.fourfun.R;
import com.joker.fourfun.adapter.PictureOneAdapter;
import com.joker.fourfun.base.BaseMvpFragment;
import com.joker.fourfun.presenter.PicturePresenter;
import com.joker.fourfun.presenter.contract.PictureContract;
import com.joker.fourfun.utils.SystemUtil;
import com.joker.fourfun.widget.ZoomOutPageTransformer;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PictureFragment extends BaseMvpFragment<PictureContract.View, PicturePresenter> implements
        PictureContract.View {
    @BindView(R.id.vp_content)
    ViewPager mVpContent;
    private Bundle mPictureBundle;
    private List<PictureChildFragment> mFragments;

    public static PictureFragment newInstance(Bundle bundle) {
        PictureFragment pictureFragment = new PictureFragment();
        pictureFragment.setArguments(bundle);

        return pictureFragment;
    }

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        analyseArguments();
        View view = inflater.inflate(R.layout.fragment_picture, container, false);
        ButterKnife.bind(this, view);
        mFragments = new ArrayList<PictureChildFragment>();
        mFragments.add(PictureChildFragment.newInstance(mPictureBundle));
        mFragments.add(new PictureChildFragment());
        mFragments.add(new PictureChildFragment());
        mFragments.add(new PictureChildFragment());
        mFragments.add(new PictureChildFragment());
        mFragments.add(new PictureChildFragment());
        mFragments.add(new PictureChildFragment());
        mVpContent.setOffscreenPageLimit(1);
        mVpContent.setPageTransformer(true, new ZoomOutPageTransformer());
        mVpContent.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                mFragments.get(position).setFragmentPosition(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
        PictureOneAdapter mAdapter = new PictureOneAdapter(getChildFragmentManager(), mFragments);
        mVpContent.setAdapter(mAdapter);

        return view;
    }

    private void analyseArguments() {
        Bundle bundle = getArguments();
        mPictureBundle = bundle.getBundle(Constants.PICTURE_BUNDLE);
    }

    @Override
    protected void initInject() {
        getComponent().inject(this);
    }

    @Override
    public void showError(String message) {
        SystemUtil.showToast(mActivity, message);
    }
}

@@ -684,16 +684,49 @@
 erKnife;
+%0Aimport butterknife.OnPageChange;
 %0A%0Apublic
@@ -1971,9 +1971,9 @@
 mit(
-1
+6
 );%0A 
@@ -2058,262 +2058,215 @@
     
-mVpContent.addOnPageChangeListener(new ViewPager.OnPa
+PictureOneAdapter mAdapter = new PictureOneAdapter(
 ge
+t
 Ch
-angeListener() %7B%0A            @Override%0A            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) %7B%0A            %7D%0A%0A            @Override%0A            public
+ildFragmentManager(), mFragments);%0A        mVpContent.setAdapter(mAdapter);%0A%0A        return view;%0A    %7D%0A%0A    @OnPageChange(value = R.id.vp_content)%0A   
  voi
@@ -2294,32 +2294,24 @@
 position) %7B%0A
-        
         mFra
@@ -2366,295 +2366,8 @@
 n);%0A
-            %7D%0A%0A            @Override%0A            public void onPageScrollStateChanged(int state) %7B%0A            %7D%0A        %7D);%0A        PictureOneAdapter mAdapter = new PictureOneAdapter(getChildFragmentManager(), mFragments);%0A        mVpContent.setAdapter(mAdapter);%0A%0A        return view;%0A
     

refactor code