<?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 Anang Kurniawan on Medium]]></title>
        <description><![CDATA[Stories by Anang Kurniawan on Medium]]></description>
        <link>https://medium.com/@anangkur?source=rss-20d6240683ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YZuWjRm8sbhD6W8jrrm89g.jpeg</url>
            <title>Stories by Anang Kurniawan on Medium</title>
            <link>https://medium.com/@anangkur?source=rss-20d6240683ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:58:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anangkur/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[Optimizing Room Database Usage in Android]]></title>
            <link>https://medium.com/@anangkur/optimizing-room-database-usage-in-android-15d5065b20f0?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/15d5065b20f0</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-room-using-kotlin]]></category>
            <category><![CDATA[android-room]]></category>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Sat, 14 Oct 2023 15:30:04 GMT</pubDate>
            <atom:updated>2023-10-14T15:30:04.408Z</atom:updated>
            <content:encoded><![CDATA[<p>Previously, I only used Room to store simple data and only used a simple query like select * from the table and all other processes done in Kotlin. But now I try to optimize those processes. Let’s see how it is done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RlPcJyzh46FORyQij2SiSw.png" /></figure><p>Room is arguably the best local database framework in android. it provides an abstraction layer over SQLite, so we can still use the power of SQLite more easily to access the database.</p><p>Since the first time I use Room, I only use it as a cache to store simple data like a list of something, provided by API. The only operation I use is select * from table with a simple where clause.</p><p>But, recently I got a chance to learn Room by doing a project that was hardly coupled to a local database. And I found that room is more powerful than I thought.</p><p>Let’s discuss it.</p><h3>Verifying queries at compile time</h3><p>Room verify your query at compile time, so you don’t have to be worried if there’s a wrong syntax or typo in your query, the IDE will show it as an error and you won’t meet any runtime error because of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*iqrAVqiQc1QOtphRopc3aQ.png" /></figure><h3>Using Room with Coroutine</h3><p>As we know, Room will give an exception if we access it in the main thread. the best way to solve this problem is to integrate Room with Coroutine. To use it, we can just add suspend in the function declared in Dao .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d901871985a19fd6a1714d64e31d557c/href">https://medium.com/media/d901871985a19fd6a1714d64e31d557c/href</a></iframe><p>with coroutine, we can easily call it within a ViewModel using viewModelScope.</p><h3>Integration with Paging Library</h3><p>If you ever work with huge data, you may have to face performance issues. especially when we want to show the data to RecyclerView. To solve the issue, Google has a library called Paging Library that supports Room and also RecyclerView. To integrate Room with Paging Library, we can just change the return value of a function in Dao to PagingSource.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15d312d10222dca0367da326af11d3dd/href">https://medium.com/media/15d312d10222dca0367da326af11d3dd/href</a></iframe><blockquote>To read more about Paging Library, please go to the <a href="https://developer.android.com/topic/libraries/architecture/paging/v3-overview">official documentation</a>.</blockquote><h3>Merging Data Classes to Represent Joined Table</h3><p>We all know that Room is actually just an abstraction layer over SQLite. So, we can still use more complex queries like join. And to represent the data returned by Room we can use data class, but if we join two or more tables in a query how can we represent the data?</p><p>Still, we can use our previous data class that represents our table. To merge two or more @Entity we can use @Embedded annotation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff6470d0eee76977589d9c9dba96b670/href">https://medium.com/media/ff6470d0eee76977589d9c9dba96b670/href</a></iframe><p>That way works for 1 to 1 relation, what if we want to represent 1 to many relations?</p><p>To represent that relation, we can use Map&lt;*,*&gt; or annotate the data class with @Relation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/811fc2bc82ff1e0a2fcd4bb64b7e6699/href">https://medium.com/media/811fc2bc82ff1e0a2fcd4bb64b7e6699/href</a></iframe><p>That’s all I learned in Room while doing my project. Hopefully, it can help you when working with Room.</p><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15d5065b20f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Snapshot Testing in Android app using Shot library]]></title>
            <link>https://medium.com/sampingan-tech/snapshot-testing-in-android-app-using-shot-library-1edbb3b8c76c?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/1edbb3b8c76c</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[snapshot-testing]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Tue, 01 Mar 2022 05:46:49 GMT</pubDate>
            <atom:updated>2022-03-01T05:46:49.841Z</atom:updated>
            <content:encoded><![CDATA[<p>Testing is always complex, especially when it comes to testing a UI. This article will discuss how to make UI Testing in android easier using snapshot testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*8RJbvvGegUthlQXnnEs-1A.png" /></figure><p>When I heard about snapshot testing, I thought this was a great way to test my UI; it is fast and reflects what we are doing in the real world (comparing the UI presented by our app with what designers expect in <a href="http://figma.com/">Figma</a>/<a href="http://zeplin.io/">Zeplin</a>).</p><p>To do snapshot testing, you only need a recorded/expected snapshot to verify the UI and the new/actual snapshot to check any unexpected changes in our UI.</p><p>You can find a good explanation about snapshot testing in this article.</p><p><a href="https://sergiosastre.hashnode.dev/an-introduction-to-snapshot-testing-on-android-in-2021">An introduction to snapshot testing on Android in 2021 📸</a></p><p>As for me, of the recommended ways for the snapshot testing is using a library called Shot.</p><p><a href="https://github.com/pedrovgs/Shot">GitHub - pedrovgs/Shot: Screenshot testing library for Android</a></p><p>This library provides simple, configurable, and reliable snapshot testing for our android app. Let’s try to implement Shot Library.</p><h3>Setup</h3><p>The setup process is easy, and the original GitHub repository already gives a complete setup process. So, I will just be telling you what I do to set up Shot in my sample project.</p><p>Add the dependency in our project/build.gradle.</p><pre>buildscript <strong>{<br>    ...<br>    </strong>dependencies <strong>{<br>        </strong>classpath &quot;com.karumi:shot:5.13.0&quot;<br>    <strong>}</strong></pre><pre><strong>    ...<br>}</strong></pre><p>apply the plugin in all our modules inside our project. In my case, since this is only a sample project with only one app module, I only applied the plugin in app/build.gradle.</p><pre>plugins <strong>{<br>    ...</strong><br><strong>}<br><br></strong>apply plugin: &quot;shot&quot;<br><br>android <strong>{</strong></pre><pre>    ...<br>}</pre><p>configure the testInstrumentationRunner in all modules.</p><pre>android <strong>{<br>    </strong>...<br>    defaultConfig <strong>{<br>        ...</strong><br>        testInstrumentationRunner &quot;com.karumi.shot.ShotTestRunner&quot;<br>        <strong>...<br>    }<br>}</strong></pre><p>just like that, now sync the gradle and you are ready to go.</p><h3>Testing</h3><p>As I mentioned at the beginning of the article, snapshot testing requires the recorded/expected snapshot as the source to verify the test.</p><p>To get the recorded/expected snapshot, first, we need to create the test script. In my case, I am creating the UI using jetpack compose. So, the test script would look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ebba3bb49c13558a8286eaf6a3c4b08/href">https://medium.com/media/8ebba3bb49c13558a8286eaf6a3c4b08/href</a></iframe><p>If you want to learn more about testing in jetpack compose, I have written an article that discusses the topic, go read it here:</p><p><a href="https://medium.com/sampingan-tech/test-your-jetpack-compose-layout-2f0613b0106b">Test Your Jetpack Compose Layout</a></p><p>then run this gradle script to generate the recorded/expected snapshots.</p><pre>./gradlew executeScreenshotTests -Precord</pre><p>you can find the result in /app/build/reports/shot/debug/record/index.html . It should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UxDCuft4QPp0LiJEXmyrDg.png" /></figure><p>now, to verify the actual snapshots, run this Gradle script.</p><pre>./gradlew executeScreenshotTests -Precord</pre><p>you can find the result in /app/build/reports/shot/debug/verification/index.html . It should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_5-CG5fhZzokDXBCxw5b1A.png" /></figure><p>As you can see, Shot will compare the expected and actual screenshots and give the diff, so we can notice if there are unexpected changes in our UI.</p><p>Now try to add some changes to our UI, and let’s see if Shot can notice it.</p><p>Let’s say we change the number of posts, followers, and following in the UI.<br>When I run the Gradle script to verify the test, it will fail and shows something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bK9YJUJW_PPYHwCnAWbA1Q.png" /></figure><p>and if we open the index.html will show something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dtf1N0hN9Tkx_Ih5kNeUSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*s1zGPSY9v5zCA5NeXnsaGQ.png" /></figure><p>It shows the diffs as expected!</p><p>But what if we consider the above case as the expected result as well? since it is only a small diff and can be happened since the number of posts, followers, and following will be different on every account?</p><p>Shot has provided a good configuration. We can configure the tolerance factor on a scale of 0–1, 0, but always be careful on setting the tolerance. Make sure you got the best number for your case.</p><p>In my case, the tolerance of 0.1 is already enough to cover the above case.</p><pre>android <strong>{</strong></pre><pre>    ...<br>    shot <strong>{<br>        </strong>tolerance =  0.1<br>    <strong>}</strong></pre><pre><strong>    ...<br>}</strong></pre><p>Now re-run the test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhHHp-hRJapltfA99QrzbQ.png" /></figure><p>The test passed as expected!</p><p>That’s it! We have already discussed all basic usage of Shot to do the snapshot testing in android. If you have anything to ask, feel free to write in the comment section.</p><p>Thanks for your time!</p><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1edbb3b8c76c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/snapshot-testing-in-android-app-using-shot-library-1edbb3b8c76c">Snapshot Testing in Android app using Shot library</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Android UI Library using Storybook]]></title>
            <link>https://medium.com/sampingan-tech/create-android-ui-library-using-storybook-3ab7b5ffc044?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ab7b5ffc044</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[storybook-native]]></category>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[storybook-android]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Sun, 09 Jan 2022 06:02:27 GMT</pubDate>
            <atom:updated>2022-01-09T06:02:27.540Z</atom:updated>
            <content:encoded><![CDATA[<p>Publish your UI and maintain it easily with Storybook, but how can we conduct it in an Android app?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9r7IiUbnP8rf9pOX_qgEJQ.png" /><figcaption>cover image</figcaption></figure><p>has been known as a great tool to create a UI library and publish with ease. In addition, Storybook can help us separate and isolate our UI from our app. We can easily maintain our UI in a separate repository and focus more on business use cases when developing our main app.</p><p><a href="https://storybook.js.org/">Storybook: Frontend workshop for UI development</a></p><p>Storybook only officially supports JavaScript at the moment. Hence we, as mobile developers, especially Android developers, cannot publish our UI on Storybook yet. But, some people in the community have been working on a tool that extends the functionality of Storybook to create a UI library for native mobile platforms such as Android, IOS, or even a hybrid like Flutter and React Native called <a href="https://github.com/storybookjs/native">Storybook Native</a>.</p><p><a href="https://github.com/storybookjs/native">GitHub - storybookjs/native: 📱 Storybook for Native: iOS, Android, Flutter</a></p><p>Storybook native uses a tool called <a href="https://appetize.io/">Appetize.io</a> to show our UI component in an emulator.</p><p><a href="https://appetize.io/">Appetize.io - Run native mobile apps in your browser</a></p><p>So, how to create our UI library using Storybook Native? Let’s begin to implement it.</p><h3>Implementation</h3><p>The first thing to do before we implement Storybook Native is to install <a href="https://nodejs.org/en/">Node</a> and <a href="https://yarnpkg.com/">Yarn</a> in our machine, see how to <a href="https://nodejs.org/en/download/package-manager/">install Node</a> and <a href="https://nodejs.org/en/download/package-manager/">install Yarn</a> on your machine.</p><p>After successfully installing Node we can start creating our UI library.</p><p>Let’s start with a simple activity and a text inside it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad3c73489af9fd0e8d7437ef631fb9b3/href">https://medium.com/media/ad3c73489af9fd0e8d7437ef631fb9b3/href</a></iframe><p>Now let’s create another activity that shows our UI component. Let’s start with a simple Button</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5062cc9ec627437bc15d80e67274db30/href">https://medium.com/media/5062cc9ec627437bc15d80e67274db30/href</a></iframe><p>Finalize with the screen to show our component; let’s implement DeepLink to make our app respond with the link used by Storybook to open a specific screen containing a particular element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c81c416aa9fb9951ddc080dce134436/href">https://medium.com/media/6c81c416aa9fb9951ddc080dce134436/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cc7ceb79b8df2ff4282d6a0ef99c23b/href">https://medium.com/media/6cc7ceb79b8df2ff4282d6a0ef99c23b/href</a></iframe><p>Now our app is ready to be <a href="https://docs.appetize.io/core-features/uploading-apps">published to appetize.io</a></p><p>Next step, we can start implementing Storybook Native to our app. Run this script to install Storybook Native:</p><pre>npm install @storybook/native</pre><p>Create a JavaScript file named generate.js to generate stories to be published in Storybook Native.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48dfbb99f3061a1aec656c14e0117c95/href">https://medium.com/media/48dfbb99f3061a1aec656c14e0117c95/href</a></iframe><p>To see complete tutorial on how to install Storybook, check the official github repo here:</p><p><a href="https://github.com/storybookjs/native/blob/master/packages/native/README.md">native/README.md at master · storybookjs/native</a></p><p>Then, generate stories to show in the storybook by using this script:</p><pre>node generate.js</pre><p>The above script will generate stories in ./stories with *.stories.jsx file extension.</p><p>Create a directory named .storybook contained main.js and preview.js (optional, only needed if you want to enable switching between devices)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ef3de6aaca27264d7dbaa0aa6f6d0d4/href">https://medium.com/media/2ef3de6aaca27264d7dbaa0aa6f6d0d4/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84dfc8a4efcf2d9dc4d3f52f591b4f35/href">https://medium.com/media/84dfc8a4efcf2d9dc4d3f52f591b4f35/href</a></iframe><p>Now, we can try to build our storybook by running this script:</p><pre>yarn build-storybook</pre><p>The above script will generate files inside ./storybook-static</p><p>To see if the Storybook has been successfully built. look into ./storybook-static and open index.html, it will show something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UPWuB_XqWVphoh62MZEiUg.png" /></figure><p>That’s it. you have successfully created a Storybook for your Android UI.</p><p>If you have anything to discuss, please kindly write it in the comment section.</p><p>Thank you~</p><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ab7b5ffc044" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/create-android-ui-library-using-storybook-3ab7b5ffc044">Create Android UI Library using Storybook</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Animation in Jetpack Compose]]></title>
            <link>https://medium.com/sampingan-tech/introduction-to-animation-in-jetpack-compose-aca769ad0fef?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/aca769ad0fef</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Fri, 07 Jan 2022 06:03:09 GMT</pubDate>
            <atom:updated>2022-01-07T06:03:09.335Z</atom:updated>
            <content:encoded><![CDATA[<p>Animation has been a complex task when it comes to implementing our code. But it has changed when Jetpack Compose introduces its animation library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*ToVZD0eqyv4YMN4_" /></figure><p>Animation in jetpack compose</p><p>Jetpack Compose has introduced its animation library. You can see it in its<a href="https://developer.android.com/jetpack/compose/animation"> official documentation</a>. It has covered all libraries and gives us a guide for choosing which libraries are suitable for our use case, as you can see in the flowchart below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*sYmKnMYSrmB4qhAl" /></figure><p>Great flowchart to help us choosing animation library in jetpack compose by Google</p><p>It gives us an easy way to choose what library we should use that is suitable for our use case. For example, if we just need to animate content in a layout and animate its enter/exit transition, we can use AnimatedVisibility and so on.</p><p>In the<a href="https://developer.android.com/jetpack/compose/animation"> official documentation</a>, we can see that the APIs have been separated into high-level and Low-Level APIs, which we will discuss in this article. Also, we will discuss customizing our animation params using AnimationSpec.</p><h3>High-Level APIs</h3><p>These APIs are designed to be suitable with several common animation patterns. And had been aligned with the best practices of<a href="https://material.io/design/motion/"> Material Design Motion</a>.</p><p>High-Level APIs contains:</p><ul><li>AnimatedVisibility (experimental)</li><li>animateContentSize</li><li>Crossfade</li></ul><h4>AnimatedVisibility</h4><p>AnimatedVisibility animates the visibility or appearance and disappearance of its content.</p><p>Let’s take a look at the snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd55c05a3732e375ff334ef73f84e884/href">https://medium.com/media/cd55c05a3732e375ff334ef73f84e884/href</a></iframe><p>As you can see, we will animate the visibility of a Text inside a Box. You can see the result below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*OhBoG8f0o2_UB7gi" /></figure><p>We can also customize the enter and exit animation using predefined enter and exit transitions.</p><p>EnterTransition</p><ul><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#fadein">fadeIn</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#slidein">slideIn</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#expandin">expandIn</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#expandhorizontally">expandHorizontally</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#expandvertically">expandVertically</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#slideinhorizontally">slideInHorizontally</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#slideinvertically">slideInVertically</a></li></ul><p>ExitTransition</p><ul><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#fadeout">fadeOut</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#slideout">slideOut</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#shrinkout">shrinkOut</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#shrinkhorizontally">shrinkHorizontally</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#shrinkvertically">shrinkVertically</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#slideouthorizontally">slideOutHorizontally</a></li><li><a href="https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary?hl=ja#slideoutvertically">slideOutVertically</a></li></ul><p>let’s try to use slideIn and slideOut for exit and enter transition</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5b16c2d04ed5a4582ea161bea0d69d5/href">https://medium.com/media/f5b16c2d04ed5a4582ea161bea0d69d5/href</a></iframe><p>You can see the result below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*R-dUPIZCR5rmdFOk" /></figure><p>Also, we can combine the enter and exit transition using operator +. For example, when combining fadeIn() and fadeOut() in our enter and exit transition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4af3b0201485db43f784cc19839bca0/href">https://medium.com/media/d4af3b0201485db43f784cc19839bca0/href</a></iframe><p>Result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*OyEWlUSpzTJobQDe" /></figure><p>As you can see it adds a slight fade effect at end of the enter and exit transition.</p><p>By default AnimatedVisibility using fadeIn() + expandHorizontally() as enterTransition, and fadeOut() + shrinkHorizontally() as exitTransition.</p><h4>AnimateContentSize</h4><p>We can use animateContentSize() if we want to animate the size of our layout; animateContentSize() used as modifier. As you can see at the snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a7efe35a7cbc7b1965d892792470988/href">https://medium.com/media/1a7efe35a7cbc7b1965d892792470988/href</a></iframe><p>We are going to animate the size of the Box according to the length of the text. See the result below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*PZJQ7mo3HO4xU9aX" /></figure><h4>CrossFade</h4><p>Crossfade animate the transition between two layouts using crossfade animation. Let’s try implementing crossfade.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/289fbd6edd5524a1ab299a9b57b1b4e0/href">https://medium.com/media/289fbd6edd5524a1ab299a9b57b1b4e0/href</a></iframe><p>Result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*dFERV9pICer9pnBS" /></figure><p>That’s all in the High-Level APIs. Let’s move to the Low-Level APIs in Jetpack Compose Animation.</p><h3>Low-Level APIs</h3><p>Low-Level APIs are the foundation of all High-Level APIs that we already discuss in the previous section. Low-Level APIs contains</p><ul><li>animate*AsState</li><li>Animateable</li><li>updateTransition</li><li>rememberInfiniteTransition</li><li>TargetBasedAnimation</li></ul><h4>animate*AsState</h4><p>animate*AsState only animate a single value that makes this API the simplest API in jetpack animation APIs. We can animate these values in animate*AsState</p><ul><li>Float</li><li>Color</li><li>Dp</li><li>Size</li><li>Bounds</li><li>Offset</li><li>Rect</li><li>Int</li><li>IntOffset</li><li>IntSize</li></ul><p>If you want to animate other data types that are not supported yet in animate*AsState, try using TwoWayConverter.</p><p>We can use this API in any condition as long it’s using the supported value. For example, we’re going to make a simple animation that will move the button forward and backward using animateDpAsState.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04bd22699ece62696afbb45b3684a8e4/href">https://medium.com/media/04bd22699ece62696afbb45b3684a8e4/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*uq8gIu29AJ3jOfus" /></figure><h4>updateTransition</h4><p>updateTransition manages multiple values of animations and runs them simultaneously in multiple states. In short, it combines more than one animate*AsState that runs simultaneously.</p><p>For example, you can see the implementation in the snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f79e6675a52909a3cd8630843845d019/href">https://medium.com/media/f79e6675a52909a3cd8630843845d019/href</a></iframe><p>We are going to animate four values simultaneously, it is contentColor, contentPosition, contentSize, and iconColor . And here’s the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*XwdQc56JzYUp1Ve2" /></figure><h4>rememberInfiniteTransition</h4><p>Same as the updateTransition, rememberInfiniteTransition also manages multiple animation values that runs simultaneously. But it runs right after entering the composition and doesn’t stop unless removed.</p><p>Implement rememberInfiniteTransition is just like implementing the updateTransition but, we don’t need to create a state and replace it with targetValue and initialValue as params. Let’s see on the snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f9b4dffbefe17790837715b699cb3a2/href">https://medium.com/media/3f9b4dffbefe17790837715b699cb3a2/href</a></iframe><p>And here’s the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*zbkvpNpuxjC9uem3" /></figure><h3>AnimationSpecs</h3><p>We have discussed all High-Level APIs and Low-Level APIs. But how do we customize the animation? Let’s discuss in this section.</p><p>Jetpack Compose has allowed us to customize the animation APIs using AnimationSpecs. AnimationSpecs is used as a parameter in animation APIs, and you can use different AnimationSpecs to create various animations.</p><h4>Spring</h4><p>The first AnimationSpecs we are going to discussis Spring. Spring will create a bounce effect in our animation. It takes two parameters; dampingRatio and stiffness.</p><p>dampingRatio is the parameter to define how bouncy the Spring could be. Here are some pre-defined dampingRatio that we can use:</p><ul><li>DampingRatioHighBouncy</li><li>DampingRatioMediumBouncy</li><li>DampingRatioLowBouncy</li><li>DampingRatioNoBouncy</li></ul><p>The default value is DampingRatioNoBouncy</p><p>stiffness. The speed of the spring animation to move toward the end value, we can use pre-defined stiffness that Jetpack Compose has provided.</p><ul><li>StiffnessHigh</li><li>StiffnessMedium</li><li>StiffnessLow</li><li>StiffnessVeryLow</li></ul><p>the default value is StiffnessMedium</p><p>Let’s see how we implemented spring as a spec in our animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33b4aece5d327030099e41554c5033f3/href">https://medium.com/media/33b4aece5d327030099e41554c5033f3/href</a></iframe><p>For example, when we are using DampingRatioHighBouncy and StiffnessMedium</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*UMDJWJ07292wwa3I" /></figure><h4>tween</h4><p>Tween is the spec if you want to manipulate the speed of the animation. It animates between the start and end value over the durationMilis and delayMilis params.</p><p>With tween, you can easily manage when your animation should start or set the duration, and also you can manipulate its movement speed using<a href="https://easings.net/"> an easing curve</a>.</p><p>There are several pre-defined easing curves that you can implement such as:</p><ul><li>FastOutSlowInEasing</li><li>LinearOutSlowInEasing</li><li>FastOutLinearEasing</li><li>LinearEasing</li><li>CubicBezierEasing</li></ul><p>Or, if you have a better understanding of creating an easing curve, you can create your easing curve as described in the <a href="https://developer.android.com/jetpack/compose/animation#easing">official documentation</a>. The default value of the easing curve in tween is FastOutSlowInEasing. And for the duration is 300ms.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84e97d51a613be60b9f643719fb0dd03/href">https://medium.com/media/84e97d51a613be60b9f643719fb0dd03/href</a></iframe><p>In the above example, we are using FastOutLinearEasing in every entry and exit animation so you can see the tween better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*TY-FD6-PaxclmzYS" /></figure><h4>KeyFrame</h4><p>KeyFrame gives you more control over the animation. With KeyFrame you can specify easing at the specific timestamp in the duration of the animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95277faeb9550482ccd7df37d8cad94a/href">https://medium.com/media/95277faeb9550482ccd7df37d8cad94a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*aEgdPsx0Xq53Mh4_" /></figure><h4>repeatable</h4><p>Repeatable will run your animation repeatedly until it reaches the iteration count. To implement repeatable as a spec, we need to specify these three params:</p><ul><li>iterations (how many times the animation should repeat)</li><li>animations (animation that will be repeated, you can use the duration based animations such as tween, keyframe, and snap)</li><li>repeatMode (how the animation should repeat from start (Restart) or from the end (Reverse))</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9a65552883a13acfc4e43e43a4b7c88e/href">https://medium.com/media/9a65552883a13acfc4e43e43a4b7c88e/href</a></iframe><p>In the above example, we are using repeatable with 3 iterations; tween animation, and Reverse as repeatMode. you can see the result below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*36oqDTsWaQ4k8Aqw" /></figure><p>Now let’s try the RepeatMode.Restart</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*zFDlbZ-hQjO5Ovpo" /></figure><h4>infiniteRepeatable</h4><p>Just like the repeatable but without the iterations, so it will repeat infinitely.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23cbd212870d7c4bec02217efe54b76e/href">https://medium.com/media/23cbd212870d7c4bec02217efe54b76e/href</a></iframe><p>We are using Reverse as RepeatMode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*LQHYwXJU1SRAPh_X" /></figure><h4>Snap</h4><p>snap will skip the animation to the end value. You can specify delayMilis in the parameter to delay the start of your animation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b3682543512d8dc03b81a2f28ccff9f/href">https://medium.com/media/7b3682543512d8dc03b81a2f28ccff9f/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*g4mXy5Li1ma_InJk" /></figure><h3>Conclusion</h3><p>That’s all we have discussed all animation in jetpack compose. And to close the discussion, I can say that implementing animation in jetpack compose is relatively easy and fun.</p><p>All we need has been defined in the Low-Level to High-Level APIs. We also can easily customize our animation using AnimationSpecs. And Google has done an excellent job by providing complete documentation with examples to implement it more effortlessly.</p><p>You can find all the result of our research about jetpack compose in my GitHub repo:</p><p><a href="https://github.com/sampingantech/jetpack-compose-animation-playground">sampingantech/jetpack-compose-animation-playground</a></p><h3>References</h3><ul><li><a href="https://developer.android.com/jetpack/compose/animation">Jetpack Compose — Animation (developer.android.com)</a></li><li><a href="https://foso.github.io/Jetpack-Compose-Playground/animation/crossfade/">Animation CrossFade by Foso (foso.github.io)</a></li><li><a href="https://badassdev.io/compose-animation/">Compose Animation by BadassDev (badassdev.io)</a></li><li><a href="https://speakerdeck.com/wajahatkarim3/jetpack-compose-for-games-and-animations">Jetpack Compose for Games and Animation by Wajahat Karim (speakerdeck.com)</a></li><li><a href="https://proandroiddev.com/animate-with-jetpack-compose-animate-as-state-and-animation-specs-ffc708bb45f8">Animate with Jetpack Compose Animate as State and Animation Specs (proandroiddev.com)</a></li><li><a href="https://proandroiddev.com/animations-in-jetpack-compose-bbeaa886210e">Animations in Jetpack Compose by Rasul Aghakishiyev (proandroiddev.com)</a></li></ul><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aca769ad0fef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/introduction-to-animation-in-jetpack-compose-aca769ad0fef">Introduction to Animation in Jetpack Compose</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Glassmorphism in Android App]]></title>
            <link>https://medium.com/sampingan-tech/implementing-glassmorphism-in-android-app-e73a2fd83b80?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/e73a2fd83b80</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[style-guides]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[glassmorphism]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Thu, 06 Jan 2022 06:01:21 GMT</pubDate>
            <atom:updated>2022-01-06T06:01:21.602Z</atom:updated>
            <content:encoded><![CDATA[<h4>Glassmorphism is getting more popular in the community, but how can we implement it in a real app? Especially on the Android app. Let’s talk about it in this article.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AA_HIHM7BTZTYgRlz43UtQ.png" /></figure><p>If you are an Android developer or app designer, you must have often heard about material design; the default design system for Android applications. Material design is an excellent design system and got all we need in Android app development.</p><p>Using this design system, we can make our app look more aesthetic.<br>What if we make it even more aesthetic than the default material design? We can combine our design using the guide from material design with different styles, e.g., Glassmorphism, etc. With that, designers can explore more in their design.</p><p>But, exploring too far from the guide can lead us astray. Also, too many customizations could make our designs hard to implement in the code. So, be wise when choosing the styles.</p><h3>Glassmorphism</h3><p>Glassmorphism is a style that adopts the behavior of glass. It will look great when the background is a colorful image. Glassmorphism uses a combination of blur and transparency.</p><p>If you want to implement this style in your app, create a layer, then add a blur effect and transparency.</p><p>And voila! It will look like acrylic in the real world. Just make sure you have enough clarity to show the content above it. Also, make sure the background is always colorful to make this effect stands out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BQ1JNCL-ZgcvB3WUHb849Q.png" /></figure><p>You can learn more about Glassmorphism in this amazing article by <a href="https://medium.com/u/fde1eb3eb589">Michal Malewicz</a></p><p><a href="https://uxdesign.cc/glassmorphism-in-user-interfaces-1f39bb1308c9">Glassmorphism in user interfaces</a></p><h3>Code it!</h3><p>From a designer’s perspective, we already know that Glassmorphism is a style that combines blur and transparency. So let’s implement it in our code.</p><p>We can implement transparency in Android by using hex color code. This gist <a href="https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4">Hexadecimal color code for transparency</a> can be your guide when implementing transparency color.</p><p>We just tackle our first challenge to implementing transparency in our component. Now the next challenge is to implement blur in our component.</p><p>In Android, blur is not a default library; we need to use a hacky way to implement it by using RenderScript library. Learn how to use the RenderScript library to implement blur in this article by <a href="https://medium.com/u/a4963fa09f17">Sylvain Saurel</a></p><p><a href="https://ssaurel.medium.com/create-a-blur-effect-on-android-with-renderscript-aa05dae0bd7d">Create a Blur Effect on Android with RenderScript</a></p><p>In my case, I have found a useful and simple library to implement the blur effect in our app. You can find it here:</p><p><a href="https://github.com/Dimezis/BlurView">GitHub - Dimezis/BlurView: Dynamic iOS-like blur of underlying Views for Android</a></p><p>with this library, we can implement blur in our layout with ease in our XML like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bf896e5fdf325192f4c6fbea96c384e/href">https://medium.com/media/1bf896e5fdf325192f4c6fbea96c384e/href</a></iframe><p>and set its parameter to create the perfect blur effect</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43127391e4cb5ab17b5a38a731b51ae1/href">https://medium.com/media/43127391e4cb5ab17b5a38a731b51ae1/href</a></iframe><p>As you can see in the XML snippet above, I have used parameter app:blurOverlayColor=”@color/white_40&quot; this parameter will set the background with white color and 40% transparency. And we will get the perfect Glassmorphism in our app. Let’s see the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/0*9Ns4U3PNxHGm9NLf.png" /></figure><p>You can try different libraries that can perpetuate the same purposes to blur the view in Android.</p><p><a href="https://github.com/mmin18/RealtimeBlurView">GitHub - mmin18/RealtimeBlurView: A realtime blurring overlay for Android (like iOS UIVisualEffectView)</a></p><p>That’s it. We just learned how to implement Glassmorphism in our Android app. If you want to check my complete code, you can find it here:</p><p><a href="https://github.com/anangkur/Movie-Ku">GitHub - anangkur/Movie-Ku: This is a sample project for completing Belajar Fundamental Aplikasi Android by Dicoding</a></p><p>If you have anything to say, please kindly write it in the comment section below and discuss it there.</p><p>See you in my other article!</p><h3>References</h3><ul><li><a href="https://uxdesign.cc/glassmorphism-in-user-interfaces-1f39bb1308c9">https://uxdesign.cc/glassmorphism-in-user-interfaces-1f39bb1308c9</a></li><li><a href="https://ssaurel.medium.com/create-a-blur-effect-on-android-with-renderscript-aa05dae0bd7d">https://ssaurel.medium.com/create-a-blur-effect-on-android-with-renderscript-aa05dae0bd7d</a></li><li><a href="https://github.com/Dimezis/BlurView">https://github.com/Dimezis/BlurView</a></li><li><a href="https://github.com/mmin18/RealtimeBlurView">https://github.com/mmin18/RealtimeBlurView</a></li><li><a href="https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4">https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4</a></li><li><a href="https://github.com/anangkur/Movie-Ku">https://github.com/anangkur/Movie-Ku</a></li></ul><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e73a2fd83b80" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/implementing-glassmorphism-in-android-app-e73a2fd83b80">Implementing Glassmorphism in Android App</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Journey to Implement Web Socket in Your Android App using Scarlet]]></title>
            <link>https://medium.com/sampingan-tech/a-journey-to-implement-web-socket-in-your-android-app-using-scarlet-4c400516d350?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c400516d350</guid>
            <category><![CDATA[scarlet]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 06:02:37 GMT</pubDate>
            <atom:updated>2022-01-05T06:02:37.688Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Journey to Implement WebSocket in Your Android App Using Scarlet</h3><p>WebSocket is one of the options for implementing the data layer in Android applications, especially if the application requires data updates in real-time. This article will discuss how to implement web socket into Android applications quickly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EUjfbvzdAZLYV8OkVA6J_g.png" /></figure><p>In my journey, I had built many apps with different use cases. But none of them require real-time data changes. That makes me never touch any libraries that are suitable for real-time data changes.</p><p>Last week I just got an offer about a project from my colleague that needs an implementation of real-time data changes, and he asked me if I could do that or not. Feeling challenged, I accepted that offer. And now, I want to share my experiences in implementing Web Socket on my android app.</p><p>After spending some time exploring how to implement a web socket in the android app, I found a helpful library that works great in my case. It is Scarlet, A Retrofit-inspired WebSocket client for Kotlin, Java, and Android by Tinder.</p><p><a href="https://github.com/Tinder/Scarlet">GitHub - Tinder/Scarlet: A Retrofit inspired WebSocket client for Kotlin, Java, and Android</a></p><p>Because Scarlet is very similar to Retrofit, which I have often used, the setup process is straightforward. Let’s see how to set up Scarlet in our android project.</p><h3>Setup!</h3><p>To implement Scarlet, first add it to your app/build.gradle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae1909453f958490646e0e9335cbdf32/href">https://medium.com/media/ae1909453f958490646e0e9335cbdf32/href</a></iframe><p>In the example provided by Scarlet, RxJava is used to help manage the stream of data sent by the web socket. Implement it in app/build.gradle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/603e06c3ba52b00dbdb1ec34c58743f5/href">https://medium.com/media/603e06c3ba52b00dbdb1ec34c58743f5/href</a></iframe><blockquote>If you curious about Coroutine and Kotlin Flow support, see here: <a href="https://github.com/Tinder/Scarlet/issues/114">https://github.com/Tinder/Scarlet/issues/114</a><br>I haven’t tried it, but best of luck!</blockquote><p>Now the essential part of our setup is the service. We can test our WebSocket implementation using <a href="https://glitch.com/~websocket-echo">websocket-echo (wss://websocket-echo.glitch.me)</a></p><p>Next, create an interface to define a function to communicate with the WebSocket.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/62e3849546fec18cb7fd41da7fa9b68f/href">https://medium.com/media/62e3849546fec18cb7fd41da7fa9b68f/href</a></iframe><p>As seen above, the service interface looks very similar to retrofit. You can use @Receive annotation to observe data stream from WebSocket, and use @Send to send or subscribe data to WebSocket.</p><p>After setting up our service, we can continue to implement our service in our activity; in this case, I am not using any architecture, so we just implemented the service in the activity class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54df270baa4682e3527ad00ccb5b9726/href">https://medium.com/media/54df270baa4682e3527ad00ccb5b9726/href</a></iframe><p>all configuration used in the above snippets are just basic configurations. You can find the more complex configurations in this article</p><p><a href="https://medium.com/tinder-engineering/taming-websocket-with-scarlet-f01125427677">Taming WebSocket with Scarlet</a></p><p>or just see the sample provided officially by Scarlet in this report</p><p><a href="https://github.com/Tinder/Scarlet">GitHub - Tinder/Scarlet: A Retrofit inspired WebSocket client for Kotlin, Java, and Android</a></p><h3>Testing!</h3><p>Now we can test our code by sending something to the WebSocket. The WebSocket will send the same message as they retrieve.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7393253cc78a4d64020589a7a52303b/href">https://medium.com/media/c7393253cc78a4d64020589a7a52303b/href</a></iframe><p>You can see the result in the video below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*J37zSZYnnSpSyimw6Tvjpw.gif" /></figure><p>That’s all we can discuss in this article. Scarlet is a great library that gives you access to implement WebSocket in your Android app. Setting up Scarlet is easy, especially if you are already familiar with tools like Retrofit.</p><p>If you have any questions or anything to discuss, please kindly post it in the comment section, and for the more detailed code as mentioned above, you can see it in this report:</p><p><a href="https://github.com/anangkur/websocket-android-playground">GitHub - anangkur/websocket-android-playground: this is a playground of me implementing websocket in android using Scarlet.</a></p><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c400516d350" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/a-journey-to-implement-web-socket-in-your-android-app-using-scarlet-4c400516d350">A Journey to Implement Web Socket in Your Android App using Scarlet</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Test Your Jetpack Compose Layout]]></title>
            <link>https://medium.com/sampingan-tech/test-your-jetpack-compose-layout-2f0613b0106b?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f0613b0106b</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Tue, 04 Jan 2022 06:03:06 GMT</pubDate>
            <atom:updated>2022-01-04T07:22:03.921Z</atom:updated>
            <content:encoded><![CDATA[<p>Is writing a test for jetpack compose layout as easy as writing a test in XML layout? Let’s find out in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8cX9s_JM3Skmk5tIPY5s1Q.png" /></figure><p>Jetpack compose has slowly become popular among android developers these days. However, since it entered its beta phase, jetpack compose has proven its ability as UI tooling.</p><p>We at Sampingan have used jetpack compose in our code since they released a beta version, and until we create this article, all contain layouts we had created that has run without any problems.</p><p>But, since we previously used the XML to create our layout, migrating our configuration to jetpack has been a difficult challenge, especially when we need to test every feature affected by our migration.<br>That’s when writing automated tests can save our time a lot.</p><h3>Setup</h3><p>The writing instrument test for our jetpack compose layout does not have much distinction from the old XML layout. Therefore, if you already had a test for your previous implementation, it will help you to write the test for jetpack compose because you had just need to translate it to the composed test.</p><p>But, if your previous implementation had not a test class yet, don’t worry; this is the right time to write it.</p><p>To create a test for your jetpack compose layout, first, you need to implement these dependencies in your `build.gradle` file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f972714a4b65da39c800438074f9acd/href">https://medium.com/media/4f972714a4b65da39c800438074f9acd/href</a></iframe><p>After syncing your Gradle, you can start creating a test class for your jetpack compose layouts.</p><h3><strong>Test It!</strong></h3><p>As I said in the previous section, testing in jetpack compose is not different from testing in XML layouts. If you are familiar with espresso; writing a test for composing layout would feel comfortable.</p><p>First, you need to define your Rule . Rule is where your layout shows; in jetpack compose test dependencies, you can select either composeTestRule or androidComposeTestRule based on your needs.</p><p>Use composeTestRule when you need to test a compose layout in an empty activity to freely customize your layout state. And use androidComposeTestRule if you need to test your compose layout in a specific action with all logic that changes your compose layout based on what form that currently applies.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/830b90fe3abb2221d17a2ee231ac965f/href">https://medium.com/media/830b90fe3abb2221d17a2ee231ac965f/href</a></iframe><p>After you decide what Rule are suitable for your case, you need to define the layout that you want to test using setContent {}</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed1d28cbc7388274f13d99908d2983f4/href">https://medium.com/media/ed1d28cbc7388274f13d99908d2983f4/href</a></iframe><p>If you have called your composable function into your Rule , you are now ready to test it by calling what components you want to try, performing an action, or asserting it to check if it has met the required conditions.</p><p>For example, I have created a Button with three predefined sizes:</p><ul><li>small (height = 28dp)</li><li>medium (height = 36dp)</li><li>large (height = 44dp)</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b66be310e56c2c93143cc68ce3814aca/href">https://medium.com/media/b66be310e56c2c93143cc68ce3814aca/href</a></iframe><p>And I want to test if the button has shown the sizes correctly</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3798f8746b9a46cf79f692e5be971b3/href">https://medium.com/media/a3798f8746b9a46cf79f692e5be971b3/href</a></iframe><p>Jetpack compose using semantic to interact with the UI hierarchy. In the approach above, since our composable component has a text inside it, we can use hasText() as the semantic matcher. That matcher will search through the semantic tree that suits with the matcher. In this case, you will explore any component with the text “Small Button” inside it.</p><blockquote>You can also use an extension called onNodeWithText() to search any node that contains specified text.</blockquote><p>If your composable components contain text, it should be easy to match it, but not all components include text; how can we test it? Try using testTag in the modifier as the simplest way to suit the semantic matcher.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/674ed00ab24c17de5883f624d5501ff7/href">https://medium.com/media/674ed00ab24c17de5883f624d5501ff7/href</a></iframe><blockquote>Another way to search your component through the semantic hierarchy is using Role Semantic Property. You can explore how to use it in <a href="https://proandroiddev.com/test-jetpack-compose-layouts-easily-with-role-semanticproperty-dcf19f64130f">this article by Yasin Kacmac</a>.</blockquote><p>If you find any trouble when looking for ways to select any component that you want to test, try to print your semantic tree to log printToLog() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca6fd56e6af4facb3012a5e214f67ebd/href">https://medium.com/media/ca6fd56e6af4facb3012a5e214f67ebd/href</a></iframe><p>And it will show you the semantic tree, so you can find the exact component you want to test, using any semantic matcher that suits the component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14c834141f608e79a6aaaa6da4db48fc/href">https://medium.com/media/14c834141f608e79a6aaaa6da4db48fc/href</a></iframe><p>You can explore any ways to search your composable components with any combinations of the semantic matches since jetpack compose has provided many matchers you can use. For example, you can check it in the image below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QB76cJGp7MYTWq4Kj9zL4Q.png" /></figure><blockquote>In some cases, you might find a situation where your test passes, and sometimes it doesn’t; it is called flaky. In jetpack compose, flaky tests rarely happen. But if this happens to you, try reading <a href="https://proandroiddev.com/managing-flaky-tests-in-jetpack-compose-89c598590068">Dealing with flaky test by Igor Escodro</a> to solve that issue.</blockquote><p>That’s it. We just learned how to create a simple jetpack compose test. If you have found any trouble while creating your test class, just write comments below, and hopefully, we can solve it here.</p><p>Anyways, thanks for reading my article! 🚀</p><h3>References</h3><ul><li><a href="https://developer.android.com/jetpack/compose/testing">Official documentation of testing in jetpack compose</a></li><li><a href="https://proandroiddev.com/test-jetpack-compose-layouts-easily-with-role-semanticproperty-dcf19f64130f">Test Jetpack Compose UI easily with the Role SemanticProperty</a></li><li><a href="https://proandroiddev.com/managing-flaky-tests-in-jetpack-compose-89c598590068">Dealing with flaky test by Igor Escodro</a></li></ul><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f0613b0106b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/test-your-jetpack-compose-layout-2f0613b0106b">Test Your Jetpack Compose Layout</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adapter Delegate (Favor Composition Over Inheritance in Multiple Layout RecyclerView Adapter)]]></title>
            <link>https://medium.com/sampingan-tech/adapter-delegate-favor-composition-over-inheritance-in-multiple-layout-recyclerview-adapter-bfa0c48b43b4?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfa0c48b43b4</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[adapter-delegate]]></category>
            <category><![CDATA[adapter]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[recyclerview]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 04:56:45 GMT</pubDate>
            <atom:updated>2022-01-03T05:09:52.651Z</atom:updated>
            <content:encoded><![CDATA[<p>Creating multiple item layouts in the list can make our RecyclerView adapter complex and hard to read, even difficult to maintain. Here, Adapter Delegate comes to solve these problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/0*XauSeglIPQWbEufg" /><figcaption>example of multiple view type in a single list</figcaption></figure><h3>Found a New Problem</h3><p>Inside the <a href="https://play.google.com/store/apps/details?id=com.sampingan.agentapp">Sampingan</a> app, several pages display a list with more than two ViewItems. At first, We didn’t see any problem with it until we read this article:</p><p><a href="http://hannesdorfmann.com/android/adapter-delegates/">Joe&#39;s great adapter hell escape</a></p><p>We believe that the adapter will become a big problem one day, and we need to fix it before that happens. Therefore, we started researching to solve this problem.</p><p>Let’s say we want to create this layout:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/0*Jl2xCdwlOSOjxBZV" /><figcaption>example of the layout we want to create</figcaption></figure><p>As we can see, the above layout contains several ViewItems:</p><ul><li>Banner</li><li>Promotion</li></ul><p>And I’m adding several other views to make that layout more complex. Let’s say we have:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/0*YA-0CM2Y3H5btBix" /><figcaption>additional layouts</figcaption></figure><ul><li>Campaign</li><li>Featured</li></ul><p>If we’re still using the typical approach of creating the RecyclerView, our adapter will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba680b85d5d14e02195dac5fcfe4ebd1/href">https://medium.com/media/ba680b85d5d14e02195dac5fcfe4ebd1/href</a></iframe><p>The above snippet looks good, but when we want to add more layouts to it, it will become more complex than it should be. And we have to add more logic to getItemViewType(), onCreateViewHolder(), and onBindViewHolder(). That’s the problem that we should avoid.</p><h3>Fixing the Problem</h3><p>It appears that <a href="https://medium.com/u/8d7e1c8b6297">Hannes Dorfmann</a> in his<a href="http://hannesdorfmann.com/android/adapter-delegates/"> article</a> has given great ways to solve this problem using a library named<a href="https://github.com/sockeqwe/AdapterDelegates"> AdapterDelegate</a></p><p><a href="https://github.com/sockeqwe/AdapterDelegates">GitHub - sockeqwe/AdapterDelegates: &quot;Favor composition over inheritance&quot; for RecyclerView Adapters</a></p><p>But, we were still curious to find another approach to understand the solution better. And finally, we have found an interesting article that shows us how to create adapter delegates independently.</p><p>The idea is still the same: we need to simplify our adapter to maintain it quickly, even when we have a lot of viewType on the adapter.</p><p>You can find the detailed solution in this article:</p><p><a href="https://medium.com/@seidalins/delegate-adapters-building-heterogeneous-recyclerviewadapter-877cb7d3c6c0">Delegate Adapters: Building Heterogeneous RecyclerViewAdapter</a></p><p>The main idea of this approach was to create an abstract class (AdapterDelegate) that any adapter will implement. But before we begin the abstract class, we need to create an interface that will be used to define our model and a DiffUtilCallback. Take a look at the snippet below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26196f8e24a2b64bfadde707aa5d010e/href">https://medium.com/media/26196f8e24a2b64bfadde707aa5d010e/href</a></iframe><p>Implement the above interface to our model</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d124d4f6ef3786f50b2b6448f32b021e/href">https://medium.com/media/d124d4f6ef3786f50b2b6448f32b021e/href</a></iframe><p>And create a DiffUtilCallback to help us calculate the diff in our list and make updating our list more intelligent and straightforward.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/514d77192c27b9f3e5e8e57a171e4426/href">https://medium.com/media/514d77192c27b9f3e5e8e57a171e4426/href</a></iframe><p>Finally, we can start creating our abstract class DelegateAdapter</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a040afa61723d227c9cadb66ad55d7c/href">https://medium.com/media/4a040afa61723d227c9cadb66ad55d7c/href</a></iframe><p>and then, continue to Implement abstract AdapterDelegate to our Adapter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a80dea3fa4348de3d4af16ae2d9421d/href">https://medium.com/media/2a80dea3fa4348de3d4af16ae2d9421d/href</a></iframe><p>And our MainAdapter will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75ff8f3ff290991c8912201efb92df64/href">https://medium.com/media/75ff8f3ff290991c8912201efb92df64/href</a></iframe><p>And last but not least, implemented it in our MainActivity like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13f6148a31edcc04296d65ba6975c707/href">https://medium.com/media/13f6148a31edcc04296d65ba6975c707/href</a></iframe><p>We don’t need to change our MainAdapterusing this approach. Which means, have to follow the O in the S.O.L.I.D principle.</p><blockquote>Objects or entities should be open for extension but closed for modification.</blockquote><p>When we need to add another View to the adapter, we need to add a new model and implement it with our previous interface DelegateAdapterItem and create an adapter class that implements DelegateAdapter.</p><p>Just like that, we can add more item views to our adapter without worrying it will look like a monster!</p><h3>Another Way to Fix the Problem</h3><p>As I mentioned in the previous section, <a href="https://medium.com/u/8d7e1c8b6297">Hannes Dorfmann</a> has created a library to fix the “adapter hell” problem.</p><p><a href="https://github.com/sockeqwe/AdapterDelegates">GitHub - sockeqwe/AdapterDelegates: &quot;Favor composition over inheritance&quot; for RecyclerView Adapters</a></p><p>To implement it, we can choose the suitable one for our project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d01cd496b45d4bb6d4f40a33a9d406d/href">https://medium.com/media/4d01cd496b45d4bb6d4f40a33a9d406d/href</a></iframe><p>Since my project has using ViewBinding. So, I just need to implement this in my build.gradle</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb29f8e97b475b3db1997712d341d451/href">https://medium.com/media/fb29f8e97b475b3db1997712d341d451/href</a></iframe><p>And for using that lib, firstly, we need to create an interface for our model</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a6776be4cbc785236577ce272847af8/href">https://medium.com/media/2a6776be4cbc785236577ce272847af8/href</a></iframe><p>then, create our model and implement it with the interface</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edeebeca63743f751f345e8e997f55ac/href">https://medium.com/media/edeebeca63743f751f345e8e997f55ac/href</a></iframe><p>next, create a function to handle the adapter delegate for our layout</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78bca8bc24d17ebe0331bb318da48db6/href">https://medium.com/media/78bca8bc24d17ebe0331bb318da48db6/href</a></iframe><p>our MainAdapter will look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50f9cabdf05f5f926a7498d6885c44c1/href">https://medium.com/media/50f9cabdf05f5f926a7498d6885c44c1/href</a></iframe><p>finally, implement the adapter on our activity</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ed3c171b0648dba284c15a3569e38f1/href">https://medium.com/media/1ed3c171b0648dba284c15a3569e38f1/href</a></iframe><p>This approach has the same goal as the previous approach; I like to use the<a href="https://github.com/sockeqwe/AdapterDelegates"> AdapterDelegates library</a> from <a href="https://medium.com/u/8d7e1c8b6297">Hannes Dorfmann</a> because we need to implement it, and voila, all the complex works done by the library.</p><p>But if you want to understand the concept, I suggest creating your own adapter delegate as I described in the first approach.</p><h3>Conclusion</h3><p>The list has been an essential component in our app, as it shows a large amount of data on a page. However, maintaining a list can be a problem when having more than one view type. The adapter delegate comes to save our time solving these issues.</p><p>You can take a look at my playground project here:</p><p><a href="https://github.com/sampingantech/adapter-delegate-playground">sampingantech/adapter-delegate-playground</a></p><h3>References</h3><ul><li><a href="https://medium.com/@seidalins/delegate-adapters-building-heterogeneous-recyclerviewadapter-877cb7d3c6c0">Delegate Adapters: Building Heterogeneous RecyclerViewAdapter</a></li><li><a href="http://hannesdorfmann.com/android/adapter-delegates/">Joe&#39;s great adapter hell escape</a></li></ul><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> •<a href="https://medium.com/@anangk97"> Medium</a> •<a href="https://dribbble.com/anangkur"> Dribbble</a> •<a href="https://twitter.com/anang_kur"> Twitter</a> •<a href="https://instagram.com/anang.kur"> Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfa0c48b43b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/adapter-delegate-favor-composition-over-inheritance-in-multiple-layout-recyclerview-adapter-bfa0c48b43b4">Adapter Delegate (Favor Composition Over Inheritance in Multiple Layout RecyclerView Adapter)</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: Jetpack Compose in Our Production Code]]></title>
            <link>https://medium.com/sampingan-tech/part-2-jetpack-compose-in-our-production-code-d17e5a02af4f?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/d17e5a02af4f</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Wed, 07 Apr 2021 04:08:00 GMT</pubDate>
            <atom:updated>2021-04-07T09:13:49.356Z</atom:updated>
            <content:encoded><![CDATA[<h4>After a 2 sprint, we’re shipping our last development code to production. We can claim that<a href="https://developer.android.com/jetpack/compose"> Jetpack Compose</a> is stable enough to be used, even though with a few constraints discussed in the previous article, here</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Ad5ZfQrQarilpw_vjr6JA.png" /></figure><p>In the previous article, we discussed how we implemented Jetpack Compose in our development codebase.</p><p>For more details, please read the following article: <a href="https://medium.com/sampingan-tech/part-1-integrating-jetpack-compose-to-our-development-code-9a9d25c70979">Part 1: Integrating Jetpack Compose to Our Development Code</a>.</p><p>It turns out that the environment on the Android Studio Canary provides so many drawbacks that it makes the refactor process very difficult because there are so many constraints that have to be changed, which are not even related to Jetpack Compose at all. So in this article, we want to discuss the obstacle, its drawbacks, and why we still implemented Jetpack Compose in our production environment even though we were aware of all those drawbacks.</p><h3>What we have found so far…</h3><p>In the previous article, we used the android Gradle plugin version 7.0.0-alpha to develop UI using Jetpack Compose. Still, it provides some drawbacks, which eventually became the reason for us to downgrade the Android Gradle plugin version back to 4.1.3, which of course, already supports jetpack compose and is much more stable to implement in the production environment. Here are the drawbacks we have found so far:</p><ul><li>Android Gradle plugin 7.0.0-alpha requires java JDK version 11, this requires a lot of changes in our codebase, plus in our team, 3 developers have different devices/machines with different operating systems, so it will cost a lot of money to just refactor the Java JDK.</li></ul><pre>Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.</pre><pre>You can try some of the following options:<br>   - changing the IDE settings.<br>   - changing the JAVA_HOME environment variable.<br>   - changing `org.gradle.java.home` in `gradle.properties`.</pre><ul><li>We have installed several 3rd party Gradle plugins that have the potential to fail the building process on the CI Pipeline or local machines such as Triple-T, Jacoco, SonarQube, Hilt, Firebase Crashlytics.</li></ul><pre>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</pre><ul><li>We are also using an Annotation processor (kapt) that has the potential to break if it is not fully supported on android Gradle plugin 7.0.0-alpha and Java JDK 11.</li><li>Related to kapt, we also haven’t removed some of the dependencies which are directly related to kapt like glide, dagger, hilt, etc. Hopefully, some of the libraries that using kapt will be removed to increase build time as well.</li><li>Some Gradle settings like configuration cache, parallel, build cache, etc., will have different settings and can also break our code.</li><li>We also use the Kotlin DSL Gradle to manage dependencies in our code. This also needs to be considered if we upgrade the Gradle version; of course, there will be many changes that need to be made and will break the reusable dependencies management approach that we have used.</li><li>We are using coreDesugarLibrary to use Java JDK 8 API on android versions below API 26. upgrading the android Gradle plugin and Java JDK will result in runtime errors on our system (yes, we are in the process of migrating from java to kotlin)</li><li>We are also worried that upgrading the android Gradle plugin to version 7.0.0-alpha will break the unit testing we made on the dynamic feature module due to changes in Gradle behavior.</li></ul><p>The things mentioned above finally made us decide to downgrade the android Gradle plugin to 4.1.3 to still use Jetpack Compose with only a few refactors on the Gradle setting and our entire production codebase.</p><h3>Jetpack compose on android studio 4.1.3</h3><p>Developing UI with Jetpack Compose on Android Gradle plugin 4.1.3 is not that different from Android Gradle plugin 7.0.0-alpha. But once again, there are drawbacks that we have to accept. One of the drawbacks is we cannot use the preview feature of Jetpack Compose because this feature is only available on Android Studio Canary with Android Gradle plugin 7.0.0-alpha.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*i-UwARgaGDkPU3lsqMfsTw.png" /></figure><p>We still can use the @Composable annotation and use all components in the jetpack compose library. All functions except preview are run well. For us, this is not a deal-breaker. Hopefully, they can make the preview feature available on android studio production soon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCyF41WSJXvagR_SdH-EkA.png" /></figure><p>Even so, in our opinion, you can still develop UI even without the preview feature if you are used to using jetpack compose. at the same time, you can practice blind code skills :)</p><h3>Conclusion</h3><p>So far, our approach in implementing jetpack compose has run smoothly. Regardless of some drawbacks, it is still worth it because jetpack composes offers many benefits on increasing development experience and increasing our app performance.</p><p>We have decided to wait for at least the android Gradle plugin version 7.0.0 has entered the beta phase, so we are confident to refactor our code by implementing the android Gradle plugin version 7.0.0 and Java JDK 11.</p><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> • <a href="https://medium.com/@anangk97">Medium</a> • <a href="https://dribbble.com/anangkur">Dribbble</a> • <a href="https://twitter.com/anang_kur">Twitter</a> • <a href="https://instagram.com/anang.kur">Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d17e5a02af4f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/part-2-jetpack-compose-in-our-production-code-d17e5a02af4f">Part 2: Jetpack Compose in Our Production Code</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: Integrating Jetpack Compose to Our Development Code]]></title>
            <link>https://medium.com/sampingan-tech/part-1-integrating-jetpack-compose-to-our-development-code-9a9d25c70979?source=rss-20d6240683ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a9d25c70979</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <dc:creator><![CDATA[Anang Kurniawan]]></dc:creator>
            <pubDate>Wed, 07 Apr 2021 04:03:05 GMT</pubDate>
            <atom:updated>2021-04-07T04:03:05.634Z</atom:updated>
            <content:encoded><![CDATA[<h4>An exciting experiment in our development code, implementing Jetpack Compose and exploring its interoperability.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Ad5ZfQrQarilpw_vjr6JA.png" /></figure><p>Android development continues to evolve. The developer community and developer companies continue to contribute to simplifying the development process. One of the most impactful contributions to the development of modern Android applications is <a href="https://developer.android.com/jetpack/compose">Jetpack Compose</a>.</p><p>Jetpack Compose is an alternative toolkit for creating native UI on the Android platform. With jetpack compose, you no longer need to create UI with XML; just call the compose function that is already available or create your own compose components using the<a href="http://twitter.com/composable"> </a>@composable annotation and jetpack compose will take care of everything.</p><pre>@Composable<br>fun greeting() {<br>    <em>Text</em>(text = &quot;Hello World&quot;)<br>}</pre><p>We at<a href="https://sampingan.co.id/"> Sampingan</a> are very interested in trying Jetpack Compose. Moreover, Google announced that Jetpack Compose has entered the beta phase (but still has to use<a href="https://developer.android.com/studio/preview"> Android Studio Canary</a> to use the preview feature). And also, jetpack compose has an<a href="https://developer.android.com/jetpack/compose/interop"> interoperability feature</a> with XML vice-versa, so you don’t need to refactor the entire code, but it can be done slowly and partially.</p><h3>How We Setup Jetpack Compose On Our Project</h3><p>Our codebase has been modularized and already using Kotlin, so the refactoring process in our codebase is more straightforward. We started implementing jetpack compose in a dynamic feature module to keep the refactor simple and reduce its complexity. Our changes will occur only in the module and will not touch another module.</p><p>We started implementing Jetpack Compose by upgrading the Android Gradle Plugin version to 7.0.0-alpha09 so that it can run on Android Studio Canary.</p><pre>buildScript {<br>   dependencies {<br>      classpath &#39;com.android.tools.build:gradle:7.0.0-alpha09&#39;<br>   }<br>}</pre><p>Do Gradle sync to check whether there are dependencies that need to support the Android Gradle plugin version 7.0.0-alpha09.</p><p>Check the version of Kotlin that is installed on your project, and make sure it has version 1.4.30 or newer.</p><pre>plugins {<br>  id &#39;org.jetbrains.kotlin.android&#39; version &#39;1.4.30&#39;<br>}</pre><p>Install the dependencies from jetpack compose according to what you need.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab353c11d5910b41e6849ad74951eb8a/href">https://medium.com/media/ab353c11d5910b41e6849ad74951eb8a/href</a></iframe><p>Since we only need a few dependencies, we only install the following libraries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/537191355480e79bdb4621dc86eaf85f/href">https://medium.com/media/537191355480e79bdb4621dc86eaf85f/href</a></iframe><p>Do the Gradle sync again to check if the installation was done. If there is an error like this:</p><pre>e: This version (1.0.0-alpha11) of the Compose Compiler requires Kotlin version 1.4.21-2 but you appear to be using Kotlin version 1.4.21 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don&#39;t say I didn&#39;t warn you!).</pre><p>You can add the command for supressKotlinVersion in the module/build.gradle to solve this problem.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6dc6cad46f31fc491a2fd01446e1b93/href">https://medium.com/media/f6dc6cad46f31fc491a2fd01446e1b93/href</a></iframe><h3>Creating Our First Jetpack Compose Component</h3><p>After completing the setup process, we are ready to create our first Jetpack Compose Component.</p><p>You can start making components from the smallest component on the UI, such as buttons, text, chips, and other components. For example, let’s see on the UI below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fc-f8SVMHcLCQ7bMyZ7ww.png" /></figure><p>As you can see in the UI above, It has TopAppBar, CheckBox, and Button.</p><p>Let’s start with creating the Button component first.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80267213566b64a5112381c9cbc56b1b/href">https://medium.com/media/80267213566b64a5112381c9cbc56b1b/href</a></iframe><p>Now, we have created the button component. Then we can start including it in our UI by taking advantage of the interoperability features in Jetpack Compose. We can use ComposeView in our XML and attach it to the button component we created earlier.</p><pre>...</pre><pre>&lt;androidx.compose.ui.platform.ComposeView<br>        android:id=&quot;@+id/button&quot;<br>        android:layout_width=&quot;match_parent&quot;<br>        android:layout_height=&quot;wrap_content&quot; /&gt;</pre><pre>...</pre><pre>...</pre><pre>binding.button.setContent {<br>    <em>SampinganButton</em>(<br>        modifier = Modifier.<em>padding</em>(<br>            top = 20.<em>dp</em>, <br>            bottom = 60.<em>dp</em>, <br>            start = 16.<em>dp</em>, <br>            end = 16.<em>dp<br>        </em>),<br>        onClick = { /* do something */ },<br>        text = buttonSaveText<br>    )</pre><pre>...</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*u237gVBHnaoGID_y.jpg" /></figure><p>Then continue to create other components contained in the layout that you want to refactor until all components have been successfully replaced with jetpack compose, and in the end, you can refactor the entire layout with composable function.</p><h3>Conclusion</h3><p>The process above looks easy, but it cannot be denied that the refactor process that we experienced is not that easy. We found that several layouts in the androidX library is not available yet in Jetpack compose, and it took a lot of time and effort to make these layouts.</p><p>Therefore, we take advantage of the Jetpack Compose interoperability feature, which allows us to insert a custom view class in the android library in the Jetpack Compose layout. by using AndroidView.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/609f1959ef7b6ef632bbb96020d04a63/href">https://medium.com/media/609f1959ef7b6ef632bbb96020d04a63/href</a></iframe><p>Or if you want to embed an XML layout to compose, you can use AndroidViewBinding</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/395c9e860f52b32a696fba0f2cb9ccce/href">https://medium.com/media/395c9e860f52b32a696fba0f2cb9ccce/href</a></iframe><p>With interoperability, we can continue the refactor another UI so that our code will partially implement jetpack compose and still use the custom view that we have created before, as well as the android view in the AndroidX library.</p><p>That’s all. In my opinion, jetpack compose is ready to be used with some drawbacks, such as the learning curve, we need an adjustment in our team with declarative UI paradigm, some component materials that are not yet available (can be “tricked” with interoperability) and android studio which still has to use the canary version. But we believe that soon, jetpack compose will be ready to use in android studio production, and when that time comes, we are ready, and we don’t even need to do anything because we’ve set jetpack to compose in our project.</p><p>To see some sample jetpack compose you can access on the following page:</p><pre><a href="https://github.com/android/compose-samples">https://github.com/android/compose-samples</a></pre><p>Thank you for taking the time to read this article. If you have questions, please submit them in the comments section below. We will be delighted to discuss them with you.</p><h3>Sources</h3><ol><li><a href="https://developer.android.com/jetpack/compose">https://developer.android.com/jetpack/compose</a></li><li><a href="https://developer.android.com/jetpack/compose/setup">https://developer.android.com/jetpack/compose/setup</a></li><li><a href="https://developer.android.com/jetpack/compose/interop">https://developer.android.com/jetpack/compose/interop</a></li></ol><h3>About The Author</h3><p>I am an Android Developer who loves the world of arts. I work as an Android Developer, but sometimes I do a design challenge with my friends to fill my spare time.</p><p><a href="https://www.linkedin.com/in/anangkur">LinkedIn</a> • <a href="https://medium.com/@anangk97">Medium</a> • <a href="https://dribbble.com/anangkur">Dribbble</a> • <a href="https://twitter.com/anang_kur">Twitter</a> • <a href="https://instagram.com/anang.kur">Instagram</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a9d25c70979" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sampingan-tech/part-1-integrating-jetpack-compose-to-our-development-code-9a9d25c70979">Part 1: Integrating Jetpack Compose to Our Development Code</a> was originally published in <a href="https://medium.com/sampingan-tech">Staffinc Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>