package com.ahau.againstpest.presenter;

import com.ahau.againstpest.bean.PestBean;
import com.ahau.againstpest.model.IPestModel;
import com.ahau.againstpest.model.PestModelImpl;
import com.ahau.againstpest.view.IPestView;

import java.util.List;

/**
 * 注释:表示层
 *
 * @author fanchunchun
 * @date 2018/4/3
 */

public class PestPresenter<T extends IPestView> extends BasePresenter<T> {

    //2, model层的引用
    IPestModel pestModel = new PestModelImpl();

    //3, 构造方法
    public PestPresenter() {
    }

    //4, 执行操作(UI)逻辑
    public void fetch() {

        if (mViewRef.get() != null) {
            if (pestModel != null) {
                //获取pest的名字
                pestModel.getPest(new IPestModel.PestGetListener() {
                    @Override
                    public void onComplete(List<PestBean.Pest> pest) {
                        if (mViewRef.get() != null) {
                            mViewRef.get().showPest(pest);
                        }
                    }
                });
                //设置当前时间
                pestModel.getDate(new IPestModel.DateListener() {
                    @Override
                    public void onComplete(String date) {
                        if (mViewRef.get() != null) {
                            mViewRef.get().setDate(date);
                        }
                    }
                });
                //设置经纬度
                pestModel.getLatlng(new IPestModel.LatlngListener() {
                    @Override
                    public void onComplete(String[] latlng) {
                        if (mViewRef.get() != null) {
                            mViewRef.get().setLatlng(latlng);
                        }
                        System.out.println(latlng[0]);
                    }

                });
                //设置调查人姓名
                pestModel.getResearName(new IPestModel.ResearNameListener() {
                    @Override
                    public void onComplete(String researName) {
                        if (mViewRef.get() != null) {
                            mViewRef.get().setResearName(researName);
                        }
                        System.out.println(researName);
                    }
                });
            }

        }


    }
}
