一套可以直接复制使用的MVP框架

通过对MVP设计模式学习,对MVP也有了一个初步的认识,以登录Login模块为例,封装MVP如下:

package com.example.administrator.frameapp.api;

/**
* 存放url的接口
* Created by Zyh on 2016/11/17.
*/
public interface ApiUrl {
String IP="http://192.168.8.4/tp3/";
String BASEURL=IP+"api.php/Home/";
}
package com.example.administrator.frameapp.api;
import io.reactivex.Flowable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST; /**
* Created by Zyh on 2016/11/17.
*/
public interface ApiService {
@FormUrlEncoded
@POST("login/login")
Flowable<ApiResult> login(@Field("name") String name, @Field("password") String password);
}
package com.example.administrator.frameapp.api;

/**
* Created by Zyh on 2016/11/17.
*/
public class ApiResult<T> {
private int code;
private String Msg;
private T data; public int getCode() {
return code;
} @Override
public String toString() {
return "ApiResult{" +
"code=" + code +
", Msg='" + Msg + '\'' +
", data=" + data +
'}';
} public void setCode(int code) {
this.code = code;
} public String getMsg() {
return Msg;
} public void setMsg(String msg) {
Msg = msg;
} public T getData() {
return data;
} public void setData(T data) {
this.data = data;
}
}
package com.example.administrator.frameapp.api;

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory; /**
* Created by Zyh on 2016/11/17.
*/
public class Api {
private Retrofit mRetrofit;
public ApiService mApiservice;
private Api() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);//请求的内容和响应的内容都存在这个系统的BODY中
OkHttpClient mOkHttpClient = new OkHttpClient.Builder().addInterceptor(interceptor).build();
mRetrofit = new Retrofit.Builder()
.client(mOkHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(ApiUrl.BASEURL)
.build();
mApiservice = mRetrofit.create(ApiService.class);
}
//静态内部类的单例模式:内部类决定了什么时候加载他就什么时候进行加载,
private static class SingleHolder {
private static final Api INSTANCE = new Api();
} public static Api getInstance() {
return SingleHolder.INSTANCE; }
}
package com.example.administrator.frameapp.ui.base;

/**
* 创建base类是为了统一管理
* BasePresent是抽象类
* 将model和view关联起来
* Created by Zyh on 2016/11/17.
*/
public abstract class BasePresent<M,V> {
public M mModel;
public V mView;
public void setVM(V v,M m){
//这个方法将LoginPresenter中方法中类型映射成具体的类型
this.mModel=m;
this.mView=v;
}
}
package com.example.administrator.frameapp.ui.base;

/**
* Created by Zyh on 2016/11/17.
*/
public interface BaseView {
}
package com.example.administrator.frameapp.ui.base;

/**
* Created by Zyh on 2016/11/17.
*/
public interface BaseModel {
}

MVP解析的更多相关文章

  1. Android优秀资源整理合集(论菜鸟到高级攻城狮)

    转载请注明转自:http://blog.csdn.net/u011176685/article/details/51434702 csdn文章:Android优秀资源整理合集(论菜鸟到高级攻城狮) 时 ...

  2. Android开发MVP模式解析

    http://www.cnblogs.com/bravestarrhu/archive/2012/05/02/2479461.html 在开发Android应用时,相信很多同学遇到和我一样的情况,虽然 ...

  3. 转:Android官方MVP架构示例项目解析

    转自: http://www.infoq.com/cn/articles/android-official-mvp-architecture-sample-project-analysis 作者 吕英 ...

  4. mvp架构解析

    MVP现在已经是目前最火的架构,很多的框架都是以MVP为基础,甚至于Google自己都出一个MVP的开源架构.https://github.com/googlesamples/android-arch ...

  5. Google官方MVP模式示例项目解析 todo-mvp

    转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6700668.html 引言:在Google没有给出一套权威的架构实现之前,很多App项目在架构方面都有或多 ...

  6. android中MVC,MVP和MVVM三种模式详解析

    我们都知道,Android本身就采用了MVC模式,model层数据源层我们就不说了,至于view层即通过xml来体现,而 controller层的角色一般是由activity来担当的.虽然我们项目用到 ...

  7. MVC、MVP、MVVM概念解析

    详细请看阮一峰网站 1.MVC Model(数据) - View(视图) - Controller(业务逻辑) 通信方式:单向 交互方式两种,如下 应用:(BackBone)不完全和设计模式一致 2. ...

  8. [Android]使用MVP解决技术债务(翻译)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5892671.html 使用MVP解决技术债务 原文:https ...

  9. Android应用中MVP开发模式

    所谓MVP(Model-View-Presenter)模式.是将APP的结构分为三层: view - UI显示层 view 层主要负责: 提供UI交互 在presenter的控制下修改UI. 将业务事 ...

随机推荐

  1. 如何安装并简单的使用OwinHost——Katana

    微软OWIN的提出必然会引起一场风暴,而我们作为C#阵营中一份子,自然免不了会卷入其中.OWIN是什么东西,我在这里就不解析了,还不知道是OWIN是什么的读者请打开浏览器,然后搜索即可,中文的英文的应 ...

  2. Linux 安装Mono环境 运行ASP.NET(一)

    1.先看一下Linux环境下面请求的过程,(画的不是很好,简单的了解一下原理.) .NET跨平台其实需要这三个关键:编译器.CLR和基础类库.在.NET下我们编写一个最简单的"Hello W ...

  3. Spring8:一些常用的Spring Bean扩展接口

    前言 Spring是一款非常强大的框架,可以说是几乎所有的企业级Java项目使用了Spring,而Bean又是Spring框架的核心. Spring框架运用了非常多的设计模式,从整体上看,它的设计严格 ...

  4. Phaser-游戏之旅

    虽然这个小游戏逻辑不是很复杂,但为了熟悉Phaser这个游戏框架的使用方法所以就选择了它. 另外第一次在项目中尝试使用ES6,之后利用babel进行转换. 自动化构建:gulp(其他文件复制和解析) ...

  5. Spring cookie 实战

    测试环境搭建 使用Springboot构建web server, 在测试方法中打印接收的cookie. @RestController @RequestMapping("/register/ ...

  6. 我写的一些前端开源项目(均托管到github)

    大部分项目都是平时项目用到的某些功能,觉得有趣或者复用性有点高就提取成一个单独项目来做维护 coffee-tmpl : 一个极简的模板引擎和ejs及underscore的template类似 turn ...

  7. AOP概述

    了解AOP之前,先大概讲述一下SOC: Soc:Separation of concerns 关注分离点, 在不同的场景SOC有着不同的含义 Soc是一个过程:Soc是一个将功能点分解以尽量减小功能交 ...

  8. iOS开发之浅谈MVVM的架构设计与团队协作

    今天写这篇博客是想达到抛砖引玉的作用,想与大家交流一下思想,相互学习,博文中有不足之处还望大家批评指正.本篇博客的内容沿袭以往博客的风格,也是以干货为主,偶尔扯扯咸蛋(哈哈~不好好工作又开始发表博客啦 ...

  9. C# 获取Excel中的合并单元格

    C# 获取Excel中的合并单元格 我们在制作表格时,有时经常需要合并及取消合并一些单元格.在取消合并单元格时需要逐个查找及取消,比较麻烦.这里分享一个简单的方法来识别Excel中的合并单元格,识别这 ...

  10. Vertica 业务用户指定资源池加载数据

    之前在"Vertica 安装,建库,新建测试用户并授予权限,建表,入库"这篇文章也简单介绍过入库部分的内容. 但之前测试用例若用于生产环境有明显的局限性: 1.是用dbadmin管 ...