<?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 Burak Eregar on Medium]]></title>
        <description><![CDATA[Stories by Burak Eregar on Medium]]></description>
        <link>https://medium.com/@burakeregar?source=rss-fda4b1ae5ae5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5y4ixmJ9hf6t5DOrXA6jcA@2x.jpeg</url>
            <title>Stories by Burak Eregar on Medium</title>
            <link>https://medium.com/@burakeregar?source=rss-fda4b1ae5ae5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 16:59:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@burakeregar/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[Jetpack Compose — Android Apps without XML]]></title>
            <link>https://medium.com/android-news/jetpack-compose-android-apps-without-xml-534d74448778?source=rss-fda4b1ae5ae5------2</link>
            <guid isPermaLink="false">https://medium.com/p/534d74448778</guid>
            <category><![CDATA[google-io-2019]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Burak Eregar]]></dc:creator>
            <pubDate>Wed, 08 May 2019 14:47:51 GMT</pubDate>
            <atom:updated>2019-05-10T19:23:34.517Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jetpack Compose — Android Apps without XML</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*QtjMvjLK-iJ1Ehtnh4HbNQ.jpeg" /><figcaption>Source: Jetpack Hero by <a href="https://developer.android.com/images/jetpack/jetpack-hero.svg">Google</a></figcaption></figure><h3>What is Jetpack Compose?</h3><p>Jetpack Compose has been announced by Google at Google I/O 2019.</p><blockquote>Jetpack Compose is an unbundled toolkit designed to simplify UI development. It combines a reactive programming model with the conciseness and ease of use of the Kotlin programming language.</blockquote><p>Jetpack Compose has two major components which are:</p><ul><li>Compose UI Library</li><li>Compose Compiler</li></ul><p>Both of them live in the Android Open Source Project and all the code can be found <a href="https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/ui/">here</a> and <a href="https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/compose/">here</a>.</p><h3>How does it work under the hood?</h3><p>A custom Kotlin compiler plugin reads all the functions with @Composable annotation which are <a href="https://en.wikipedia.org/wiki/Pure_function">pure functions</a> and transforms them into a UI hierarchy. As they are pure functions, they should be side-effect free, which means we are not able to use global or static variables, hence, we need to pass the data directly to the function.</p><h3>What does the code look like?</h3><pre>@Composable<br>fun Greeting(name: String) {<br>   Text (&quot;Hello $name!&quot;)<br>}</pre><p>The code above will generate a TextView and set the name property to it.</p><p>Now we can use it in our Activity. From now on, we don’t need to call setContentView and pass the XML layout file. Instead, we create our Kotlin DSL block and put our scaffold like below.</p><pre>class Activity : AppCompatActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br><br>        setContent <strong>{<br>            </strong>Scaffold <strong>{<br>                </strong>Greeting(&quot;Adam Smith&quot;)<br>            <strong>}<br>        }<br>    </strong>}<br>}</pre><h3>Benefits</h3><ul><li>100% Kotlin 😎</li><li>It is not part of Android OS which would allow us to keep the same minSdkVersion when we face a bug in the library as it would be fixed separately in the next versions of Jetpack Compose Library.</li><li>No need to write XML anymore.</li><li>Can be part of our lovely Android Architecture!</li><li>Potential flexible reusability ❤</li><li>It is part of AOSP, therefore, anyone can contribute to it.</li></ul><h3>Can I use it on my prod app?</h3><p>Since it is still experimental and in an early-exploration pre-alpha stage, it should <strong>not </strong>be used in a production app for now.</p><p>P.S: Since it is a very early stage of this library, I am planning to keep this blog post updated. I will also provide a sample project soon.</p><p>Thanks for reading!</p><p>You can follow me on <a href="https://github.com/burakeregar">GitHub</a> and <a href="https://twitter.com/burakeregar">Twitter</a>!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=534d74448778" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/jetpack-compose-android-apps-without-xml-534d74448778">Jetpack Compose — Android Apps without XML</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yet Another Awesome Kotlin Feature: Parcelize]]></title>
            <link>https://medium.com/android-news/yet-another-awesome-kotlin-feature-parcelize-5439718ba220?source=rss-fda4b1ae5ae5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5439718ba220</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[parcelable]]></category>
            <dc:creator><![CDATA[Burak Eregar]]></dc:creator>
            <pubDate>Sat, 02 Dec 2017 00:29:56 GMT</pubDate>
            <atom:updated>2019-04-18T13:10:56.332Z</atom:updated>
            <content:encoded><![CDATA[<p>You are going to delete lots of lines of code! Yes, it is not a clickbait!</p><p><strong>How do you pass your model between activities?</strong></p><ul><li>Serializable?</li><li>EventBus / Otto ?</li><li>Parcelable?</li></ul><p>Serializable = Reflection! Run Forest Run!!! It is terrible for Android performance.</p><p>Bus libraries like EventBus or Otto are easy to use and have good performance but after some time they cause too much complexity in your code.</p><p>Parcelable interface is great for Android performance but it has too much boilerplate.</p><h3>Parcelize 😍</h3><p>Kotlin added parcelable support in version 1.1.4.</p><p><em>Android Extensions plugin now includes an automatic </em><a href="https://developer.android.com/reference/android/os/Parcelable.html"><em>Parcelable</em></a><em> implementation generator. Declare the serialized properties in a primary constructor and add a </em><em>@Parcelize annotation, and </em><em>writeToParcel()/</em><em>createFromParcel() methods will be created automatically.</em></p><h3>Java model vs Kotlin model</h3><p>I have created two samples of the exact same class with Java and with Kotlin using Parcelable.</p><p>Student.java</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20b944b11f14b85f36c8ffd9d55bb1f7/href">https://medium.com/media/20b944b11f14b85f36c8ffd9d55bb1f7/href</a></iframe><p>Student.kt 😍</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f76a08c635fcbc871f7bda1471f40a4d/href">https://medium.com/media/f76a08c635fcbc871f7bda1471f40a4d/href</a></iframe><h3>Prerequisites:</h3><p>Kotlin version 1.1.4 or newer</p><h3>How To Use:</h3><p>Add the code below into your gradle.</p><pre>androidExtensions {<br>    experimental = true<br>}</pre><p>You also need to add <strong>apply plugin: ‘kotlin-android-extensions’ </strong>to your gradle file.<strong> </strong>However, if you have created your project using Kotlin support, it should be added automatically.</p><p>Then add @Parcelize annotation to your model. That’s it! You don’t need to write any parcel methods anymore!</p><p>Our awesome Kotlin model looks like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d84626de3a7617dc9e3af388a62114d/href">https://medium.com/media/3d84626de3a7617dc9e3af388a62114d/href</a></iframe><h3>About Lint Error</h3><p>Android Studio gives the Lint error below right now. It is a reported bug to IntelliJ. You can find the corresponding issue in the link below.</p><p><a href="https://youtrack.jetbrains.com/issue/KT-19300">https://youtrack.jetbrains.com/issue/KT-19300</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BGh9nkjLQWMLb_8GWwGMGw.png" /></figure><p>You can run your project without any errors so you can just ignore the Lint error for now.</p><p>Please find the sample project for Kotlin Parcelize in the link below.</p><p><a href="https://github.com/burakeregar/KotlinParcelize">https://github.com/burakeregar/KotlinParcelize</a></p><p>If you liked the article, please don’t forget to clap it :)</p><p><strong><em>You can also follow me on Twitter and GitHub</em></strong><br><a href="https://twitter.com/burakeregar">https://twitter.com/burakeregar</a></p><p><a href="https://github.com/burakeregar">https://github.com/burakeregar</a></p><p>Thanks!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5439718ba220" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/yet-another-awesome-kotlin-feature-parcelize-5439718ba220">Yet Another Awesome Kotlin Feature: Parcelize</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin + RxJava + Dagger2 + MVP = Clean Architecture + Easy Unit Testing]]></title>
            <link>https://medium.com/android-news/kotlin-rxjava-dagger2-mvp-clean-architecture-easy-unit-testing-5a756c4f2c93?source=rss-fda4b1ae5ae5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a756c4f2c93</guid>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[unittest]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Burak Eregar]]></dc:creator>
            <pubDate>Wed, 29 Nov 2017 11:53:29 GMT</pubDate>
            <atom:updated>2019-04-05T21:45:26.513Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi Everyone,</p><p>First of all, please find the code related to this article in the repo below.</p><p><a href="https://github.com/burakeregar/KotlinRxMvpArchitecture">burakeregar/KotlinRxMvpArchitecture</a></p><p>I have created a sample project to use RxJava in Kotlin and tried to make it easy for unit testing. But I have faced some problems and I wanted to explain how have I achieved them.</p><p><strong>First Problem</strong>: <em>Mockito cannot mock/spy because : – final class</em></p><p><strong>Reason</strong>: <em>All classes are closed by default in Kotlin.</em></p><p><strong>How to fix</strong>: <em>We need to enable MockMaker plugin.</em></p><p>Firstly, If you are using Mockito you need to update it to Mockito2. After that, create ‘mockito-extensions’ package under resources. Then create a file named ‘org.mockito.plugins.MockMaker’ under ‘mockito-extensions’ package. Lastly, add the text ‘mock-maker-inline’ to the file.</p><p>It should be like the image below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JYY-tTZr1BIrcV7CWOWWBw.png" /></figure><h3>Schedulers</h3><p>When it comes to the schedulers in testing we can follow two ways. First one is using RxAndroidPlugins and RxJavaPlugins and the second one is going for Scheduler Injection using Strategy Pattern. I am not going to dive deep into this but If you don’t have any idea about them you can read <a href="https://medium.com/@peter.tackage/an-alternative-to-rxandroidplugins-and-rxjavaplugins-scheduler-injection-9831bbc3dfaf">this</a> article.</p><p>I preferred using Scheduler Injection in this project. I have created TestSchedulerProvider class which implements Scheduler Provider in the test package.</p><p>TestSchedulerProvider.kt</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/452e624721c6f89b56e7d0ec9df12b76/href">https://medium.com/media/452e624721c6f89b56e7d0ec9df12b76/href</a></iframe><h3>Syntax Problems While Using Mockito</h3><p>I would recommend <a href="https://github.com/nhaarman/mockito-kotlin">this library</a> to achieve the most annoying syntax problems.</p><p>Basically, instead of writing this</p><pre>val mockClass <strong>=</strong> mock<strong>(Foo::class</strong>.<strong>java)</strong></pre><p>we just need to write</p><pre>val mockClass: Foo <strong>=</strong> mock<strong>()</strong></pre><h3>The Problem With “When”</h3><p>As “when” keyword is used by Kotlin we are not able to use it in our tests. We have to use it like `when`. It will take our time until we get used to it. However, we can also use “<strong>given</strong>” instead of “<strong>`when`</strong>”.</p><h3>Let’s Test!</h3><p><strong>Testing Our Presenter</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63fe4a49705e198157e70c0fd610595a/href">https://medium.com/media/63fe4a49705e198157e70c0fd610595a/href</a></iframe><p>In the setup method, we need to provide the needed dependencies to our presenter. So, I created compositeDisposable and testSchedulerProvider to create HomePresenter. After creating the presenter, I have attached the mock view to the presenter.</p><h4>Testing getRepos method From HomePresenter</h4><pre>fun getRepos(searchKey: String) {<br>    view?.showProgress()<br>    disposable.add(api.search(searchKey)<br>            .subscribeOn(scheduler.io())<br>            .observeOn(scheduler.ui())<br>            .subscribe(<br>                    <strong>{ </strong>result <strong>-&gt;<br>                        </strong>view?.hideProgress()<br>                        view?.onSearchResponse(result?.items)<br><br>                        if (result.items == null <br>                           || result.items.isEmpty()) {<br>                            view?.noResult()<br>                        }<br>                    <strong>}</strong>,<br>                    <strong>{ </strong>_ <strong>-&gt;<br>                        </strong>view?.hideProgress()<br>                        view?.onError()<br>                    <strong>}</strong>)<br>    )<br>}</pre><p><strong>Steps</strong></p><ul><li>Verify showProgress method is called</li><li>Verify hideProgress method is called</li><li>Create test scenarios to ensure that onSearchResponse, noResult and onError methods are calling correctly.</li></ul><p>Since our onAttach belongs to BasePresenter we shouldn’t test it on each presenter. We should test BasePresenter class instead.</p><p><strong>Success Scenario</strong></p><pre>@Test<br>fun test_getRepos_should_callSuccess() {<br>    val mockedResponse: RepoResponse = <em>mock</em>()<br>    val searchKey = &quot;test&quot;<br><br>    <em>doReturn</em>(Observable.just(mockedResponse))<br>            .`when`(api)<br>            .search(searchKey)<br><br>    presenter.getRepos(searchKey)<br><br>    testScheduler.triggerActions()<br><br>    <em>verify</em>(view).showProgress()<br>    <em>verify</em>(view).onSearchResponse(mockedResponse.items)<br>    <em>verify</em>(view).hideProgress()<br><br>}</pre><p>I mocked the response and added a rule which returns mockedResponse when API&#39;s “search” function called with “searchKey” param.</p><p>After that, I called presenter.getRepos function with the predefined searchKey. This function will trigger API&#39;s “search” function.</p><p>We have to trigger the actions if we use RxJava. So I have called testScheduler.triggerActions().</p><p>Now we can test our expectations. For this scenario verifying showProgress, hideProgress and onSearchResponse method are enough.</p><p><strong>Other Scenarios</strong></p><p>As I have mentioned almost every line of the tests I am pasting the test functions directly. I have followed the same path with the success scenario.</p><pre>@Test<br>fun test_getRepos_shouldNot_callNoResult() {<br>    val mockedResponse: RepoResponse = <em>mock</em>()<br>    val items = ArrayList&lt;RepoItem&gt;()<br>    val searchKey = &quot;test&quot;<br><br>    items.add(Mockito.mock(RepoItem::class.<em>java</em>))<br><br>    `when`(mockedResponse.items).thenReturn(items)<br><br>    <em>doReturn</em>(Observable.just(mockedResponse))<br>            .`when`(api)<br>            .search(searchKey)<br><br>    presenter.getRepos(searchKey)<br><br>    testScheduler.triggerActions()<br><br>    <em>verify</em>(view, times(0)).noResult()<br>}<br><br>@Test<br>fun test_getRepos_should_callNoResult() {<br>    val mockedResponse: RepoResponse = <em>mock</em>()<br>    val items = ArrayList&lt;RepoItem&gt;()<br>    val searchKey = &quot;test&quot;<br><br>    `when`(mockedResponse.items).thenReturn(items)<br><br>    <em>doReturn</em>(Observable.just(mockedResponse))<br>            .`when`(api)<br>            .search(searchKey)<br><br>    presenter.getRepos(searchKey)<br><br>    testScheduler.triggerActions()<br><br>    <em>verify</em>(view).noResult()<br>}<br><br>@Test<br>fun test_getRepos_should_callError() {<br>    val mockedResponse: Throwable = <em>mock</em>()<br>    val searchKey = &quot;test&quot;<br><br>    <em>doReturn</em>(Observable.just(mockedResponse))<br>            .`when`(api)<br>            .search(searchKey)<br><br>    presenter.getRepos(searchKey)<br><br>    testScheduler.triggerActions()<br><br>    <em>verify</em>(view).showProgress()<br>    <em>verify</em>(view).onError()<br>    <em>verify</em>(view).hideProgress()<br>}</pre><p>The project also contains test classes for Shared Preferences Helper and BasePresenter.</p><p>Please find the code related to this article in the repo below.</p><p><a href="https://github.com/burakeregar/KotlinRxMvpArchitecture">burakeregar/KotlinRxMvpArchitecture</a></p><p>If you <strong>don’t prefer</strong> using RxJava you can check the repo below.</p><p><a href="https://github.com/burakeregar/KotlinMvpArchitecture">burakeregar/KotlinMvpArchitecture</a></p><p>If you liked the article, please clap it. Thanks!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2F3e491f%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2F3e491f%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252F3e491f%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href">https://medium.com/media/fedb9f91e907af2468a937c944ed32ab/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a756c4f2c93" width="1" height="1" alt=""><hr><p><a href="https://medium.com/android-news/kotlin-rxjava-dagger2-mvp-clean-architecture-easy-unit-testing-5a756c4f2c93">Kotlin + RxJava + Dagger2 + MVP = Clean Architecture + Easy Unit Testing</a> was originally published in <a href="https://medium.com/android-news">AndroidPub</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>