序言
MVP这个架构已经诞生好久了,为啥现在才用。因为啊,项目不需要啊!你工作就懂了。
什么?MVP是啥?
楼上链接出门直走,不谢!
一、butterknife
1.1 MVP繁琐吗,其实很简单
这个可以自动生成MVP三部分的接口哦,神不神奇?

LoginContract这个文件要自己写,其实就是简单的接口定义

划线处右键Generate选MVP Helper,就生成图一的model和presenter目录了。
1.2 MVP Helper安装

在AS的File里选Setting然后在Plugins里搜索MVPHelper就能找到了。
具体的gradle,你们可以下源码看的。demo可以上传git,跟公司无关[机智]!
二、接口实现
就是图一那些接口的实现,你愿意也可以打桩,我的话呢,写了个手机短信第三方登录的功能,不是装X哦~
2.1 Presenter
肯定先介绍这个中间层,小时候语文课讲过,承上启下关键嘛。
这个模块处理所有逻辑部分,通过调用viewer层提供的接口呈现给用户,例如,发送验证码。

你看,构造时,已经获取到view了,并跟model对象产生了联系。
接下来,获取view提供的电话号码通过model申请短信验证码再反馈给activity结果即可。


其他的都是逻辑代码,你们可以看,不喜可喷,但要给红包,一个字一元。哈哈哈!大过年的嘛~~
2.2 model
这个超级简单,因为防护啥的复杂逻辑都在presenter了,就是网络请求部分,直接掉sdk接口,连这个错误处理都省了。

真没啥说的,聊十块钱都聊不了。
2.3 view即activity

这里没啥意思,突然想说下bindview,毕竟我是一名佛系程序员嘛~
赠品
赠一、bindview
朋友,你是否还为繁琐的实现findViewById而呕吐不已,这里有个神器,只要自己写好layout,右键,自动就会帮你写好这些了哦,就是这么神奇,好像刚才也很神奇,好吧,老规矩,装上就好,有没有效谁用谁知道。

使用的话,在activity上的layout上直接右键generate选Generate Butterknife Injections。然后Duang的一下就完成所有代码了。

赠二、免费的短信登录
感谢Mob官网提供免费的短信登录,作为穷人家的孩子,没有什么比免费更实用了的吧。

去官网下载后按照说明安装即可,别忘了在gradle上加入。注意下面两点,应该没有问题


尾声
其实啊,写代码哪有那么复杂,程序员哪有那么神秘,就像人人都是产品经理一样,其实人人都是程序员,莫名感觉到了失业危机。
网友评论