<?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 Harshith Shetty on Medium]]></title>
        <description><![CDATA[Stories by Harshith Shetty on Medium]]></description>
        <link>https://medium.com/@har5hitn95?source=rss-2e2e2de3b6df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*o_ldSVZoVQTNPKOc56X6Wg.jpeg</url>
            <title>Stories by Harshith Shetty on Medium</title>
            <link>https://medium.com/@har5hitn95?source=rss-2e2e2de3b6df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 14:10:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@har5hitn95/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[Gradle — Multi repository modules linking]]></title>
            <link>https://har5hitn95.medium.com/gradle-multi-repository-modules-linking-f4e195af9c8?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4e195af9c8</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 14:53:21 GMT</pubDate>
            <atom:updated>2022-12-24T17:28:33.872Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gradle — Multi repository modules linking</h3><p>This post is for people who want to:</p><ul><li>Split a Mono-repo into multiple independent repositories without any impact on development velocity.</li><li>Have development velocity like Mono repo in Multi repository projects.</li></ul><h3>Simple setup</h3><p>Let&#39;s assume a mono-repo SimpleApp with 3 modules</p><ul><li>app</li><li>feature-auth</li><li>repository-auth</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ZGAIWGOzN8cQpk1LhNVYNQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/221/1*kLlXgYhEp11P81KR5rRsSQ.png" /><figcaption>SimpleApp</figcaption></figure><ul><li>Create a common dependency record file to maintain all dependent library (androidx, compose, etc) versions across projects for consistency and ease of maintenance. We are using buildSrc for this.</li></ul><p><a href="https://github.com/har5hit/SimpleApp/blob/main/buildSrc/src/main/kotlin/AndroidDependencies.kt">https://github.com/har5hit/SimpleApp/blob/main/buildSrc/src/main/kotlin/AndroidDependencies.kt</a></p><ul><li>Our app/build.gradle dependencies will be looking like this:</li></ul><pre>app/build.gradle.kts<br><br><br>dependencies {<br>    implementation(AndroidDependencies.AndroidX.core)<br>    implementation(AndroidDependencies.AndroidX.appCompat)<br>    implementation(AndroidDependencies.Material.core)<br>    implementation(AndroidDependencies.AndroidX.constraintLayout)<br>    implementation(project(&quot;:feature-auth&quot;))<br>}</pre><p>Let&#39;s split feature-auth into a separate repository to share feature-auth with multiple apps in an org</p><ul><li>Create a new repository FeatureAuth in the same directory as SimpleApp . It should look like this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*cU6CRwNPtjLzM4K50N-Fbg.png" /></figure><ul><li>Move feature-auth and auth-repository in it.</li><li>Link the moved modules to the SimpleApp via settings.gradle</li></ul><p><a href="https://github.com/har5hit/SimpleApp/blob/main/settings.gradle.kts">https://github.com/har5hit/SimpleApp/blob/main/settings.gradle.kts</a></p><pre>settings.gradle.kts<br><br>// Comment local includes<br>// include(&quot;:feature-auth&quot;)<br>// include(&quot;:repository-auth&quot;)<br><br><br>// Local Project link - This will find the given external modules in other projects in the same level as current project.<br><br>fun findAndLinkExternalModules(list: List&lt;String&gt;) {<br>    val matchingModules = File(&quot;$rootDir/../&quot;).listFiles(java.io.FileFilter {<br>        it.isDirectory &amp;&amp; it.name.startsWith(&quot;Feature&quot;)<br>    }).flatMap {<br>        it.listFiles(java.io.FileFilter {<br>            it.isDirectory &amp;&amp; list.contains(it.name)<br>        }).toList()<br>    }<br>    println(&quot;findAndLinkExternalModules: ${matchingModules.size}/${externalModules.size}&quot;)<br>    matchingModules.forEach {<br>        println(it)<br>        val moduleName = it.name<br>        include(&quot;:$moduleName&quot;)<br>        project(&quot;:$moduleName&quot;).projectDir = it<br>    }<br>}<br>val externalModules = listOf(&quot;feature-auth&quot;, &quot;repository-auth&quot;)<br><br>findAndLinkExternalModules(externalModules)</pre><ul><li>Run app</li></ul><p>Voila! We have successfully split the modules and are still able to work like mono-repo!</p><p>Notes:</p><ul><li>Version control of each repository needs to be managed separately. Don’t forget to push changes in all repositories.</li><li>As a convention, keep the branch name the same for Pull requests (PR) in all repositories to keep it simple.</li><li>You can even do the same steps with the auth-repository, if needed, to separate it into another repository.</li></ul><p>This completes our use case and will work for development and making builds locally but will break for remote builds/CI-CD as these projects will not be available in the same root directory in remote servers. For complete setup with remote builds, read on.</p><h3>Production setup</h3><ul><li>For local development, we are relying on multiple repositories to exist in the same root directory and linking them to the main repository</li><li>For remote, we will need to push and pull the submodules through maven.</li><li><em>Maven push is out of scope for this blog, you can use any blog to configure maven push. Let me know in the comments if need to add it to this blog</em></li><li>We only need to do the below changes in SimpleApp repository.</li></ul><p>Let use abstraction to handle this:</p><ul><li>Let&#39;s createbuildSrc/src/main/kotlin/ExternalProjectDependencies.kt</li></ul><p><a href="https://github.com/har5hit/SimpleApp/blob/main/buildSrc/src/main/kotlin/ExternalProjectDependencies.kt">https://github.com/har5hit/SimpleApp/blob/main/buildSrc/src/main/kotlin/ExternalProjectDependencies.kt</a></p><pre>// Summary<br><br>interface IExternalProjectDependencies - Interface to add external modules (&quot;feature-auth&quot;, &quot;repository-auth&quot;)<br><br>object LocalExternalProjectDependencies : IExternalProjectDependencies - Implementation detail which adds from local file system<br><br>object RemoteExternalProjectDependencies : IExternalProjectDependencies - Implementation detail which pulls from maven<br><br>// Remote builds to pass this flag while building. Local will default to false.<br>fun remoteBuild(): Boolean {<br>    return System.getProperty(&quot;CI_BUILD&quot;).toBoolean()<br>}<br><br>// object instantiated basis on which implementation to load. <br>val externalProjectDependencies =<br>    if (remoteBuild()) RemoteExternalProjectDependencies else LocalExternalProjectDependencies</pre><pre>// ExternalProjectDependencies.kt<br><br>interface IExternalProjectDependencies {<br>    fun addFeatureAuth(projectHandler: (String) -&gt; Any): Any<br>    fun addRepositoryAuth(projectHandler: (String) -&gt; Any): Any<br>}<br><br>object LocalExternalProjectDependencies : IExternalProjectDependencies {<br><br>    override fun addFeatureAuth(projectHandler: (String) -&gt; Any): Any {<br>        return projectHandler(&quot;:feature-auth&quot;)<br>    }<br><br>    override fun addRepositoryAuth(projectHandler: (String) -&gt; Any): Any {<br>        return projectHandler(&quot;:repository-auth&quot;)<br>    }<br><br>}<br><br>object RemoteExternalProjectDependencies : IExternalProjectDependencies {<br>    const val authRepoVersion = &quot;1.0.0&quot;<br><br><br>    override fun addFeatureAuth(projectHandler: (String) -&gt; Any): Any {<br>        return &quot;com.justadeveloper96:feature-auth:$authRepoVersion&quot;<br>    }<br><br>    override fun addRepositoryAuth(projectHandler: (String) -&gt; Any): Any {<br>        return &quot;com.justadeveloper96:repository-auth:$authRepoVersion&quot;<br>    }<br><br>}<br><br><br>fun externalProjectDependencies() =<br>    if (ProjectProperties.remoteBuild()) RemoteExternalProjectDependencies else LocalExternalProjectDependencies</pre><p>Let&#39;s update app/build.gradle.kts</p><pre><br>dependencies {<br>    implementation(AndroidDependencies.AndroidX.core)<br>    implementation(AndroidDependencies.AndroidX.appCompat)<br>    implementation(AndroidDependencies.Material.core)<br>    implementation(AndroidDependencies.AndroidX.constraintLayout)<br>    // implementation(project(&quot;:feature-auth&quot;))<br>    implementation(externalProjectDependencies().addFeatureAuth { project(it) })<br>}</pre><ul><li>Now the app will use local configuration when running on the local machine as CI_BUILD flag is not found.</li><li>When building remotely pass -DCI_BUILD=true to gradle commands.</li></ul><pre>// Example<br>gradle app:assembleDebug -DCI_BUILD=true</pre><ul><li>Done!</li></ul><p>This is a simplified process. This can be used to link any gradle projects. For ex: Pure Android, Kotlin Multiplatform projects, etc.</p><p>Demo projects created for the blog for reference:</p><ul><li><a href="https://github.com/har5hit/SimpleApp">GitHub - har5hit/SimpleApp: Gradle - Multi repository modules linking</a></li><li><a href="https://github.com/har5hit/FeatureAuth">GitHub - har5hit/FeatureAuth: Gradle - Multi repository modules linking</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4e195af9c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Experience After Using Kotlin Multiplatform in Production Apps for a Year]]></title>
            <link>https://medium.com/better-programming/experience-using-kmp-in-production-apps-for-a-year-2474406d99d4?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/2474406d99d4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Mon, 11 Jul 2022 15:40:40 GMT</pubDate>
            <atom:updated>2022-07-22T07:07:29.482Z</atom:updated>
            <content:encoded><![CDATA[<h4>With a kickstarter project goodie to help you get started</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HccUGUuqxDx6mCKS" /><figcaption>Photo by <a href="https://unsplash.com/@gift_habeshaw?utm_source=medium&amp;utm_medium=referral">Gift Habeshaw</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>After using Kotlin Multiplatform (KMP) in production apps, Android and iOS, for approx a year now here are some of our statistics:</p><ul><li>2.5 Million+ MAU(s)</li><li>Perfectly stable. Crash-free sessions: &gt;99.75 %</li><li>&gt;70% code reuse.</li><li>24 mobile devs (14 Android + 10 iOS)</li><li>Kotlin version currently: 1.6.21</li></ul><p>Here’s a look at the processes we use to keep development velocity high!</p><h3>Keep KMP repository separate from your app repositories.</h3><ul><li>Results into better segregation of common modules from specific platform app repository(android, ios, web, backend app, etc).</li><li>This will keep common KMP tooling, plugins, libraries, etc away from existing/new apps.</li><li>This makes it easy for existing/new apps to plug and play common code as a third-party library instead of setting up common KMP tooling, plugins, libraries, integration, etc in a platform-specific app repository.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*mpSYx5Bk5Y3Hv5ad38LUHQ.png" /></figure><h3>Publish the common KMP code as libraries.</h3><ul><li>You can share common KMP code as libraries for the android and ios apps via maven.</li><li>Publishing will output the common KMP code into all the targets(android, ios, js, etc) and maven will host the artifacts.</li><li>The host apps will just load their own platform artifacts from the maven just like we load a third-party library via maven in Gradle.</li><li>For local development, maven has a local repository that hosts it on the same machine for easy sharing artifacts between projects on the same machine with just a single Gradle command: publishToMavenLocal</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*5qrTtpc5gREWsS-p6EuGhg.png" /></figure><p><strong>Tip</strong>:</p><ul><li>You can use GitLab to make it super easy as it has a maven repository out of the box. So the git repository and the maven packages will be accessible from a single GitLab repository.</li><li>By adding remote maven configuration in “KMP Repository”, you can directly use the gradle publish task to build and push the artifacts on the maven.</li><li>On the App Repository side, the same maven configuration will be needed to pull the libraries from maven.</li><li>Example: Maven configuration to be added <a href="https://github.com/har5hit/PokeDex-KMP/blob/master/plugins/publish.gradle">here</a>.</li></ul><h3>Study Kotlin Native (K/N) rules and create a PoC.</h3><ul><li>The Worst part of KMP is that anyone can build common KMP code like they write Kotlin in android and it will run flawlessly in Android.</li><li>It is worst because it will crash in iOS due to Kotlin Native rules like freezing of objects in multithreading etc so a PoC should be made to understand what is possible and what is not to make guidelines and rules for development in common code. For e.g: InvalidMutabilityException</li><li>Learn about the rules from <a href="https://kotlinlang.org/docs/multiplatform-mobile-concurrency-overview.html">here</a>. Create a list of guidelines so that other developers can follow them when working on any new/existing KMP features.</li></ul><h3>Use expect-actual rarely. Depend on interfaces.</h3><ul><li><strong>Expect-actual</strong> gives a very easy way of creating platform-specific access but it has limitations like the same constructor signature.</li><li>Has scalability issues to support new platform dependencies. For e.g: A new platform may need some different constructor dependencies.</li><li>Also, you will need to make actual class from the Kotlin file only.</li></ul><pre><em>// commonMain<br></em><strong>expect class </strong>NetworkGateway(debug: Boolean) {<br>    <strong>val </strong>client: HttpClient<br>}</pre><pre><em>// androidMain<br></em><strong>actual class </strong>NetworkGateway <strong>actual constructor</strong>(debug: Boolean) {<br>    <strong>actual val client</strong>: HttpClient = <em>TODO</em>(<strong>&quot;Not yet implemented&quot;</strong>)<br>}</pre><pre><em>// iosMain<br></em><strong>actual class </strong>NetworkGateway <strong>actual constructor</strong>(debug: Boolean) {<br>    <strong>actual val client</strong>: HttpClient = <em>TODO</em>(<strong>&quot;Not yet implemented&quot;</strong>)<br>}</pre><ul><li>Using abstractions instead will let you freely create the implementation with any platform-specific constructor.</li><li>You can implement the interface in any platform-specific language like Swift for iOS. So you can send dependency from platform sides too.</li><li>So you can pass existing platform dependencies implementing the interfaces and passing via DI to common KMP code with more freedom.</li></ul><pre><em>// commonMain<br></em><strong>interface </strong>INetworkGateway{<br>    <strong>val client</strong>: HttpClient<br>}</pre><pre><em>// androidMain or from Android App Repository.<br></em><strong>class </strong>AndroidNetworkGateway(<br>    debug: Boolean,<br>    interceptors: List&lt;Interceptor&gt;,<br>    networkInterceptor: List&lt;Interceptor&gt;<br>) : INetworkGateway {<br>    <strong>override val client</strong>: HttpClient = <em>TODO</em>(<strong>&quot;Not yet implemented&quot;</strong>)<br>}<br><br><em>// iosMain<br></em><strong>class </strong>IOSNetworkGateway(<br>    debug: Boolean<br>) : INetworkGateway {<br>    <strong>override val client</strong>: HttpClient = <em>TODO</em>(<strong>&quot;Not yet implemented&quot;</strong>)<strong><br></strong>}</pre><h3>Write lots of unit tests</h3><ul><li>Even after adhering to K/N rules, there is always room to miss some rules or some conditions, so there should be a plan to accommodate them.</li><li>Suppose a common feature is already rolled out on android and while integrating it into iOS, there is an issue and the code needs to be fixed.</li><li>Now the fix will impact both android and iOS on the next KMP library release. So to minimize the impact, if unit tests are already present after whatever changes we do for K/N, we can be sure that it is not breaking any existing flow while updating code to adhere to rules for iOS.</li><li>Writing Integration tests for iOS will be much better as it will create a regression suite for K/N rule crashes.</li></ul><h3>Use the android and ios modules in your separate KMP repository as testing hosts.</h3><ul><li>Publishing a common code locally and including it in the actual app repository for integration testing and rebuilding will slow you down.</li><li>So if you need to test it E2E then you can connect the shared code in the testing host modules that are already made in a new KMP project and use that to test any integration before local/remote publishing.</li><li>This will be much faster to work and even debug issues.</li></ul><h3>Keep Common KMP and platform-specific dependency in different files.</h3><ul><li>You can create a common dependency file and different platform dependency files.</li><li>For e.g: <a href="https://github.com/har5hit/PokeDex-KMP/blob/master/buildSrc/src/main/kotlin/Dependencies.kt">CommonDependencies</a>, <a href="https://github.com/har5hit/PokeDex-KMP/blob/master/buildSrc/src/main/kotlin/AndroidDependencies.kt">AndroidDependencies</a>, etc.</li><li>This lets you keep common platform third-party libraries in sync on both KMP Repository and platform app Repository.</li></ul><h3>Improve Crash logging for iOS</h3><ul><li>By default, crashes on common KMP code in the iOS app reported on Crashlytics will not have any significant cause/trace of the crash which will make it useless for debugging the cause.</li></ul><p>For e.g. Crash log of InvalidMutabilityException<strong> </strong>on var loading1: Boolean</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9t2ZGaWlLqjXepsXyO15A.png" /></figure><ul><li>The above doesn’t have any useful info about the crash.</li><li>We can solve this using <a href="https://github.com/touchlab/Kermit">Kermit</a> on the iOS side. It will capture a lot of significant information about crashes from the Kotlin side which can be used for debugging.</li></ul><p>Same above crash example after using Kermit,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzFYSweGLlRT1nD33DpEkA.png" /></figure><p>The exception is clearly visible in the heading and index 7 makes it clear where the crash happened, i.e line 94. The overall information is useful for understanding and fixing the crash. (Note: The log says <strong>Non-fatal</strong> which is incorrect.)</p><h3>Some guidelines we use to avoid K/N crashes:</h3><ul><li>Don’t use <em>var</em> for larger scopes in Common code. Use MutableStateFlow instead. For example, for class scoped variables. So goes without saying, use <em>val</em> mostly. To avoid: InvalidMutabilityException<strong> </strong>(as the variable may be mutated by different threads in a class)</li></ul><pre><em>// Don&#39;t<br></em><strong>class </strong>PersonViewModel{<br>    <strong>private var </strong>loading:Boolean = <strong>false</strong><em><br></em>}</pre><pre><em>// Do<br></em><strong>class </strong>PersonViewModel{<br><em>    </em><strong>private val </strong>loading = <em>MutableStateFlow</em>(<strong>false</strong>)<em><br></em>}</pre><ul><li>Even in the case of using <em>val , </em>make sure it&#39;s final.</li></ul><pre><em>// Don&#39;t</em><strong><br>abstract class </strong>BaseView() {<br>    <strong>abstract val screenName</strong>: String     <br>    <strong>val title </strong>= <strong>&quot;$screenName Screen&quot;    </strong><em>//</em><strong><em>screenName</em></strong><em> is not final<br></em>}</pre><pre><em>// Do</em><br><strong>abstract class </strong>BaseView(<strong>val screenName</strong>: String) {<br>    <strong>val title </strong>= <strong>&quot;$screenName Screen&quot;    </strong><em>//</em><strong><em>screenName</em></strong><em> is final<br></em>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DL98veBEsuFdjl1e5iWNvw.png" /><figcaption>Even IDE will give a warning.</figcaption></figure><ul><li>Use init {} block after declaring all class variables. This is to avoid anyone creating a coroutine in init, which will make the whole class instance freeze and result in throwing an exception on the loading field declared after it.</li></ul><pre><em>// Don&#39;t</em><strong><br>class </strong>PersonViewModel{<br>    <br>    <strong>init </strong>{<br><br>    }<em><br><br>    </em><strong>private val loading </strong>= <em>MutableStateFlow</em>(<strong>false</strong>)<br>    <br>}</pre><pre><em>// Do</em><br><strong>class </strong>PersonViewModel{<br>    <br>    <strong>private val loading </strong>= <em>MutableStateFlow</em>(<strong>false</strong>)<br>    <br>    <strong>init </strong>{<br><br>    }<br>}</pre><ul><li>Actual <a href="https://github.com/har5hit/PokeDex-KMP/blob/master/feature_pokemon_list/src/commonMain/kotlin/com/justadeveloper96/pokedex_kmp/feature_pokemon_list/presentation/pokemon_list/viewmodel/PokemonListViewModel.kt">ViewModel</a> for reference.</li></ul><p>Create DI File in the platform apps to let the host app have the freedom and flexibility to pass different dependency implementations as it needs. Use cases can be:</p><ul><li>Passing an existing UserRepository in platform app to common KMP Code instead of creating it from scratch in common code.</li><li>There can be multiple implementations of a dependency in the KMP repository and platform repository. So switching or A/B can be done on the platform level as per needs.</li></ul><p>The below repository is used for blog reference. Also if you need a KMP project template for reference, quickstart, or play with then also you can check it out:</p><p><a href="https://github.com/har5hit/PokeDex-KMP">GitHub - har5hit/PokeDex-KMP: PokeDex using Kotlin Multiplatform</a></p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2474406d99d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/experience-using-kmp-in-production-apps-for-a-year-2474406d99d4">My Experience After Using Kotlin Multiplatform in Production Apps for a Year</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Boilerplate Generation]]></title>
            <link>https://har5hitn95.medium.com/android-boilerplate-generation-a118b90708be?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/a118b90708be</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[code-generation]]></category>
            <category><![CDATA[hygen]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Tue, 30 Mar 2021 10:59:12 GMT</pubDate>
            <atom:updated>2021-03-30T11:46:43.294Z</atom:updated>
            <content:encoded><![CDATA[<h3>Eliminate Boilerplate with Android Code Generation</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fule4vhcY1xEKQ%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fule4vhcY1xEKQ%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fule4vhcY1xEKQ%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/c081eb81f2252f059c169b0900b3c7f6/href">https://medium.com/media/c081eb81f2252f059c169b0900b3c7f6/href</a></iframe><p>Are you and your team wasting time on creating the same <strong>boring</strong> <strong>boilerplate</strong> <strong>components</strong> manually for new features?</p><p><strong>Tired</strong> of creating setup component files like fragment, layouts, views, viewmodel, repositories , doa, network , test files etc <strong>repeatedly</strong> in their specific <strong>directories,</strong> adhering to specific <strong>app</strong> <strong>architecture,</strong> and glue code for binding?</p><p><strong>Answer</strong>: <strong>Generate It!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*8dYIezSd09plTUfspRkmqA.png" /></figure><p>Creating a generator one time for components will let you and your team members save time, enforce standards and be consistent throughout projects.</p><p>Also, there is a simple way to do it. Let’s start!</p><h3>Steps</h3><ul><li>Install <a href="https://nodejs.org/en/">Node</a></li><li>Install <a href="https://www.hygen.io/">Hygen</a></li></ul><pre>$ npm i -g hygen</pre><ul><li>Go to your android project root directory and create initialize hygen</li></ul><pre>$ hygen init self</pre><ul><li>Create a new generator (Ex: Fragment)</li></ul><pre>hygen generator new --name fragment</pre><p>A new _templates folder will be created in your root directory which will have all your project code generators. Add it to version control to share it with all team members.</p><ul><li>Add a template file in the created generator to describe destination and contents for the file generation. You can have 1 to N templates for a generator. (“/_templates/fragment/new/<strong>FragmentTemplate.ejs.t”)</strong></li><li>We are creating two parameters: module and name to keep it dynamic</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3b1ee664b3b987cd54d6f8fd73d2ca3/href">https://medium.com/media/b3b1ee664b3b987cd54d6f8fd73d2ca3/href</a></iframe><ul><li>Run generator with parameters we want.</li></ul><pre>hygen fragment new --name UserList --module user</pre><p>Done. This creates a Fragment UserListFragment in user module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*VSBzxpfAW4uKOrmJe5QRhg.png" /></figure><h3>Conclusion</h3><p>Now you nor anyone else working on project will need to create this component manually.</p><p>This was a small walkthrough of the flow to create a generator and 1 template file. We can use this to create <strong>N number of files</strong> and injections like proguard mapping for dao,network models etc.</p><p>This is not limited to <strong>android</strong>, understanding it will help you to create it for any platform like <strong>backend, web, ios, flutter</strong> etc.</p><p>You can <strong>save hours of time</strong> wasted on manally creating/copy pasting code and teaching/knowledge sharing the structure of your project and <strong>keeping it consistent</strong> across team. Also adding/changing standards will not need much meetings and screen sharing!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5IMcyqKbkg0O4%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F5IMcyqKbkg0O4%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F5IMcyqKbkg0O4%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="239" frameborder="0" scrolling="no"><a href="https://medium.com/media/5544c4e271df0bb334ab46bf8c4663f0/href">https://medium.com/media/5544c4e271df0bb334ab46bf8c4663f0/href</a></iframe><p>For Full Sample Repository and templates:</p><p><a href="https://github.com/har5hit/PokeDex-Android">har5hit/PokeDex-Android</a></p><p>Also flutter one:</p><p><a href="https://github.com/har5hit/PokeDex-Flutter">har5hit/PokeDex-Flutter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a118b90708be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pagination Simplified]]></title>
            <link>https://har5hitn95.medium.com/pagination-simplified-285642c6f8ea?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/285642c6f8ea</guid>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Tue, 30 Jul 2019 11:52:50 GMT</pubDate>
            <atom:updated>2019-07-30T11:53:27.617Z</atom:updated>
            <content:encoded><![CDATA[<p>During our journey as front end developers we come across lists of data for which requires us to implement pagination.</p><p>The process is simple as load the list of data, and when the end is reaching, if server has more data then fetch the data from the server with the next page information and also it’s state that is loading or completed.</p><h3><strong>Level 1:</strong></h3><p>We may have a single list in our screen.</p><p>We have to fetch the list, keep the count of items available at server and then check whether list is approaching end to make load more call.</p><p>Simple right.</p><p><strong>Level 2:</strong></p><p>There can be a scenario where there are multiple lists in a single screen which needs pagination.</p><p>Now we have to handle the whole process for each lists.</p><p><strong>Level 3:</strong></p><p>Even complex , where the user can click item from list and then want to continue pagination from the detail page which is swipe-able and also continue from the list after coming back and maintain same list of data on both side.</p><p>Where we may have to keep sending next page information between screens.</p><p><strong>Level 4:</strong></p><p>This can get even complex, when there is same listing in different screens, all needs pagination and have to maintain sync across all the listings.</p><p><strong>Solution</strong></p><p>Now this problem has a really simple and effective solution which can be used which will abstract the pagination from the views.</p><p>Let’s see how.</p><p><strong>Step 1</strong></p><p>All the listing types will be identified by a unique name or the types can be a Enum.</p><p><strong>Step 2</strong></p><p>A PageRepository class, this class just have a single responsibility of saving page information of listings.</p><p><strong>Step 3</strong></p><p>A PaginationChecker, which will tell whether the load more should be called or not.</p><h3><strong>The process:</strong></h3><ul><li>Whenever a screen ask for a list of data, the data will first be retrieved from the database with max count that is available from the server.</li><li>The Data when received will be sent to list and also on the PaginationChecker.</li><li>When the list is scrolled, the currentIndex will be updated in the PaginationChecker and the PaginationChecker can be asked whether load more should be called or not.</li><li>When the PaginationChecker returns true, then on the PageRepository should be called to loadMore().</li><li>On loadMore call, the PaginationChecker can be asked for isNextPageAvailable() if it says true, then the API can be hit with the pagination data from pageRepo.getNextPage(type).</li><li>Before initiating the API call, as the list loading is going to start, the same must be marked in PageRepository that the list type is loading, to prevent repeated calls, till the API completes.</li><li>After the response is received, the new pagination info and the api status needs to be updated in the PageRepository.</li><li>After inserting data into db, the list will be updated reactively and the whole process will continue effortlessly.</li></ul><p>A simple abstract illustration of the whole flow will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*nnz9VcT6GAL_jIt4cexOcQ.png" /></figure><p>The whole setup can be reused in any View(Activity/Fragment) with Listing (ViewPager/ RecyclerView/ListView) without needing to implement any pagination again!</p><p>The great thing, load a listing and the scrolling can be continued from any screen and all the lists in all the screens will be in sync with the data and also the status of the data, in loading or completed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=285642c6f8ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing with expectations, not implementations.]]></title>
            <link>https://har5hitn95.medium.com/designing-with-expectations-not-implementations-f107e0ae3c9a?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/f107e0ae3c9a</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[junit]]></category>
            <category><![CDATA[test-driven-development]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 03:26:31 GMT</pubDate>
            <atom:updated>2018-12-21T09:51:41.635Z</atom:updated>
            <content:encoded><![CDATA[<p>If you heard about test driven development (TDD) and wanted to get started somewhere then this is for you. This is in short the experience got through implementing TDD as part of our development process.</p><p><strong>2</strong> <strong>Things</strong> to ask yourself before going through this test process</p><h3>When should I write tests?(Before vs After)</h3><p>After is like getting an architect to create design after a building is built. People say developers are not good testers because we test the app as how we have implemented it. when we have already have implemented something and know that it works, it narrows down your thinking based on implementation you have done and we Write tests which shows our implementation works not if the expectations works. We even Hacks to make test pass, mess code and extra effort.<br>You will know whether what you built broke, but not what you missed in the first place.</p><p>Result: Fail.</p><p>Before: you are free to think about the task at hand, what are the expectations from the system, without having any constraints of your implementation, so you are free to think as a user, as a tester and then as a developer. And you clearly know beforehand where you are headed</p><p>Result: 💯</p><h3>Does my test run fast?</h3><p>Obviously you won’t write tests if it takes as much time as running it on device and verify it manually. It should run as fast as possible and that’s why we are focusing on just plain Junit testing rather than integration tests here.</p><p>“But dude, the unit tests doesn’t cover the whole system and how will I know if my API doesn’t work”</p><p>First of all, APIs and backend request response structure are already thought of before implementing client side, so you’ll either have Swagger/Raml/Postman already to make a mock factory with JSON from them or if you don’t have then also during TDD when you’ll think of the data of request you will send and the type of response you expect to make your feature work, you can send this data factories you made to the server team to make APIs. A win-win situation.</p><p>“But how will I know that my View/UI will be as I am expecting”</p><p>Well you have to really keeps things simple enough that all the required data that is shown in UI comes from your viewmodel/presenter and view just takes that data and shows it without manipulating or adding some logic to it.</p><p>This mocking of view and data let’s you test everything as JUnit tests which are 10000x times faster than instrumentation test and will save u alot of time and give quick results even in a test suite of million test cases.</p><h3>Why TDD?</h3><p>So when you are given a task, we think about contracts, Architecture and get down implementation it, but what do users and product want? They don&#39;t care about code, they care about their expectations, so why shouldn&#39;t we think alike, and start our feature with writing down expectations and implementing around it.<br>But even after listing down out expectations we need some way to verify that our expectation is working or completed as we expected so for that we the best way is to write tests. So that when we click that green button we know whether we achieved what we wanted or not. and when we do change something, there is something to tell whether you messed up or not.</p><p>This is Test driven development. Letting your expectations become test cases and let that tests lead your development process. And the reason why you should use it.</p><p>And they give you greatest and foremost quality of any product i.e it should <strong>work as expected</strong>. Test maintain that.</p><p>And your QA will cry to test regression again and again bt your machine won&#39;t.</p><h3>Process</h3><h4>Ask:</h4><p>Here you ask what this feature should be doing?</p><p>In return you get,</p><ul><li>Expectations of the feature.</li><li>Clarity about building.</li><li>Documention of features.</li></ul><h4>Describe:</h4><p>You define the flow of the feature, how it starts, what message it passes to other objects and when it ends.</p><p>In return you get,</p><ul><li>Relationship between objects.</li><li>Flow of the feature.</li><li>Mocks you will need.</li><li>Knowing when it’s done.</li></ul><h4>Fulfill:</h4><p>Note: Until this process, you won’t be creating any classes or interfaces. When you reach here then you will start creating all the interface and classes with the methods you came to know in above 2 steps.</p><p>You will give life to the feature by creating them and now filling the implementation details of the flow to make it work. You will implement, run the test, check the result and repeat this till your test turn green.</p><h4>Move on:</h4><p>After you are done with making the test pass and are done with it,</p><blockquote>You leave the test and move on to another test, never wanting to see that test again.</blockquote><p>You don’t have to bother testing the feature again or looking back as it’s in the test suite and your tests can run regression by themselves and give you output what broke during modification or updates to your application.</p><p>For code samples checkout this slide:</p><p><a href="https://www.slideshare.net/harshitshetty7/tdd-designing-with-expectations-not-implementations-119317289">TDD — Designing with expectations not implementations</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f107e0ae3c9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Funny Chronometer]]></title>
            <link>https://har5hitn95.medium.com/funny-chronometer-a7a95d07c3cc?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7a95d07c3cc</guid>
            <category><![CDATA[easter-egg]]></category>
            <category><![CDATA[funny-stuff]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[android-sdk]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Tue, 11 Sep 2018 17:18:34 GMT</pubDate>
            <atom:updated>2018-09-11T18:53:14.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UgeAFMor5xIyxzBnNsn8DA.jpeg" /><figcaption>Photo by Shawn Stutzman from Pexels</figcaption></figure><p>So I had a task to implement a timer in my app, I just added a chronometer widget in my layout and was starting with implementation in my activity.</p><p>Thanks to the autocomplete, I saw two methods, isCountDown() and isTheFinalCountDown() and I wondered what exactly is different, which made me curious and I opened the source code, Chronometer.java and was really laughing at the implementation of latter.😂😂</p><pre><strong>public boolean </strong>isTheFinalCountDown() {<br>    <strong>try </strong>{<br>        getContext().startActivity(<br>                <strong>new </strong>Intent(Intent.<strong><em>ACTION_VIEW</em></strong>, Uri.<em>parse</em>(<strong>&quot;https://youtu.be/9jK-NcRmVcw&quot;</strong>))<br>                        .addCategory(Intent.<strong><em>CATEGORY_BROWSABLE</em></strong>)<br>                        .addFlags(Intent.<strong><em>FLAG_ACTIVITY_NEW_DOCUMENT<br>                                </em></strong>| Intent.<strong><em>FLAG_ACTIVITY_LAUNCH_ADJACENT</em></strong>));<br>        <strong>return true</strong>;<br>    } <strong>catch </strong>(Exception e) {<br>        <strong>return false</strong>;<br>    }<br>}</pre><p>This method basically opened “Europe -The Final Countdown” music video on youtube.😂😂</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F9jK-NcRmVcw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D9jK-NcRmVcw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F9jK-NcRmVcw%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcb8f5f300a21e793d8a80306b294dc0/href">https://medium.com/media/bcb8f5f300a21e793d8a80306b294dc0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7a95d07c3cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Dagger 2?]]></title>
            <link>https://har5hitn95.medium.com/why-dagger-2-53d4dd9c4bd6?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/53d4dd9c4bd6</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[dagger-2]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Mon, 10 Sep 2018 05:52:35 GMT</pubDate>
            <atom:updated>2018-09-11T18:43:48.530Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aRBTt9SZlEoxuhhYBAcBQw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/-YPxLkfj3Ao?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Thanh Tran</a> on <a href="https://unsplash.com/search/photos/stab?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><strong>Why Dagger 2?</strong></p><p>Problem 1:</p><p>Lets imagine we are making a new project so start importing our base classes, retrofit singleton, database singleton classes in our project and then start on the modules we are given. Same even when working on existing project with new dependencies.</p><p>Now basic singleton pattern looks like,</p><pre>RetrofitClient.instance(ApiConstants.BASE_URL);</pre><p>and we are happy with our network client and we keep making calls with it, we make our module and release the build and then to the next module,</p><p>Again, we take a new module and reuse the same wherever we need to use the client and it is spread across the project, repeating the same initialization code.</p><p>Now suppose we have to introduce a interceptors in our network client so the signature becomes different like,</p><pre>RetrofitClient.instance(ApiConstants.BASE_URL,interceptors);</pre><p>Here the problem arises that we have to change it at each and every place refactoring it, even worse if some dependencies needs context so we start passing context everywhere in presenter, interactor, repository everywhere and we end up with a untestable code, thereby making architecture useless.</p><p>Problem 2:</p><p>We are great developers so we use Interfaces and rely on interfaces than concrete class reference like, RetrofitClient implements INetworkClient, passing the S.O.L.I.D principles,<br>Liskov substitution principle, and in all places where we need network client we keep a member variable, and then initalize it with Retrofit instance;</p><pre>private val networkClient = RetrofitInstance.instance();</pre><p>and we are happy that all the functionalities are accessed through interface definitions and we can switch the implementation in future if network client changes by just changing the assignment.</p><p>Now when we have to change this, we also have to go to each individual files and change the implementation their to new class like</p><pre>private val networkClient = FuelInstance.instance(ApiConstants.BASE_URL);</pre><p>Problem 3:</p><p>From the above examples, there lies one more common issue that the person who created the module knows the dependency(url, interceptors) and enforces that the other people working in the project should also know how to create before they can use it which needs another message board in basecamp.</p><p><strong>Solution</strong>:</p><p>So how dagger solves this problem.</p><p>By Providing dependencies directly from a module, implemetation code is written only once at only one place</p><pre>public class RetrofitModule(){ <br> @Provides<br> @Singleton <br> fun provideNetworkClient(String baseUrl):INetworkClient<br> { <br>   return RetrofitInstance(baseUrl) <br> } </pre><pre>}</pre><p>Setting our dependency module to Component</p><pre>@Component(modules = arrayOf(RetrofitModule::class))</pre><p>And injecting it in places where you need them</p><pre>@Inject lateinit var networkClient:INetworkClient</pre><p>By Changing module, all the Interfaces will be switched to our new implementation without touching any feature.</p><pre>public class FuelModule(){ <br> @Provides<br> @Singleton <br> fun provideNetworkClient(String baseUrl):INetworkClient<br> { <br>   return FuelInstance(baseUrl) <br> } </pre><pre>}</pre><pre>...</pre><pre>@Component(modules = arrayOf(FuelModule::class))</pre><p>And the next person who wants to use your model doesnt need to know how its made, they can directly use it by asking the name of the interface and dagger will inject it for them.</p><pre>@Inject lateinit var networkClient:INetworkClient</pre><p>Thereby, less redundant, decoupled and testable code, acheiving S.O.L.I.D Dependency Injection too.</p><p><strong>Bonus</strong>:</p><p>If a presenter or a helper has 3 dependencies and you have to mock a dependency, so instead of making mocks everywhere, we can make a mock of that interface or class and provide it through DI.</p><p>If you have a class SnakesLadders with dependencies Snake, Board and Ladder, then if your modules in the component already provide these 3 dependencies, you can ask for a instance of it and dagger will get the dependencies, build the class and inject it for you.</p><pre>class SnakesLadders @Inject constructor(val snake: Snake, val board: Board, val ladder:Ladder)</pre><pre>...</pre><pre>@Inject lateinit var game:SnakesLadders</pre><p>Happy injecting!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53d4dd9c4bd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Application Architecture]]></title>
            <link>https://har5hitn95.medium.com/android-application-architecture-6587705480b0?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/6587705480b0</guid>
            <category><![CDATA[android-architecture]]></category>
            <category><![CDATA[dagger-2]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Sun, 22 Apr 2018 16:33:29 GMT</pubDate>
            <atom:updated>2018-04-23T04:43:18.830Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_vQCLACetCQL6wfqtrR85Q.jpeg" /></figure><p>In Android world, there is a lot of design patterns and many libraries which are used to make a great App Architecture.</p><p>In Google I/O 2017, Google introduced <strong>Android architecture</strong> <strong>components</strong> which brought a host of libraries which made handling lifecycles and reactive pattern easier to implement than ever before and also a <strong>recommended</strong> guide to <strong>app architecture</strong>.</p><p>And <strong>Kotlin</strong> which reduces our code and also brings a lot of inbuilt features on top of Java.</p><p>Then there are other libraries like <strong>Dagger2</strong> which are crucial for any large scale app where there are lots of dependencies and it’s better to handle them and provide them from one place rather than creating instances all over the places.</p><p>I have made a demo project with simplest implementation of these libraries which may help as a starter project or boilerplate to understand how they work together in a <strong>MVVM </strong>(Model-View-ViewModel) pattern as mentioned in <strong>Guide to app architecture</strong> by Google.</p><p><strong>Link:</strong> <a href="https://github.com/har5hit/MiniAndroidArchitecture">Mini Android Architecture</a></p><h3>Screenshots:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GVnT5ppGPAz5rdNQ6jUPrQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WUu-TsaJ3m8Fe-wJ18y76g.png" /></figure><h3>Libraries implemented:</h3><ol><li><strong>Viewmodel</strong> — For keeping our business logic seperate from the view layer(activity, Fragments). It also survives orientation changes.</li><li><strong>Room</strong> — Local ORM Database</li><li><strong>LiveData</strong> — Observable data which respects lifecycle. i.e. Data is emitted only when view is in Active state(after OnStart and before OnPause)</li><li><strong>Dagger</strong> <strong>2</strong> — Dependency injection</li><li><strong>SortedList</strong> — notifying adapter about changes in list efficiently.</li><li><strong>Retrofit</strong> — Network API calls</li><li><strong>Gson</strong> — Json parsing</li></ol><p>There are lots of resources and tutorials for each of these libraries by great people explaining them in detail and with abundant knowledge.</p><p>If you are new to android you can use this project as a template for playing and learning about <strong>MVVM</strong> pattern, also go through the documentation and tutorials to learn about them in depth.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6587705480b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple permission Helper for Android.]]></title>
            <link>https://har5hitn95.medium.com/simple-permission-helper-for-android-c397a6601c01?source=rss-2e2e2de3b6df------2</link>
            <guid isPermaLink="false">https://medium.com/p/c397a6601c01</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-m]]></category>
            <dc:creator><![CDATA[Harshith Shetty]]></dc:creator>
            <pubDate>Tue, 30 Jan 2018 08:03:03 GMT</pubDate>
            <atom:updated>2018-09-11T18:34:10.433Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UsNCI7ptA67XdfrOgwHy2w.jpeg" /><figcaption>Source: <a href="https://pixabay.com/en/padlock-lock-chain-key-security-597495/">pixabay.com</a></figcaption></figure><p>Well if you’re new to Android, you’ll come across Android Marshmallow (M) run-time permissions and then you’ll have to implement handler for it.</p><p>Main checklist for this is:</p><ul><li>Check if the phone is having version less than Android Marshmallow (API level 23), if yes then you’re good to go and skip the rest, if not then following steps apply</li><li>Check if you already have the permissions you wish for by checking,</li></ul><pre>ContextCompat.checkSelfPermission(thisActivity,<br>        Manifest.permission.READ_CONTACTS)<br>    == PackageManager.PERMISSION_GRANTED)</pre><ul><li>If this gives false, then your app doesn’t have permissions to access it so you have to request for permissions,</li></ul><pre>ActivityCompat.requestPermissions(thisActivity,<br>                new String[]{Manifest.permission.READ_CONTACTS},<br>                MY_PERMISSIONS_REQUEST_READ_CONTACTS);</pre><ul><li>And after that you have to handle the result in the callback,</li></ul><pre>@Override<br>public void onRequestPermissionsResult(int requestCode,<br>        String permissions[], int[] grantResults) {<br>    switch (requestCode) {<br>        case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {<br>            // If request is cancelled, the result arrays are empty.<br>            if (grantResults.length &gt; 0<br>                &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {<br><br>                // permission was granted, yay! Do the<br>                // contacts-related task you need to do.<br><br>            } else {<br><br>                // permission denied, boo! Disable the<br>                // functionality that depends on this permission.<br>            }<br>            return;<br>        }<br><br>        // other &#39;case&#39; lines to check for other<br>        // permissions this app might request.<br>    }<br>}</pre><ul><li>And we also have to check if we have to show user some info as why we are asking for the permissions,</li></ul><pre>ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,<br>            Manifest.permission.READ_CONTACTS)</pre><ul><li>If we are asking permission for the first time, this gives false as ask the user directly, after we asked once and user denies then this function returns true, but if the user selects deny and don’t ask again then this gives false in onRequestPermissionsResult then we have to ask him to turn it on from settings, and navigate user to the app settings</li></ul><p>So, handling permissions is a tiresome task if we have to do all the steps for each and every time we need permissions so bored of it, I made a simple solution,</p><h3><a href="https://github.com/har5hit/PermissionHelper">PermissionHelper</a></h3><p>This is a small utility library I have made to simplify this task, it handles permission handling for you and give you 2 simple callbacks for success or fail and includes a alert for asking permission again and even asking user to turn on permissions from settings if they have checked “never ask again”.</p><p>Its implementation is just,</p><ul><li>Declare</li></ul><pre>PermissionHelper permissionHelper;</pre><ul><li>Initialize with the current Activity/Fragment and set the listener</li></ul><pre>permissionHelper=new PermissionHelper(this).setListener(new PermissionHelper.PermissionsListener() {<br>		@Override<br>		public void onPermissionGranted(int request_code) {<br><br>			//if user grants permission.<br><br>		}<br><br>		@Override<br>		public void onPermissionRejectedManyTimes(List&lt;String&gt; rejectedPerms,int request_code) {<br><br>			//if user keeps on denying request<br>		}<br>	});</pre><ul><li>Request permission(s)</li></ul><pre>String[] needed_permissions=new String[]{Manifest.permission.CAMERA, Manifest.permission.CALL_PHONE};</pre><pre>permissionHelper.requestPermission(needed_permissions,100);</pre><ul><li>Add a hook on callback and you’re done.</li></ul><pre><a href="http://twitter.com/Override">@Override</a><br>public void onRequestPermissionsResult(int requestCode, <a href="http://twitter.com/NonNull">@NonNull</a> String[] permissions, <a href="http://twitter.com/NonNull">@NonNull</a> int[] grantResults) {<br> super.onRequestPermissionsResult(requestCode, permissions, grantResults);</pre><pre>/**<br> * pass the permission results to the PermissionHelper for processing.<br> */</pre><pre> permissionHelper.onRequestPermissionsResult(requestCode,permissions,grantResults);</pre><pre>}</pre><ul><li>It will ask the user for the permissions you need and if he denies, will ask him to accept as the app needs it and based on that will give you callback.</li></ul><p>A minimal library to simplify and let you focus on task and handles the permission itself.</p><p>References:</p><p><a href="https://developer.android.com/training/permissions/requesting.html">https://developer.android.com/training/permissions/requesting.html</a><br><a href="https://github.com/har5hit/PermissionHelper">https://github.com/har5hit/PermissionHelper</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c397a6601c01" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>