最新消息:欢迎访问Android开发中文站!商务联系QQ:1304524325

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

开发进阶 loading 395浏览 0评论

为了月薪1.8万,我们要不断地学习和总结,今天给大家带来常见的android架构模式——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 添加依赖

compile 'cn.finalteam:okhttpfinal:2.0.7'

6.2 初始化okhttpfinal

public class App extends Application {
   @Override
   public void onCreate() {
      super.onCreate();
      OkHttpFinalConfiguration.Builder builder = new OkHttpFinalConfiguration.Builder();
      OkHttpFinal.getInstance().init(builder.build());
   }
}

6.3 实现Model ① 创建实体类TitleData:

public class TitleData {

   /**

    * reason : 成功的返回
    * 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"}]}
    * error_code : 0
    */

   private String reason;

   private ResultBean result;
   private int error_code;

   public String getReason() {

      return reason;
   }

   public void setReason(String reason) {

      this.reason = reason;
   }

   public ResultBean getResult() {

      return result;
   }

   public void setResult(ResultBean result) {

      this.result = result;
   }

   public int getError_code() {

      return error_code;
   }

   public void setError_code(int error_code) {

      this.error_code = error_code;
   }

   public static class ResultBean {

      /**
       * 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"}]
       */

      private String stat;

      private List<DataBean> data;

      public String getStat() {

         return stat;
      }

      public void setStat(String stat) {

         this.stat = stat;
      }

      public List<DataBean> getData() {

         return data;
      }

      public void setData(List<DataBean> data) {

         this.data = data;
      }

      public static class DataBean {

         /**
          * 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
          */

         private String uniquekey;

         private String title;
         private String date;
         private String category;
         private String author_name;
         private String url;
         private String thumbnail_pic_s;
         private String thumbnail_pic_s02;
         private String thumbnail_pic_s03;

         public String getUniquekey() {

            return uniquekey;
         }

         public void setUniquekey(String uniquekey) {

            this.uniquekey = uniquekey;
         }

         public String getTitle() {

            return title;
         }

         public void setTitle(String title) {

            this.title = title;
         }

         public String getDate() {

            return date;
         }

         public void setDate(String date) {

            this.date = date;
         }

         public String getCategory() {

            return category;
         }

         public void setCategory(String category) {

            this.category = category;
         }

         public String getAuthor_name() {

            return author_name;
         }

         public void setAuthor_name(String author_name) {

            this.author_name = author_name;
         }

         public String getUrl() {

            return url;
         }

         public void setUrl(String url) {

            this.url = url;
         }

         public String getThumbnail_pic_s() {

            return thumbnail_pic_s;
         }

         public void setThumbnail_pic_s(String thumbnail_pic_s) {

            this.thumbnail_pic_s = thumbnail_pic_s;
         }

         public String getThumbnail_pic_s02() {

            return thumbnail_pic_s02;
         }

         public void setThumbnail_pic_s02(String thumbnail_pic_s02) {

            this.thumbnail_pic_s02 = thumbnail_pic_s02;
         }

         public String getThumbnail_pic_s03() {

            return thumbnail_pic_s03;
         }

         public void setThumbnail_pic_s03(String thumbnail_pic_s03) {

            this.thumbnail_pic_s03 = thumbnail_pic_s03;
         }
      }
   }
}

② 定义网络监听回调接口


public interface LoadTasksCallBack<T> {

   void onStart();

   void onFinish();

   void onSuccess(T t);

   void onFailed();

}

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


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

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


public class IpInfoTask implements NetTask<String> {

   private IpInfoTask() {

   }

   public static IpInfoTask getInstance() {

      return SingletonHolder.sInstance;
   }

   private static class SingletonHolder {

      private static final IpInfoTask sInstance = new IpInfoTask();
   }

   @Override

   public void execute(final String url, final LoadTasksCallBack callBack) {

      HttpRequest.get(url, new BaseHttpRequestCallback<TitleData>() {

         @Override
         public void onStart() {
            super.onStart();
            callBack.onStart();
         }

         @Override

         protected void onSuccess(TitleData ipInfo) {
            super.onSuccess(ipInfo);
            callBack.onSuccess(ipInfo);
         }

         @Override

         public void onFinish() {
            super.onFinish();
            callBack.onFinish();
         }

         @Override

         public void onFailure(int errorCode, String msg) {
            super.onFailure(errorCode, msg);
            callBack.onFailed();
         }
      });
   }
}

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

6.4 实现Presenter ① 定义契约接口IpInfoContract


public interface IpInfoContract {
   interface Presenter {
      void getIpInfo(String url);
   }

   interface View extends BaseView<Presenter> {

      void setIpInfo(TitleData ipData);

      void showLoading();

      void hideLoading();

      void showError();

      boolean isActivie();

   }
}

说明:

  1. 契约接口主要用来存放相同业务的Presenter和View的接口,便于查找和维护。
  2. 在此看到Presenter接口定义了获取数据的方法,而View定义了与界面交互的方法。其中,isActive方法用于判断Fragment是否添加到了Activity中。
  3. 另外:View接口继承自BaseView接口,BaseView接口的目的就是给View绑定Presenter:
public interface BaseView<T> {
    void setPresenter(T presenter);
}

