// Path: app/src/main/java/com/mummyding/app/leisure/database/cache/BaseCollectionCache.java
// public abstract class BaseCollectionCache<T> implements ICache<T> {
// 
//     protected DatabaseHelper mHelper;
//     protected SQLiteDatabase db;
// 
// 
//     protected List<T> mList = new ArrayList<>();
// 
//     protected Handler mHandler;
// 
//     public BaseCollectionCache(Handler mHandler) {
//         this.mHandler = mHandler;
//         mHelper = DatabaseHelper.instance(LeisureApplication.AppContext);
//     }
// 
//     @Override
//     public void addToCollection(T object) {
// 
//     }
// 
//     @Override
//     public void execSQL(String sql) {
//         db = mHelper.getWritableDatabase();
//         db.execSQL(sql);
//     }
// 
//     @Override
//     public List<T> getList() {
//         return mList;
//     }
// 
//     @Override
//     public boolean hasData() {
//         return !mList.isEmpty();
//     }
// 
//     @Override
//     public void load() {
// 
//     }
// 
// 
//     @Override
//     public void cache() {
// 
//     }
// 
//     protected Cursor query(String sql){
//         return mHelper.getReadableDatabase().rawQuery(sql,null);
//     }
// 
// }
// 
// Path: app/src/main/java/com/mummyding/app/leisure/database/cache/ICache.java
// public interface ICache<T>{
//     void addToCollection(T object);
//     void execSQL(String sql);
//     List<T> getList();
//     boolean hasData();
//     void load();
//     void loadFromCache();
//     void cache();
// }
// 
// Path: app/src/main/java/com/mummyding/app/leisure/support/HttpUtil.java
// public class HttpUtil {
//     private static final OkHttpClient mOkHttpClient = new OkHttpClient();
//     public static boolean isWIFI = true;
//     static{
//         mOkHttpClient.setConnectTimeout(30, TimeUnit.SECONDS);
//         mOkHttpClient.setReadTimeout(30, TimeUnit.SECONDS);
//         mOkHttpClient.setWriteTimeout(30, TimeUnit.SECONDS);
//     }
//     /**
//      * 该不会开启异步线程。
//      * @param request
//      * @return
//      * @throws IOException
//      */
//     public static Response execute(Request request) throws IOException{
//         return mOkHttpClient.newCall(request).execute();
//     }
//     /**
//      * 开启异步线程访问网络
//      * @param request
//      * @param responseCallback
//      */
//     public static void enqueue(Request request, Callback responseCallback){
//         mOkHttpClient.newCall(request).enqueue(responseCallback);
//     }
//     /**
//      * 开启异步线程访问网络, 且不在意返回结果（实现空callback）
//      * @param request
//      */
//     public static void enqueue(Request request){
//         mOkHttpClient.newCall(request).enqueue(new Callback() {
// 
//             @Override
//             public void onResponse(Response arg0) throws IOException {
// 
//             }
// 
//             @Override
//             public void onFailure(Request arg0, IOException arg1) {
// 
//             }
//         });
//     }
// 
//     public static boolean readNetworkState() {
// 
//         ConnectivityManager cm = (ConnectivityManager) LeisureApplication.AppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
// 
//         if (cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
//             isWIFI = (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI);
//             return true;
//         } else {
// 
//             return false;
//         }
//     }
// }


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import com.mummyding.app.leisure.database.cache.BaseCollectionCache;
import com.mummyding.app.leisure.database.cache.ICache;
import com.mummyding.app.leisure.support.HttpUtil;
import java.util.List;
/*
 *  Copyright (C) 2015 MummyDing
 *
 *  This file is part of Leisure( <https://github.com/MummyDing/Leisure> )
 *
 *  Leisure is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *                             ｀
 *  Leisure is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Leisure.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.mummyding.app.leisure.support.adapter;




/**
 * Created by mummyding on 15-12-3.<br>
 * Abstract. It provides a common framework for RecyclerView adapter.<br>
 * All RecyclerView adapter inherits from this method.
 * @author MummyDing
 * @version Leisure 1.0
 */
public abstract class BaseListAdapter<M,VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH>{

    protected List<M> mItems;
    protected Context mContext;
    protected ICache<M> mCache;

    protected boolean isCollection = false;


    public BaseListAdapter(Context context, ICache<M> cache) {
        mContext = context;
        mCache = cache;
        mItems = cache.getList();

        if(cache instanceof BaseCollectionCache){
            isCollection = true;
        }

        HttpUtil.readNetworkState();
    }

