<?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 Nikola Despotoski on Medium]]></title>
        <description><![CDATA[Stories by Nikola Despotoski on Medium]]></description>
        <link>https://medium.com/@nikoladespotoski?source=rss-54df77ce6735------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XaIOA97OWEUOa1qWaNK74g.jpeg</url>
            <title>Stories by Nikola Despotoski on Medium</title>
            <link>https://medium.com/@nikoladespotoski?source=rss-54df77ce6735------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 06:26:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nikoladespotoski/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[Generate proguard rules out of apiDump output]]></title>
            <link>https://nikoladespotoski.medium.com/generate-proguard-rules-out-of-apidump-output-cb0c32b10603?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb0c32b10603</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[sdk-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin-libraries]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Fri, 10 Oct 2025 08:26:49 GMT</pubDate>
            <atom:updated>2025-10-10T08:26:49.232Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3FL6MYthTd_BaG3xunS3A.png" /></figure><p>When delivering libraries or proprietary SDKs, obfuscation is just as mandatory as it is for applications. However, integration on the client side can easily turn into a disaster — even if you were celebrating that release — once integration begins.</p><p>Typical symptoms of such a derailed release include missing imports, the inability to override functions or access class members that were previously available. These issues often occur because obfuscation assigned new symbols to those members.</p><p>In larger teams, where changes are constantly coming from multiple directions, it’s easy to lose track of which APIs are publicly exposed and forget to exclude them from the obfuscation process.</p><p>This inconvenience can be completely avoided by using the <a href="https://github.com/Kotlin/binary-compatibility-validator"><strong>Kotlin Binary Compatibility Validator</strong></a><strong> (KBCV)</strong> to inventory your exposed APIs, along with a bit of Gradle task automation to make your life — and your release — a little easier.</p><p>The solution revolves around the output of the KBCV’s apiDump task. By comparing your current ProGuard rule set against the list of publicly exposed APIs in the .api file, the task can detect missing rules and perform a line-by-line comparison to ensure all public entries are properly preserved.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50ad2300c8ac48b24d63448500cc6df7/href">https://medium.com/media/50ad2300c8ac48b24d63448500cc6df7/href</a></iframe><p>The output of this task is updated .api file and updated proguard rules, that you might like to review and later commit.</p><h4>Of course, you should not make this part of your pipeline, glad you asked, not explicitly, for starters just add this.</h4><pre>  api_check:<br>    name: 🔌 API Compatibility Check<br>    ....<br>    steps:<br>      - uses: actions/checkout@v5<br>        ....<br>        uses: gradle/gradle-build-action@v3<br>      - run: chmod +x ./gradlew<br>      - run: ./gradlew :service-sdk:apiCheck</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb0c32b10603" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pass data in the Modifier tree and beyond]]></title>
            <link>https://nikoladespotoski.medium.com/pass-data-in-the-modifier-tree-and-beyond-dfdfd4892228?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfdfd4892228</guid>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[compose-ui]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 10:49:04 GMT</pubDate>
            <atom:updated>2024-09-18T10:59:31.482Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lP8oE21a0d8AtxeW-Eyjzw.jpeg" /><figcaption>ModifierLocal didn’t get enough attention to be cancelled like CompositionalLocal</figcaption></figure><p>One of the reasons why the order of Modifiers is important could be summed by passing data from one modifier node to other nodes right of it.</p><p>Why to the right? You can pass data from a node in the tree to the right along the modifier chain. Modifiers can pass data to all the modifiers to the right using Modifier.modifierLocalProvider(key) { value }. Modifiers can retrieve and update data using Modifier.modifierLocalConsumer { }. The lambda block of the consumer will be called each time the state (attached, detached, etc.), the order of the modifier nodes, or the provided data changes.</p><p>Similar to CompositionLocal, ModifierLocal works the same way but in the modifier tree.</p><p>Let’s look at this example where we declare our ModifierLocal to allow other modifiers in the tree to pass the instance of MyScope.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0392d133488d5057855202fd6d65f7fa/href">https://medium.com/media/0392d133488d5057855202fd6d65f7fa/href</a></iframe><p>You can notice that passed modifier is concatenated last in the chain, to the right of the modifier that starts the chain and to the right of modifierLocalProvider { }.</p><pre>Modifier.fillMaxSize()<br>        .modifierLocalProvider(ModifierLocalMyScope) { scope }<br>        .then(modifier)</pre><h3>Within Modifier tree</h3><p>There are two ways to read data from ModifierLocals: using modifierLocalConsumer { } or implementing ModifierLocalConsumer. The ModifierLocalConsumer interface has an onModifierLocalsUpdated function that is called whenever there is a change in the modifier order or local data. By implementing this interface, you can delegate the task of passing data to other modifier implementations.</p><h3>Beyond Modifier tree</h3><p>As the passed modifier is added last, we can get an instance of the scope at the calling site and use it in the composition context. By setting the passed modifier last in the chain, you can pass data up from the modifier tree to higher levels and even interact with the composition context.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6ea6818df1a40125530c1120a7e3cea/href">https://medium.com/media/f6ea6818df1a40125530c1120a7e3cea/href</a></iframe><p>Observing changes in the Locals within the modifier trees allows us to get an instance and use it in the composition context later.</p><pre>.modifierLocalConsumer {<br>  myScope = ModifierLocalMyScope.current<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfdfd4892228" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrate your composed { } modifiers]]></title>
            <link>https://nikoladespotoski.medium.com/migrate-your-composed-modifiers-1b45503491f4?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b45503491f4</guid>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Tue, 12 Mar 2024 13:12:43 GMT</pubDate>
            <atom:updated>2024-03-12T13:12:43.142Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://github.com/slackhq/compose-lints">Compose lint</a> checks used in the project raised warning that composed { } implementation is no longer recommended because of performance issues it causes. Without further investigation, accepted that statement as true and started working on replacing them with Node implementation.</p><p><strong>Steps:</strong></p><ol><li>A Modifier receiver function that will create the ModifierNodeElement implementation and appended to the Modifier chain list. This function shoul act as a factory of the ModifierNodeElement.</li><li>A ModifierNodeElement that has responsibility to create instance of the Node and updating it, this implementation should not hold any state. This class is immutable, consequentially, it should be a data class . update(node) function is called when inputs have changed, the parameter is the current instance of the node and has to be updated with the new inputs.</li><li>A Node implementation, this is the functional implementation. This is where you hold and update the state. Cordially put, this is where you put everything you had in a remember{ } block in thecomposed { } block.</li></ol><p><strong>Interface for your Node</strong></p><p>You may need to know to make right choice which implementation of Node you need to use for your functionality. Namely, if your node has to draw, you should implement <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/DrawModifierNode.kt">DrawModifierNode</a> . For improving accessibility, or maybe you have custom test tags, <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/SemanticsModifierNode.kt">SemanticsModifierNode</a> is best choice. Layout and measuring related operations are covered in <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutModifierNode.kt">LayoutModifierNode</a> , <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/LayoutAwareModifierNode.kt">LayoutAwareModifierNode</a> and <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/GlobalPositionAwareModifierNode.kt">GlobalPositionAwareModifierNode</a> . <br>Most common use case is implementing exotic touch behaviors, you can do so with <a href="https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/node/PointerInputModifierNode.kt">PointerInputModifierNode</a> .</p><h4>Before</h4><p>This is pretty straight forward example, where we draw a Path behind the content. In the composed{ } block we remember the Path to reuse it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7d1314b1babf2e2f84ec30a95774b6a/href">https://medium.com/media/a7d1314b1babf2e2f84ec30a95774b6a/href</a></iframe><h4>After</h4><ol><li>First we have the Modifier.curve function that works as factory for the our custom modifier.</li><li>Next is our ModifierNodeElement implementation that will create and update our Node implementation. This new modifier will be called on the next composition of modifier tree, if the inputs have changed and will update our Node .</li><li>Finally, CurveNode is actual class that draws and contains the state that was remembered previously in the composed {} block. <br>The complexity has increased for the price of the performance.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b946130444ed25bf8e926a0bd3a27a7/href">https://medium.com/media/0b946130444ed25bf8e926a0bd3a27a7/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b45503491f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Compose CompositionLocalProvider]]></title>
            <link>https://nikoladespotoski.medium.com/compose-compositionlocalprovider-ec05df25fd1a?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec05df25fd1a</guid>
            <category><![CDATA[jetpack]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Wed, 18 May 2022 09:43:20 GMT</pubDate>
            <atom:updated>2022-05-18T09:43:20.253Z</atom:updated>
            <content:encoded><![CDATA[<p>CompositionLocalProvideris useful for sharing objects between composables without passing them as function parameters. Objects are stored in the composer and are available in the current tree that CompositionLocalProvider wraps.</p><p>Compose offers providing data in static and observable manner, compositionLocalOf maintains a mutable state of the provided object and forces recomposition where the provided value is read. On the other hand, staticCompositionalLocalOf doesn’t observe changes in the object and will not trigger recomposition where the provided value is read.</p><h4>Static</h4><p>staticCompositionalLocalOf can be used when we are sure that the object will most likely not change, practically immutable. staticCompositionalLocalOf is efficient when used for values that are stored once and we want to make sure that updates to it do not have side effects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IicMhooNlJW_iDU0hQhIJw.png" /></figure><p>Initially, the value for our LocalActivityIntent is not provided and calling it prior it will force the default value factory that is called lazily throw and error.</p><p>We have to provide the value before it is used any where in our composables in the scope of the CompositionLocalProvider.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8_LOrRAIn65DCaqA69nrw.png" /></figure><h4>Non-static</h4><p>Objects provided with compositionLocalOf can be easily misused and tracking the unnecessary recompositions is hard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E9_IrG0FsVEvIJwJxKk-Aw.png" /></figure><p>Updating the state of the Shape object our LocalShape will trigger recomposition where the value is read, but it can be done from anywhere because of the CompositionLocalProvider . If we would have used the Shape as parameter in the composables then we are in control when and where the object mutates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec05df25fd1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Eliminating backing property type in Kotlin 1.7]]></title>
            <link>https://nikoladespotoski.medium.com/overriding-backing-property-type-in-kotlin-1-7-5581cd30e77a?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/5581cd30e77a</guid>
            <category><![CDATA[androiddevelopmentcompany]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 16:46:50 GMT</pubDate>
            <atom:updated>2022-04-11T12:53:13.107Z</atom:updated>
            <content:encoded><![CDATA[<p>At one KotlinConf, I don’t quite recall which year it was, overriding backing properties type (eliminating the backing prop completely) was most wanted language feature along side with contextual receiver extension functions.</p><p>It is certain that every kotlin codebase now has following, one private property that is mutable and one immutable backed by the mutable, that is exposed for consuming:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ByTuTFzyw61erGZqavJtZw.png" /></figure><p>In Kotlin 1.7, this will be history, and we will be able to override property getter type. This language feature will enable having one property for updating and read-only operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*baEpYRjRAnbcpUznTGzA2w.png" /></figure><p>I assume the compile sees that the property is private but the getter is explicitly set as public and generates getter function with the immutable type. This does not interferes with private getter which probably uses the local context and does not mix up the public getter.</p><p>In current Kotlin version this is conflicting visibility and getter must follow property declared visibility.</p><p>Personally, I can’t wait to start using this feature!</p><p>Follow full discussion here:</p><p><a href="https://youtrack.jetbrains.com/issue/KT-14663">https://youtrack.jetbrains.com/issue/KT-14663</a></p><p>Update (11.04.2022): <br>Thank you <a href="https://medium.com/u/be40b368c57e">Matthew Dolan</a> for linking the update readme on backing property proposal:<br><a href="https://github.com/Kotlin/KEEP/blob/explicit-backing-fields-re/proposals/explicit-backing-fields.md">https://github.com/Kotlin/KEEP/blob/explicit-backing-fields-re/proposals/explicit-backing-fields.md</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5581cd30e77a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hands on Google KSP]]></title>
            <link>https://nikoladespotoski.medium.com/hands-on-google-ksp-c0508d623863?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0508d623863</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Mon, 27 Sep 2021 13:09:58 GMT</pubDate>
            <atom:updated>2021-09-27T13:09:58.532Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*ciIprPJqgl_gOq-DAAMc7w.png" /></figure><h3>Documentation</h3><p>KSP documentation is both, the quite and the confusion of my heart. It lacks details how to setup the project, but provides amazing map on how KSP sees symbols. No, there are no stackoverflow posts on how to use KSP beside using it as alternative to kapt .</p><h3>Setup</h3><p>Official setup guide has failed to mention how and where to reference your processor provider. Use META-INF resource directory to reference your processor processor in your processormodule:</p><pre>src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider</pre><p>In this file you reference your ProcessorProvider:</p><pre>com.my.package.processor.MySymbolProcessorProvider</pre><p>This is important step in order your processor provider be recognized and later instantiate the actual processor.</p><h3>Dependency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*IJQwRu_ef2rkzUf4QZ1DZQ.png" /><figcaption>LEnk is just a name for the project</figcaption></figure><p>In the figure you notice the how modules relate between each other. It is important caveat to that only and only the application module will reference the processor with ksp(project(&quot;:processor&quot;)) . And only the application module will apply the ksp plugin and be able to provide arguments to the KSP plugin:</p><pre>plugins <strong>{<br>    </strong>id(&quot;com.android.application&quot;)<br>    id(&quot;kotlin-android&quot;)<br>    id(&quot;com.google.devtools.ksp&quot;)<br><strong>}</strong></pre><pre>ksp {<br>  arg(&quot;verbose&quot;, &quot;true&quot;)<br>}</pre><h3>Processor</h3><p>Official manual provides you with sufficient information how to utilize the Resolver to search for annotated symbols and validation of each symbol found.</p><p>KSP implemented, what they call, <a href="https://github.com/google/ksp/blob/main/docs/multi-round.md">multiple-round symbol processing</a> which you might notice that it runs your processor multiple times. This will allow you to process even newly generated files from any previous round. Multiple round will stop when no more files are generated. At first, I wasn’t getting how it impacts the processing until I end up in <a href="https://github.com/google/ksp/issues/624">this dead end.</a></p><h3>Mind Map</h3><p>Luckily the documentation describes how KSP sees your kotlin files in details. Essentially it also covers in detail how nodes are represented in KSP context.</p><p>Each keyword in the kotlin file is a KSNode the building interface of KSDeclaration . KSDeclaration is key interface when it comes to resolving the types or KSType in your implementation.</p><p>On multiple occasions, I was at a position to backtrack to KSDeclaration to find the KSType .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*zVE6MUnk19o6kBFSAfJf0g.png" /><figcaption>Taken from <a href="https://github.com/google/ksp#how-ksp-looks-at-source-files">https://github.com/google/ksp#how-ksp-looks-at-source-files</a></figcaption></figure><h3>Visitors</h3><p>Symbol or Annotation processing starts by visiting the KSAnnotated results upon Resolver has delivered the look up for your symbols.</p><p>Each KSNode has accept(visitor, data) function that will visit next KSDeclaration .</p><p>Example:</p><pre>override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: FuncSpec) {<br>val functionSpecs = classDeclaration.<em>getDeclaredFunctions</em>()<br>    .<em>toSet</em>()<strong><br>    </strong>.<em>map </em><strong>{</strong><br>        <strong>it</strong>.accept(MyFunctionVisitor(resolver), <strong>it</strong>)<br>    <strong>}<br> return </strong>functionSpecs<br><strong>}</strong></pre><p>Logically, each class contains functions, as seen in Mind Map section of this article,MyFunctionVisitor will visit all KSFunctionDeclaration in it’s visitFunctionDeclaration function. You may guess, next to visit is function parameters which are represented as KSValueParameters therefore visitValueParameters will be called on the next visit when params.accept(visitor, data) is called. defaultHandler function will be called if you haven’t provided implementation for visiting particular KSDeclaration . I leave a TODO() so I everything blows up and I have to be forced to implement a visit.</p><h3>KotlinPoet interop</h3><p>I prefer to use KotlinPoet for code generation, as of 1.10.0 it has nice set of extensions for working with KSP.</p><h3>Other</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dbc66103f03a758c269381383a43877/href">https://medium.com/media/1dbc66103f03a758c269381383a43877/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0508d623863" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Repeatedly, I made few mistakes while using the new `registerForActivityResult` API, resulting in…]]></title>
            <link>https://nikoladespotoski.medium.com/repeatedly-i-made-few-mistakes-while-using-the-new-registerforactivityresult-api-resulting-in-75931cdd43b2?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/75931cdd43b2</guid>
            <category><![CDATA[intellij]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-lint]]></category>
            <category><![CDATA[android-studio]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Mon, 02 Nov 2020 16:02:44 GMT</pubDate>
            <atom:updated>2020-11-02T16:07:58.424Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linting functions that need to be called from specific lifecycle methods</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*vuNsHR15L8MlAvsUlE5_WA.png" /><figcaption>google: lint</figcaption></figure><p>Repeatedly, I made few mistakes while using the new <a href="https://developer.android.com/reference/androidx/fragment/app/Fragment#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract%3CI,%20O%3E,%20androidx.activity.result.ActivityResultCallback%3CO%3E)">registerForActivityResult</a>API, resulting in error:</p><pre>Fatal Exception: java.lang.IllegalStateException: Fragment MyFragment{e964a6} (573498bb-7d87–4d58–9e84–59223f13f14c) id=0x7f0a00b3} is attempting to registerForActivityResult after being created. Fragments must call registerForActivityResult() before they are created (i.e. initialization, onAttach(), or onCreate()). at androidx.fragment.app.Fragment.prepareCallInternal(Fragment.java:3) at com.package.name.android.ui.MyFragment.registerForActivityResult(MyFragment.java:15)</pre><p>Developers should be provided with compile-time lint error or/and <a href="https://www.jetbrains.com/help/idea/code-inspection.html">Code Inspections </a>for such specific misuse of lifecycle-sensitive function calls.</p><p>I wrote myself one to remind me that I’m ending up in usability issue. This lint check searches for usage of registerForActivityResultoutside onCreateor onAttachlifecycle functions in Fragmentor Activitysubclasses.</p><p>It considers unary expressions, such as:</p><pre>registerForActivityResult(contract, callback).launch(argument)</pre><p>and binary expressions:</p><pre>launcher = registerForActivity(contract, callback)</pre><p>which object will be used to call launch(arguments) .</p><p>This lint won’t show warning, if function call is made in another function, unfortunately deeper function stacks are not considered, also calls inside lambdas remain unchecked.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64a3779145400d929ffb81686e2e65e0/href">https://medium.com/media/64a3779145400d929ffb81686e2e65e0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75931cdd43b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Consume Activity result directly in the ViewModel]]></title>
            <link>https://nikoladespotoski.medium.com/consume-activity-result-directly-in-the-viewmodel-3faeac191920?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/3faeac191920</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Tue, 31 Mar 2020 09:53:39 GMT</pubDate>
            <atom:updated>2020-03-31T09:56:37.052Z</atom:updated>
            <content:encoded><![CDATA[<p>Most common implementation of Delegation pattern is when the responsibility of the class is delegated to a real object of a concrete implementation of the same interface.</p><pre>class HomeAcrobat implements Acrobat {<br>   private final Acrobat mProAcrobat = new CircusAcrobat();<br>   <a href="http://twitter.com/Override">@Override</a><br>   public void doAmazingStuff(){<br>      mProAcrobat.doAmazingStuff();<br>  } <br>}</pre><p>Kotlin gives amazing and neat way to implement Delegation pattern using the keyword by. This gives impression of having multiple inheritance, it is still a polymorphisms in a sense.</p><p>In activity-ktx:1.3.+, requesting and receiving results where taken to a new level with introduction of ActivityResultContract&lt;I, O&gt; and ActivityResultCallback. ActivityResultContract&lt;I, O&gt; is an interface that performs how and who will get the request for result, and ActivityResultCallback is how the consumer will consume the result.</p><p>But Google left us with ActivityResultContract abstract class which is the only obstacle we have to jump.</p><p>Consider we are advocates of separation of concerns and we want to take take the parsing of the result in another class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4169806f057870337c54b3cd842f5228/href">https://medium.com/media/4169806f057870337c54b3cd842f5228/href</a></iframe><p>You may notice the interface ActivityResultContractor&lt;I, O&gt;, this is extracted interface from ActivityResultContract.</p><p>With a minor tweak to the prepareCall() function, we can wrap our contractor to work as library providedActivityResultContract.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82582a56722a3fa4523f703a2bb9e703/href">https://medium.com/media/82582a56722a3fa4523f703a2bb9e703/href</a></iframe><p>This function will be called from the Fragment or Activity, since they are only able to launch another Activity.</p><p>Our goal is to make the ViewModel be able to parse and receive the result. You may notice that now the ProductViewModelalso acts like a contractor but the parsing of the result is delegated to the activityResultContract using this syntax ActivityResultContractor&lt;Nothing, String&gt; <strong>by</strong> activityResultContractor.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/83695e67f10c7310cc85d448a2cc98f9/href">https://medium.com/media/83695e67f10c7310cc85d448a2cc98f9/href</a></iframe><p>Final call to the tweaked prepareCall() would be:</p><pre> chooseProductFilter.setOnClickListener {<br>    prepareCall(productViewModel, productViewModel)<br> }</pre><p>Another example of calling launch(), when the input type is not Unit:</p><pre><br> textLiveData.observe(viewLifecycle){<br> prepareCall(productViewModel, productViewModel).launch(it)<br> }<br></pre><p>Thank you and #StayAtHome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3faeac191920" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Centralized LiveData with Kotlin 1.2]]></title>
            <link>https://nikoladespotoski.medium.com/centralized-livedata-with-kotlin-1-2-97bff1b2cb5c?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/97bff1b2cb5c</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Mon, 04 Dec 2017 15:44:45 GMT</pubDate>
            <atom:updated>2017-12-04T15:56:43.383Z</atom:updated>
            <content:encoded><![CDATA[<p>The very first crash I got when started Kotlin was, you may guess, UninitializedPropertyAccessException, because somewhere I used lateinit var property without prior initialization. This thought me to be more careful with fields (Java) and properties.</p><h3>1.2, y tho?</h3><p>In Kotlin 1.2 <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-property0/index.html">KProperty0&lt;..&gt;</a> was introduced with really helpful property isInitialized. This inherited property denotes wither your property has been intialized in given receiver (<em>reciever</em> is the class that contains your property you are accessing isInitialized).</p><blockquote>This property is annotated with @Since(&quot;1.2&quot;), therefore you must use 1.2 version. In previous versions there is option to use <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-lazy/is-initialized.html"><em>isInitialized()</em></a> for lazy references.</blockquote><h3>MediatorLiveData is awesome</h3><p>MediatorLiveData is extremely seamless way to combine other LiveDatasources (of different types, Yas!) and all start being observed at same time.</p><p>Having separate LiveData channels for each type of event (result, error, progress, loading state etc), that is govern by one implementation on top of MediatorLiveData and takes the centralization inside BaseMediatorLiveData instead inside the Observer-end. You may say the graph you are about to see, resembles a simple LiveData for API request, you are not far from the truth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*njaVpyGurC9-v5I2x8gCMg.png" /><figcaption>Centralized</figcaption></figure><p>isInitialized comes handy when we have to decide if the other LiveData channels have been initialized or not, before they are plugged to be observed. If the observers are not initialized, there is no need to create instances of the other LiveData sources. Please note, that that sources are added for observing, <strong>before </strong>our MediatorLiveData makes the final call to be active.</p><p>Without further ado, take a look at the code. Cheers!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51787964b84e14b1794c95b037e27d88/href">https://medium.com/media/51787964b84e14b1794c95b037e27d88/href</a></iframe><ul><li><a href="https://medium.com/@nullthemall/make-use-of-kotlin-operator-overloading-for-your-recyclerview-adapter-operation-e1f896c24b17">Make use of Kotlin operator overloading for your RecyclerView.Adapter operations</a></li><li><a href="https://medium.com/@nullthemall/parameterized-viewmodelprovider-s-9148207ec048">Parameterized ViewModelProvider(s)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97bff1b2cb5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make use of Kotlin operator overloading for your RecyclerView.Adapter operations]]></title>
            <link>https://nikoladespotoski.medium.com/make-use-of-kotlin-operator-overloading-for-your-recyclerview-adapter-operation-e1f896c24b17?source=rss-54df77ce6735------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1f896c24b17</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[recyclerview]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nikola Despotoski]]></dc:creator>
            <pubDate>Wed, 29 Nov 2017 17:59:58 GMT</pubDate>
            <atom:updated>2017-11-29T18:26:56.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4cbVVnqQ851nQv8p6ozgQ.png" /><figcaption>courtesy of <a href="https://proandroiddev.com/@manuelvicnt?source=post_header_lockup">Manuel Vicente Vivo</a></figcaption></figure><p>I always liked and found entertaining messing around with operators in C++, back in the days.</p><p>There are plethora of short ways to write RecyclerView.Adapter in Kotlin, I wondered how can I get rid of functions that perform operations on the adapter.</p><p>Kotlin offers ability to <a href="https://kotlinlang.org/docs/reference/operator-overloading.html">overload operator</a> for all types like ol’good C++. Imagine interrelating RecyclerView.Adapter and any Collection&lt;T&gt; , single value of type T and Int to perform operations on the adapter just by using signs?</p><h3>Ground rules for each operator</h3><p>1. adapter += collection <strong>plus and assign</strong> operator will take the collection and replace existing data set.<br>2. adapter + singleItemT <strong>plus</strong> operator will add the item to the data set and notify the adapter that new item has been added to the end of the set.</p><p>3. adapter — position <strong>minus </strong>operator will remove item at position and notify the adapter that item has been removed.</p><p>4. adapter — itemT <strong>minus</strong> operator will remove item from the adapter data set and notify the adapter that item has been removed.</p><p>5. adapter..collection <strong>range</strong> operator will add Collection&lt;T&gt; to the existing data set and notify the adapter that new item has been added to the end of the set.</p><p>6. adapter[position] <strong>get </strong>operator will work as call to <em>getItemAt(position).</em></p><p>7. adapter[position] = newValue<strong>set </strong>operator will replace item at specific position and will notify the adapter that item has changed.</p><p>8. !adapter <strong>not</strong> operator will clear data set of the underlying adapter.</p><h3>Operator code</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cdd9323889dc46ce5048690eb98e3ebd/href">https://medium.com/media/cdd9323889dc46ce5048690eb98e3ebd/href</a></iframe><p><a href="https://medium.com/@nullthemall/parameterized-viewmodelprovider-s-9148207ec048">Parameterized ViewModelProvider(s)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1f896c24b17" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>