zoukankan      html  css  js  c++  java
  • Presenter 层

    后是 Presenter 层,它是处理业务逻辑和业务数据的,所以必须持有 Model 的引用,同时要将处理完的数据交给 View 层用于显示,也必须持有 View 的引用,那么,一开始我们就要把这两层给实例化,具体看下面的代码:

    package com.test.mvp.mvpdemo.mvp.v1.presenter;

    import com.test.mvp.mvpdemo.mvp.v1.MainContract;
    import com.test.mvp.mvpdemo.mvp.v1.model.DataModel;

    import java.io.IOException;

    import okhttp3.Call;
    import okhttp3.Callback;
    import okhttp3.Response;

    /**
    * presenter 层,承担业务逻辑处理,数据源处理等
    */
    public class MainPresenter implements MainContract.IMainPresenter {

    private MainContract.IMainModel mModel;
    private MainContract.IMainView mView;

    public MainPresenter(MainContract.IMainView view) {
    this.mView = view;
    mModel = new DataModel();
    }

    @Override
    public void handlerData() {
    if (mView != null) {
    mView.showDialog();
    }
    /**
    * 发起请求,获得回调数据
    */
    mModel.requestBaidu(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {
    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {
    String content = response.body().string();
    if (mView != null) {
    mView.succes(content);
    }
    }
    });
    }
    }
    ---------------------

  • 相关阅读:
    poj 1321 棋盘问题 (DFS深度优先搜索)
    HDOJ1312 Red and black(DFS深度优先搜索)
    《数据结构》例1.3
    hdoj1905 Pseudoprime numbers (基础数论)
    百练4003 十六进制转十进制(水题)
    第二天——2.23
    第一天——2.22
    返校——2.21
    被盗号了——2.19
    继续咸鱼——2.18
  • 原文地址:https://www.cnblogs.com/ly570/p/11342613.html
Copyright © 2011-2022 走看看