爽翻天!告别Java。一起来使用kotlin开发完整客户端

 

必须写在前面:从Java转向Kotlin,只需要几天时间!

本篇是kotlin开发Android系列教程的最后一篇。前面几篇介绍了kotlin的基本语法、与java的不同之处等。在本篇文章中,将使用到前面的知识点,从零开发一款Gank.io 干活集中营App(感谢Gank提供的Api)。 该App完全使用了Kotlin语言开发,基于MVP模式,并使用如下主流开源框架:

除了以上主流库,还运用到了我的一个导航栏滑动隐藏库:

  • ByeBurger
    该项目地址为GankClient-Kotlin ,如果你想学习Kotlin,那么这个项目应该会给予你不少的帮助。

界面风格采用了MD风格,多数控件都是design包里的内容。主要实现了一个客户端该有的内容,界面交互,信息展示,数据获取等等。

笔者已经将Kotlin运用在项目开发2个月了,期间难免有一些坑,但是在坑之外,是他带给我的快感,从此以后。用Kotlin写代码相较于Java完全是一种享受。鉴于有些同学没有看前面的文章,这里再简单介绍一下Kotlin。

Kotlin是又一个基于JVM的语言,由JetBrains开发(你用的Android Studio就是他家的)。 如果你有java基础,那么他上手极其容易。

除了无缝调用java(所有java类、java库皆可不作任何处理的兼容)、一键将java转为Kotlin、空指针安全这些特性,还有许多比Java屌的特性。下面举一些栗子:

1.代码量对比( 参考使用Kotlin开发Android(一)):

Java

Kotlin


下面是扩展函数展示,参考使用Kotlin开发Android(二)

扩展函数简单来说,就是将某个类不通过继承动态扩展,来添加方法等,比如下面的toast就是扩展了Context类。

Java

Kotlin


POJO类(Java Bean对比)

java

kotlin (不要被吓到,确实这么短!!)


栗子完毕

相信看到上面的一些代码对比,大家心里已经比较清楚kotlin的特点了。相比java,代码少了至少三倍。这简直是大快人心!

开发完整App客户端

现在,假定你已经了解了Kotlin的基本用法,那么我将给你介绍这个客户端App的结构。

MVP

通过契约类Contract管理View Model Presenter接口(如果你项目写烦了MVP,那么安利下自动生成MVP代码的插件MVPHelper)。

  • Model — 主要处理业务,用于数据的获取(如网络、本地缓存)。
  • View — 用于把数据展示,并且提供交互。
  • Presenter — View和Model交互的桥梁,二者通过Presenter建立联系。

主要流程如下: 用户与View交互,View得知用户需要加载数据,告知Presenter,Presenter则告知Model,Model拿到数据反交于Prsenter,Presenter将数据交给View进行展示。

偷一张老图:


Dagger2

项目中,主要进行presenter、model、retrofit Api等类的注入操作。这里不做详细Dagger2用法解释,还不太会的同学可以先去拜读下大神的教程。Dagger2在Kotlin中使用有一些配置是不一样的,详细配置请看项目源码

ApiComponent

主Component、用于注入AppComponent、便于提供子Component依赖。

依赖于:

1.ApiModule(提供okhttpClient、Retrofit、Api等)

2.AppModule(提供context对象(okhttp拦截器所需))

FuckGoodsComponent

父Component为ApiComponent 用于注入FuckGoodsPresenter

依赖于: FuckGoodsModule(提供FuckGoodsView)

RandomComponent

父Component为ApiComponent 用于注入RandomPresenter

依赖于 : RandomModule(提供RandomView)


Rxjava + Retrofit + okhttp3

主要用于网络访问。这些都是主流的库,使用方式与java相同(当然除了语法以外)


DeepLinkDispatch

基于路由进行页面转发。可以解决多人多模块协作转跳的问题。

GankClientUri 定义一些路由规则、URI等

GankRouter 统一由此进行路由操作


GSON

用于json的解析操作。


Glide

用于图片的加载。


ByeBurGer

用于导航栏以及悬浮按钮滑动隐藏。


