// Path: rxretrofitlibrary/src/main/java/com/wzgiceman/rxretrofitlibrary/retrofit_rx/utils/AppUtil.java
// public class AppUtil {
//     /**
//      * 描述：判断网络是否有效.
//      *
//      * @return true, if is network available
//      */
//     public static boolean isNetworkAvailable(Context context) {
//         try {
//             ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             if (connectivity != null) {
//                 NetworkInfo info = connectivity.getActiveNetworkInfo();
//                 if (info != null && info.isConnected()) {
//                     if (info.getState() == NetworkInfo.State.CONNECTED) {
//                         return true;
//                     }
//                 }
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//             return false;
//         }
//         return false;
//     }
// 
// 
//     /**
//      * 读取baseurl
//      * @param url
//      * @return
//      */
//     public static String getBasUrl(String url) {
//         String head = "";
//         int index = url.indexOf("://");
//         if (index != -1) {
//             head = url.substring(0, index + 3);
//             url = url.substring(index + 3);
//         }
//         index = url.indexOf("/");
//         if (index != -1) {
//             url = url.substring(0, index + 1);
//         }
//         return head + url;
//     }
// }


import com.wzgiceman.rxretrofitlibrary.retrofit_rx.RxRetrofitApp;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.utils.AppUtil;
import java.io.IOException;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
package com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.cookie;




/**
 * get缓存方式拦截器
 * Created by WZG on 2016/10/26.
 */

public class CacheInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();

// Path: rxretrofitlibrary/src/main/java/com/wzgiceman/rxretrofitlibrary/retrofit_rx/utils/AppUtil.java
// public class AppUtil {
//     /**
//      * 描述：判断网络是否有效.
//      *
//      * @return true, if is network available
//      */
//     public static boolean isNetworkAvailable(Context context) {
//         try {
//             ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//             if (connectivity != null) {
//                 NetworkInfo info = connectivity.getActiveNetworkInfo();
//                 if (info != null && info.isConnected()) {
//                     if (info.getState() == NetworkInfo.State.CONNECTED) {
//                         return true;
//                     }
//                 }
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//             return false;
//         }
//         return false;
//     }
// 
// 
//     /**
//      * 读取baseurl
//      * @param url
//      * @return
//      */
//     public static String getBasUrl(String url) {
//         String head = "";
//         int index = url.indexOf("://");
//         if (index != -1) {
//             head = url.substring(0, index + 3);
//             url = url.substring(index + 3);
//         }
//         index = url.indexOf("/");
//         if (index != -1) {
//             url = url.substring(0, index + 1);
//         }
//         return head + url;
//     }
// }


// Path: rxretrofitlibrary/src/main/java/com/wzgiceman/rxretrofitlibrary/retrofit_rx/http/cookie/CacheInterceptor.java
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.RxRetrofitApp;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.utils.AppUtil;
import java.io.IOException;
import okhttp3.CacheControl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

package com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.cookie;




/**
 * get缓存方式拦截器
 * Created by WZG on 2016/10/26.
 */

public class CacheInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();

        if (!AppUtil.isNetworkAvailable(RxRetrofitApp.getApplication())) {//没网强制从缓存读取(必须得写，不然断网状态下，退出应用，或者等待一分钟后，就获取不到缓存）