// Path: adapter/src/main/java/com/fashare/adapter/viewpager/CommonPagerAdapter.java
// public abstract class CommonPagerAdapter<T> extends PagerAdapter {
// 
//     protected final String TAG = this.getClass().getSimpleName();
//     protected Context mContext;
//     protected List<T> mDataList;
//     private OnItemClickListener<T> mOnItemClickListener;
//     private int mLayoutId;
// 
//     public List<T> getDataList() {
//         return mDataList;
//     }
// 
//     public void setDataList(List<T> dataList) {
//         if(dataList != null) {
//             this.mDataList = dataList;
//             notifyDataSetChanged();
//         }else{
//             Log.e(TAG, "mDataList is null");
//         }
//     }
// 
//     public void setDataListWithoutNotify(List<T> dataList) {
//         if(dataList != null) {
//             this.mDataList = dataList;
//         }else{
//             Log.e(TAG, "mDataList is null");
//         }
//     }
// 
// 
//     /**
//      * reutrn POSITION_NONE 使得 notifyDataSetChanged() 会触发 instantiateItem() -> onBindViewHolder()
//      * @param object
//      * @return
//      */
//     @Override
//     public int getItemPosition(Object object) {
//         return POSITION_NONE;
//     }
// 
//     public void setOnItemClickListener(OnItemClickListener<T> onItemClickListener) {
//         this.mOnItemClickListener = onItemClickListener;
//     }
// 
//     public CommonPagerAdapter(final Context context, final int layoutId, List<T> dataList) {
//         mContext = context;
//         mLayoutId = layoutId;
//         mDataList = dataList;
//     }
// 
//     @Override
//     public int getCount() {
//         return mDataList == null? 0: mDataList.size();
//     }
// 
//     @Override
//     public boolean isViewFromObject(View view, Object object) {
//         return view == object;
//     }
// 
//     @Override
//     public Object instantiateItem(ViewGroup container, int position) {
//         ViewHolder viewHolder = createViewHolder(container, position);
//         onBindViewHolder(viewHolder, position);
//         return viewHolder.itemView;
//     }
// 
//     protected final ViewHolder createViewHolder(ViewGroup container, int position) {
//         ViewHolder viewHolder;
//         viewHolder = onCreateViewHolder(container);
// 
//         if(viewHolder != null) {
//             container.addView(viewHolder.itemView);
//         }else {
//             Log.e(TAG, "viewHolder is null");
//         }
// 
//         return viewHolder;
//     }
// 
//     protected ViewHolder onCreateViewHolder(ViewGroup parent){
//         return ViewHolder.createViewHolder(mContext, parent, mLayoutId);
//     }
// 
//     public void onBindViewHolder(final ViewHolder holder, final int position) {
//         setListener(holder, position);
// 
//         T data = getDataList().get(position);
//         if(data != null) {
//             convert(holder, data, position);
//         }else{
//             Log.e(TAG, String.format("mDataList.get(%d) is null", position));
//         }
//     }
// 
//     protected void setListener(final ViewHolder viewHolder, final int position) {
//         viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
//             @Override
//             public void onClick(View v) {
//                 if (mOnItemClickListener != null) {
//                     mOnItemClickListener.onItemClick(viewHolder, mDataList.get(position), position);
//                 }
//             }
//         });
// 
//         viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() {
//             @Override
//             public boolean onLongClick(View v) {
//                 if (mOnItemClickListener != null) {
//                     return mOnItemClickListener.onItemLongClick(viewHolder, mDataList.get(position), position);
//                 }
//                 return false;
//             }
//         });
//     }
// 
//     protected abstract void convert(ViewHolder holder, T t, int position);
// 
//     @Override
//     public void destroyItem(ViewGroup container, int position, Object object) {
//         container.removeView((View)object);
//     }
// }


import android.os.Parcelable;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import com.fashare.adapter.viewpager.CommonPagerAdapter;
import java.util.List;
/*
 * Copyright (C) 2013 Leszek Mzyk
 *
 * 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 com.fashare.adapter.viewpager.loop;




/**
 * A PagerAdapter wrapper responsible for providing a proper page to
 * LoopViewPager
 * 
 * This class shouldn't be used directly
 */
public class LoopPagerAdapterWrapper extends PagerAdapter {

    private PagerAdapter mAdapter;

    private SparseArray<ToDestroy> mToDestroy = new SparseArray<ToDestroy>();

    private boolean mBoundaryCaching;

    ViewPager mViewPager;

    void setBoundaryCaching(boolean flag) {
        mBoundaryCaching = flag;
    }

    LoopPagerAdapterWrapper(PagerAdapter adapter) {
        this.mAdapter = adapter;
    }

