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. 将业务事 ...
随机推荐
- ubuntu-14.04-server配置Jexus --安装步骤记录
作者:郝喜路 个人主页:http://www.cnicode.com 博客地址:http://haoxilu.cnblogs.com 说明:我是Linux菜鸟,自己尝试配置Jexus服务 ...
- Linux学习日记-(一)
一.为什么学习Linux 大学时开始接触Linux,最开始学习的是RedHat(小红帽),感觉Linux好像很久不见的老朋友,用起来很舒服(虽然我们用的是DotNet).很喜欢它的命令模式,让我能接触 ...
- ASP.NET Linux部署(2) - MS Owin + WebApi + Mono + Jexus
ASP.NET Linux部署(2) - MS Owin + WebApi + Mono + Jexus 本文承接我的上一篇博文: ASP.NET 5 Linux部署,那篇文章主要是针对最新的ASP. ...
- [Mahout] 完整部署过程
概述 Mahout底层依赖Hadoop,部署Mahout过程中最困难的就是Hadoop的部署 本文假设用户本身没有进行Hadoop的部署,记述部署Mahout的过程 ...
- 将一句话里的单词进行倒置,标点符号不倒换。比如将“I come from Shanghai.”倒换后变为“Shanghai. from come I”
string str = "I come from Shanghai."; //根据空格切割 string[] strS = str.Split(' '); string temp ...
- 设置Debian8 光秃秃的桌面(图标,窗口样式等)
在虚拟机里按抓了Debian8, 然后进入桌面后很不习惯,最主要是桌面光秃秃的, 今天终于不小心找到办法了: 按[Win]键, 找到"优化工具"程序; 或者是在右上角的[应用程序] ...
- 阿里云 SDK python3支持
最近的一个项目需要操作阿里云的RDS,项目使用python3,让人惊讶的是官方的SDK竟然只支持python2 在阿里云现有SDK上改了改,文件的修改只涉及aliyun/api/base.py,详见h ...
- 【WCF】基址与默认终结点
五月份的时候,有位老友给老周提了个建议:希望老周写一写WCF的文章.其实老周以前是写过WCF的文章的,只是不是写在这个博客里,老周并不打算把X年前的博客导进来,要写的话,重新写吧.毕竟,那个时候写的文 ...
- 支持高并发的IIS Web服务器常用设置
适用的IIS版本:IIS 7.0, IIS 7.5, IIS 8.0 适用的Windows版本:Windows Server 2008, Windows Server 2008 R2, Windows ...
- 网站实现微信登录之嵌入二维码——基于yii2开发的描述
之前写了一篇yii2获取登录前的页面url地址的文章,然后发现自己对于网站实现微信扫码登录功能的实现不是很熟悉,所以,我会写2-3篇的文章来描述下一个站点如何实现微信扫码登录的功能,来复习下微信扫码登 ...