    @Override
    public int getItemCount() {
        return mItems.size();
    }
// Path: app/src/main/java/com/mummyding/app/leisure/database/cache/BaseCollectionCache.java
// public abstract class BaseCollectionCache<T> implements ICache<T> {
// 
//     protected DatabaseHelper mHelper;
//     protected SQLiteDatabase db;
// 
// 
//     protected List<T> mList = new ArrayList<>();
// 
//     protected Handler mHandler;
// 
//     public BaseCollectionCache(Handler mHandler) {
//         this.mHandler = mHandler;
//         mHelper = DatabaseHelper.instance(LeisureApplication.AppContext);
//     }
// 
//     @Override
//     public void addToCollection(T object) {
// 
//     }
// 
//     @Override
//     public void execSQL(String sql) {
//         db = mHelper.getWritableDatabase();
//         db.execSQL(sql);
//     }
// 
//     @Override
//     public List<T> getList() {
//         return mList;
//     }
// 
//     @Override
//     public boolean hasData() {
//         return !mList.isEmpty();
//     }
// 
//     @Override
//     public void load() {
// 
//     }
// 
// 
//     @Override
//     public void cache() {
// 
//     }
// 
//     protected Cursor query(String sql){
//         return mHelper.getReadableDatabase().rawQuery(sql,null);
//     }
// 
// }
// 
// Path: app/src/main/java/com/mummyding/app/leisure/database/cache/ICache.java
// public interface ICache<T>{
//     void addToCollection(T object);
//     void execSQL(String sql);
//     List<T> getList();
//     boolean hasData();
//     void load();
//     void loadFromCache();
//     void cache();
// }
// 
// Path: app/src/main/java/com/mummyding/app/leisure/support/HttpUtil.java
// public class HttpUtil {
//     private static final OkHttpClient mOkHttpClient = new OkHttpClient();
//     public static boolean isWIFI = true;
//     static{
//         mOkHttpClient.setConnectTimeout(30, TimeUnit.SECONDS);
//         mOkHttpClient.setReadTimeout(30, TimeUnit.SECONDS);
//         mOkHttpClient.setWriteTimeout(30, TimeUnit.SECONDS);
//     }
//     /**
//      * 该不会开启异步线程。
//      * @param request
//      * @return
//      * @throws IOException
//      */
//     public static Response execute(Request request) throws IOException{
//         return mOkHttpClient.newCall(request).execute();
//     }
//     /**
//      * 开启异步线程访问网络
//      * @param request
//      * @param responseCallback
//      */
//     public static void enqueue(Request request, Callback responseCallback){
//         mOkHttpClient.newCall(request).enqueue(responseCallback);
//     }
//     /**
//      * 开启异步线程访问网络, 且不在意返回结果（实现空callback）
//      * @param request
//      */
//     public static void enqueue(Request request){
//         mOkHttpClient.newCall(request).enqueue(new Callback() {
// 
//             @Override
//             public void onResponse(Response arg0) throws IOException {
// 
//             }
// 
//             @Override
//             public void onFailure(Request arg0, IOException arg1) {
// 
//             }
//         });
//     }
// 
//     public static boolean readNetworkState() {
// 
//         ConnectivityManager cm = (ConnectivityManager) LeisureApplication.AppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
// 
//         if (cm != null && cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected()) {
//             isWIFI = (cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI);
//             return true;
//         } else {
// 
//             return false;
//         }
//     }
// }


// Path: app/src/main/java/com/mummyding/app/leisure/support/adapter/BaseListAdapter.java
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import com.mummyding.app.leisure.database.cache.BaseCollectionCache;
import com.mummyding.app.leisure.database.cache.ICache;
import com.mummyding.app.leisure.support.HttpUtil;
import java.util.List;

/*
 *  Copyright (C) 2015 MummyDing
 *
 *  This file is part of Leisure( <https://github.com/MummyDing/Leisure> )
 *
 *  Leisure is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *                             ｀
 *  Leisure is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Leisure.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.mummyding.app.leisure.support.adapter;




/**
 * Created by mummyding on 15-12-3.<br>
 * Abstract. It provides a common framework for RecyclerView adapter.<br>
 * All RecyclerView adapter inherits from this method.
 * @author MummyDing
 * @version Leisure 1.0
 */
public abstract class BaseListAdapter<M,VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH>{

    protected List<M> mItems;
    protected Context mContext;
    protected ICache<M> mCache;

    protected boolean isCollection = false;


    public BaseListAdapter(Context context, ICache<M> cache) {
        mContext = context;
        mCache = cache;
        mItems = cache.getList();

        if(cache instanceof BaseCollectionCache){
            isCollection = true;
        }

        HttpUtil.readNetworkState();
    }

    @Override
    public int getItemCount() {
        return mItems.size();
    }
    protected M getItem(int position){