    public void setDataList(List<?> dataList) {
// Path: adapter/src/main/java/com/fashare/adapter/viewpager/CommonPagerAdapter.java
// public abstract class CommonPagerAdapter<T> extends PagerAdapter {
// 
//     protected final String TAG = this.getClass().getSimpleName();
//     protected Context mContext;
//     protected List<T> mDataList;
//     private OnItemClickListener<T> mOnItemClickListener;
//     private int mLayoutId;
// 
//     public List<T> getDataList() {
//         return mDataList;
//     }
// 
//     public void setDataList(List<T> dataList) {
//         if(dataList != null) {
//             this.mDataList = dataList;
//             notifyDataSetChanged();
//         }else{
//             Log.e(TAG, "mDataList is null");
//         }
//     }
// 
//     public void setDataListWithoutNotify(List<T> dataList) {
//         if(dataList != null) {
//             this.mDataList = dataList;
//         }else{
//             Log.e(TAG, "mDataList is null");
//         }
//     }
// 
// 
//     /**
//      * reutrn POSITION_NONE 使得 notifyDataSetChanged() 会触发 instantiateItem() -> onBindViewHolder()
//      * @param object
//      * @return
//      */
//     @Override
//     public int getItemPosition(Object object) {
//         return POSITION_NONE;
//     }
// 
//     public void setOnItemClickListener(OnItemClickListener<T> onItemClickListener) {
//         this.mOnItemClickListener = onItemClickListener;
//     }
// 
//     public CommonPagerAdapter(final Context context, final int layoutId, List<T> dataList) {
//         mContext = context;
//         mLayoutId = layoutId;
//         mDataList = dataList;
//     }
// 
//     @Override
//     public int getCount() {
//         return mDataList == null? 0: mDataList.size();
//     }
// 
//     @Override
//     public boolean isViewFromObject(View view, Object object) {
//         return view == object;
//     }
// 
//     @Override
//     public Object instantiateItem(ViewGroup container, int position) {
//         ViewHolder viewHolder = createViewHolder(container, position);
//         onBindViewHolder(viewHolder, position);
//         return viewHolder.itemView;
//     }
// 
//     protected final ViewHolder createViewHolder(ViewGroup container, int position) {
//         ViewHolder viewHolder;
//         viewHolder = onCreateViewHolder(container);
// 
//         if(viewHolder != null) {
//             container.addView(viewHolder.itemView);
//         }else {
//             Log.e(TAG, "viewHolder is null");
//         }
// 
//         return viewHolder;
//     }
// 
//     protected ViewHolder onCreateViewHolder(ViewGroup parent){
//         return ViewHolder.createViewHolder(mContext, parent, mLayoutId);
//     }
// 
//     public void onBindViewHolder(final ViewHolder holder, final int position) {
//         setListener(holder, position);
// 
//         T data = getDataList().get(position);
//         if(data != null) {
//             convert(holder, data, position);
//         }else{
//             Log.e(TAG, String.format("mDataList.get(%d) is null", position));
//         }
//     }
// 
//     protected void setListener(final ViewHolder viewHolder, final int position) {
//         viewHolder.getConvertView().setOnClickListener(new View.OnClickListener() {
//             @Override
//             public void onClick(View v) {
//                 if (mOnItemClickListener != null) {
//                     mOnItemClickListener.onItemClick(viewHolder, mDataList.get(position), position);
//                 }
//             }
//         });
// 
//         viewHolder.getConvertView().setOnLongClickListener(new View.OnLongClickListener() {
//             @Override
//             public boolean onLongClick(View v) {
//                 if (mOnItemClickListener != null) {
//                     return mOnItemClickListener.onItemLongClick(viewHolder, mDataList.get(position), position);
//                 }
//                 return false;
//             }
//         });
//     }
// 
//     protected abstract void convert(ViewHolder holder, T t, int position);
// 
//     @Override
//     public void destroyItem(ViewGroup container, int position, Object object) {
//         container.removeView((View)object);
//     }
// }


// Path: adapter/src/main/java/com/fashare/adapter/viewpager/loop/LoopPagerAdapterWrapper.java
import android.os.Parcelable;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import com.fashare.adapter.viewpager.CommonPagerAdapter;
import java.util.List;

/*
 * Copyright (C) 2013 Leszek Mzyk
 *
 * 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 com.fashare.adapter.viewpager.loop;




/**
 * A PagerAdapter wrapper responsible for providing a proper page to
 * LoopViewPager
 * 
 * This class shouldn't be used directly
 */
public class LoopPagerAdapterWrapper extends PagerAdapter {

    private PagerAdapter mAdapter;

    private SparseArray<ToDestroy> mToDestroy = new SparseArray<ToDestroy>();

    private boolean mBoundaryCaching;

    ViewPager mViewPager;

    void setBoundaryCaching(boolean flag) {
        mBoundaryCaching = flag;
    }

    LoopPagerAdapterWrapper(PagerAdapter adapter) {
        this.mAdapter = adapter;
    }

    public void setDataList(List<?> dataList) {
        if(mAdapter instanceof CommonPagerAdapter) {