<?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 Vinay John on Medium]]></title>
        <description><![CDATA[Stories by Vinay John on Medium]]></description>
        <link>https://medium.com/@vinayjohn?source=rss-b39f625ae68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*BNPOuN4BzguF_v56.</url>
            <title>Stories by Vinay John on Medium</title>
            <link>https://medium.com/@vinayjohn?source=rss-b39f625ae68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:55:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vinayjohn/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[From India to Londroid: What I Learned Delivering My First Tech Talk in London]]></title>
            <link>https://medium.com/@vinayjohn/from-india-to-londroid-what-i-learned-delivering-my-first-tech-talk-in-london-6e3c9f0fd681?source=rss-b39f625ae68------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e3c9f0fd681</guid>
            <dc:creator><![CDATA[Vinay John]]></dc:creator>
            <pubDate>Tue, 29 Sep 2026 11:18:58 GMT</pubDate>
            <atom:updated>2026-10-04T22:20:30.588Z</atom:updated>
            <content:encoded><![CDATA[<p><em>How a relocation across continents, a passion for accessibility, and deep-diving into Jetpack Compose semantics brought me to the stage at Londroid.</em></p><p>Almost four years ago, I packed my bags and relocated from India to the United Kingdom.</p><p>Moving across countries brings a whirlwind of transitions — new cities, new accents, new transit lines, and a completely new tech ecosystem to navigate. Back home, I had honed my craft across large-scale retail apps with millions of active users, from Sephora to Falabella. I had also led the mobile engineering team at PowerSchool for its flagship platform, Schoology — serving as the foundational first developer on the mobile team — and founded the Litmus7 Kochi Toastmasters Club to help engineers find their voice.</p><p>Over the past few years, while settling into life and engineering in the UK, I often reflected on a question many international engineers face: <em>How and when do you take that leap into the local developer community and share your voice on stage?</em></p><p>Last week, that question found its answer when I stepped up to the podium at <strong>Londroid</strong> to deliver my very first UK tech talk: <strong>“Beyond </strong><strong>contentDescription: Demystifying Compose Semantics for Production Apps.&quot;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KlgvMZ787fwlnak79nQWcQ@2x.jpeg" /></figure><p>Here is the story of how that talk came together, the invaluable support I received along the way, and what I learned from taking the stage in London.</p><h3>1. Finding the Mission: The Ocado Accessibility Centre of Excellence</h3><p>About a year ago, my work took a defining turn when I gravitated toward an area too often treated as an afterthought in mobile development: accessibility (a11y). Joining Ocado’s newly formed Accessibility Centre of Excellence provided the perfect platform to transform how we think, design, and build inclusive user experiences at scale — a journey that ultimately led to sharing our learnings on stage at Londroid.</p><p>Too often in mobile engineering, accessibility is reduced to a superficial checklist: <em>Did you add a </em><em>contentDescription string to your </em><em>Image? Great, ticket closed.</em></p><p>In complex production design systems, however, that mindset falls apart. Custom interactive cards, asynchronous payment banners, dynamic list filtering, and 200%+ font scaling create invisible barriers for assistive technology users. When a screen reader user encounters a poorly architected custom card, they don’t just experience minor friction — they can get trapped in repetitive multi-swipe loops or completely locked out of purchasing groceries.</p><p>Under the mentorship of <strong>Kinga Kozioł</strong> and <strong>Thomas Brennan</strong> in the Ocado Accessibility Centre of Excellence, I had the privilege of tackling these accessibility challenges at massive scale. We didn’t just fix bugs; we investigated the foundational mechanisms of how Jetpack Compose communicates with the Android operating system.</p><p>That hands-on experience sparked an idea: <em>The wider Android community needs to see what happens under the hood.</em></p><h3>2. The LinkedIn Moment: Community That Lifts You Up</h3><p>Submitting a proposal to Londroid — one of the UK’s most respected Android communities — was an exciting milestone. When my talk was accepted alongside <strong>Sam Piercy</strong> (who shared his <em>Startup Survival Kit</em>), the reality set in: I had 25 minutes to deliver high-impact value to senior Android engineers.</p><p>I shared the announcement on LinkedIn, excited to invite local developers:</p><blockquote><em>🔗 </em><strong><em>My LinkedIn Announcement:</em></strong></blockquote><blockquote><a href="https://lnkd.in/p/eEY3YCDg"><em>View Post on LinkedIn</em></a></blockquote><blockquote>“Excited to give my first London tech talk at Londroid next week! I’ll be diving deep into Jetpack Compose accessibility, performance, and UI testing…”</blockquote><p>What happened next reminded me why the developer community is so special. Kinga reshared the post with words of encouragement that truly meant the world to me:</p><blockquote>“A year ago, I had the privilege of starting our Accessibility Centre of Excellence… I’m incredibly proud that Vinay Mathew John, one of our brilliantaccessibility advocates, will be taking that work beyond our organisation by speaking at Londroid… Congratulations, Vinay. I’m excited to see you take the stage!”</blockquote><blockquote><em>🔗 </em><strong><em>Kinga Kozioł’s LinkedIn Reshare:</em></strong><em> </em><a href="https://lnkd.in/p/ed9E6zmM"><em>View Kinga’s Post on LinkedIn</em></a></blockquote><p>Seeing your leads champion your growth publicly is an unforgettable feeling. It transformed any lingering stage jitters into genuine excitement.</p><blockquote><em>📢 </em><strong><em>Londroid’s Official Event Announcement:</em></strong></blockquote><blockquote><a href="https://www.linkedin.com/feed/update/urn:li:share:7506682433342320640/"><em>View Londroid Event Post</em></a></blockquote><h3>3. Demystifying the Talk: What We Covered</h3><p>To make the talk practical, I avoided high-level preaching and focused on the <strong>mechanics of Compose Semantics</strong>:</p><h3>The Dual-Tree Architecture</h3><p>We explored how Compose splits UI execution into parallel representations:</p><ul><li>The <strong>LayoutNode Tree:</strong> Focuses strictly on measurement, layout bounds, and pixel rendering at 60/120 FPS.</li><li>The <strong>SemanticsNode Tree:</strong> Carries the semantic meaning (unmerged vs. merged).</li><li>The <strong>ComposeAccessibilityDelegate:</strong> Translates SemanticsNodes into native Android AccessibilityNodeInfo objects for TalkBack and Switch Access.</li></ul><pre>[ LayoutNode Tree ] --------&gt; [ SemanticsNode Tree ] --------&gt; [ AccessibilityNodeInfo ]<br>(Measure/Layout/Draw)          (Unmerged -&gt; Merged)              (TalkBack / OS Bridge)</pre><h3>Eliminating the “5-Swipe Focus Trap”</h3><p>We examined a standard production card (image + title + price + badge) that inadvertently forced TalkBack users to swipe 5 separate times just to pass one item. We solved it using <strong>Node Merging</strong>:</p><ul><li>Applying .semantics(mergeDescendants = true) or Modifier.clickable to collapse child text into a single unified announcement.</li><li>Using clearAndSetSemantics { } to silence visual noise in custom widgets like star rating bars.</li></ul><h3>200%+ Non-Linear Font Scaling</h3><p>We demonstrated how fixed container heights (Modifier.height(56.dp)) silently truncate text under Android 14&#39;s non-linear font scaling, and why production design systems should adopt fluid constraints like Modifier.heightIn(min = 56.dp) paired with sp units.</p><h3>Automating in CI with SemanticsMatcher</h3><p>Finally, we proved that accessibility doesn’t require constant manual regression testing. By asserting against the merged semantics tree using useUnmergedTree = false in ComposeTestRule, developers can catch broken focus targets directly in their automated test suites.</p><h3>4. The Companion App: “Compose Semantics Lab”</h3><p>To ensure the audience could take the learnings home, I open-sourced an interactive companion app: <strong>Compose Semantics Lab</strong>.</p><p>Every slide in the talk corresponds to a dedicated screen with a live <strong>BAD / GOOD toggle</strong>, allowing developers to turn on TalkBack and physically experience the difference rather than just reading code snippets.</p><ul><li>💻 <strong>GitHub Repository:</strong> <a href="https://github.com/vinay4791/ComposeSemanticsLab">vinay4791/ComposeSemanticsLab</a></li></ul><pre>// From Screen 1: PrimaryProductCard semantics test<br>@Test<br>fun primaryProductCard_hasCorrectMergedSemantics() {<br>    composeTestRule.setContent {<br>        PrimaryProductCard(<br>            title = &quot;Wireless Headphones&quot;,<br>            price = &quot;$99.00&quot;,<br>            onClick = {}<br>        )<br>    }</pre><pre>    // Asserts against the Merged Tree as TalkBack sees it<br>    composeTestRule<br>        .onNode(<br>            matcher = hasText(&quot;Wireless Headphones&quot;) and hasParent(hasClickAction()),<br>            useUnmergedTree = false <br>        )<br>        .assertIsDisplayed()<br>        .assert(hasStateDescription(&quot;In stock, ready to ship&quot;))<br>}</pre><h3>5. The Night of the Talk: Under the Lights at Muzz HQ</h3><p>Arriving at Muzz HQ on Thursday evening, the room was packed with engineers, engineering leads, and community regulars.</p><p>When my session began, I walked through the code, played TalkBack audio samples, and demonstrated how small modifier adjustments dramatically alter the user experience for assistive tools. The engagement was incredible — questions ranged from handling custom canvas semantics to integrating accessibility checks into release pipelines.</p><p>After stepping off the stage, conversations continued late into the evening over pizza and drinks. Meeting engineers from across the UK who share a genuine commitment to quality and accessibility made London feel even closer to home.</p><h3>6. Key Takeaways for Fellow Engineers</h3><p>If you are thinking about stepping up to speak at a meetup or diving into mobile accessibility, here are my three biggest takeaways:</p><ol><li><strong>Build a demo app, not just slides:</strong> Having a working, verified repository (ComposeSemanticsLab) made the concepts concrete and gave attendees immediate value to test in their own IDEs.</li><li><strong>Find champions who believe in you:</strong> My gratitude goes out my seniors in the Ocado team, Londroid, and Novoda. Surround yourself with peers and mentors who push you to share your knowledge.</li><li><strong>Accessibility is an architectural discipline:</strong> Inclusive design isn’t a final sprint polish — it is built into your design tokens, component modifiers, and automated tests from day one.</li></ol><p>London, this was just the beginning. I can’t wait for what’s next! 🚀</p><h3>Resources &amp; Links:</h3><ul><li><strong>GitHub Repository:</strong> <a href="https://github.com/vinay4791/ComposeSemanticsLab">ComposeSemanticsLab</a></li><li><strong>My LinkedIn Post:</strong> <a href="https://lnkd.in/p/eEY3YCDg">Vinay Mathew John on LinkedIn</a></li><li><strong>Kinga Kozioł’s LinkedIn Reshare:</strong> <a href="https://lnkd.in/p/ed9E6zmM">View on LinkedIn</a></li><li><strong>Event Announcement:</strong> <a href="https://www.linkedin.com/feed/update/urn:li:share:7506682433342320640/">Londroid Post</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e3c9f0fd681" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master the Stack: A Guide to Android Launch Modes]]></title>
            <link>https://medium.com/@vinayjohn/master-the-stack-a-guide-to-android-launch-modes-d02236354613?source=rss-b39f625ae68------2</link>
            <guid isPermaLink="false">https://medium.com/p/d02236354613</guid>
            <dc:creator><![CDATA[Vinay John]]></dc:creator>
            <pubDate>Mon, 16 Mar 2026 11:00:44 GMT</pubDate>
            <atom:updated>2026-03-16T11:00:44.478Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of Android development, managing the <strong>Back Stack</strong> is the difference between a fluid user experience and a navigation nightmare. We’ve all used that one app where you have to press the ‘Back’ button thirteen times just to exit. That is the calling card of poorly managed <strong>Launch Modes</strong>.</p><p>Launch Modes dictate the relationship between a new Activity instance and the current Task. Here is a breakdown of the four primary modes, how they behave, and — most importantly — when to actually use them.</p><h3>1. standard: The “Stack ’Em Up” Mode</h3><p>This is the default behavior. The system always creates a new instance of the Activity in the task from which it was started. It doesn’t check for existing instances; it simply pushes a new one onto the top of the stack.</p><p><strong>Behavior:</strong> If you launch Activity B three times, you get three distinct instances of B.</p><ul><li><strong>The Stack:</strong> A → B → B → B</li><li><strong>Real-World Scenario:</strong> <strong>Email Compose or Message Threads.</strong> If you are composing an email and click “Attach Contact,” which opens a new contact picker, and then “Compose” again from there, you want each screen to stay in the history. When the user hits back, they expect to retreat through every specific step they took.</li></ul><h3>2. singleTop: The “Don’t Duplicate the Top” Mode</h3><p>This mode is your first line of <em>defense</em> against redundant screens. If an instance of the Activity already exists <strong>at the top</strong> of the current stack, Android routes the intent to that existing instance via onNewIntent() instead of creating a new one.</p><p><strong>Behavior:</strong> If B is at the top and you launch B again, nothing changes on the stack — the existing B just updates its data. If B is <em>not</em> at the top, a new instance is created.</p><ul><li><strong>The Stack:</strong> A → B → C (singleTop) + Launching C which is singleTop</li></ul><p>= A → B → C (Updated).</p><p>Launch B (singleTop): Stack becomes A -&gt; B -&gt; C -&gt; B (New instance created because B wasn’t at the top).</p><ul><li><strong>Real-World Scenario:</strong> <strong>Search Results.</strong> Imagine you’re in a shopping app searching for “Shoes.” You then click a “Refine” filter for “Red Shoes.” You don’t want a stack of ten different search activities. You want the current screen to simply refresh with the new filtered results.</li></ul><h3>3. singleTask: The “Clear the Path” Mode</h3><p>This is the “Home Base” mode. The system creates a new task and puts the activity at the root. However, if an instance already exists in any task, the system routes the intent to that instance and <strong>clears every other activity on top of it.</strong></p><p><strong>Behavior:</strong> It acts as a vacuum. It finds the existing instance, pulls it to the front, and destroys everything that was sitting above it.</p><ul><li><strong>The Stack:</strong> A → B (singleTask) → C → D + Launching B = A → B (C and D are destroyed).</li><li><strong>Real-World Scenario:</strong> <strong>The Main Dashboard.</strong> In an Email app, you might be deep in Settings &gt; Account &gt; Change Password. If you tap a “Home” button or a notification to go to your <strong>Inbox</strong>, you want those sub-menus discarded. The Inbox should now be the top (and only) thing the user sees.</li></ul><h3>4. singleInstance: The “Lone Wolf” Mode</h3><p>This is the most restrictive mode. It is similar to singleTask, but the system ensures that <strong>no other activities</strong> are launched into the task holding this activity. It is the only member of its task. If it starts another activity, that new activity is automatically forced into a separate task.</p><p><strong>Behavior:</strong> It lives in its own bubble. It refuses to share its task with any other Activity.</p><ul><li><strong>Real-World Scenario:</strong> <strong>The Dialer or Alarm Clock.</strong> When you are on an active phone call, that interface is its own entity. If you switch to a browser to look something up, the “Call” screen stays isolated. You wouldn’t want a “Share” dialog or a random sub-menu to be pushed onto the same task as your active call.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvZqpvmOUGC8lYOUM_bpsQ.png" /></figure><h3>Pro-Tip: The Manifest vs. Intent Flags</h3><p>While you can set these in your AndroidManifest.xml, remember that you can also override behavior dynamically using <strong>Intent Flags</strong> like FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TOP.</p><p>Use the Manifest for the <em>intended</em> nature of the Activity, but use Flags when you need to handle specific, one-off navigation logic.</p><p><em>Thanks for reading. Happy Learning!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d02236354613" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Achieving Interface segregation in Android using Kotlin extension and inline functions]]></title>
            <link>https://medium.com/@vinayjohn/achieving-interface-segregation-in-android-using-kotlin-extension-and-inline-functions-f99f952fa6ca?source=rss-b39f625ae68------2</link>
            <guid isPermaLink="false">https://medium.com/p/f99f952fa6ca</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[inline]]></category>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[interface-segregation]]></category>
            <dc:creator><![CDATA[Vinay John]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 05:21:30 GMT</pubDate>
            <atom:updated>2022-03-13T06:33:57.797Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>SOLID Principles</em></strong></p><p>Robert C Martin famously known as <em>“Uncle Bob” </em>defined <em>Solid Principles </em>which<em> </em>are guidelines to follow when building software so that it is easier to scale and maintain. <a href="https://en.wikipedia.org/wiki/SOLID"><em>SOLID</em></a> is an acronym and each letter denotes an object-oriented design (OOD) principle. In this article we are going to focus on letter “<strong>I” from </strong><em>SOLID </em>which explains the idea of <strong><em>Interface segregation principle.</em></strong></p><p>So what does <strong><em>Interface segregation principle</em></strong> say :</p><h3><strong><em>“The clients shouldn’t be forced to implement the methods that they do not use”.</em></strong></h3><p>Let us take an example of the <a href="https://developer.android.com/reference/android/text/TextWatcher"><strong>TextWatcher</strong></a><strong> </strong>interface in Android. This interface is widely used in development when we want to receive callbacks when a user changes the text in any <a href="https://developer.android.com/reference/android/widget/TextView">TextView</a> Inheriting <a href="https://developer.android.com/reference/android/view/View">View</a> (for eg : <a href="https://developer.android.com/reference/android/widget/EditText">EditText</a>). We can add a TextWatcher interface to an EditText using <a href="https://developer.android.com/reference/android/widget/TextView#:~:text=provided%20no%20arguments.-,addTextChangedListener,-Added%20in%20API">addTextChangedListener</a> Function which is added in the <a href="https://developer.android.com/reference/android/widget/TextView">TextView</a> class.</p><p>Example Scenario : Need to show a Toast message with the current text whenever user enters a character into <a href="https://developer.android.com/reference/android/widget/EditText">EditText</a>.</p><p>To achieve this we need to attach the TextWatcher interface to an <a href="https://developer.android.com/reference/android/widget/EditText">EditText</a> using the <a href="https://developer.android.com/reference/android/widget/TextView#:~:text=provided%20no%20arguments.-,addTextChangedListener,-Added%20in%20API">addTextChangedListener</a> function. Here, we are forced to implement all 3 functions of the TextWatcher interface.</p><p>The Code will look like this :</p><pre>binding.editText.addTextChangedListener(object: TextWatcher {<br>    override fun beforeTextChanged(charSequence: CharSequence?, p1: Int, p2: Int, p3: Int) {<br>        //NO OP<br>    }<br><br>    override fun onTextChanged(charSequence: CharSequence?, p1: Int, p2: Int, p3: Int) {<br>        showToast(charSequence.<em>toString</em>())<br>    }<br><br>    override fun afterTextChanged(charSequence: Editable?) {<br>        //NO OP<br>    }<br><br>})</pre><p>Here, we only require onTextChanged function for showing the functionality. We don’t require <strong><em>beforeTextChanged</em></strong> and <strong><em>afterTextChanged </em></strong>functions and implementing this is a violation to <strong><em>Interface segregation principle.</em></strong></p><p>Now the question arise — How can we segregate the functions in the TextWatcher interface and use only onTextChanged function.</p><p><em>With the help of powerful Extension function in Kotlin and the use of inline function which enhances the efficiency of the Kotlin code when using Higher Order Functions, let us optimise the code to satisfy </em><strong><em>Interface segregation principle</em></strong><em>.</em></p><p>Let’s start with creating a new <a href="https://kotlinlang.org/docs/extensions.html">Extension</a> function <strong><em>onTextChanged</em></strong> on the EditText class. This will add the function to EditText class and we can use it wherever we need the functionality.</p><p>Please check the below Code :</p><pre>inline fun EditText.onTextChange(crossinline listener: (String) -&gt; Unit) {<br>    this.addTextChangedListener(object: TextWatcher {<br>        override fun beforeTextChanged(charSequence: CharSequence?, p1: Int, p2: Int, p3: Int) {<br>            //NO OP<br>        }<br><br>        override fun onTextChanged(charSequence: CharSequence?, p1: Int, p2: Int, p3: Int) {<br>            listener(charSequence.<em>toString</em>())<br>        }<br><br>        override fun afterTextChanged(p0: Editable?) {<br>            //NO OP<br>        }<br><br>    })<br>}</pre><p>Here, we are adding a lambda function <em>listener</em> as a parameter to our onTextChange Extension function. The function <em>listener </em>takes String as an argument. Whenever the callback function onTextChanged in TextWatcher is called we will invoke the function <em>listener </em>and pass a string argument to it.</p><p>This extension function can be used with the EditText like :</p><pre>binding.editText.<em>onTextChange </em><strong>{<br>    </strong>showToast(<strong>it</strong>)<br><strong>}</strong></pre><p>Inside <em>onTextChange </em>you will receive the String which is passed from the onTextChanged function of the TextWatcher interface and we can add our functionality of showing a Toast.</p><p><strong><em>inline</em></strong> : The use of <a href="https://kotlinlang.org/docs/inline-functions.html">inline</a> function enhances the performance of higher order function. The inline function tells the compiler to copy parameters and functions to the call site.</p><p><strong><em>crossinline</em></strong> : <a href="https://kotlinlang.org/docs/inline-functions.html#:~:text=parameter%20with%20the-,crossinline,-modifier%3A">crossinline</a> keyword is added to avoid non-local returns. <em>ie, if </em>we have added the <strong>return</strong> inside the lambdas, it will allow the non-local returns and left the code below that. To avoid this we are using crossinline keyword before the lambda function <em>listener.</em></p><p>We can use the same approach when we are trying to implement interfaces which contain a lot of functions and we need to use only one/two at a time. Using this approach will make the code more concise and efficient.</p><p>Thanks for Reading!!! Happy Coding!!!</p><p>Github Link : <a href="https://github.com/vinay4791/SolidPrinciples">https://github.com/vinay4791/SolidPrinciples</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f99f952fa6ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Dagger2 — Simple Steps for Beginners.]]></title>
            <link>https://medium.com/@vinayjohn/integrating-dagger2-simple-steps-553b8462177b?source=rss-b39f625ae68------2</link>
            <guid isPermaLink="false">https://medium.com/p/553b8462177b</guid>
            <category><![CDATA[dagger-2]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[simple]]></category>
            <dc:creator><![CDATA[Vinay John]]></dc:creator>
            <pubDate>Tue, 26 Jun 2018 07:30:36 GMT</pubDate>
            <atom:updated>2018-06-26T07:32:26.661Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Dependency injection</strong> is a technique whereby one object (or static method) supplies the dependencies of another object.</p><p>A <strong>Dependency</strong> can be an instance of a Class(an Object) which can be used in another instance of a Class. An <strong>Injection</strong> is the process of passing a <strong>Dependency</strong> to a dependent object that would use it.</p><p><strong>Dagger2</strong> is a widely used Dependency Injection FrameWork which is used in Android application development.It uses code generation and is based on annotations.</p><p>The Commonly used annotations in Dagger2 are :<br><strong>@Module : </strong>This annotation is used with a class which is called a <strong>Module</strong> in which we will define functions which will return the <strong>Dependencies</strong> that can be used in a <strong>Dependent</strong> class.</p><p><strong>@Provides : </strong>This annotation is used with a function which will return a <strong>Dependency .</strong>These functions will be written in the Module class.We need to add the <strong><em>@Provides</em> </strong>annotation on methods that construct our dependencies</p><p><strong>@Component : </strong>This Annotation is used with an interface which is called a <strong>Component,</strong> in which we will specify all the <strong>Dependent</strong> Classes which uses the <strong>Dependencies</strong> defined in a module.In short Component is the thing which will link the Module which define the <strong>Dependencies</strong> with the classes which uses the <strong>Dependents</strong>.</p><p>@<strong>Inject</strong> : This annotation request dependencies. Can be used on a constructor, a field, or a method.</p><p><strong>So,Why Dependency Injection?</strong></p><p>Consider that I have a Class Dog that is dependent on a Class Animal.<em>ie</em>, for carrying out some functionality in Class Dog I need an instance on Class Animal.Usually we do Animal animal = new Animal(); inside Dog.<br>But, when using Dependency injection we will get an instance of Animal from outside.This has the following benefits :-</p><ul><li>We can use Dog in a different context as a separate component.</li><li>We can a use a mock implementation of Animal and test the Dog component independently.</li><li>The readability of Dog gets increased.You don’t have to look through all the code to see what dependencies you need to satisfy for a given component.</li></ul><p>So, we are going to use Dagger2 in an Android project.This is a simple example in which we have two Java classes <strong>Animal</strong> and <strong>Dog</strong> and an Activity <strong>MainActivity</strong>.Here MainActivity is dependent on Dog and Dog is dependent on Animal.We will inject Animal class into Dog via the constructor of Dog class and will inject Dog into MainActivity via a field.We have already stated that we can do dependency injection via a Constructor, a Field or a Method.</p><p>First step, is to add the dependencies in your <strong><em>build.gradle</em></strong> file</p><pre>implementation <strong>&#39;com.google.dagger:dagger-android:2.11&#39;<br></strong>implementation <strong>&#39;com.google.dagger:dagger-android-support:2.11&#39;<br></strong>annotationProcessor <strong>&#39;com.google.dagger:dagger-android-processor:2.11&#39;<br></strong>annotationProcessor <strong>&#39;com.google.dagger:dagger-compiler:2.11&#39;</strong></pre><p>Next we will create two Java Classes namely <strong>Animal</strong></p><pre><strong>public class </strong>Animal {<br><br>    <strong>private </strong>String <strong>type</strong>;<br><br>    <strong>public </strong>Animal() {<br>        <strong>this</strong>.<strong>type </strong>= <strong>&quot;Mammal&quot;</strong>;<br>    }<br><br>    <strong>public </strong>String getType() {<br>        <strong>return type</strong>;<br>    }<br>}</pre><p>and <strong>Dog</strong></p><pre><strong>public class </strong>Dog {<br><br>    <strong>private </strong>Animal <strong>animal</strong>;<br><br>    @Inject<br>    <strong>public </strong>Dog(Animal animal) {<br>        <strong>this</strong>.<strong>animal </strong>= animal;<br>    }<br><br>    <strong>public </strong>String getType() {<br>        <strong>return animal</strong>.getType();<br>    }<br><br>}</pre><p>In the above class <strong>Dog</strong> we can see that we have used the <strong><em>@Inject</em></strong> annotation on the constructor which will inject <strong>Animal</strong> into the <strong>Dog</strong> class.Now, we will see How the injection is Done.</p><p>We will define our <strong>AppModule</strong>.</p><pre>@Module<br><strong>public class </strong>AppModule {</pre><pre>    App <strong>mApplication</strong>;</pre><pre>    <strong>public </strong>AppModule(App application) {<br>        <strong>mApplication </strong>= application;<br>    }</pre><pre>    @Provides<br>    Animal provideAnimal() {<br>        <strong>return new </strong>Animal();<br>    }</pre><pre>    @Provides<br>    Dog providesDog(Animal animal) {<br>        <strong>return new </strong>Dog(animal);<br>    }</pre><pre>}</pre><p>Here we can see that via a function <strong><em>provideAnimal()</em></strong> we are returning an Instance of the Animal class and via a a function <strong><em>providesDog() </em></strong>we are returning an Instance of the Dog class.</p><p><em>Please note : Since, </em><strong><em>provideAnimal()</em></strong><em> is declared before </em><strong><em>providesDog()</em></strong><em> and we have specified the </em><strong><em>@Inject</em></strong><em> annotation in the constructor of the Dog class we will get the instance of Class Animal as an argument in providesDog(Animal animal).</em></p><p>Now we are going to create our Component interface.</p><p>We already stated above that Component is an interface which is annotated by the <strong><em>@Component</em></strong> annotation.</p><pre>@Singleton<br>@Component(modules = {AppModule.<strong>class</strong>})<br><strong>public interface </strong>AppComponent {<br><br>    <strong>void </strong>inject(MainActivity mainActivity);<br><br>}</pre><p><strong>@Singleton</strong> makes your class a single instance in your dependencies graph.In short — everytime you’re injecting @Singleton annotated class (with @Inject annotation) it will be the same instance as long as you inject it from the same Component.</p><p><em>Normally we give Singleton annotation for components which we specify as the Base Component in the Application class.</em></p><p>In the above piece of code you can see that we can specify the Modules which are linked to a Component using the @Component annotation. In the above piece of code @Component(modules = {AppModule.<strong>class</strong>}).</p><p><em>In short we can say that Component will have a </em><strong><em>HAS-A</em></strong><em> relationship with the Modules specified in it.</em></p><p>So, in this case AppComponent <strong>HAS-A</strong> AppModule.</p><p><em>Components are basically used to specify Dependent Classes such as ViewModels or Activities which will use the Dependencies specified in the related Modules using the @Provides annotation.</em></p><p>During compilation, <em>Dagger2 </em>creates concrete class implementations triggered on the <em>Component</em> interfaces with names prefixed with <em>Dagger</em>, e.g., <strong><em>DaggerAppComponent</em></strong> in this case.</p><p>So, we need to instantiate these class in the Application class since, the Application class starts first.</p><p>So,I created my Application class named <strong>App </strong>and defined the<strong> AppComponent </strong>instance<strong>.</strong></p><pre><strong>public class </strong>App <strong>extends </strong>Application {<br><br>    <strong>private static </strong>AppComponent <em>mAppComponent</em>;<br>    <strong>private static </strong>App <em>instance </em>= <strong>null</strong>;<br><br>    <strong>public static </strong>App getInstance() {<br>        <strong>return </strong><em>instance</em>;<br>    }<br><br>    @Override<br>    <strong>public void </strong>onCreate() {<br>        <strong>super</strong>.onCreate();<br>        <em>instance </em>= <strong>this</strong>;<br>        <br>        <em>mAppComponent </em>= DaggerAppComponent.<em>builder</em>() <br>                .appModule(<strong>new </strong>AppModule(<strong>this</strong>))<br>                .build();<br>    }<br><br>    <strong>public static </strong>AppComponent getAppComponent() {<br>        <strong>return </strong><em>getInstance</em>().<em>mAppComponent</em>;<br>    }<br>}</pre><p>Don’t forget to specify the Application class in Manifest file.</p><pre>&lt;<strong>application<br>    android:name=&quot;.App&quot;<br>    android:allowBackup=&quot;true&quot;<br>    ......</strong></pre><pre>&lt;/<strong>application</strong>&gt;</pre><p>Now inside our MainActivity we can access the Dog instance using the <strong><em>@inject </em></strong>annotation.</p><p>Please note : If you want to use the injection in an Activity or a ViewModel we should setup the component in the respective classes.</p><pre><strong>public class </strong>MainActivity <strong>extends </strong>AppCompatActivity {<br><br>    @Inject<br>    Dog <strong>dog</strong>;<br><br>    @Override<br>    <strong>protected void </strong>onCreate(Bundle savedInstanceState) {<br>        <strong>super</strong>.onCreate(savedInstanceState);<br>        setContentView(R.layout.<strong><em>activity_main</em></strong>);<br>        setupActivityComponent();<br>        printDependencyExample();<br>    }<br><br>    <strong>private void </strong>setupActivityComponent(){<br>        App.<em>getAppComponent</em>().inject(<strong>this</strong>);<br>    }<br><br>    <strong>private void </strong>printDependencyExample(){<br>        Toast.<em>makeText</em>(<strong>this</strong>, <strong>dog</strong>.getType(), Toast.<strong><em>LENGTH_SHORT</em></strong>).show();<br>    }<br>}</pre><p><em>Inside the </em><strong><em>setupActivityComponent()</em></strong><em> it is not mandatory that we should name the function as inject we can use any word .if we are using plus instead of inject ie,<br>App.getAppComponent().plus(this) then the code inside the AppComponent will be generated as </em><strong><em>void plus</em></strong><em>(MainActivity mainActivity).</em></p><p><em>You can find the complete project in this </em><a href="https://github.com/vinay4791/DaggerSimplified"><strong><em>link</em></strong></a><em> .</em></p><p>sources :<br><a href="https://en.wikipedia.org/wiki/Dependency_injection">https://en.wikipedia.org/wiki/Dependency_injection</a><br><a href="https://github.com/google/dagger">https://github.com/google/dagger</a></p><p><a href="http://tutorials.jenkov.com/dependency-injection/dependency-injection-benefits.html">http://tutorials.jenkov.com/dependency-injection/dependency-injection-benefits.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=553b8462177b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactive Programming in Android]]></title>
            <link>https://medium.com/digital-banking-labs/reactive-programming-in-android-10d66fc7813?source=rss-b39f625ae68------2</link>
            <guid isPermaLink="false">https://medium.com/p/10d66fc7813</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[rxjava]]></category>
            <dc:creator><![CDATA[Vinay John]]></dc:creator>
            <pubDate>Thu, 13 Apr 2017 06:20:31 GMT</pubDate>
            <atom:updated>2017-04-17T09:55:49.659Z</atom:updated>
            <content:encoded><![CDATA[<p>In most Android applications, you are reacting to user interactions (clicks, swipes and etc.) while doing something else in the background for eg. networking.</p><p>One hard thing is that we should orchestrate all these and the application should react accordingly.</p><p>Consider that in an application we send a request to a database over the network to fetch the details of a user and after that completes based on some key we need to fetch the preferences of the user at the same time, and after all of that is we should populate the UI combining both the responses.<br>Normally in android, we will possibly use:</p><ol><li>3–4 different <a href="https://developer.android.com/reference/android/os/AsyncTask.html">AsyncTasks</a>.</li><li>Some locking mechanism.</li><li>Object-level fields to store the results.</li><li>Some functionality to combine the results.</li><li>Some code to manipulate the incoming data if needed.</li></ol><p>Here comes the advantage of Reactive programming with <a href="https://github.com/ReactiveX/RxJava"><strong>RxJava</strong></a>. All of this can be written in a single flow in one place based on a functional paradigm.</p><blockquote>RxJava is a Java VM implementation of <a href="http://reactivex.io/">Reactive Extensions</a>: a library for composing asynchronous and event-based programs by using observable sequences.</blockquote><blockquote>It extends the <a href="http://en.wikipedia.org/wiki/Observer_pattern">observer pattern</a> to support sequences of data/events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety and concurrent data structures.</blockquote><p>It is a style of programming where you define a source of data and a consumer of that data. Once you connect the consumer to the source, the framework takes care of pushing the data, generated by the source, to the consumer.</p><p>The above definition talks about three important things. I will be explaining each of these in detail.</p><ul><li>Source of data</li><li>Consumer of data</li><li>Connecting Consumer to Source</li></ul><p>The major building blocks of RxJava are the <strong>Observer </strong>and the <strong>Observable</strong>.<br><strong>Observer</strong> — any object that wishes to be notified when the state of another object changes(consumer of data). The corresponding functions are <strong>onNext()</strong>, <strong>onError()</strong>, and <strong>onCompleted()</strong> from the <a href="https://github.com/ReactiveX/RxJava/blob/1.x/src/main/java/rx/Observer.java">Observer interface</a>.</p><p><strong>Observable</strong> — any object whose state may be of interest, and in whom another object may register an interest(source of data).</p><p><strong>Subscription</strong> instance- is responsible for connecting the consumer to the source.</p><p>A <strong>Subscription</strong> instance represents the connection between an observer and an observable. We can call unsubscribe() on the particular instance whenever we want to remove the connection between the observer and the observable.When an observable object is newly created, its set of observers is empty until we connect an Observer with it using the Subscription interface.</p><p>For using RxJava in Android we need to add the following libraries in your <em>build.gradle </em>file.</p><pre>compile &#39;io.reactivex:rxjava:1.1.0&#39;<br>compile &#39;io.reactivex:rxandroid:1.1.0&#39; // for android platform</pre><p><em>Please note: recommended to use the latest versions.</em></p><p>Let us go through a simple example:</p><pre>Observable&lt;String&gt; observable = Observable.<em>just</em>(<strong>&quot;Piano&quot;, &quot;Violin&quot;</strong>);</pre><p>This is an <strong>Observable</strong> which will emit the strings “Piano” and “Violin” and it can be observed by an <strong>Observer</strong>.</p><p>Now Let us create an Observer:</p><pre>Observer&lt;String&gt; observer = <strong>new </strong>Observer&lt;String&gt;() {<br>    @Override<br>    <strong>public void </strong>onCompleted() {<br>        //do something when the emission completes<br>    }<br><br>    @Override<br>    <strong>public void </strong>onError(Throwable e) {<br>        //do something when error happens<br>    }<br><br>    @Override<br>    <strong>public void </strong>onNext(String response) {<br>        <strong>System.out.println(&quot;instruments : &quot; </strong>+ response);<br>    }<br>};</pre><p>Finally, we have to connect both <strong>Observable</strong> and <strong>Observer</strong> with a subscription.</p><pre>observable.subscribe(observer);</pre><p>This will produce the following output:</p><pre>instruments : Piano<br>instruments : Violin</pre><p>The <strong>Observable</strong> emits the two objects (strings in this case) which are observed by the <strong>Observer</strong>. At this point, you can use a variety of operators to filter or transform the data according to your business needs. See the official Rx operator documentation or <a href="http://rxmarbles.com/">this</a> page for a list of operators.</p><p>The onCompleted() is invoked once the observable has no other data to emit, terminating the emission.</p><p>The onError() function will be invoked if there are any errors during processing an object. You can use this callback to handle error propagation.</p><p>sources :</p><p><a href="http://reactivex.io/documentation/observable.html">http://reactivex.io/documentation/observable.html</a><br><a href="https://github.com/ReactiveX/RxJava/wiki">https://github.com/ReactiveX/RxJava/wiki</a><br><a href="https://dzone.com/articles/rxjava-part-1-a-quick-introduction">https://dzone.com/articles/rxjava-part-1-a-quick-introduction</a><br><a href="http://blog.feedpresso.com/2016/01/25/why-you-should-use-rxjava-in-android-a-short-introduction-to-rxjava.html">http://blog.feedpresso.com/2016/01/25/why-you-should-use-rxjava-in-android-a-short-introduction-to-rxjava.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10d66fc7813" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digital-banking-labs/reactive-programming-in-android-10d66fc7813">Reactive Programming in Android</a> was originally published in <a href="https://medium.com/digital-banking-labs">Digital Banking Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>