content: package com.lance.freebook.Data.Retrofit;
  
  import android.content.Context;
  import android.widget.Toast;
  
  import java.net.ConnectException;
  import java.net.SocketTimeoutException;
  
  import rx.Subscriber;
  
  /**
   * 用于在Http请求开始时，自动显示一个ProgressDialog
   * 在Http请求结束是，关闭ProgressDialog
   * 调用者自己对请求数据进行处理
   * Created by liukun on 16/3/10.
   */
  public class ProgressSubscriber<T> extends Subscriber<T> {
      private SubscriberOnNextListener mSubscriberOnNextListener;
  
  
      private Context context;
  //    private MyDialogloging myDialogloging;
  
      public ProgressSubscriber(SubscriberOnNextListener mSubscriberOnNextListener, Context context) {
          this.mSubscriberOnNextListener = mSubscriberOnNextListener;
          this.context = context;
  //        myDialogloging = new MyDialogloging(context, R.style.MyDialog1);
  //        myDialogloging.setCanceledOnTouchOutside(false);
      }
  
      private void showProgressDialog(){
  //        if (myDialogloging != null) {
  //            myDialogloging.show();
  //        }
      }
  
      private void dismissProgressDialog(){
  //        if (myDialogloging != null) {
  //            myDialogloging.dismiss();
  //            myDialogloging = null;
  //        }
      }
  
      /**
       * 订阅开始时调用
       * 显示ProgressDialog
       */
      @Override
      public void onStart() {
          showProgressDialog();
      }
  
      /**
       * 完成，隐藏ProgressDialog
       */
      @Override
      public void onCompleted() {
          if (mSubscriberOnNextListener != null) {
              mSubscriberOnNextListener.onCompleted();
          }
          dismissProgressDialog();
      }
  
      /**
       * 对错误进行统一处理
       * 隐藏ProgressDialog
       * @param e
       */
      @Override
      public void onError(Throwable e) {
          if (mSubscriberOnNextListener != null) {
              mSubscriberOnNextListener.onError(e);
          }
          if (e instanceof SocketTimeoutException) {
              Toast.makeText(context, "网络中断，请检查您的网络状态", Toast.LENGTH_SHORT).show();
          } else if (e instanceof ConnectException) {
              Toast.makeText(context, "网络中断，请检查您的网络状态", Toast.LENGTH_SHORT).show();
          }
          dismissProgressDialog();
  
      }
  
      /**
       * 将onNext方法中的返回结果交给Activity或Fragment自己处理
       *
       * @param t 创建Subscriber时的泛型类型
       */
      @Override
      public void onNext(T t) {
          if (mSubscriberOnNextListener != null) {
              mSubscriberOnNextListener.onNext(t);
          }
      }
  }