Giter VIP home page Giter VIP logo

mvp_rxjava_retrofit's Introduction

MVP_Rxjava_Retrofit

MVP+Retrofit+RxJava实战小Demo,可快速移植到自己的项目中进行运用。

本Demo主要涉及到以下内容:

1、如何将Retrofit+RxJava联网框架,结合泛型MVP架构,优雅灵活地运用到项目中。
2、BaseMvpActivity和BaseMvpFragment的封装
3、统一封装接口返回的json数据
4、自定义接口对网络请求的异常回调进行统一的处理。
5、MVC、MVP架构的运用

使用MVP+Retrofit+RxJava框架后Activity的代码:

/**
 * 测试MVP + Retrofit +RxJava
 */
public class MainActivity extends BaseMvpActivity<MainPresenter, MainModel> implements MainContract.View {
    @BindView(R.id.tv_quality)
    TextView tv_quality;
    @BindView(R.id.tv_pm)
    TextView tv_pm;
    @BindView(R.id.tv_wendu)
    TextView tv_wendu;
    @BindView(R.id.tv_notice)
    TextView tv_notice;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_main;
    }

    @Override
    protected void initViewAndEvents() {
        //发起请求
        mMvpPresenter.getWeather("101030100", mMultipleStateView);
    }

    /**
     * 接口请求成功的回调方法
     *
     * @param bean
     */
    @Override
    public void getWeather(WeatherEntity bean) {
        Log.e("TAG", "请求成功");
        tv_quality.setText("空气质量:" + bean.quality);
        tv_pm.setText("Pm10" + bean.pm10);
        tv_wendu.setText("温度:" + bean.wendu);
        tv_notice.setText("提醒:" + bean.ganmao);
    }
}

详情讲解可阅读文章高级MVP+Retrofit+RxJava实战——一步步带你搭建一套好用的项目框架

mvp_rxjava_retrofit's People

Contributors

gracejojo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.