② 实现Presenter接口:

public class IpInfoPresenter implements IpInfoContract.Presenter, LoadTasksCallBack<IpInfo> {

   private NetTask mNetTask;

   private IpInfoContract.View mAddTaskView;

   public IpInfoPresenter(NetTask netTask, IpInfoContract.View addTaskView) {

      mNetTask = netTask;
      mAddTaskView = addTaskView;
   }

   @Override

   public void onStart() {
      if (mAddTaskView.isActivie()) {
         mAddTaskView.showLoading();
      }
   }

   @Override

   public void onFinish() {
      if (mAddTaskView.isActivie()) {
         mAddTaskView.hideLoading();
      }
   }

   @Override

   public void onSuccess(IpInfo ipInfo) {
      if (mAddTaskView.isActivie()) {
         mAddTaskView.setIpInfo(ipInfo);
      }
   }

   @Override

   public void onFailed() {
      if (mAddTaskView.isActivie()) {
         mAddTaskView.showError();
         mAddTaskView.hideLoading();
      }
   }

   @Override

   public void getIpInfo(String ip) {
      mNetTask.execute(ip, this);
   }
}

说明:

  1. IpInfoPresenter中含有NetTask和InfoContract.View的实例,并且实现了LoadTasksCallBack接口。
  2. mNetTask.execute(ip, this)这句话用于获取数据并且回调给InInfoPresenter,回调给InInfoPresenter后通过mAddTaskView和页面进行交互,更改界面。

实质:

  1. Presenter实际就是一个中间人,它通过NetTask(Model层)获取和保存数据,然后通过View更新界面。
  2. 期间通过定义接口使得View和Model没有任何交互。

6.5 实现View

public class IpInfoFragment extends Fragment implements IpInfoContract.View {

   private Button mBt_ipinfo;

   private TextView mNews;
   private ProgressDialog mProgressDialog;

   private IpInfoContract.Presenter mPresenter;

   private static final String URL = "http://v.juhe.cn/toutiao/index?type=top&key=cc651913ae067cf88c7d9ec710fe5b3a";

   public static IpInfoFragment newInstance() {

      return new IpInfoFragment();
   }

   @Nullable

   @Override
   public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      View root = inflater.inflate(R.layout.fragment_ipinfo, container, false);
      mNews = (TextView) root.findViewById(R.id.tv_news);
      mBt_ipinfo = (Button) root.findViewById(R.id.bt_ipinfo);
      return root;
   }

   @Override

   public void onActivityCreated(@Nullable Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
      mProgressDialog = new ProgressDialog(getActivity());
      mProgressDialog.setTitle("获取数据中");
      mBt_ipinfo.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            mPresenter.getIpInfo(URL);
         }
      });
   }

   @Override

   public void setPresenter(IpInfoContract.Presenter presenter) {
      mPresenter = presenter;
   }

   @Override

   public void setIpInfo(TitleData ipInfo) {
      if (ipInfo != null && ipInfo.getResult().getData() != null) {
         List<TitleData.ResultBean.DataBean> data = ipInfo.getResult().getData();
         mNews.setText(data.get(0).getTitle());
      }
   }

   @Override

   public void showLoading() {
      mProgressDialog.show();
   }

   @Override

   public void hideLoading() {
      if (mProgressDialog.isShowing()) {
         mProgressDialog.dismiss();
      }
   }

   @Override

   public void showError() {
      Toast.makeText(getActivity(), "网络出错", Toast.LENGTH_SHORT).show();
   }

   @Override

   public boolean isActivie() {
      return isAdded();
   }
}

说明:

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

6.6 Activity中的setPresenter

  1. 把IpInfoTask(Model)和Fragment(View)注入到Presenter.
  2. 通过setPresenter将Presenter注入Fragment

public class MainActivity extends AppCompatActivity {

   private IpInfoPresenter ipInfoPresenter;

   @Override

   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
// 把Fragment添加到Activity中
      IpInfoFragment ipInfoFragment = (IpInfoFragment) getSupportFragmentManager().findFragmentById(R.id.contentFrame);
      if (ipInfoFragment == null) {
         ipInfoFragment = IpInfoFragment.newInstance();
         ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), ipInfoFragment, R.id.contentFrame);
      }
// 把Model和View注入Presenter,并且把Presenter注入Fragment
      IpInfoTask ipInfoTask = IpInfoTask.getInstance();
      ipInfoPresenter = new IpInfoPresenter(ipInfoTask, ipInfoFragment);
      ipInfoFragment.setPresenter(ipInfoPresenter);
   }
}

public class ActivityUtils {
   public static void addFragmentToActivity(FragmentManager fragmentManager, Fragment fragment, int frameId) {
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
      fragmentTransaction.add(frameId, fragment);
      fragmentTransaction.commit();
   }
}

6.6. 总结

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

7. 下载地址(欢迎Star)

https://github.com/OnlyYouMyLove/MVP

8. 后续

如果大家喜欢这篇文章,欢迎点赞;如果想看更多前端移动端后端Java或Python方面的技术,欢迎关注!

转载请注明:Android开发中文站 » 看完不会写MVP架构我跪搓板

您必须 登录 才能发表评论!