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);
    }
    }
    });
    }
    }
    ---------------------

  • 相关阅读:
    confluence重置admin密码
    oracle 11g密码永不过期
    GCC编译器使用
    Emacs常用命令汇总
    bash shell命令(1)
    进程管理3--经典的进程同步问题
    进程管理2--进程的同步与信号量
    C安全问题与指针误用
    C迷途指针
    进程管理1--进程的概念与操作
  • 原文地址:https://www.cnblogs.com/ly570/p/11342613.html
Copyright © 2011-2022 走看看