本客户端项目的地址:
https://github.com/githubwing/GankClient-Kotlin

开源本客户端的原因旨在让更多人了解Kotlin,接触Kotlin,从而使用Kotlin,实在是好东西不敢私藏。并且希望通过Kotlin能认识更多志同道合的朋友们,一起讨论技术共同进步。

如果该项目能帮助到你学习Kotlin,那是最好不过的事情了。欢迎star.

爽翻天!告别Java。一起来使用kotlin开发完整客户端》有88个想法

  1. [url=http://www.jacqueli.cybersite.nu/blogg?ibe=187074]www.jacqueli.cybersite.nu[/url] [url=http://alejandr.nation2.com/sverige-troja]alejandr.nation2.com[/url] [url=http://enriquet.blogfree.net/]enriquet.blogfree.net[/url] [url=http://www.professiondex.com/blogs/479/1034/manchester-united-troja-forklarat-att-han-inte-skulle]www.professiondex.com[/url]

  2. Pearls are mushy and easily broken, so they should at all times be stored in a comfortable
    back that is free of dust and other tiny particles that might scratch the fragile surface.
    Many other pure gem stones also ought to be stored in individual pouches to keep
    them safe from different stones and metals in your jewellery box.

  3. Nice post. I learn something new and challenging on websites I stumbleupon on a daily basis.
    It’s always useful to read content from other writers and use a little something
    from other web sites.

  4. Before you begin to search online for your style jewelry you must determine what kind of
    fashion jewelry you might be on the lookout for.
    Are you in search of designer items?

  5. India’s exports of cut and polished diamonds between April to November jumped by
    12.2 % from a year ago to $15.four billion, the
    Gems and Jewelry Export Promotion Council said last month.

  6. Middle Minoan period, in Greece, when rapid social adjustments took
    place, with palaces rising for the primary time, but also being
    destroyed and having to be rebuilt.

  7. This small silver-gilt bridal crown has six upright
    openwork elements of renaissance inspiration, joined collectively at
    the top by a hoop of silver-gilt wire, with utilized
    winged angel’s heads.

  8. I just want to mention I’m new to blogs and actually enjoyed your website. More than likely I’m want to bookmark your site . You absolutely come with very good articles. Appreciate it for sharing your web page.

  9. My spouse and i have been very thrilled that Jordan could carry out his inquiry using the ideas he received out of the blog. It’s not at all simplistic just to find yourself making a gift of tactics some others may have been making money from. We really fully understand we’ve got the website owner to thank for that. Those explanations you made, the easy blog navigation, the relationships you can aid to create – it’s got mostly excellent, and it’s letting our son and us imagine that that matter is enjoyable, which is particularly fundamental. Many thanks for the whole lot!

  10. I must point out my passion for your kind-heartedness giving support to men who really need guidance on this particular topic. Your very own dedication to passing the message all around had become rather helpful and have continuously enabled employees much like me to achieve their targets. Your personal warm and friendly useful information implies a great deal to me and additionally to my mates. Thanks a ton; from all of us.

  11. My wife and i got fulfilled Emmanuel managed to conclude his survey out of the ideas he made through your weblog. It is now and again perplexing just to possibly be giving away tips and tricks that many people today might have been making money from. Therefore we already know we have you to appreciate for that. All of the illustrations you’ve made, the straightforward web site menu, the friendships you can aid to instill – it’s got most remarkable, and it is aiding our son in addition to the family reason why this matter is thrilling, which is exceedingly mandatory. Many thanks for everything!

  12. Needed to draft you that little word just to give many thanks the moment again about the awesome tactics you’ve shared on this site. It is simply strangely generous of you to make unreservedly just what most of us would have supplied as an ebook in making some money for their own end, specifically now that you could have tried it if you decided. The tips likewise served to become a easy way to be sure that other people have the identical passion just as my personal own to learn more related to this issue. I think there are some more enjoyable instances up front for individuals that browse through your site.

  13. I simply wished to appreciate you again. I’m not certain the things that I would’ve used in the absence of the pointers shown by you concerning that situation. This has been a difficult issue for me personally, however , witnessing a well-written fashion you resolved it forced me to leap with happiness. I’m just thankful for this assistance and in addition hope that you realize what a great job you have been getting into educating many others all through a web site. More than likely you have never got to know any of us.

  14. My spouse and i felt absolutely ecstatic Raymond could deal with his survey while using the ideas he obtained while using the blog. It is now and again perplexing just to be giving away tips and hints which usually a number of people may have been trying to sell. So we do know we have got the website owner to thank for that. All the explanations you made, the simple site navigation, the relationships you make it easier to create – it is all incredible, and it is leading our son in addition to our family feel that the subject is excellent, and that is quite essential. Thank you for the whole thing!

  15. I just wish to advise you that I am new to writing a blog and thoroughly loved your website. Likely I am going to remember your blog post . You indeed have extraordinary article content. Value it for sharing with us your current domain document

  16. I simply have to show you that I am new to wordpress blogging and totally loved your information. Very possible I am prone to bookmark your blog post . You indeed have lovely article content. Acknowledge it for share-out with us your own internet report

  17. The URL is needed to figure out the security zone, which is needed to ascertain the condition of the ActiveScripting setting. Completely ad-free, this website is quite easy to navigate and enables you to locate what you need fast. It’s a website that will permit you to really observe plenty of svg files created by very talented people at an affordable price. Everyone can join and add to the undertaking. This facility is known as SVG fonts.

  18. I enjoy you because of all of your hard work on this website. My niece takes pleasure in doing investigations and it is easy to understand why. Many of us hear all relating to the powerful means you provide sensible thoughts on this web blog and in addition welcome participation from other people on the content and our child is without a doubt understanding a whole lot. Enjoy the remaining portion of the year. You are performing a glorious job.

  19. I have been surfing on-line more than 3 hours as of late, yet I by no means discovered any attention-grabbing article like yours. It is lovely value enough for me. In my opinion, if all site owners and bloggers made just right content material as you did, the web will likely be a lot more useful than ever before.

  20. Hi here, just became familiar with your weblog through Search engines like google, and discovered that it’s truly informative. I will be grateful should you continue on this post.

  21. Needed to draft you this tiny observation to say thanks over again regarding the pleasant techniques you’ve discussed in this article. It’s so shockingly open-handed of you to present unreservedly what exactly numerous people would have supplied as an electronic book to generate some bucks on their own, primarily considering that you might have tried it if you ever considered necessary. Those advice additionally acted as the fantastic way to fully grasp that some people have the same fervor like my own to find out whole lot more with respect to this matter. I’m certain there are some more pleasant sessions ahead for those who scan your website.

  22. You actually make it appear really easy along with your presentation but I to find this topic to be really something which I think I’d never understand. It sort of feels too complex and extremely wide for me. I am having a look forward for your next post, I will try to get the hold of it!

  23. I enjoy you because of your entire hard work on this site. My niece really loves doing investigations and it’s simple to grasp why. We all hear all concerning the compelling means you provide advantageous tricks via this web blog and as well strongly encourage response from others about this area of interest while our own girl is in fact studying so much. Take pleasure in the rest of the year. Your performing a dazzling job.

  24. I wish to show my passion for your kindness giving support to men who really want guidance on this important situation. Your special dedication to getting the message around came to be extremely good and have continually permitted men and women much like me to get to their targets. Your personal interesting hints and tips means much to me and substantially more to my fellow workers. Regards; from all of us.

  25. I really need to inform you you that I am new to writing a blog and completely adored your work. Quite possibly I am going to save your blog post . You undoubtedly have excellent article blog posts. Love it for expressing with us your own website post

  26. I just intend to inform you you that I am new to online blogging and totally enjoyed your information. Most likely I am going to save your blog post . You absolutely have superb article information. Truly Appreciate it for telling with us your very own internet site information

  27. It is usually perfect time to prepare some options for the possible future. I’ve browsed this article and if I have the ability to, I want to suggest you couple of appealing tip.

  28. I and my pals were going through the best helpful tips found on the blog and so immediately I got a terrible suspicion I never thanked the website owner for those tips. Most of the men are already for that reason warmed to read all of them and now have very much been having fun with them. We appreciate you truly being so thoughtful as well as for opting for such remarkable tips millions of individuals are really eager to be informed on. My honest apologies for not expressing appreciation to earlier.

  29. Thanks for all of your work on this blog. My daughter enjoys working on internet research and it’s easy to see why. My partner and i know all regarding the compelling form you make both interesting and useful guides through your web site and in addition cause contribution from the others on this theme and my simple princess is without question becoming educated a whole lot. Have fun with the remaining portion of the year. You’re carrying out a great job.

  30. I wish to show thanks to you just for bailing me out of this type of incident. Because of looking out throughout the world-wide-web and meeting proposals which were not productive, I figured my entire life was over. Existing minus the solutions to the issues you have resolved all through your entire article is a crucial case, and those that could have negatively damaged my entire career if I hadn’t discovered your web page. The understanding and kindness in maneuvering all things was crucial. I’m not sure what I would’ve done if I had not encountered such a stuff like this. I am able to at this moment look forward to my future. Thanks for your time so much for your specialized and result oriented help. I won’t hesitate to recommend your site to anybody who would like recommendations on this matter.

  31. Hey just wanted to give you a quick heads up and let you know a few
    of the images aren’t loading properly. I’m not sure why but I think its a linking issue.

    I’ve tried it in two different internet browsers and
    both show the same results.
    fotballdrakter

  32. I must convey my gratitude for your kindness giving support to those who really want assistance with this situation. Your very own dedication to getting the message along turned out to be remarkably advantageous and have continuously encouraged women much like me to realize their pursuits. Your own warm and friendly tutorial can mean a great deal to me and much more to my colleagues. Warm regards; from all of us.

  33. Thank you so much for providing individuals with such a superb possiblity to read in detail from this site. It really is so terrific and also full of a good time for me and my office mates to visit your website at the very least 3 times a week to read through the latest tips you will have. And of course, we’re actually satisfied with the exceptional knowledge you serve. Certain 2 areas on this page are honestly the finest I’ve had.

  34. To attempt a successaful home poker tournament you desire a poker
    table orr other suitable playing surface, soje quality playing cards, poker
    chips, ssome sort of blinds timer, wheen a plan. Sure you can starrt to play on the floor wth some cheap cards and pennies, but
    objective here ended up being to make this an enjoyable game.

    When looking to buy a table saw, the rip fence is definitely the waqys to look.
    The fence should be onstantly parallel to the blade.
    The table saw must be equipped with controls to
    fine tune the fence adjustments. Bigger best table saw are created with Biesemeyer fence for sturdily yet
    smoothly ripping large wood pieces go for walks . also allows a feather board or sacrificial
    strip to bee secured int the fence.

    The rolling tables are easy to keep at home, as they occupy
    very little space. These tables maay apso be kept beside cargo area.

    You could go foor that portasble laptop tables.
    Product have been perfect space savers along with intensely comfortable maske
    use of. A best portable table saw is a small wooden urface that is sufffering
    from a cushiokn bzse under this particular. The slightly tilted wooden surface
    supports the laptop very perfectly. It is just the thing for using against your own lapp while at house hold.
    You can use the handle on side aand easily carrying it from one room to an alternative.

    The Ryobi BTS10S table saw is along with a 13-amp motor.
    It may well provide a maximum no-load speed off 4,800
    Revolutions per minute. The saw also has a oft start benefit.
    This wwill help reduce the possibility off yyou tripping a circuit breaker.

    A table saw iss for you tto bee one of thee many most versatile
    tools in a shop review is why users ought to able find
    out which ones are the best. Table saws which have a good quality
    will be given the chance to increase the speed the associated with completing different woodworks from
    a shorter period of time. This can bee a fact muych more preseented
    to all biig table saw. Portable saws are alsao lighter rather than the stationary ones, making
    them easier to hae around, especially to internet sites where are usually needed.

    The purposes of them range from rough cutting lumber tto moldings.
    Many complex joinery tecniques can be accomplished these kind of tools, provided the user is familiar
    with the machine.

    The next level of saws in the audience would emerge as contractor’s
    saws. Many are obtainable with stands that fold and are fitted
    with wheels to make them very light-weight. They are generally larger than those in former group, have a more powerful motor, also having
    the next stae of beneficial quality. They are primarily designed in the package on job sites, by carpenteres and contractors.

  35. It’s the best time to make a few plans for the longer term and it’s
    time to be happy. I’ve read this publish and if I could I desire to
    counsel you few attention-grabbing things
    or advice. Perhaps you can write subsequent articles relating to this article.
    I want to read even more issues about it!

  36. When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each
    time a comment is added I get four e-mails with the same comment.

    Is there any way you can remove me from that service? Bless you!

  37. I’ve been surfing online greater than three hours lately, but I by no means discovered any fascinating article like yours. It is lovely price sufficient for me. Personally, if all website owners and bloggers made excellent content material as you probably did, the web can be a lot more helpful than ever before.

  38. I will right away seize your rss feed as I can’t in finding your email subscription hyperlink or e-newsletter service. Do you’ve any? Kindly let me recognise in order that I may subscribe. Thanks.

  39. You really make it seem so easy with your presentation but I find this matter to be really something that I think I would never understand.

    It seems too complex and very broad for me. I’m looking forward for your next
    post, I’ll try to get the hang of it!

  40. What’s up i am kavin, its my first occasion to commenting
    anyplace, when i read this piece of writing i thought i could also
    make comment due to this sensible paragraph.

  41. Howdy! I realize this is somewhat off-topic however I needed to ask.
    Does running a well-established website such as yours take a large amount of work?
    I’m brand new to blogging but I do write in my journal everyday.
    I’d like to start a blog so I can share my own experience and feelings online.
    Please let me know if you have any kind of
    ideas or tips for brand new aspiring blog owners. Appreciate it!

  42. My spouse and i ended up being so thrilled Louis could do his analysis while using the precious recommendations he was given from your own web site. It is now and again perplexing to simply continually be releasing steps which some others may have been trying to sell. And we also discover we’ve got the blog owner to appreciate for that. All the illustrations you made, the easy web site menu, the friendships you aid to engender – it’s everything terrific, and it’s making our son in addition to us understand that situation is pleasurable, which is extraordinarily mandatory. Many thanks for everything!

  43. Good site! I really love how it is simple on my eyes and the data are well written. I am wondering how I could be notified whenever a new post has been made. I’ve subscribed to your RSS feed which must do the trick! Have a great day!

  44. Having read this I thought it was rather enlightening.
    I appreciate you finding the time and energy to put
    this article together. I once again find myself spending way too much time both
    reading and commenting. But so what, it was still worth it!

  45. Hey there! This is kind of off topic but I need some guidance from an established blog.
    Is it difficult to set up your own blog? I’m not very techincal but I can figure
    things out pretty quick. I’m thinking about setting up my own but I’m not sure where to start.
    Do you have any points or suggestions? Thanks

  46. Great paintings! This is the type of info that should be shared around the web. Shame on the seek engines for not positioning this publish upper! Come on over and visit my site . Thanks =)

  47. It¡¦s in point of fact a great and useful piece of information. I¡¦m happy that you simply shared this helpful information with us. Please keep us informed like this. Thank you for sharing.

  48. ナースさんに人気の富山の病院ってどの病院?自分に見合う医院を見つけよう!転職を検討している方は、富山県のナースの転職事情について確認しておきましょう。トレーニングが充実している職場が多いので、未経験やブランクがある方も安心して入職出来るエリアと言えるでしょう。|
    富山県ではナースの募集案件が多くなっており、すぐに看護師の医療機関を見つけられるという魅力があります。スピーディーな転職を希望している方も、富山県なら希望を叶える事が出来るでしょう。また、今までとは異なる職種や科目で働きたいと考える方も多いと思いますが、練習体制を充実させているクリニックが多いので、未経験でも安心して新しい環境で働けるようになると思います

  49. ทุกๆคนในที่สนามฟุตบอลบาเซโลน่าได้กล่าวว่า linefifa
    นั้นดีมาก มี บอลสด ให้ดูเยอะมาก สามารถดูได้ที่เว็บ linefifa.com ดานิเอล่า ชาเวซ นางแบบสาวสุดเอ็กซ์ ชาวชิลี เปิดใจกับ Reforma หนังสือพิมพ์เม็กซิโก โดยอ้างว่า เธอเคยทำสงครามบนเตียงกับ คริสเตียโน่ โรนัลโด้
    แข้งซูเปอร์สตาร์เรอัล มาดริด เมื่อช่วงเดือนพฤศจิกายนปีที่แล้ว ทั้งที่ช่วงนั้น อิริน่า เชค นางแบบชาวรัสเซีย ยังคบหากับ โรนัลโด้ อยู่ด้วย
    “ฉันเจอ คริสเตียโน่ เมื่อเดือนพฤศจิกายน ปี 2014 ที่สหรัฐอเมริกา เราติดต่อพูดคุยกันผ่านทางอีเมล และ สไกป์ ตอนนั้นฉันต้องไปทำงานที่นั้น และจะต้องอยู่ที่สหรัฐฯ 2-3 วัน” “คริสเตียโน่ เป็นคนขี้อายมากๆ ในตอนแรก แต่เมื่อเขามีความมั่นใจแล้ว เขาทำให้ฉันรู้สึกกลัว และเขาก็รักฉัน แต่เขาไม่แสดงออกมาให้ใครรู้” linefifa มี ลิ้งดูบอล เยอะมากว่าทุกที่มีบอลให้ดูทุกคู่ “ฉันแค่อยากจะเป็นคนที่มาเติมเต็มความฝันและมีเซ็กซ์กับเขาฉันหลงใหลในร่างกายของโรนัลโด้ความจริงก็คือ ใบหน้าของฉัน และหน้าอกของฉัน มันไม่เคยหลับ เมื่อได้พบกับคู่หูของฉันเลย” เมื่อไม่นานมานี้ อิริน่า เชค เพิ่งเปิดใจถึงสาเหตุที่ต้องเลิกรากับ โรนัลโด้ เนื่องจากพบหลักฐานในโทรศัพท์มือถือของอดีตแข้งแมนฯ ยูฯ ที่แอบนอกใจเธอและมีกิ๊กมากมายหลายคน ขณะเดียวกัน เดอะซัน สื่อจอมแฉเมืองผู้ดี เชื่อว่า โรนัลโด้ แอบนอกใจ
    อิริน่า เชค หลายสิบครั้ง จนสุดท้ายแล้วนางแบบชาวรัสเซียต้องเป็นฝ่ายขอแยกทาง ยุติความสัมพันธ์หลังจากคบหาดูใจและดูทุกสิ่งทุกอย่างกันมานานถึง
    5 ปีภาพจาก : http://www.dailymail.co.uk linefifa มี บอลสด
    ให้ดูทุกคู่ แนะนำเลย ลิ้งดูบอล ดูบอลสด

  50. fast and furious 8 film completo
    http://fastandfurious8streaming.com/fastandfurious8filmcompleto/

    ast & furious 8 streaming ita,fast & furious 8 streaming vf,fast e furious
    8 streaming,fast and furious 8 streaming film senza limiti,fast and furious 8 streaming nowvideo,fast and
    furious 8 streaming altadefinizione,fast and furious 8 streaming ita
    gratis,fast and furious 8 streaming ita nowvideo,fast and furious 8 streaming ita
    film senza limiti,fast and furious 8 streaming film completo,fast and furious 8 streaming ita,fast and furious 8 streaming cineblog01,fast
    and furious 8 streaming italiano,fast and furious 8 streaming vk,
    fast and furious 8 streaming bande annonce,fast and furious 8 streaming ita cineblog01,
    fast and furious 8 film completo italiano streaming,fast furious 8 streaming ita,fast furious
    8 streaming altadefinizione,fast furious 8 streaming cineblog01,fast furious
    8 streaming cb01,fast furious 8 streaming ita alta definizione,

发表评论

电子邮件地址不会被公开。