Giter Site home page Giter Site logo

mvplibrary's Introduction

MVPLibrary

MVP设计模式,提供BaseActivity、BasePresenter等公共基础类。

更新日志查看这里

引用

在项目build.gradle下添加:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

app -> build.gradle

dependencies {
        implementation 'com.github.JJput:MVPLibrary:v1.0.5'
}

基本使用

MVPLibrary详细定义了V层和P层基础内容。使其V层和P层只通过接口进行通讯。详情可以将项目下载下来,查看其示例,下面也会简单介绍。

目录结构

  • MainActivity V层。
  • MainContract 协议者,主要控制V层和P层之间的接口。
  • MainPresente P层。

V层

V层实现V层接口,主要实现各种界面交互、显示功能。

MainActivity

public class MainActivity extends BaseActivity<MainContract.Presenter> implements MainContract.View {

    private TextView tvText;

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


    @Override
    protected MainContract.Presenter initInjector() {
        return new MainPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        tvText = findViewById(R.id.main_tv);
        mPresenter.startRequsetData();
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void showText(String text) {
        tvText.setText(text);
    }
}

P层

MainPresenter

实现Presenter的接口,主要完成业务逻辑,并将最后结果通过接口返回至V层。

public class MainPresenter extends BasePresenter<MainContract.View> implements MainContract.Presenter {

    @Override
    public void startRequsetData() {
        String data = "Hello MVP";
        /**
         * ...
         */
        mView.showText(data);
    }
}

MainContract

定义V层与P层的接口。

public interface MainContract {


    interface View extends IView{

        /**
         * 显示Text内容
         * @param text 文本内容
         */
        void showText(String text);

    }

    interface Presenter extends IPresenter {

        /**
         * 开始获取数据
         */
        void startRequsetData();

    }
}

mvplibrary's People

Contributors

jjput avatar

Watchers

James Cloos 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.