Code Monkey home page Code Monkey logo

androidbase's Introduction

Name Explain Sample
MVP MVP使用
MVP+Dagger MVP+Dagger使用 MVP+Dagger:实现一个数据源数据返回
MVP+Dagger:使用基类列表页面实现两个数据源数据返回
列表页面 列表页面使用
网络状态 网络状态提示

MVP

V层处理UI视图操作;P层实现业务逻辑操作(有设计需要的时候,核心业务甚至可以写到一个核心的P里面去);M层为数据仓库,后台管理数据来源与数据控制,数据是来自网络、数据库、SP、缓存,示例:你可能会需要这样一个实现,一个数据列表,不需要实时性,但是需要给网络情况有问题时的用户提升用户体验,需要使用网络数据+本地缓存数据机制,那么,都可以统一在这个数据仓库做处理,代码逻辑层次很清晰,你应该会喜欢上这个设计。

V-P之间的调用方式采取依赖倒置原则,俗话就是使用抽象接口(回调);P与V,代码写多了,其实会发现,V可以正常的调用P,P则要尽量少调用V,或者使用DataBinding,数据的变化使用绑定方式;P与M,M只与P做沟通,数据一般来自后台延时操作,这块也就是使用RxJava情况较多的地方,网络请求可以尝试使用ReTrofit。一般情况下,一个V对应一个P,而P和M,会出现一个P对应多个M的情况(M的接口多了,或许会把M按模块创建)。

Dagger+MVP,则是实现在MVP 结构代码中,P、M 的对象创建使用 Dagger 注入方式。

Gradle

    allprojects {
        repositories {
            jcenter()
            maven { url "https://jitpack.io" }
        }
    }

    android {
        dataBinding {
            enabled = true
        }
    }

    dependencies {
        compile 'com.better.android:appbase:x.y.z'
    }

gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

致谢

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.