package com.leelit.stuer.presenter;

import com.leelit.stuer.bean.BaseInfo;
import com.leelit.stuer.bean.CarpoolingInfo;
import com.leelit.stuer.model.CarpoolModel;
import com.leelit.stuer.viewinterface.IMyOrderView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import okhttp3.ResponseBody;
import rx.Subscriber;

/**
 * Created by Leelit on 2016/3/9.
 */
public class MyCarpoolPresenter implements IMyOrderPresenter {

    // 为何Model不抽象接口
    // 因为CarpoolModel和DateModel接口不同
    // 运用多态时，则需要判断是哪个Model，再转型，再调用，会使这个基类膨胀。

    private CarpoolModel mModel = new CarpoolModel();

    private IMyOrderView mView;

    public MyCarpoolPresenter(IMyOrderView view) {
        mView = view;
    }

    @Override
    public void doLoadingInfos(String imei) {
        mModel.getPersonalRelativeRecords(imei, new Subscriber<List<List<CarpoolingInfo>>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                mView.notRefreshing();
                mView.netError();
            }

            @Override
            public void onNext(List<List<CarpoolingInfo>> lists) {
                mView.notRefreshing();
                List<List<? extends BaseInfo>> result = new ArrayList<>();
                for (int i = 0; i < lists.size(); i++) {
                    result.add(lists.get(i));
                }
                mView.showInfos(result);
                if (lists.isEmpty()) {
                    mView.noInfos();
                }
            }
        });
    }

    @Override
    public void doQuitOrder(Map<String, String> map, final int position) {
        mView.showDeleteProgressDialog("退出中...");
        mModel.quitOrder(map, new Subscriber<ResponseBody>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissDeleteProgressDialog();
                mView.netError();
            }

            @Override
            public void onNext(ResponseBody responseBody) {
                mView.dismissDeleteProgressDialog();
                mView.deleteOrder(position);
            }
        });
    }

    @Override
    public void doFinishOrder(String uniquecode, final int position) {
        mView.showDeleteProgressDialog("解散中...");
        mModel.finishOrder(uniquecode, new Subscriber<ResponseBody>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                mView.dismissDeleteProgressDialog();
                mView.netError();
            }

            @Override
            public void onNext(ResponseBody responseBody) {
                mView.dismissDeleteProgressDialog();
                mView.deleteOrder(position);
            }
        });
    }
}

@@ -454,100 +454,188 @@
  // 
-%E4%B8%BA%E4%BD%95
 Model
-%E4%B8%8D%E6%8A%BD%E8%B1%A1%E6%8E%A5%E5%8F%A3%0A    // %E5%9B%A0%E4%B8%BACarpoolModel%E5%92%8CDateModel%E6%8E%A5%E5%8F%A3%E4%B8%8D%E5%90%8C%0A    // %E8%BF%90%E7%94%A8%E5%A4%9A%E6%80%81%E6%97%B6%EF%BC%8C%E5%88%99%E9%9C%80%E8%A6%81%E5%88%A4%E6%96%AD%E6%98%AF%E5%93%AA%E4%B8%AAModel%EF%BC%8C%E5%86%8D%E8%BD%AC%E5%9E%8B%EF%BC%8C%E5%86%8D%E8%B0%83%E7%94%A8%EF%BC%8C%E4%BC%9A%E4%BD%BF%E8%BF%99%E4%B8%AA%E5%9F%BA%E7%B1%BB%E8%86%A8%E8%83%80
+%E6%AD%A4%E5%A4%84%E6%97%A0%E6%B3%95%E6%8A%BD%E8%B1%A1%EF%BC%8C%E5%9B%A0%E4%B8%BA%E6%8E%A5%E5%8F%A3%E4%B8%8D%E5%90%8C%EF%BC%9B%0A    // Retrofit%E4%BD%BF%E7%94%A8Gson%E8%BF%9B%E8%A1%8C%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%A7%A3%E6%9E%90%EF%BC%8C%E5%B9%B6%E4%B8%94RxJava#Observable%3CT%3E%E4%B8%8D%E8%83%BD%E4%BD%BF%E7%94%A8%E9%80%9A%E9%85%8D%E7%AC%A6%EF%BC%8C%E6%89%80%E4%BB%A5Gson%E4%BB%8EString-Object%E6%97%B6%E5%BF%85%E9%A1%BB%E6%8C%87%E5%AE%9A%E7%A1%AE%E5%88%87%E7%B1%BB%E5%9E%8B%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%8C%87%E5%AE%9A%E7%88%B6%E7%B1%BB%EF%BC%8C%E5%88%99%E4%BC%9A%E4%B8%A2%E5%A4%B1%E4%BF%A1%E6%81%AF%E3%80%82%0A    // %E4%BD%BF%E7%94%A8Retrofit%E9%85%8D%E5%90%88Gson%E4%B8%8D%E7%AE%A1%E6%98%AFpost%E8%BF%98%E6%98%AFget%EF%BC%8C%E8%A7%A3%E6%9E%90%E7%9A%84%E7%B1%BB%E5%9E%8B%E9%83%BD%E6%98%AF%E7%89%B9%E5%AE%9A%E7%9A%84%EF%BC%8C%E7%88%B6%E7%B1%BB%E4%BC%9A%E4%B8%A2%E5%A4%B1%E5%AD%90%E7%B1%BB%E4%BF%A1%E6%81%AF
 %E3%80%82%0A%0A 

add some key comment & prepare for SELL module