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.R;
import com.joker.fourfun.adapter.PicOneAdapter;
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 com.orhanobut.logger.Logger;

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 PicOneAdapter mAdapter;
    private List<PictureChildFragment> mFragments;

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_picture, container, false);
        ButterKnife.bind(this, view);
        mVpContent.setOffscreenPageLimit(1);
        mVpContent.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
//                mPresenter.getContent((position + 1) * -1);
                Logger.i(position + "selected", position + "selected");
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
        mFragments = new ArrayList<PictureChildFragment>();
        mFragments.add(new PictureChildFragment());
        mFragments.add(new PictureChildFragment());
        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.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) {
//                Logger.e("the " + position + " page is selected", "");
                mFragments.get(position).setFragmentPosition(position);
            }

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

        return view;
    }

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

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

    public static PictureFragment newInstance() {
        return null;
    }
}

@@ -195,16 +195,52 @@
 Group;%0A%0A
+import com.joker.fourfun.Constants;%0A
 import c
@@ -295,16 +295,20 @@
 pter.Pic
+ture
 OneAdapt
@@ -574,44 +574,8 @@
 mer;
-%0Aimport com.orhanobut.logger.Logger;
 %0A%0Aim
@@ -894,30 +894,29 @@
 ate 
-PicOneAdapter mAdapter
+Bundle mPictureBundle
 ;%0A  
@@ -965,16 +965,230 @@
 ments;%0A%0A
+    public static PictureFragment newInstance(Bundle bundle) %7B%0A        PictureFragment pictureFragment = new PictureFragment();%0A        pictureFragment.setArguments(bundle);%0A%0A        return pictureFragment;%0A    %7D%0A%0A
     @Ove
@@ -1290,32 +1290,60 @@
 nstanceState) %7B%0A
+        analyseArguments();%0A
         View vie
@@ -1496,566 +1496,8 @@
 1);%0A
-        mVpContent.addOnPageChangeListener(new ViewPager.OnPageChangeListener() %7B%0A            @Override%0A            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) %7B%0A            %7D%0A%0A            @Override%0A            public void onPageSelected(int position) %7B%0A//                mPresenter.getContent((position + 1) * -1);%0A                Logger.i(position + %22selected%22, position + %22selected%22);%0A            %7D%0A%0A            @Override%0A            public void onPageScrollStateChanged(int state) %7B%0A            %7D%0A        %7D);%0A
     
@@ -1567,36 +1567,32 @@
  mFragments.add(
-new 
 PictureChildFrag
@@ -1587,33 +1587,59 @@
 ureChildFragment
-(
+.newInstance(mPictureBundle
 ));%0A        mFra
@@ -2077,752 +2077,314 @@
     
-mVpContent.addOnPageChangeListener(new ViewPager.OnPageChangeListener() %7B%0A            @Override%0A            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) %7B%0A            %7D%0A%0A            @Override%0A            public void onPageSelected(int position) %7B%0A//                Logger.e(%22the %22 + position + %22 page is selected%22, %22%22);%0A                mFragments.get(position).setFragmentPosition(position);%0A            %7D%0A%0A            @Override
+PictureOneAdapter mAdapter = new PictureOneAdapter(getChildFragmentManager(), mFragments);%0A        mVpContent.setAdapter(mAdapter);%0A%0A        return view;
 %0A    
-    
+%7D%0A%0A
     p
-ublic void onPageScrollStateChanged(int state) %7B%0A            %7D%0A        %7D);%0A        mAdapter = new PicOneAdapter(getChildFragmentManager(), mFragments);%0A        mVpContent.setOffscreenPageLimit(1);%0A        mVpContent.setAdapter(mAdapter);%0A%0A        return view
+rivate void analyseArguments() %7B%0A        Bundle bundle = getArguments();%0A        mPictureBundle = bundle.getBundle(Constants.PICTURE_BUNDLE)
 ;%0A  
@@ -2597,85 +2597,7 @@
    %7D
-%0A%0A    public static PictureFragment newInstance() %7B%0A        return null;%0A    %7D
 %0A%7D%0A

delete odd code