|
|
|
|
移动端

看完不会写MVP架构我跪搓板

为了月薪1.8万,我们要不断地学习和总结,今天给大家带来常见的android架构模式——mvp,非常详细,很值得学习。为什么要去学习MVP,看看下面的一张图就知道了。

作者:佚名来源:Android开发中文站|2018-06-08 14:06

技术沙龙 | 邀您于8月25日与国美/AWS/转转三位专家共同探讨小程序电商实战

为了月薪1.8万,我们要不断地学习和总结,今天给大家带来常见的android架构模式——mvp,非常详细,很值得学习。

为什么要去学习MVP,看看下面的一张图就知道了。

看完不会写MVP架构我跪搓板

1. 序言

实际开发中根据业务选择合适的架构。

这篇博客简单介绍MVC模式,详细介绍MVP模式。

看完这篇博客,不会写MVP,直接留言,我跪搓板!

2. MVC模式简介

  • M:Model:模型层:负责业务逻辑。
  • V:View:视图层:负责界面呈现
  • C:Controller:控制层:负责Model与View交互。

简单说:MVC就是通过Controller来操作Model层的数据,并且返回给View层展示。

3. Android中的MVC模式缺点

Android并不是一个标准的MVC模式中的Controller,它的首要职责是加载应用的布局和初始化用户界面,接受并处理来自用户的操作请求,进而做出响应。随着界面及其逻辑的复杂度不断提升,Activity类的职责不断增加,以致变得庞大臃肿。

由于Android的Controller通常在Activity、Fragment中,所以Model和View层耦合严重,不易开发和维护。

4. MVP模式简介

  • M:Model:负责获取和存储数据。
  • V:View:负责用户事件和视图部分的展示。
  • P:Presenter:作为View和Model之间沟通的桥梁。

简单说:MVP就是通过Presenter从Model层检索数据后返回给View层。

5. Android中的MVP模式的优点

Presenter完全将Model和View进行了分离,主要逻辑在Presenter里实现。

6. MVP示例

6.1 添加依赖

  1. compile 'cn.finalteam:okhttpfinal:2.0.7' 

