MVP解析
一套可以直接复制使用的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解析的更多相关文章
- Android优秀资源整理合集(论菜鸟到高级攻城狮)
转载请注明转自:http://blog.csdn.net/u011176685/article/details/51434702 csdn文章:Android优秀资源整理合集(论菜鸟到高级攻城狮) 时 ...
- Android开发MVP模式解析
http://www.cnblogs.com/bravestarrhu/archive/2012/05/02/2479461.html 在开发Android应用时,相信很多同学遇到和我一样的情况,虽然 ...
- 转:Android官方MVP架构示例项目解析
转自: http://www.infoq.com/cn/articles/android-official-mvp-architecture-sample-project-analysis 作者 吕英 ...
- mvp架构解析
MVP现在已经是目前最火的架构,很多的框架都是以MVP为基础,甚至于Google自己都出一个MVP的开源架构.https://github.com/googlesamples/android-arch ...
- Google官方MVP模式示例项目解析 todo-mvp
转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6700668.html 引言:在Google没有给出一套权威的架构实现之前,很多App项目在架构方面都有或多 ...
- android中MVC,MVP和MVVM三种模式详解析
我们都知道,Android本身就采用了MVC模式,model层数据源层我们就不说了,至于view层即通过xml来体现,而 controller层的角色一般是由activity来担当的.虽然我们项目用到 ...
- MVC、MVP、MVVM概念解析
详细请看阮一峰网站 1.MVC Model(数据) - View(视图) - Controller(业务逻辑) 通信方式:单向 交互方式两种,如下 应用:(BackBone)不完全和设计模式一致 2. ...
- [Android]使用MVP解决技术债务(翻译)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5892671.html 使用MVP解决技术债务 原文:https ...
- Android应用中MVP开发模式
所谓MVP(Model-View-Presenter)模式.是将APP的结构分为三层: view - UI显示层 view 层主要负责: 提供UI交互 在presenter的控制下修改UI. 将业务事 ...
随机推荐
- 【Win10】UAP/UWP/通用 开发之 x:Bind
[Some information relates to pre-released product which may be substantially modified before it's co ...
- Vue.js——使用$.ajax和vue-resource实现OAuth的注册、登录、注销和API调用
概述 上一篇我们介绍了如何使用vue resource处理HTTP请求,结合服务端的REST API,就能够很容易地构建一个增删查改应用.这个应用始终遗留了一个问题,Web App在访问REST AP ...
- ES6+ 现在就用系列(二):let 命令
系列目录 ES6+ 现在就用系列(一):为什么使用ES6+ ES6+ 现在就用系列(二):let 命令 ES6+ 现在就用系列(三):const 命令 ES6+ 现在就用系列(四):箭头函数 => ...
- 架构设计:一种远程调用服务的设计构思(zookeeper的一种应用实践)
在深入学习zookeeper我想先给大家介绍一个和zookeeper相关的应用实例,我把这个实例命名为远程调用服务.通过对这种应用实例的描述,我们会对zookeeper应用场景会有深入的了解. 远程调 ...
- Java模块化规范之争(转载)
经过近20年的发展,Java语言已成为今日世界上最成功.使用的开发者人数最多的语言之一,Java世界中无数商业的或开源的组织.技术和产品共同构成了一个无比庞大的生态系统. 与大多数开发人员的普遍认知不 ...
- springmvc的图片上传与导出显示
1.前端文件上传需要在form表单内添加enctype="multipart/form-data" ,以二进制传递: 2.web.xml文件内配置 <servlet-mapp ...
- windows下使用VS2015编译V8 JavaScript引擎(v5.5 - 2016/09)
今天心血来潮, 下载了 v8,,然后就想着用vs编译 但是大家都苦恼的是 v8并不直接提供 vs用的项目文件和解决方案(.sln) 于是,在网上搜来搜去, 折腾来折腾去的; 终于一点一点的尝试, 可以 ...
- ActiveMQ的集群方案对比及部署
转载:http://blog.csdn.net/lifetragedy/article/details/51869032 ActiveMQ的集群 内嵌代理所引发的问题: 消息过载 管理混乱 如何解决这 ...
- DotNet程序配置文件
在实际的项目开发中,对于项目的相关信息的配置较多,在.NET项目中,我们较多的将程序的相关配置直接存储的.config文件中,例如web.config和app.config. .NET中配置文件分为两 ...
- MVP社区巡讲-云端基础架构:12月5日北京站 12月12日上海站
紧跟当今的技术发展趋势还远远不够,我们要引领变革!加入本地技术专家社区,获取真实案例.实况培训演示以及探讨新一代解决方案.在此活动中,您将: 了解如何运用开源(OSS)技术.Microsoft 技术及 ...