<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Danny Lamarti on Medium]]></title>
        <description><![CDATA[Stories by Danny Lamarti on Medium]]></description>
        <link>https://medium.com/@lamartio?source=rss-b91c72b5380d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gYPpITKdx7iAZU9V.</url>
            <title>Stories by Danny Lamarti on Medium</title>
            <link>https://medium.com/@lamartio?source=rss-b91c72b5380d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 09:21:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lamartio/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Kotlin’s simple layout trick (part 2)]]></title>
            <link>https://medium.com/@lamartio/kotlins-simple-layout-trick-part-2-def94a434d9a?source=rss-b91c72b5380d------2</link>
            <guid isPermaLink="false">https://medium.com/p/def94a434d9a</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-data-binding]]></category>
            <category><![CDATA[data-binding]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[layout]]></category>
            <dc:creator><![CDATA[Danny Lamarti]]></dc:creator>
            <pubDate>Mon, 24 Sep 2018 08:47:31 GMT</pubDate>
            <atom:updated>2018-09-24T08:49:59.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NhR9qUGjYwy1A2dq" /><figcaption>“white and blue Sato chart” by <a href="https://unsplash.com/@gtomassetti?utm_source=medium&amp;utm_medium=referral">Giorgio Tomassetti</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the <a href="https://medium.com/@lamartio/kotlins-simple-layout-trick-65cabb0deb26">previous post</a> I described how we can create layouts in code that look the same as XML. Yet in XML we have the option to add data binding directives that will update our layouts whenever our data changes. In this article we will extend the Layout DSL with a function that will grant us the data binding we know from XML.</p><p>This example will have a User data class with a name and age property. As a data source, the User will be emitted and with every second the age of the user will increment. For this example Rx is used for creating a data source, but this could easily have been LiveData or even plain old callbacks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a91d3ae19e6403c35453b8c56d8afc15/href">https://medium.com/media/a91d3ae19e6403c35453b8c56d8afc15/href</a></iframe><p>Within the layout, the User will be received in the callback passed into the bind method. There the User is accessible either through the argument or as the this pointer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a78ec9ad6b9d76c8cfdf09b0e682826/href">https://medium.com/media/4a78ec9ad6b9d76c8cfdf09b0e682826/href</a></iframe><p>After defining the way the bind function should behave, the implementation must follow. Let’s extends the Layout class from previous article and add the bind method. Whenever the method is called, its argument will be added to a list of observers. These observers will later be added to the data source.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/155433773970a84c4babd77983fb6c04/href">https://medium.com/media/155433773970a84c4babd77983fb6c04/href</a></iframe><p>The technique is of data binding is essentially the Observer pattern. This pattern learned us that whenever a listener is registered, it must unregister to prevent memory leaks.</p><p>In Android the Activity and Fragment lifecycle is used for registering and unregistering, but in Views there is no such thing. Instead the OnAttachStateChanged listener is used.</p><p>The word attach and detach refers state where the View is attached to the screen and detached from the screen. This attaching and detaching is a good replacement for, for instance, the onStart and onStop methods that are used for lifecycle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b8065c9807d62987e7adff5e44ef437/href">https://medium.com/media/5b8065c9807d62987e7adff5e44ef437/href</a></iframe><p>Let’s recap what is accomplished in this article:</p><ul><li>Defined sample data</li><li>Defined data source</li><li>Defined the bind method</li><li>Implemented the bind method</li><li>Used the lifecycle of a View to register and unregister</li></ul><p>These steps result in the example shown below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bb9e54b14da50725a5fbda2d9bea967/href">https://medium.com/media/4bb9e54b14da50725a5fbda2d9bea967/href</a></iframe><p>Some technical details are skipped in this article, but the general way of data binding is properly implemented here. If you have any tips or questions or you just want to see the source, please refer to the <a href="https://github.com/Lamartio/Kotlin-s-simple-layout-trick">github repositiory</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=def94a434d9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin's simple layout trick (part 1)]]></title>
            <link>https://medium.com/@lamartio/kotlins-simple-layout-trick-65cabb0deb26?source=rss-b91c72b5380d------2</link>
            <guid isPermaLink="false">https://medium.com/p/65cabb0deb26</guid>
            <category><![CDATA[layout]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-layout]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Danny Lamarti]]></dc:creator>
            <pubDate>Mon, 10 Sep 2018 12:56:18 GMT</pubDate>
            <atom:updated>2018-09-24T08:48:04.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mRqRZKNTMoxo7l7g" /><figcaption>“turned on Android smartphone” by <a href="https://unsplash.com/@pathum_danthanarayana?utm_source=medium&amp;utm_medium=referral">Pathum Danthanarayana</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When developing Android applications, I create my layouts in XML. Despite the preview mode there is not much that I like about it: All the properties are prefixed with android:(which doesn&#39;t promote readability), the files are lengthy and… it is not code!</p><p>When moving from XML to Kotlin, the first thing we can apply is Anko Layouts: A fast and type-safe way to write dynamic Android layouts. Although this is a great alternative for XML, it has some drawbacks:</p><ul><li>It is hard to extent.</li><li>It does not distinguish between creating a view and adding it to the layout.</li><li>It is a complex library for the simple thing we want to achieve.</li></ul><p>This sounds negative, but there is a lot to love about Anko Layouts and actually the whole Anko family. So don&#39;t feel discouraged in using it. Yet having a library for everything quickly enlarges your APK size and leaves you, the developer, without knowledge and control.</p><p>Enough introduction, let&#39;s write some code! The first achievement we will be creating is a layout and we will add some views to it through code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/457731fd5ee2aecc100b6985ab6556ef/href">https://medium.com/media/457731fd5ee2aecc100b6985ab6556ef/href</a></iframe><p>Within this code there are some things that could be prettier:</p><ol><li>The addviewmethod is trivial.</li><li>Same for the apply function</li><li>Within the LinearLayout, creating children should be easier.</li></ol><p>We only want this functionality for a Viewgroup so we will create a DSL for it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/daca2e08ce4ae6cbfc07b20d7c08e109/href">https://medium.com/media/daca2e08ce4ae6cbfc07b20d7c08e109/href</a></iframe><p>Within the layout class we can add the utility we need. Lets start with replacing the addView method with a unaryPlus operator function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69a0ee802811a296fd34d71e2b6d922d/href">https://medium.com/media/69a0ee802811a296fd34d71e2b6d922d/href</a></iframe><p>Next we want to avoid to call apply every time to we need to initialize the child view.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd5b410beb0299c58db90d0321306391/href">https://medium.com/media/dd5b410beb0299c58db90d0321306391/href</a></iframe><p>Our last point is adding utility for quickly creating new views. This can be accomplished by creating extension properties.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9658c42d73ebe023d1b248a351339350/href">https://medium.com/media/9658c42d73ebe023d1b248a351339350/href</a></iframe><p>Thats it! In about 20 lines of code we created a Kotlin DSL that simplifies the layout creation and grants us access to all the goodness Kotlin is supplying. If you liked this article, please give it some claps. If you have any tips or questions, please file an issue on the repo: <a href="https://github.com/Lamartio/Kotlin-s-simple-layout-trick">https://github.com/Lamartio/Kotlin-s-simple-layout-trick</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65cabb0deb26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KotlinConf 2017]]></title>
            <link>https://medium.com/elements/kotlinconf-2017-d93df16bc5e3?source=rss-b91c72b5380d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d93df16bc5e3</guid>
            <category><![CDATA[jetbrains]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Danny Lamarti]]></dc:creator>
            <pubDate>Thu, 30 Nov 2017 00:00:00 GMT</pubDate>
            <atom:updated>2018-05-16T15:47:56.781Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://kotlinlang.org/">Kotlin</a> boasts to be the new, pragmatic language that will boost our productivity. Not only on Android, but on all popular platforms! Is it just a hype? Is it too good to be true? Or is it really that good? Let’s find out on the debut conference of Kotlin, held early November in the beautiful city of San Francisco.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAZctXtggs7LGnW3v6vlqw.jpeg" /></figure><p>In the morning developers from all over the world gathered at Pier 27 to witness the first <a href="https://www.kotlinconf.com/">Kotlin conference</a>. After grabbing our tickets, we headed to the opening talk given by the developers of the language themselves. The lead language designer, <a href="https://twitter.com/abreslav?lang=en">Andrey Breslav</a>, showed us how it is possible to build a language that support multiple platforms: Kotlin itself is merely a syntax that is compiled to platform-specific language. For Android it gets compiled to JVM bytecode, for the browser it gets compiled to JavaScript and for iOS it gets compiled to native binaries.</p><p>Wait, iOS? Yes! The engineers at <a href="https://www.jetbrains.com/">JetBrains</a> are working hard to make Kotlin fully available on iOS! In fact there are already two Kotlin apps available for Android and iOS. Even better; they share the same codebase. Be sure to check it out on <a href="https://github.com/JetBrains?q=kotlinconf">their Github page</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*AKPxU_nTf51TVK7UaCXo9g.png" /></figure><p>Not only the client side is well supported this great new language. Thanks to the interoperability with the JVM, Java based server technologies automagically gain the power of Kotlin. In Josh Long’s <a href="https://youtu.be/naUSEu79d4Y">live demo</a>, we learned how simple it is to build a Spring server based on Kotlin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-JPu6IVI2xb3vG6Kq_twKg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hZvjsfUR-Zc2uyww6rcjzA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9_qK50EpWwxiqzESKI95yQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oj2ttIUwsmLDv-s9Ks2wsA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vvswKjlt_0-Oce5CLaoWsQ.jpeg" /></figure><p>So web front-end, mobile and even server-side applications can be developed through Kotlin. Is there more? Yes there is! The CEO of <a href="https://gradle.com/">Gradle</a>, <a href="https://twitter.com/hans_d?lang=en">Hans Dockter</a>, showed how Gradle benefits of Kotlin. To me, Gradle is a black box that starts when I click the build button and ends when it deploys an app on my device. Thanks to the <a href="https://kotlinlang.org/docs/reference/using-gradle.html">Kotlin plugin</a>, this box gets opened by supplying a DSL that enables code hint and documentation for Gradle.</p><p>Conclusion: Kotlin is here to stay. It is based on languages and features developers already know and like and it is rapidly evolving to a language we can use on many platforms. The community is enthusiastic and two magnificent tech companies, JetBrains and Google, are pushing the language to a scale no other language has ever been.</p><p>Many thanks to Elements for offering the opportunity attend the conference, all the way in San Francisco!</p><p>— <br> Follow Elements on <a href="https://www.facebook.com/elementsbuildsapps">Facebook</a>, <a href="http://twitter.com/elementsinter">Twitter</a> and <a href="https://www.linkedin.com/company/elementsinteractive">LinkedIn</a>!</p><p><em>Originally published at www.elements.nl on November 30, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d93df16bc5e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/elements/kotlinconf-2017-d93df16bc5e3">KotlinConf 2017</a> was originally published in <a href="https://medium.com/elements">Elements blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>