6.2 初始化okhttpfinal

  1. public class App extends Application { 
  2.    @Override 
  3.    public void onCreate() { 
  4.       super.onCreate(); 
  5.       OkHttpFinalConfiguration.Builder builder = new OkHttpFinalConfiguration.Builder(); 
  6.       OkHttpFinal.getInstance().init(builder.build()); 
  7.    } 

6.3 实现Model

① 创建实体类TitleData:

  1. public class TitleData { 
  2.    /** 
  3.     * reason : 成功的返回 
  4.     * result : {"stat":"1","data":[{"uniquekey":"68388dafd210bd9e6e733f28f35d36d9","title":"不用去健身房的徒手健身14式!随时让你身体泵感飙升!","date":"2018-04-15 22:27","category":"头条","author_name":"极限肌汤","url":"http://mini.eastday.com/mobile/180415222744706.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_9_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_15_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_14_mwpm_03200403.jpg"},{"uniquekey":"c792b6c975915e0f353e1525d74361a2","title":"王毅同日本外相河野太郎举行会谈","date":"2018-04-15 22:06","category":"头条","author_name":"外交部新闻","url":"http://mini.eastday.com/mobile/180415220602296.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415220602_8c06c36f699b2cdb6e7fbcabe0980cb2_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415220602_8c06c36f699b2cdb6e7fbcabe0980cb2_2_mwpm_03200403.jpg"},{"uniquekey":"393182746325575e28816c7a52fcd891","title":"叙利亚遭美再轰炸证明弱小才会挨打?错了,是内部不团结才挨的打","date":"2018-04-15 21:58","category":"头条","author_name":"清风晓","url":"http://mini.eastday.com/mobile/180415215840462.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415_d00823627f77600d8294d9a8927b59dd_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415_454c1ef82a92a1c6ba787e763c275b89_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415_08123e1f126ec2b83ca5325ed7f0fb62_cover_mwpm_03200403.jpg"},{"uniquekey":"21a6ff821f95eb5b36783f68aeea103c","title":"今早发生飞机被劫持事件 你知道机长是如何用代码通知地面吗?","date":"2018-04-15 21:57","category":"头条","author_name":"1039航空在线","url":"http://mini.eastday.com/mobile/180415215736534.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415215736_9bea759e1382a2b897cbb9e40d8e37fd_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415215736_add9d74fe93e7e6c5b107aab523a6395_2_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415215736_680d3e100a59ae3aa6dee89cc8b39eac_3_mwpm_03200403.jpg"},{"uniquekey":"56fb7f21b478d88d29513f84f8b6ea67","title":"未经国内授权就发动对叙打击,英法领导人被批u201c跟在特朗普后面u201d","date":"2018-04-15 21:52","category":"头条","author_name":"观察者网","url":"http://mini.eastday.com/mobile/180415215211363.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415215211_05ec6bcc67f0f14bb72cb6f6fe4f5b9e_4_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415215211_05ec6bcc67f0f14bb72cb6f6fe4f5b9e_5_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415215211_05ec6bcc67f0f14bb72cb6f6fe4f5b9e_3_mwpm_03200403.jpg"},{"uniquekey":"6378cc37d7cd029989058172c115da59","title":"叙利亚被轰炸,海南被刷屏,该满仓还是空仓?","date":"2018-04-15 21:35","category":"头条","author_name":"澄泓财经","url":"http://mini.eastday.com/mobile/180415213527945.html","thumbnail_pic_s":"http://02.imgmini.eastday.com/mobile/20180415/20180415213527_456b2a35bbbe09f2a1e48d65556b591b_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://02.imgmini.eastday.com/mobile/20180415/20180415213527_456b2a35bbbe09f2a1e48d65556b591b_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://02.imgmini.eastday.com/mobile/20180415/20180415213527_456b2a35bbbe09f2a1e48d65556b591b_3_mwpm_03200403.jpg"},{"uniquekey":"610d5f5ae0b7649e55c2b9c4c376a49a","title":"湘雅医院45个口腔癌患者中,44人长期大量嚼槟榔","date":"2018-04-15 21:17","category":"头条","author_name":"澎湃新闻网","url":"http://mini.eastday.com/mobile/180415211747158.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415211747_bb6663066717047a755cf1dc406940e6_1_mwpm_03200403.jpg"},{"uniquekey":"9b264e90b08601075c184967360d11d0","title":"沙特和以色列关系逐步提升 伊朗:他们正进行联合犯罪","date":"2018-04-15 21:13","category":"头条","author_name":"中东研究通讯","url":"http://mini.eastday.com/mobile/180415211352158.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415211352_85311a103046811efbf4b604d63ff949_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415211352_85311a103046811efbf4b604d63ff949_4_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415211352_85311a103046811efbf4b604d63ff949_5_mwpm_03200403.jpg"},{"uniquekey":"931a6c79dd80e7c66c4f07e093f56bbd","title":"印度洋岛国毛里求斯的华人故事:盼与中国共发展","date":"2018-04-15 21:13","category":"头条","author_name":"中国新闻网","url":"http://mini.eastday.com/mobile/180415211349598.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415211349_0166b7c8152d1f8559d9440af2f0d7b3_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415211349_0166b7c8152d1f8559d9440af2f0d7b3_1_mwpm_03200403.jpg"},{"uniquekey":"9247330c735b0659b69c57b9575853fd","title":"男子在地里干活,发现自家坟墓出现一个洞,里面的景象让他傻了眼","date":"2018-04-15 21:02","category":"头条","author_name":"奇闻达人","url":"http://mini.eastday.com/mobile/180415210205138.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415_2f3e4f4f731ed25bb5326153f5e1f6df_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415_99ee412a06367ae94c45d5d0e7eec74e_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415_f8627d97c7d3f333233a9fa5762e43ff_cover_mwpm_03200403.jpg"},{"uniquekey":"bdc1efa1c2deff034f8e3cd8cd1d4a49","title":"瑜伽疗愈身心其实很简单 只需会呼吸就好","date":"2018-04-15 21:00","category":"头条","author_name":"瑜伽体式精讲","url":"http://mini.eastday.com/mobile/180415210010479.html","thumbnail_pic_s":"http://02.imgmini.eastday.com/mobile/20180415/20180415_dc6d0c014ca7a6590974ded3664f56f9_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://02.imgmini.eastday.com/mobile/20180415/20180415_98a99725b647080e302912d8895b8107_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://02.imgmini.eastday.com/mobile/20180415/20180415_6ff58e524feddd2983bd555008b9454b_cover_mwpm_03200403.jpg"},{"uniquekey":"d840acd294d7d3d7224f775b40a31f22","title":"马云说:2018年只要抓住这个行业 将会有大批人暴富 !","date":"2018-04-15 20:58","category":"头条","author_name":"星座的情感巫师","url":"http://mini.eastday.com/mobile/180415205834831.html","thumbnail_pic_s":"http://05.imgmini.eastday.com/mobile/20180415/20180415_5898b55ce7882d86bb3d5d5db9110296_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://05.imgmini.eastday.com/mobile/20180415/20180415_e0c5592edf6745d7bdbdc2bfa49eee61_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://05.imgmini.eastday.com/mobile/20180415/20180415_497e816851327038a86ffb15e2c4ac7d_cover_mwpm_03200403.jpg"},{"uniquekey":"3af2890c7503ecb5ac8d6e857baca49b","title":"如何推动东北高质量发展?专家:首先多提u201c新东北u201d概念","date":"2018-04-15 20:57","category":"头条","author_name":"澎湃新闻网","url":"http://mini.eastday.com/mobile/180415205719783.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415205719_e2ab1c506ddf063125e41dde1651db6d_1_mwpm_03200403.jpg"},{"uniquekey":"81c06482d6b62ebb89e24b902de05370","title":"戊戌年澳大利亚华人恭拜轩辕黄帝大典在悉尼举行","date":"2018-04-15 20:54","category":"头条","author_name":"人民网","url":"http://mini.eastday.com/mobile/180415205436408.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415205436_53b5c2ea3edef971d0e9edaf373b6875_5_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415205436_53b5c2ea3edef971d0e9edaf373b6875_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://08.imgmini.eastday.com/mobile/20180415/20180415205436_53b5c2ea3edef971d0e9edaf373b6875_4_mwpm_03200403.jpg"},{"uniquekey":"0f2e01526bc03873e14c7af24715f1c9","title":"南极下的雪越来越多,200年增加10%!然而这是大坏事的开始!","date":"2018-04-15 20:33","category":"头条","author_name":"中国气象爱好者","url":"http://mini.eastday.com/mobile/180415203300175.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415203300_eebd0303e57d1ffda38264ca0ad9527f_3_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415203300_eebd0303e57d1ffda38264ca0ad9527f_2_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415203300_eebd0303e57d1ffda38264ca0ad9527f_1_mwpm_03200403.jpg"},{"uniquekey":"c6d48e1ce2b07f411533f4c2e1ab336a","title":"把宪法精神融入公证实践","date":"2018-04-15 20:31","category":"头条","author_name":"法制网","url":"http://mini.eastday.com/mobile/180415203159176.html","thumbnail_pic_s":"http://03.imgmini.eastday.com/mobile/20180415/20180415203159_4586775d679b2a5b89662570e41bd0c0_1_mwpm_03200403.jpg"},{"uniquekey":"9a12e11575a3e258ed577e26c802bcdb","title":"解放军新条令释放红利:官兵节假日值班后安排补休","date":"2018-04-15 20:27","category":"头条","author_name":"环球网","url":"http://mini.eastday.com/mobile/180415202715963.html","thumbnail_pic_s":"http://02.imgmini.eastday.com/mobile/20180415/20180415202715_f7a7655284bcd56685b5b47808a3089c_1_mwpm_03200403.jpg"},{"uniquekey":"d8b3e71020284251c4e73956ccf684ae","title":"死者入土为安?印尼神秘村庄人死后十年依然吃饭洗澡,堪称活死人","date":"2018-04-15 20:26","category":"头条","author_name":"格林憋闷ss","url":"http://mini.eastday.com/mobile/180415202626177.html","thumbnail_pic_s":"http://04.imgmini.eastday.com/mobile/20180415/20180415202626_54722af09b478d592ad7301984a63444_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://04.imgmini.eastday.com/mobile/20180415/20180415202626_54722af09b478d592ad7301984a63444_3_mwpm_03200403.jpg","thumbnail_pic_s03":"http://04.imgmini.eastday.com/mobile/20180415/20180415202626_54722af09b478d592ad7301984a63444_2_mwpm_03200403.jpg"},{"uniquekey":"f3d228eecfd4793f166e79914ad92374","title":"想要丰胸和瘦臂却做不了俯卧撑?试试这六个动作吧!","date":"2018-04-15 20:25","category":"头条","author_name":"丰胸导师_晓雨","url":"http://mini.eastday.com/mobile/180415202535878.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415202535_a42e5527a457894d2a6f4f7db9625096_6_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415202535_a42e5527a457894d2a6f4f7db9625096_2_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415202535_a42e5527a457894d2a6f4f7db9625096_1_mwpm_03200403.jpg"},{"uniquekey":"8a909ff6fd43d4e092eabd5e5576cafe","title":"如何续写u201c来了就不想走u201d的海南故事? | 锐评","date":"2018-04-15 20:24","category":"头条","author_name":"人民日报","url":"http://mini.eastday.com/mobile/180415202409259.html","thumbnail_pic_s":"http://03.imgmini.eastday.com/mobile/20180415/20180415202409_db2bf6b3f75b110448a65f9d1bc83659_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://03.imgmini.eastday.com/mobile/20180415/20180415202409_db2bf6b3f75b110448a65f9d1bc83659_2_mwpm_03200403.jpg"},{"uniquekey":"86bb5027d938238d8606c6d1c1740e52","title":"70%成功拦截率 俄罗斯和美国到底谁在说谎?现实让该国打脸","date":"2018-04-15 20:20","category":"头条","author_name":"火线前沿","url":"http://mini.eastday.com/mobile/180415202013958.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415_6532706a61497aa32b70eddd8bcb3962_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415_0928e06e8a0fcfcb3c1ed05032772c53_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://08.imgmini.eastday.com/mobile/20180415/20180415_d57856f7e01bfa71ab29e0ee3145fa07_cover_mwpm_03200403.jpg"},{"uniquekey":"3f42a0b047d6ab4870eca9d18c5b1ecf","title":"无烧烤,不夏天!这些才是成都烧烤界的扛把子!","date":"2018-04-15 20:19","category":"头条","author_name":"成都生活圈","url":"http://mini.eastday.com/mobile/180415201933928.html","thumbnail_pic_s":"http://09.imgmini.eastday.com/mobile/20180415/20180415201933_ad77866ffc53dd21f26db58b0c7af8c2_28_mwpm_03200403.jpg","thumbnail_pic_s02":"http://09.imgmini.eastday.com/mobile/20180415/20180415201933_ad77866ffc53dd21f26db58b0c7af8c2_12_mwpm_03200403.jpg","thumbnail_pic_s03":"http://09.imgmini.eastday.com/mobile/20180415/20180415201933_ad77866ffc53dd21f26db58b0c7af8c2_66_mwpm_03200403.jpg"},{"uniquekey":"949c8738919d784b49c9ced4a426a14c","title":"林郑月娥:香港具备条件成为创科枢纽","date":"2018-04-15 20:18","category":"头条","author_name":"国际在线","url":"http://mini.eastday.com/mobile/180415201853732.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415201853_1a2a3e54aea6c551f4d2e617a7574fd4_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415201853_1a2a3e54aea6c551f4d2e617a7574fd4_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://08.imgmini.eastday.com/mobile/20180415/20180415201853_1a2a3e54aea6c551f4d2e617a7574fd4_3_mwpm_03200403.jpg"},{"uniquekey":"6e405694c1e5d4ee4c9bdcf36d7891c6","title":"澳大利亚将中国妖魔化企图没有成功,反而让更多的国家理解中国!","date":"2018-04-15 20:13","category":"头条","author_name":"环球新闻","url":"http://mini.eastday.com/mobile/180415201358006.html","thumbnail_pic_s":"http://04.imgmini.eastday.com/mobile/20180415/20180415201358_7174cd1b5a28c3bf37cf12719f935f61_3_mwpm_03200403.jpg","thumbnail_pic_s02":"http://04.imgmini.eastday.com/mobile/20180415/20180415201358_7174cd1b5a28c3bf37cf12719f935f61_2_mwpm_03200403.jpg"},{"uniquekey":"1932da294e569b5177b5013593a2b7d7","title":"第十二届河南投洽会邀海内外客商近两万人 突出国际性","date":"2018-04-15 20:12","category":"头条","author_name":"中国新闻网","url":"http://mini.eastday.com/mobile/180415201258277.html","thumbnail_pic_s":"http://07.imgmini.eastday.com/mobile/20180415/20180415201258_25ee36c89b0b8c28d55f373e3c4f0783_1_mwpm_03200403.jpg"},{"uniquekey":"1b1b2d050ed24ce7804fb19db5fec1bc","title":"第八届北京电影节开幕 红毯仪式星光熠熠","date":"2018-04-15 20:12","category":"头条","author_name":"中国新闻网","url":"http://mini.eastday.com/mobile/180415201257389.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415201257_5e767f1c848445b38a961be448891242_8_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415201257_5e767f1c848445b38a961be448891242_5_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415201257_5e767f1c848445b38a961be448891242_6_mwpm_03200403.jpg"},{"uniquekey":"86d60fe3db18a77f00d3f58f5fe6aa52","title":"u201c幼升小u201d公民同招,受u201c新中考u201d引导,今年校园开放日家长日趋理性","date":"2018-04-15 20:08","category":"头条","author_name":"解放网","url":"http://mini.eastday.com/mobile/180415200807125.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415200807_c093b191b7c42d8b61123396c93cc872_3_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415200807_c093b191b7c42d8b61123396c93cc872_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415200807_c093b191b7c42d8b61123396c93cc872_2_mwpm_03200403.jpg"},{"uniquekey":"f570d395e734c3a81a9c02cbbad5b36d","title":"安倍晋三隐忍多年,未能摆脱u201c绿帽子u201d头衔,如今终于决定离婚!","date":"2018-04-15 20:05","category":"头条","author_name":"战魂不息","url":"http://mini.eastday.com/mobile/180415200557521.html","thumbnail_pic_s":"http://09.imgmini.eastday.com/mobile/20180415/20180415_de26aaf0831973b0e0341f26b4aff3d4_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://09.imgmini.eastday.com/mobile/20180415/20180415_c9d9ea6863bb00bce5ae429236991b58_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://09.imgmini.eastday.com/mobile/20180415/20180415_54a1150e82fcd52b6e950ad3c8353794_cover_mwpm_03200403.jpg"},{"uniquekey":"99e3626c3f70b4b99c094be3613364cb","title":"金正恩在平壤会见中国艺术团团长宋涛","date":"2018-04-15 20:04","category":"头条","author_name":"央视网","url":"http://mini.eastday.com/mobile/180415200405028.html","thumbnail_pic_s":"http://01.imgmini.eastday.com/mobile/20180415/20180415200405_b738aea415821905d6a3165d74490caa_1_mwpm_03200403.jpg"},{"uniquekey":"65e0297026cbefe2a2a38d720393372d","title":"【中国梦·大国工匠篇】精益求精勤钻研,匠人精神塑楷模","date":"2018-04-15 20:03","category":"头条","author_name":"中国日报网","url":"http://mini.eastday.com/mobile/180415200354400.html","thumbnail_pic_s":"http://09.imgmini.eastday.com/mobile/20180415/20180415200354_d686eba1caaf4314de166fcfe22e1898_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://09.imgmini.eastday.com/mobile/20180415/20180415200354_d686eba1caaf4314de166fcfe22e1898_1_mwpm_03200403.jpg"}]} 
  5.     * error_code : 0 
  6.     */ 
  7.    private String reason; 
  8.    private ResultBean result; 
  9.    private int error_code; 
  10.    public String getReason() { 
  11.       return reason; 
  12.    } 
  13.    public void setReason(String reason) { 
  14.       this.reason = reason; 
  15.    } 
  16.    public ResultBean getResult() { 
  17.       return result; 
  18.    } 
  19.    public void setResult(ResultBean result) { 
  20.       this.result = result; 
  21.    } 
  22.    public int getError_code() { 
  23.       return error_code; 
  24.    } 
  25.    public void setError_code(int error_code) { 
  26.       this.error_code = error_code; 
  27.    } 
  28.    public static class ResultBean { 
  29.       /** 
  30.        * stat : 1 
  31.        * data : [{"uniquekey":"68388dafd210bd9e6e733f28f35d36d9","title":"不用去健身房的徒手健身14式!随时让你身体泵感飙升!","date":"2018-04-15 22:27","category":"头条","author_name":"极限肌汤","url":"http://mini.eastday.com/mobile/180415222744706.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_9_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_15_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_14_mwpm_03200403.jpg"},{"uniquekey":"c792b6c975915e0f353e1525d74361a2","title":"王毅同日本外相河野太郎举行会谈","date":"2018-04-15 22:06","category":"头条","author_name":"外交部新闻","url":"http://mini.eastday.com/mobile/180415220602296.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415220602_8c06c36f699b2cdb6e7fbcabe0980cb2_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415220602_8c06c36f699b2cdb6e7fbcabe0980cb2_2_mwpm_03200403.jpg"},{"uniquekey":"393182746325575e28816c7a52fcd891","title":"叙利亚遭美再轰炸证明弱小才会挨打?错了,是内部不团结才挨的打","date":"2018-04-15 21:58","category":"头条","author_name":"清风晓","url":"http://mini.eastday.com/mobile/180415215840462.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415_d00823627f77600d8294d9a8927b59dd_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415_454c1ef82a92a1c6ba787e763c275b89_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415_08123e1f126ec2b83ca5325ed7f0fb62_cover_mwpm_03200403.jpg"},{"uniquekey":"21a6ff821f95eb5b36783f68aeea103c","title":"今早发生飞机被劫持事件 你知道机长是如何用代码通知地面吗?","date":"2018-04-15 21:57","category":"头条","author_name":"1039航空在线","url":"http://mini.eastday.com/mobile/180415215736534.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415215736_9bea759e1382a2b897cbb9e40d8e37fd_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415215736_add9d74fe93e7e6c5b107aab523a6395_2_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415215736_680d3e100a59ae3aa6dee89cc8b39eac_3_mwpm_03200403.jpg"},{"uniquekey":"56fb7f21b478d88d29513f84f8b6ea67","title":"未经国内授权就发动对叙打击,英法领导人被批u201c跟在特朗普后面u201d","date":"2018-04-15 21:52","category":"头条","author_name":"观察者网","url":"http://mini.eastday.com/mobile/180415215211363.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415215211_05ec6bcc67f0f14bb72cb6f6fe4f5b9e_4_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415215211_05ec6bcc67f0f14bb72cb6f6fe4f5b9e_5_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415215211_05ec6bcc67f0f14bb72cb6f6fe4f5b9e_3_mwpm_03200403.jpg"},{"uniquekey":"6378cc37d7cd029989058172c115da59","title":"叙利亚被轰炸,海南被刷屏,该满仓还是空仓?","date":"2018-04-15 21:35","category":"头条","author_name":"澄泓财经","url":"http://mini.eastday.com/mobile/180415213527945.html","thumbnail_pic_s":"http://02.imgmini.eastday.com/mobile/20180415/20180415213527_456b2a35bbbe09f2a1e48d65556b591b_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://02.imgmini.eastday.com/mobile/20180415/20180415213527_456b2a35bbbe09f2a1e48d65556b591b_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://02.imgmini.eastday.com/mobile/20180415/20180415213527_456b2a35bbbe09f2a1e48d65556b591b_3_mwpm_03200403.jpg"},{"uniquekey":"610d5f5ae0b7649e55c2b9c4c376a49a","title":"湘雅医院45个口腔癌患者中,44人长期大量嚼槟榔","date":"2018-04-15 21:17","category":"头条","author_name":"澎湃新闻网","url":"http://mini.eastday.com/mobile/180415211747158.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415211747_bb6663066717047a755cf1dc406940e6_1_mwpm_03200403.jpg"},{"uniquekey":"9b264e90b08601075c184967360d11d0","title":"沙特和以色列关系逐步提升 伊朗:他们正进行联合犯罪","date":"2018-04-15 21:13","category":"头条","author_name":"中东研究通讯","url":"http://mini.eastday.com/mobile/180415211352158.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415211352_85311a103046811efbf4b604d63ff949_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415211352_85311a103046811efbf4b604d63ff949_4_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415211352_85311a103046811efbf4b604d63ff949_5_mwpm_03200403.jpg"},{"uniquekey":"931a6c79dd80e7c66c4f07e093f56bbd","title":"印度洋岛国毛里求斯的华人故事:盼与中国共发展","date":"2018-04-15 21:13","category":"头条","author_name":"中国新闻网","url":"http://mini.eastday.com/mobile/180415211349598.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415211349_0166b7c8152d1f8559d9440af2f0d7b3_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415211349_0166b7c8152d1f8559d9440af2f0d7b3_1_mwpm_03200403.jpg"},{"uniquekey":"9247330c735b0659b69c57b9575853fd","title":"男子在地里干活,发现自家坟墓出现一个洞,里面的景象让他傻了眼","date":"2018-04-15 21:02","category":"头条","author_name":"奇闻达人","url":"http://mini.eastday.com/mobile/180415210205138.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415_2f3e4f4f731ed25bb5326153f5e1f6df_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415_99ee412a06367ae94c45d5d0e7eec74e_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415_f8627d97c7d3f333233a9fa5762e43ff_cover_mwpm_03200403.jpg"},{"uniquekey":"bdc1efa1c2deff034f8e3cd8cd1d4a49","title":"瑜伽疗愈身心其实很简单 只需会呼吸就好","date":"2018-04-15 21:00","category":"头条","author_name":"瑜伽体式精讲","url":"http://mini.eastday.com/mobile/180415210010479.html","thumbnail_pic_s":"http://02.imgmini.eastday.com/mobile/20180415/20180415_dc6d0c014ca7a6590974ded3664f56f9_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://02.imgmini.eastday.com/mobile/20180415/20180415_98a99725b647080e302912d8895b8107_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://02.imgmini.eastday.com/mobile/20180415/20180415_6ff58e524feddd2983bd555008b9454b_cover_mwpm_03200403.jpg"},{"uniquekey":"d840acd294d7d3d7224f775b40a31f22","title":"马云说:2018年只要抓住这个行业 将会有大批人暴富 !","date":"2018-04-15 20:58","category":"头条","author_name":"星座的情感巫师","url":"http://mini.eastday.com/mobile/180415205834831.html","thumbnail_pic_s":"http://05.imgmini.eastday.com/mobile/20180415/20180415_5898b55ce7882d86bb3d5d5db9110296_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://05.imgmini.eastday.com/mobile/20180415/20180415_e0c5592edf6745d7bdbdc2bfa49eee61_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://05.imgmini.eastday.com/mobile/20180415/20180415_497e816851327038a86ffb15e2c4ac7d_cover_mwpm_03200403.jpg"},{"uniquekey":"3af2890c7503ecb5ac8d6e857baca49b","title":"如何推动东北高质量发展?专家:首先多提u201c新东北u201d概念","date":"2018-04-15 20:57","category":"头条","author_name":"澎湃新闻网","url":"http://mini.eastday.com/mobile/180415205719783.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415205719_e2ab1c506ddf063125e41dde1651db6d_1_mwpm_03200403.jpg"},{"uniquekey":"81c06482d6b62ebb89e24b902de05370","title":"戊戌年澳大利亚华人恭拜轩辕黄帝大典在悉尼举行","date":"2018-04-15 20:54","category":"头条","author_name":"人民网","url":"http://mini.eastday.com/mobile/180415205436408.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415205436_53b5c2ea3edef971d0e9edaf373b6875_5_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415205436_53b5c2ea3edef971d0e9edaf373b6875_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://08.imgmini.eastday.com/mobile/20180415/20180415205436_53b5c2ea3edef971d0e9edaf373b6875_4_mwpm_03200403.jpg"},{"uniquekey":"0f2e01526bc03873e14c7af24715f1c9","title":"南极下的雪越来越多,200年增加10%!然而这是大坏事的开始!","date":"2018-04-15 20:33","category":"头条","author_name":"中国气象爱好者","url":"http://mini.eastday.com/mobile/180415203300175.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415203300_eebd0303e57d1ffda38264ca0ad9527f_3_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415203300_eebd0303e57d1ffda38264ca0ad9527f_2_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415203300_eebd0303e57d1ffda38264ca0ad9527f_1_mwpm_03200403.jpg"},{"uniquekey":"c6d48e1ce2b07f411533f4c2e1ab336a","title":"把宪法精神融入公证实践","date":"2018-04-15 20:31","category":"头条","author_name":"法制网","url":"http://mini.eastday.com/mobile/180415203159176.html","thumbnail_pic_s":"http://03.imgmini.eastday.com/mobile/20180415/20180415203159_4586775d679b2a5b89662570e41bd0c0_1_mwpm_03200403.jpg"},{"uniquekey":"9a12e11575a3e258ed577e26c802bcdb","title":"解放军新条令释放红利:官兵节假日值班后安排补休","date":"2018-04-15 20:27","category":"头条","author_name":"环球网","url":"http://mini.eastday.com/mobile/180415202715963.html","thumbnail_pic_s":"http://02.imgmini.eastday.com/mobile/20180415/20180415202715_f7a7655284bcd56685b5b47808a3089c_1_mwpm_03200403.jpg"},{"uniquekey":"d8b3e71020284251c4e73956ccf684ae","title":"死者入土为安?印尼神秘村庄人死后十年依然吃饭洗澡,堪称活死人","date":"2018-04-15 20:26","category":"头条","author_name":"格林憋闷ss","url":"http://mini.eastday.com/mobile/180415202626177.html","thumbnail_pic_s":"http://04.imgmini.eastday.com/mobile/20180415/20180415202626_54722af09b478d592ad7301984a63444_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://04.imgmini.eastday.com/mobile/20180415/20180415202626_54722af09b478d592ad7301984a63444_3_mwpm_03200403.jpg","thumbnail_pic_s03":"http://04.imgmini.eastday.com/mobile/20180415/20180415202626_54722af09b478d592ad7301984a63444_2_mwpm_03200403.jpg"},{"uniquekey":"f3d228eecfd4793f166e79914ad92374","title":"想要丰胸和瘦臂却做不了俯卧撑?试试这六个动作吧!","date":"2018-04-15 20:25","category":"头条","author_name":"丰胸导师_晓雨","url":"http://mini.eastday.com/mobile/180415202535878.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415202535_a42e5527a457894d2a6f4f7db9625096_6_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415202535_a42e5527a457894d2a6f4f7db9625096_2_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415202535_a42e5527a457894d2a6f4f7db9625096_1_mwpm_03200403.jpg"},{"uniquekey":"8a909ff6fd43d4e092eabd5e5576cafe","title":"如何续写u201c来了就不想走u201d的海南故事? | 锐评","date":"2018-04-15 20:24","category":"头条","author_name":"人民日报","url":"http://mini.eastday.com/mobile/180415202409259.html","thumbnail_pic_s":"http://03.imgmini.eastday.com/mobile/20180415/20180415202409_db2bf6b3f75b110448a65f9d1bc83659_1_mwpm_03200403.jpg","thumbnail_pic_s02":"http://03.imgmini.eastday.com/mobile/20180415/20180415202409_db2bf6b3f75b110448a65f9d1bc83659_2_mwpm_03200403.jpg"},{"uniquekey":"86bb5027d938238d8606c6d1c1740e52","title":"70%成功拦截率 俄罗斯和美国到底谁在说谎?现实让该国打脸","date":"2018-04-15 20:20","category":"头条","author_name":"火线前沿","url":"http://mini.eastday.com/mobile/180415202013958.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415_6532706a61497aa32b70eddd8bcb3962_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415_0928e06e8a0fcfcb3c1ed05032772c53_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://08.imgmini.eastday.com/mobile/20180415/20180415_d57856f7e01bfa71ab29e0ee3145fa07_cover_mwpm_03200403.jpg"},{"uniquekey":"3f42a0b047d6ab4870eca9d18c5b1ecf","title":"无烧烤,不夏天!这些才是成都烧烤界的扛把子!","date":"2018-04-15 20:19","category":"头条","author_name":"成都生活圈","url":"http://mini.eastday.com/mobile/180415201933928.html","thumbnail_pic_s":"http://09.imgmini.eastday.com/mobile/20180415/20180415201933_ad77866ffc53dd21f26db58b0c7af8c2_28_mwpm_03200403.jpg","thumbnail_pic_s02":"http://09.imgmini.eastday.com/mobile/20180415/20180415201933_ad77866ffc53dd21f26db58b0c7af8c2_12_mwpm_03200403.jpg","thumbnail_pic_s03":"http://09.imgmini.eastday.com/mobile/20180415/20180415201933_ad77866ffc53dd21f26db58b0c7af8c2_66_mwpm_03200403.jpg"},{"uniquekey":"949c8738919d784b49c9ced4a426a14c","title":"林郑月娥:香港具备条件成为创科枢纽","date":"2018-04-15 20:18","category":"头条","author_name":"国际在线","url":"http://mini.eastday.com/mobile/180415201853732.html","thumbnail_pic_s":"http://08.imgmini.eastday.com/mobile/20180415/20180415201853_1a2a3e54aea6c551f4d2e617a7574fd4_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://08.imgmini.eastday.com/mobile/20180415/20180415201853_1a2a3e54aea6c551f4d2e617a7574fd4_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://08.imgmini.eastday.com/mobile/20180415/20180415201853_1a2a3e54aea6c551f4d2e617a7574fd4_3_mwpm_03200403.jpg"},{"uniquekey":"6e405694c1e5d4ee4c9bdcf36d7891c6","title":"澳大利亚将中国妖魔化企图没有成功,反而让更多的国家理解中国!","date":"2018-04-15 20:13","category":"头条","author_name":"环球新闻","url":"http://mini.eastday.com/mobile/180415201358006.html","thumbnail_pic_s":"http://04.imgmini.eastday.com/mobile/20180415/20180415201358_7174cd1b5a28c3bf37cf12719f935f61_3_mwpm_03200403.jpg","thumbnail_pic_s02":"http://04.imgmini.eastday.com/mobile/20180415/20180415201358_7174cd1b5a28c3bf37cf12719f935f61_2_mwpm_03200403.jpg"},{"uniquekey":"1932da294e569b5177b5013593a2b7d7","title":"第十二届河南投洽会邀海内外客商近两万人 突出国际性","date":"2018-04-15 20:12","category":"头条","author_name":"中国新闻网","url":"http://mini.eastday.com/mobile/180415201258277.html","thumbnail_pic_s":"http://07.imgmini.eastday.com/mobile/20180415/20180415201258_25ee36c89b0b8c28d55f373e3c4f0783_1_mwpm_03200403.jpg"},{"uniquekey":"1b1b2d050ed24ce7804fb19db5fec1bc","title":"第八届北京电影节开幕 红毯仪式星光熠熠","date":"2018-04-15 20:12","category":"头条","author_name":"中国新闻网","url":"http://mini.eastday.com/mobile/180415201257389.html","thumbnail_pic_s":"http://00.imgmini.eastday.com/mobile/20180415/20180415201257_5e767f1c848445b38a961be448891242_8_mwpm_03200403.jpg","thumbnail_pic_s02":"http://00.imgmini.eastday.com/mobile/20180415/20180415201257_5e767f1c848445b38a961be448891242_5_mwpm_03200403.jpg","thumbnail_pic_s03":"http://00.imgmini.eastday.com/mobile/20180415/20180415201257_5e767f1c848445b38a961be448891242_6_mwpm_03200403.jpg"},{"uniquekey":"86d60fe3db18a77f00d3f58f5fe6aa52","title":"u201c幼升小u201d公民同招,受u201c新中考u201d引导,今年校园开放日家长日趋理性","date":"2018-04-15 20:08","category":"头条","author_name":"解放网","url":"http://mini.eastday.com/mobile/180415200807125.html","thumbnail_pic_s":"http://06.imgmini.eastday.com/mobile/20180415/20180415200807_c093b191b7c42d8b61123396c93cc872_3_mwpm_03200403.jpg","thumbnail_pic_s02":"http://06.imgmini.eastday.com/mobile/20180415/20180415200807_c093b191b7c42d8b61123396c93cc872_1_mwpm_03200403.jpg","thumbnail_pic_s03":"http://06.imgmini.eastday.com/mobile/20180415/20180415200807_c093b191b7c42d8b61123396c93cc872_2_mwpm_03200403.jpg"},{"uniquekey":"f570d395e734c3a81a9c02cbbad5b36d","title":"安倍晋三隐忍多年,未能摆脱u201c绿帽子u201d头衔,如今终于决定离婚!","date":"2018-04-15 20:05","category":"头条","author_name":"战魂不息","url":"http://mini.eastday.com/mobile/180415200557521.html","thumbnail_pic_s":"http://09.imgmini.eastday.com/mobile/20180415/20180415_de26aaf0831973b0e0341f26b4aff3d4_cover_mwpm_03200403.jpg","thumbnail_pic_s02":"http://09.imgmini.eastday.com/mobile/20180415/20180415_c9d9ea6863bb00bce5ae429236991b58_cover_mwpm_03200403.jpg","thumbnail_pic_s03":"http://09.imgmini.eastday.com/mobile/20180415/20180415_54a1150e82fcd52b6e950ad3c8353794_cover_mwpm_03200403.jpg"},{"uniquekey":"99e3626c3f70b4b99c094be3613364cb","title":"金正恩在平壤会见中国艺术团团长宋涛","date":"2018-04-15 20:04","category":"头条","author_name":"央视网","url":"http://mini.eastday.com/mobile/180415200405028.html","thumbnail_pic_s":"http://01.imgmini.eastday.com/mobile/20180415/20180415200405_b738aea415821905d6a3165d74490caa_1_mwpm_03200403.jpg"},{"uniquekey":"65e0297026cbefe2a2a38d720393372d","title":"【中国梦·大国工匠篇】精益求精勤钻研,匠人精神塑楷模","date":"2018-04-15 20:03","category":"头条","author_name":"中国日报网","url":"http://mini.eastday.com/mobile/180415200354400.html","thumbnail_pic_s":"http://09.imgmini.eastday.com/mobile/20180415/20180415200354_d686eba1caaf4314de166fcfe22e1898_2_mwpm_03200403.jpg","thumbnail_pic_s02":"http://09.imgmini.eastday.com/mobile/20180415/20180415200354_d686eba1caaf4314de166fcfe22e1898_1_mwpm_03200403.jpg"}] 
  32.        */ 
  33.       private String stat; 
  34.       private List<DataBean> data; 
  35.       public String getStat() { 
  36.          return stat; 
  37.       } 
  38.       public void setStat(String stat) { 
  39.          this.stat = stat; 
  40.       } 
  41.       public List<DataBean> getData() { 
  42.          return data; 
  43.       } 
  44.       public void setData(List<DataBean> data) { 
  45.          this.data = data; 
  46.       } 
  47.       public static class DataBean { 
  48.          /** 
  49.           * uniquekey : 68388dafd210bd9e6e733f28f35d36d9 
  50.           * title : 不用去健身房的徒手健身14式!随时让你身体泵感飙升! 
  51.           * date : 2018-04-15 22:27 
  52.           * category : 头条 
  53.           * author_name : 极限肌汤 
  54.           * url : http://mini.eastday.com/mobile/180415222744706.html 
  55.           * thumbnail_pic_s : http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_9_mwpm_03200403.jpg 
  56.           * thumbnail_pic_s02 : http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_15_mwpm_03200403.jpg 
  57.           * thumbnail_pic_s03 : http://06.imgmini.eastday.com/mobile/20180415/20180415222744_1f0504d02a116dbd1c1b2e25c4038b5a_14_mwpm_03200403.jpg 
  58.           */ 
  59.          private String uniquekey; 
  60.          private String title; 
  61.          private String date
  62.          private String category; 
  63.          private String author_name; 
  64.          private String url; 
  65.          private String thumbnail_pic_s; 
  66.          private String thumbnail_pic_s02; 
  67.          private String thumbnail_pic_s03; 
  68.          public String getUniquekey() { 
  69.             return uniquekey; 
  70.          } 
  71.          public void setUniquekey(String uniquekey) { 
  72.             this.uniquekey = uniquekey; 
  73.          } 
  74.          public String getTitle() { 
  75.             return title; 
  76.          } 
  77.          public void setTitle(String title) { 
  78.             this.title = title; 
  79.          } 
  80.          public String getDate() { 
  81.             return date
  82.          } 
  83.          public void setDate(String date) { 
  84.             this.date = date
  85.          } 
  86.          public String getCategory() { 
  87.             return category; 
  88.          } 
  89.          public void setCategory(String category) { 
  90.             this.category = category; 
  91.          } 
  92.          public String getAuthor_name() { 
  93.             return author_name; 
  94.          } 
  95.          public void setAuthor_name(String author_name) { 
  96.             this.author_name = author_name; 
  97.          } 
  98.          public String getUrl() { 
  99.             return url; 
  100.          } 
  101.          public void setUrl(String url) { 
  102.             this.url = url; 
  103.          } 
  104.          public String getThumbnail_pic_s() { 
  105.             return thumbnail_pic_s; 
  106.          } 
  107.          public void setThumbnail_pic_s(String thumbnail_pic_s) { 
  108.             this.thumbnail_pic_s = thumbnail_pic_s; 
  109.          } 
  110.          public String getThumbnail_pic_s02() { 
  111.             return thumbnail_pic_s02; 
  112.          } 
  113.          public void setThumbnail_pic_s02(String thumbnail_pic_s02) { 
  114.             this.thumbnail_pic_s02 = thumbnail_pic_s02; 
  115.          } 
  116.          public String getThumbnail_pic_s03() { 
  117.             return thumbnail_pic_s03; 
  118.          } 
  119.          public void setThumbnail_pic_s03(String thumbnail_pic_s03) { 
  120.             this.thumbnail_pic_s03 = thumbnail_pic_s03; 
  121.          } 
  122.       } 
  123.    } 

② 定义网络监听回调接口

  1. public interface LoadTasksCallBack<T> { 
  2.    void onStart(); 
  3.    void onFinish(); 
  4.    void onSuccess(T t); 
  5.    void onFailed(); 

③ 定义获取网络数据的接口类

  1. public interface NetTask<T> { 
  2.     void execute(T data,LoadTasksCallBack callBack); 

④ 编写NetTask的实现类以获取数据

  1. public class IpInfoTask implements NetTask<String> { 
  2.    private IpInfoTask() { 
  3.    } 
  4.    public static IpInfoTask getInstance() { 
  5.       return SingletonHolder.sInstance; 
  6.    } 
  7.    private static class SingletonHolder { 
  8.       private static final IpInfoTask sInstance = new IpInfoTask(); 
  9.    } 
  10.    @Override 
  11.    public void execute(final String url, final LoadTasksCallBack callBack) { 
  12.       HttpRequest.get(url, new BaseHttpRequestCallback<TitleData>() { 
  13.          @Override 
  14.          public void onStart() { 
  15.             super.onStart(); 
  16.             callBack.onStart(); 
  17.          } 
  18.          @Override 
  19.          protected void onSuccess(TitleData ipInfo) { 
  20.             super.onSuccess(ipInfo); 
  21.             callBack.onSuccess(ipInfo); 
  22.          } 
  23.          @Override 
  24.          public void onFinish() { 
  25.             super.onFinish(); 
  26.             callBack.onFinish(); 
  27.          } 
  28.          @Override 
  29.          public void onFailure(int errorCode, String msg) { 
  30.             super.onFailure(errorCode, msg); 
  31.             callBack.onFailed(); 
  32.          } 
  33.       }); 
  34.    } 

说明:IpInfoTask是一个单例类,在execute方法中通过okhttpfinal获取数据,同时在okhttpfinal的回调函数中调用自己定义的回调函数loadTasksCallBack。

6.4 实现Presenter

① 定义契约接口IpInfoContract

  1. public interface IpInfoContract { 
  2.    interface Presenter { 
  3.       void getIpInfo(String url); 
  4.    } 
  5.    interface View extends BaseView<Presenter> { 
  6.       void setIpInfo(TitleData ipData); 
  7.       void showLoading(); 
  8.       void hideLoading(); 
  9.       void showError(); 
  10.       boolean isActivie(); 
  11.    } 

说明:

契约接口主要用来存放相同业务的Presenter和View的接口,便于查找和维护。

在此看到Presenter接口定义了获取数据的方法,而View定义了与界面交互的方法。其中,isActive方法用于判断Fragment是否添加到了Activity中。

另外:View接口继承自BaseView接口,BaseView接口的目的就是给View绑定Presenter:

  1. public interface BaseView<T> { 
  2.     void setPresenter(T presenter); 

② 实现Presenter接口:

  1. public class IpInfoPresenter implements IpInfoContract.Presenter, LoadTasksCallBack<IpInfo> { 
  2.    private NetTask mNetTask; 
  3.    private IpInfoContract.View mAddTaskView; 
  4.    public IpInfoPresenter(NetTask netTask, IpInfoContract.View addTaskView) { 
  5.       mNetTask = netTask; 
  6.       mAddTaskView = addTaskView; 
  7.    } 
  8.    @Override 
  9.    public void onStart() { 
  10.       if (mAddTaskView.isActivie()) { 
  11.          mAddTaskView.showLoading(); 
  12.       } 
  13.    } 
  14.    @Override 
  15.    public void onFinish() { 
  16.       if (mAddTaskView.isActivie()) { 
  17.          mAddTaskView.hideLoading(); 
  18.       } 
  19.    } 
  20.    @Override 
  21.    public void onSuccess(IpInfo ipInfo) { 
  22.       if (mAddTaskView.isActivie()) { 
  23.          mAddTaskView.setIpInfo(ipInfo); 
  24.       } 
  25.    } 
  26.    @Override 
  27.    public void onFailed() { 
  28.       if (mAddTaskView.isActivie()) { 
  29.          mAddTaskView.showError(); 
  30.          mAddTaskView.hideLoading(); 
  31.       } 
  32.    } 
  33.    @Override 
  34.    public void getIpInfo(String ip) { 
  35.       mNetTask.execute(ip, this); 
  36.    } 

说明:

IpInfoPresenter中含有NetTask和InfoContract.View的实例,并且实现了LoadTasksCallBack接口。

mNetTask.execute(ip, this)这句话用于获取数据并且回调给InInfoPresenter,回调给InInfoPresenter后通过mAddTaskView和页面进行交互,更改界面。

实质:

Presenter实际就是一个中间人,它通过NetTask(Model层)获取和保存数据,然后通过View更新界面。

期间通过定义接口使得View和Model没有任何交互。

6.5 实现View

  1. public class IpInfoFragment extends Fragment implements IpInfoContract.View { 
  2.    private Button mBt_ipinfo; 
  3.    private TextView mNews; 
  4.    private ProgressDialog mProgressDialog; 
  5.    private IpInfoContract.Presenter mPresenter; 
  6.    private static final String URL = "http://v.juhe.cn/toutiao/index?type=top&key=cc651913ae067cf88c7d9ec710fe5b3a"
  7.    public static IpInfoFragment newInstance() { 
  8.       return new IpInfoFragment(); 
  9.    } 
  10.    @Nullable 
  11.    @Override 
  12.    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 
  13.       View root = inflater.inflate(R.layout.fragment_ipinfo, container, false); 
  14.       mNews = (TextView) root.findViewById(R.id.tv_news); 
  15.       mBt_ipinfo = (Button) root.findViewById(R.id.bt_ipinfo); 
  16.       return root; 
  17.    } 
  18.    @Override 
  19.    public void onActivityCreated(@Nullable Bundle savedInstanceState) { 
  20.       super.onActivityCreated(savedInstanceState); 
  21.       mProgressDialog = new ProgressDialog(getActivity()); 
  22.       mProgressDialog.setTitle("获取数据中"); 
  23.       mBt_ipinfo.setOnClickListener(new View.OnClickListener() { 
  24.          @Override 
  25.          public void onClick(View v) { 
  26.             mPresenter.getIpInfo(URL); 
  27.          } 
  28.       }); 
  29.    } 
  30.    @Override 
  31.    public void setPresenter(IpInfoContract.Presenter presenter) { 
  32.       mPresenter = presenter; 
  33.    } 
  34.    @Override 
  35.    public void setIpInfo(TitleData ipInfo) { 
  36.       if (ipInfo != null && ipInfo.getResult().getData() != null) { 
  37.          List<TitleData.ResultBean.DataBean> data = ipInfo.getResult().getData(); 
  38.          mNews.setText(data.get(0).getTitle()); 
  39.       } 
  40.    } 
  41.    @Override 
  42.    public void showLoading() { 
  43.       mProgressDialog.show(); 
  44.    } 
  45.    @Override 
  46.    public void hideLoading() { 
  47.       if (mProgressDialog.isShowing()) { 
  48.          mProgressDialog.dismiss(); 
  49.       } 
  50.    } 
  51.    @Override 
  52.    public void showError() { 
  53.       Toast.makeText(getActivity(), "网络出错", Toast.LENGTH_SHORT).show(); 
  54.    } 
  55.    @Override 
  56.    public boolean isActivie() { 
  57.       return isAdded(); 
  58.    } 

说明:

  • setPresenter方法注入IpInfoPresenter。
  • getIpInfo方法获取ip地址的信息:也就是调用presenter。
  • fragment实现了view接口,用来接收IpinfoPresenter的回调并更新界面。

6.6 Activity中的setPresenter

把IpInfoTask(Model)和Fragment(View)注入到Presenter.

通过setPresenter将Presenter注入Fragment

  1. public class MainActivity extends AppCompatActivity { 
  2.    private IpInfoPresenter ipInfoPresenter; 
  3.    @Override 
  4.    protected void onCreate(Bundle savedInstanceState) { 
  5.       super.onCreate(savedInstanceState); 
  6.       setContentView(R.layout.activity_main); 
  7. // 把Fragment添加到Activity中 
  8.       IpInfoFragment ipInfoFragment = (IpInfoFragment) getSupportFragmentManager().findFragmentById(R.id.contentFrame); 
  9.       if (ipInfoFragment == null) { 
  10.          ipInfoFragment = IpInfoFragment.newInstance(); 
  11.          ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), ipInfoFragment, R.id.contentFrame); 
  12.       } 
  13. // 把Model和View注入Presenter,并且把Presenter注入Fragment 
  14.       IpInfoTask ipInfoTask = IpInfoTask.getInstance(); 
  15.       ipInfoPresenter = new IpInfoPresenter(ipInfoTask, ipInfoFragment); 
  16.       ipInfoFragment.setPresenter(ipInfoPresenter); 
  17.    } 
  18. public class ActivityUtils { 
  19.    public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) { 
  20.       FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
  21.       fragmentTransaction.add(frameId, fragment); 
  22.       fragmentTransaction.commit(); 
  23.    } 

6.6. 总结

  • View和Model之间没有联系。
  • View和Presenter通过接口进行交互。
  • 在Activity中Presenter和View相互注入。

看完不会写MVP架构我跪搓板

看完不会写MVP架构我跪搓板

看完不会写MVP架构我跪搓板

7. 下载地址(欢迎Star)

https://github.com/OnlyYouMyLove/MVP

【编辑推荐】

  1. 2018最新大厂Android面试真题
  2. 用 Kotlin 开发 Android 项目是一种什么样的感受(二)
  3. 用Kotlin开发Android项目是一种什么样的感受?
  4. iOS和Android之间还可以这样跨平台AR互动
  5. 传欧盟裁定Android存垄断行为 或开110亿美元天价罚单
【责任编辑:未丽燕 TEL:(010)68476606】

点赞 0
分享:
大家都在看
猜你喜欢

读 书 +更多

Web服务安全

Web服务技术是最近几年迅速兴起的一种应用集成技术,而安全问题是影响该技术广泛应用的一个关键因素。这个问题已成为最近几年来国内外研究...

订阅51CTO邮刊

点击这里查看样刊

订阅51CTO邮刊