<?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 Christian Gaisl on Medium]]></title>
        <description><![CDATA[Stories by Christian Gaisl on Medium]]></description>
        <link>https://medium.com/@cgaisl?source=rss-abf795a50df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_tqBn1LXaI3cONKU.jpg</url>
            <title>Stories by Christian Gaisl on Medium</title>
            <link>https://medium.com/@cgaisl?source=rss-abf795a50df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 04:36:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cgaisl/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[Kotlin Android Architecture: The Difference Between Gradle Projects, Modules, and Paths]]></title>
            <link>https://medium.com/@cgaisl/kotlin-android-architecture-the-difference-between-gradle-projects-modules-and-paths-2984064be3a5?source=rss-abf795a50df------2</link>
            <guid isPermaLink="false">https://medium.com/p/2984064be3a5</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-gradle]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Christian Gaisl]]></dc:creator>
            <pubDate>Fri, 21 Nov 2025 01:31:14 GMT</pubDate>
            <atom:updated>2025-11-21T01:31:14.376Z</atom:updated>
            <content:encoded><![CDATA[<p>In Kotlin Android development, the terms “Project”, “Module”, and “Path” are used to refer to wildly different concepts, depending on the context. Today, we will provide a definition for each of these terms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAjmzjBb3a3aCm3qi3VoVQ.png" /></figure><h3>The IDE Project — Workspace</h3><p>The IDE project, i.e., the workspace. The folder that you open with your IDE. It’s what you create when you create a new App. Confusingly, Gradle has its own definition of a Project, which we’ll get into next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FJBCqudJ5jNVItiPujGWpw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*hrfBnDvZyPrTot4POy4DdA.png" /><figcaption>What the IDE calls “The Project”</figcaption></figure><h3><strong>The Gradle Project</strong></h3><p>Gradle’s include() is a perfect example of why naming is hard. This function doesn’t include anything. When you write include(&quot;:feature:bookmarks&quot;) in settings.gradle.kts, you aren&#39;t telling Gradle &quot;Go include this folder.&quot; You are telling Gradle:</p><blockquote>“Instantiate two new <strong>Gradle Projects</strong>. Give them the names ‘feature’ and ‘bookmarks’. Attach ‘feature’ as a child of the root project and attach ‘bookmarks’ as the child of ‘feature’”</blockquote><p><strong>How to read it:</strong> When you write include(&quot;:feature:bookmarks&quot;), you are creating nodes in the Gradle <strong>Project Tree</strong>.</p><ul><li><strong>The Separator (</strong><strong>:): </strong>The colon acts as a node delimiter</li><li><strong>The Root (</strong><strong>: at the start):</strong> Indicates the path is absolute, relative to the Root Project.</li><li><strong>Implicit Parent/Child Hierarchy: </strong>If you include a node like :a:b:c , you are creating 3 nodes, with a being the parent of b, which is the parent of c. If a or b did not exist, they would be created implicitly.</li></ul><pre>// What you write:<br>include(&quot;:feature:bookmarks&quot;)<br><br>// What Gradle actually does (Pseudocode):<br>val root = getRootProject()<br>val featureNode = root.findOrCreateChild(&quot;feature&quot;)<br>val loginNode = featuresNode.createChild(&quot;bookmarks&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i850j0vtwoFxvyDrl90tTA.png" /></figure><p>Each node is a Gradle Project with properties described in the <a href="https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/ProjectDescriptor.html">ProjectDescriptor</a> interface. Notable properties are as follows:</p><h4>ProjectPath</h4><ul><li>Defined by the include() function that created the Project.</li><li>include(&quot;<strong>:feature:bookmarks</strong>&quot;) creates a Project with the ProjectPath :feature:bookmarks.</li><li><strong>NOT</strong> a file path.</li></ul><h4>Name</h4><ul><li>The name of the project</li><li>Defined by the <strong>Leaf Project</strong> (i.e., last section) of its <strong>ProjectPath</strong>: include(&quot;:feature:<strong>bookmarks</strong>&quot;)</li></ul><h4>ProjectDir</h4><ul><li>The project directory.</li><li>A file path to a physical folder where the code to be compiled by this project is located.</li><li>example: /Users/user/Developer/MyApplication/feature/bookmarks<em><br></em>or feature/bookmarks</li><li>Gets its <em>default value</em> from the <strong>ProjectPath</strong>. include(&quot;:feature:bookmarks&quot;) has a <em>default</em> projectDir of feature/bookmarks . This projectDir can be changed after the Project is created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaIJKGU-Mk2prqL02ijCjQ.png" /><figcaption>Changing the default projectDir from “feature/bookmarks” to “independent/filePath/bookmarksFeature”</figcaption></figure><h3>The Module</h3><p>A Module is a bundle of functionality with a distinct identity. It’s the abstract concept of the “Thing” you want to <em>use.</em> It is defined by what it <em>does</em>, not by the form in which it presents itself.</p><h4><strong>The Concept</strong></h4><p>Think of a Module as a <strong>Song</strong> (e.g., “Bohemian Rhapsody”). It represents a specific piece of art (functionality) that you want to experience.</p><h4><strong>The Forms</strong></h4><p>Just like a <strong>Song</strong> can exist on different media, a <strong>Module</strong> can exist in different forms in your build:</p><ul><li><strong>As a Gradle Project (The USB Stick):</strong> This is the source code. Like a USB stick with the master tracks, you can plug it in, edit the code (remix the song), and the output changes immediately.”</li><li><strong>As an Artifact (The Vinyl):</strong> This is the compiled binary. It has the soundwaves physically pressed into it. It is finished, immutable, and ready to play.</li></ul><p>Imagine a bucket of labeled USB Sticks, each containing one <strong>Song</strong>. If I told you to get “Bohemian Rhapsody”, you’d bring me the one that has the distinct identity “Bohemian Rhapsody”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*in-KMMrnE-zXF90Be_IwqA.png" /><figcaption>A bucket of USB sticks, each representing a <strong>Song</strong></figcaption></figure><p>I now have <strong>a Song</strong> in my hand. The same logic applies to Modules. In the same way we can call a USB stick a <strong>“</strong>song,” we can call a Gradle Project a “module”. The same way we can call a Vinyl a “song”, we can call a published binary artifact a “module”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvaD33MXp8U4FhCtb6SNWw.png" /><figcaption>A guy with <strong>a Song</strong> in his hand.</figcaption></figure><p>A <em>Directory</em>, a <em>Gradle Project</em>, and a <em>Published Artifact</em> are all just different containers for the same ‘Module’ concept. In casual conversation, we use the term ‘Module’ interchangeably to refer to objects representing the concept of a Module.</p><h3><strong>Distinct Module identifiers in Android/Kotlin with Gradle</strong></h3><p>Modules have a distinct identifier, similar to a song having a name. The following are some examples of such identifiers.</p><h4><strong>Gradle Project</strong></h4><p>A Gradle Project’s identifier is its Project Path. This is how it is referenced as a dependency:</p><pre>// in the build.gradle.kts of :app<br><br>dependencies {<br>    implementation(project(&quot;:feature:bookmarks&quot;))<br>}<br><br><br>// alternatively with enableFeaturePreview(&quot;TYPESAFE_PROJECT_ACCESSORS&quot;)<br>dependencies {<br>    implementation(projects.feature.bookmarks)<br>}</pre><h4>External dependency</h4><p>External dependencies from repositories like Maven Central can also be referred to as modules. The distinct identifier is their GAV (<strong>G</strong>roup<strong> A</strong>rtifact<strong> V</strong>ersion) coordinates.</p><pre>// in build.gradle.kts of main build&#39;s :app<br>dependencies {<br>    implementation(&quot;com.squareup.okhttp:okhttp:2.7.5&quot;)<br>}<br><br><br>// alternatively with .toml version catalog<br>// in libs.versions.toml<br>okhttp = { group = &quot;com.squareup.okhttp&quot;, name = &quot;okhttp&quot;, version = &quot;2.7.5&quot; }<br>// or<br>okhttp = { module = &quot;com.squareup.okhttp:okhttp:2.7.5&quot; }<br><br>// in build.gradle.kts of main build&#39;s :app<br>dependencies {<br>    implementation(libs.okhttp)<br>}</pre><h4>Gradle Project from Included Build</h4><p>In your settings.gradle.kts, you can include other builds in your build with the function includeBuild() . From your main build, however, you cannot reference Gradle Projects from the included build by their Project Path. The includeBuild() function exposes the included Gradle Projects as GAV coordinates, defined by their <em>Project Name,</em> to the main Build.</p><p>Assume the Project created by include(“:feature:bookmarks”) was part of an included Build:</p><pre>// in settings.gradle.kts of included build<br>include(&quot;:feature:bookmarks&quot;)<br><br>// in settings.gradle.kts of the main build<br>includeBuild(&quot;included-build&quot;)<br><br>// in build.gradle.kts file of the feature &#39;bookmarks&#39;<br>group = &quot;com.mycompany.myapp&quot;<br><br><br>// in build.gradle.kts of main build&#39;s :app<br>dependencies {<br>    implementation(&quot;com.mycompany.myapp:bookmarks&quot;) // version gets ignored for included Builds<br>}<br><br><br>// alternatively with .toml version catalog<br>// in libs.versions.toml<br>bookmarks = { group = &quot;com.mycompany.myapp&quot;, name = &quot;bookmarks&quot; }<br>// or<br>bookmarks = { module = &quot;com.mycompany.myapp:bookmarks&quot; }<br><br>// in build.gradle.kts of main build&#39;s :app<br>dependencies {<br>    implementation(libs.bookmarks)<br>}</pre><p>Have you enjoyed this article? Feel free to give me a clap 👏, write a comment, and follow me here on Medium to catch all my latest articles. Thanks 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2984064be3a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Reasons to Use Modules in Your App — and a Common Antipattern to Avoid]]></title>
            <link>https://medium.com/@cgaisl/3-reasons-to-use-modules-in-your-app-and-a-common-antipattern-to-avoid-771d964c6ef6?source=rss-abf795a50df------2</link>
            <guid isPermaLink="false">https://medium.com/p/771d964c6ef6</guid>
            <category><![CDATA[clean-architecture]]></category>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Christian Gaisl]]></dc:creator>
            <pubDate>Sun, 26 Oct 2025 11:51:13 GMT</pubDate>
            <atom:updated>2025-10-26T11:51:13.879Z</atom:updated>
            <content:encoded><![CDATA[<h3>3 Reasons to Use Modules in Your App — and a Common Antipattern to Avoid</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ztx9HRLyOcnTih0o9FZUfg.png" /></figure><p>In Android/Kotlin development, modules are an often misunderstood construct. Some teams have their whole codebase in a single monolithic module; others create a module for every tiny little thing. In this article, we’ll go over why modules might be a great addition to your codebase, and we’ll explore a common antipattern many teams fall prey to.</p><h4>1. Build Performance</h4><p>One of the biggest reasons to create modules is to build performance, i.e., the speed at which you can build/compile your app. A module is essentially its own self-contained build artifact. Every time you touch some code in a module, the whole module has to be rebuilt. As your App grows, this can lead to longer and longer build times as you have to build your whole App every time you change it.</p><p>When building an App, there are two kinds of builds we have to distinguish: clean builds and incremental builds. Each requires its own rationale to optimize.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8YvXVMjX0GgHRV6e4jWEg.png" /><figcaption>Build timeline of a single module app.</figcaption></figure><p><strong>Clean Builds:<br></strong>A clean build is when you have to build your app from scratch, with no build caches whatsoever. This happens a lot in CI, when switching branches, or for various other reasons. If you split up your app into modules that can be built in parallel, you can dramatically speed up your clean builds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PLrzNnANZZa4hzMiXf8O3w.png" /><figcaption>Clean builds in monolithic app vs modularized app</figcaption></figure><p><strong>Incremental Builds:<br></strong>During development, the bulk of your builds will be incremental builds. In a single-module app, every time you touch something, the whole app has to be rebuilt. If you change the code in a feature module, only that module has to be rebuilt. The other modules in the build cache remain unchanged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hCrWR4yU_El0FeCPxjLQmw.png" /><figcaption>Incremental builds in monolithic app vs modularized app when changing FeatureA</figcaption></figure><h4>2. Architectural Guardrails</h4><p>Modules can be a way to enforce architectural boundaries. As Apps grow, they need some architecture to remain manageable. A consistent architecture makes it easy for developers to pinpoint where specific functionality lies and where to add new functionality, even if they’ve just joined the team.</p><p>As an example, let’s say we have an e-commerce app that has a list of products in a database. In this app’s architecture, this is a database entity and should not be used in anything UI related.</p><pre>package com.mycompany.app.core.data<br><br>@Entity(tableName = &quot;products&quot;)<br>data class ProductEntity(<br>  @PrimaryKey val id: String,<br>  val name: String,<br>  val priceCents: Long,<br>  val imageUrl: String?<br>)</pre><p>A new developer joins the team and wants to create a new screen displaying a list of Products:</p><pre>package com.mycompany.app.feature.productList<br><br>import com.mycompany.app.core.data.ProductEntity<br><br>@Composable<br>fun ProductColumn(products: List&lt;ProductEntity&gt;) {<br>    Column {<br>        products.forEach { product -&gt;<br>            ProductRow(product)<br>        }<br>    }<br>}</pre><p>In a single-module monolithic app, this code compiles without warnings. But it violates the app’s architecture. The UI is now tightly coupled to database implementation details. If the database schema changes, the UI code breaks. If ProductEntity lives in :core:data and ProductColumn lives in :feature:productList , this code won’t compile unless someone explicitly adds a :core:data dependency in the feature module’s build file. This forces the developer to do the right thing:</p><pre>// In :core:domain<br>package com.mycompany.app.core.domain<br><br>data class Product(<br>  val id: String,<br>  val name: String,<br>  val formattedPrice: String,  // Already formatted for display<br>  val imageUrl: String?<br>)</pre><pre>// In :feature:productList<br>package com.mycompany.app.feature.productList<br><br>import com.mycompany.app.core.domain.Product  // ✓ Domain model, not entity<br><br>@Composable<br>fun ProductColumn(products: List&lt;Product&gt;) {<br>    Column {<br>        products.forEach { product -&gt;<br>            ProductRow(product)<br>        }<br>    }<br>}</pre><p>Now the architecture is enforced by the build system itself. If someone tries to add a dependency to :feature:productList on :core:data it becomes immediately visible in the module&#39;s build.gradle.kts file during code review. The boundaries aren&#39;t just documented, they&#39;re <strong>enforced</strong>.</p><h4>3. Other reasons</h4><p>The title of this article is a bit misleading. There are actually tons of reasons to use modules, but for many apps don’t even scale to a point where these come up. Here are a few:</p><ul><li><strong>Optionality &amp; flavors:</strong> Include different implementation modules depending on app flavor/configuration</li><li><strong>Dynamic Feature Modules:</strong> Download dynamic features separately from the main bundle (Play Feature Delivery)</li><li><strong>Portability:</strong> Use the same module in different apps or on different platforms (Kotlin Multiplatform)</li><li><strong>Testing:</strong> Run tests of affected modules only</li><li><strong>R8/ProGuard isolation:</strong> keep keep-rules local; fewer cross-cutting surprises.</li></ul><h3>When to Avoid Modules</h3><p>Adding a module to a codebase isn’t free. Here are a few of the costs associated with modules</p><ul><li><strong>Cognitive load &amp; onboarding:</strong> Devs must learn the module map, boundaries, DI routing, and “what lives where.”</li><li><strong>Configuration Complexity:</strong> Modules have their own project configuration, need to be added to the root project, and need to be imported by every module that uses them.</li><li><strong>Longer Gradle config/sync time:</strong> More modules = longer configuration, more variant matrices, slower IDE sync/indexing.</li><li><strong>Debug/refactor friction:</strong> Cross-module refactors touch more files</li><li><strong>Code duplication:</strong> Devs get tempted to copy-paste code if it’s not accessible in the current module</li></ul><p>Introducing a module should come with a clear benefit in build performance or boundary enforcement, <em>not solely for organizing your code. </em><strong>That’s what packages/folders are for.</strong></p><blockquote>If a module doesn’t change build behavior or enforce boundaries, it’s just an expensive way to organize your code.</blockquote><h4>Category-Based Modularization — A Common Antipattern</h4><p>Creating modules by category, e.g. :model, :interface, :util, :resources, etc. is a common antipattern. <strong>There’s no real win in speed or boundaries.</strong> These modules are very quick to compile to begin with, so parallelizing them doesn’t gain much. Most modules depend on them directly or indirectly, so a change in them triggers a big incremental build, whether they are in separate modules or not. Often, you’re better off consolidating them in a single module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZ567Xnv7G0OFASlX55kVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ewu_0nHM9azT8499slj1LQ.png" /><figcaption>Category-Based Modularization: An expensive way to organize your code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ujE8eJOM3rSpCvaDHPIlqQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*BSkdQzmbuWZ_-nziteNf-w.png" /><figcaption>Consolidated dependency graph</figcaption></figure><p>Have you enjoyed this article? Feel free to give me a clap 👏, write a comment, and follow me here on Medium to catch all my latest articles. Thanks 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=771d964c6ef6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Ultimate Digital Nomad Portable Workstation Setup]]></title>
            <link>https://medium.com/@cgaisl/the-ultimate-digital-nomad-portable-workstation-setup-ac9ae57f04f3?source=rss-abf795a50df------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac9ae57f04f3</guid>
            <category><![CDATA[portable-monitor]]></category>
            <category><![CDATA[digital-nomad-tools]]></category>
            <category><![CDATA[laptop-stand]]></category>
            <category><![CDATA[digital-nomad-lifestyle]]></category>
            <category><![CDATA[nomad]]></category>
            <dc:creator><![CDATA[Christian Gaisl]]></dc:creator>
            <pubDate>Sun, 22 Dec 2024 15:44:03 GMT</pubDate>
            <atom:updated>2024-12-22T16:35:15.536Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>I&#39;ve been traveling around the co-working spaces of Southeast Asia, where I&#39;ve seen all kinds of workstation setups. I tried many of these myself, and I want to share my observations on what worked for others and what I found to be my ultimate Digital Nomad Portable Workstation Setup.</p><h3>Portable Workstation Evolution</h3><p>Creating your portable work setup is a never-ending journey of incremental improvement. After visiting dozens of co-working spaces, I&#39;ve noticed some common patterns in the evolutions of people&#39;s setups.</p><h3>Workstation V1.0</h3><p>Imagine a fresh digital nomad, eager to get on the road, packing his backpack with nothing but a few T-shirts and a laptop. This is what they usually start out with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3jYmsEOVCSc-CPt1tyDxow.jpeg" /><figcaption>Workstation V1. Just a Laptop. Very Minimalist.</figcaption></figure><p>It doesn&#39;t take long until the ergonomic problems of this setup make themselves noticeable. Long night sessions in co-working spaces while being hunched over your laptop are poison for your neck and back.</p><h3>Workstation V2.0</h3><p>The main ergonomic problem of V1.0 is as obvious as its solution. The laptop is too low. The most common solutions to raise the monitor&#39;s height are two kinds of laptop stands.</p><h4>Workstation V2.1 — Low-Profile Laptop Stand</h4><p>When you look for laptop stands on Amazon, you&#39;ll find these a dime a dozen. These low-profile laptop stands are inexpensive, lightweight, and easy to set up. They are designed to raise the laptop&#39;s screen to eye level while keeping its keyboard usable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*AJ46ojC4P1X5CnMoRAijuQ.jpeg" /><figcaption>Workstation V2.1. Low-Profile Laptop Stand.</figcaption></figure><p>The two main complaints I&#39;ve heard about this setup are that the typing experience is a little awkward and the monitor&#39;s height is still too low, especially for taller people.</p><h4>Workstation V2.2 — High-Profile Laptop Stand</h4><p>High-profile laptop stands address some of the shortcomings of low-profile laptop stands. These kinds of stands can raise your laptop as high as you could ever need. I&#39;ve even seen people adjust them so they had to look up to their monitor instead of down. When paired with an <a href="https://amzn.to/4gvtpNM">external keyboard</a>, the typing experience can be as good as it gets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nEZVl-X7GY5WqI4ZbbMv_g.jpeg" /><figcaption>Workstation V2.2 — High-Profile Laptop Stand <a href="https://amzn.to/3ZMgRdv">https://amzn.to/3ZMgRdv</a></figcaption></figure><p>This setup is more involved. It takes up more space on the desk, and you need to bring an external keyboard. However, the superior ergonomics and typing experience more than compensate for this, making this an endgame setup for many.</p><p>I particularly recommend the <a href="https://amzn.to/3P8UZnP">Roost Laptop Stand</a>; it’s the best piece of plastic I’ve ever bought.</p><h3>Workstation V3.0</h3><p>After a while on the road, some begin to miss the large external monitor they had at the office. Since lugging around a 32&quot; 5K monitor is not an option most of the time, they start to look up portable monitor options and end up with one of the two upcoming setups.</p><h4>Workstation V3.1 —Laptop Stand + Portable Monitor with Folio Case</h4><p>A very popular kind of portable monitor is the kind that works with a single USB-C cable, which handles both power and video. These often come paired with an iPad-style folio case that acts as a travel case and as a stand.</p><p>An example for such a monitor would be the <a href="https://amzn.to/3ZJ0dLU">LG Gram+View</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H1WhpgfvKrkve_Nd5qd1qQ.jpeg" /><figcaption>Workstation 3.1 — Laptop Stand + Portable Monitor with Folio Case</figcaption></figure><p>While excitedly browsing for new portable monitors, many often lose sight of the viability of the overall setup and end up with something like this. While the new monitor might be just what they needed for their next boost in productivity, the ergonomics of this setup just don&#39;t work: The height difference between the two monitors is simply too big.</p><p>Anyone I&#39;ve met with this kind of setup either moved on to one of the following steps or ditched the second monitor entirely, reverting back to V2.0.</p><h4>Workstation V3.2— No Stand + Portable Monitor with Folio Case</h4><p>For some, the productivity boost of having a second monitor is just too significant. Instead of ditching the second monitor, they are willing to compromise on the ergonomics of their main machine and get rid of their laptop stand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wz_sq4fX_Pv6Qc-0vSdT3w.jpeg" /><figcaption>Workstation V3.2 — No Stand + Portable Monitor with Folio Case</figcaption></figure><p>This setup comes with all the ergonomic drawbacks that got us on this journey in the first place. However, I&#39;ve seen many perfectly happy with this compromise for years.</p><h3>Workstation V4.0</h3><p>The ultimate portable workstation setup has a stand both for the laptop and the portable monitor.</p><h4>Monitor Stands</h4><p>Monitor stands, however, serve a different purpose than laptop stands. They are designed to hold a monitor suspended in the air, whereas laptop stands only have to support a laptop placed on top of them. Monitor stands, therefore, need to be much sturdier and are usually much heavier. A quick search on Amazon reveals that <strong>most stands for portable monitors aren’t very portable themselves</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-1emlykPPpSw556UE-Uxg.jpeg" /><figcaption>Stands for portable monitors: some feature a heavy metal baseplate, while others have a sturdy metal frame.</figcaption></figure><p>This lack of out-of-the-box solutions for this problem has led some <a href="https://www.reddit.com/r/digitalnomad/comments/jbeju7/1kg_sharing_my_eyelevel_16in_second_monitor_setup/">Reddit users to come up with their own creative solutions.</a> The common thread between all of them is to reuse either a camera tripod or a selfie stick and then come up with a way to mount the monitor to it.</p><p>One of the Reddit users even launched his own product and <a href="https://www.flexsta.com/products/flexsta-flex-1-portable-monitor-stand">sells it on his webshop.</a></p><p>The way I solved this problem is by reusing a <a href="https://amzn.to/4057Ihs">MagSafe selfie stick</a>. It came with a metal ring that you are supposed to stick on your Android phone to make it MagSafe compatible. <strong>I super glued the MagSafe compatibility adapter to the back of my monitor,</strong> and it holds up my 654g 16-Inch monitor perfectly well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cp2Ln15BTrmevuLhiGd8vQ.jpeg" /><figcaption>DIY lightweight monitor stand: Ultralight (150g) selfie stick/tripod with MagSafe. <a href="https://amzn.to/4057Ihs">https://amzn.to/4057Ihs</a></figcaption></figure><p>The resulting setup is lightweight (654g monitor + 150g stand = 804g)and easy to set up and break down, thanks to MagSafe.</p><h4>Workstation 4.0 — Laptop Stand + Monitor Stand</h4><p>The combination of a laptop stand with a monitor stand results in the best of all worlds. The setup is still lightweight enough to be portable without compromising on ergonomics or typing experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q0Px-B8kR4qf_-TXn89SrA.jpeg" /><figcaption>Workstation 4.0 — Laptop Stand + Monitor Stand</figcaption></figure><h3>Conclusion</h3><p>Ultimately, the ultimate digital nomad workstation is a personal choice and depends on your needs and circumstances. Some are fine working with just their laptop on tiny desks in a local Cafe, while others choose to work in high-end co-working spaces that offer 32&quot; 5k monitors and standing desks for rent.</p><p>I hope my insights have been helpful to you. If you’d like to support me, feel free to use any of the affiliate links if you decide to purchase a piece of gear for your setup.</p><p>Have you enjoyed this article? Feel free to give me a clap 👏, write a comment, and follow me here on Medium to catch all my latest articles. Thanks 👋</p><p>Product Links:</p><ul><li><a href="https://amzn.to/4fz3KSV">JJC Magnetic Selfie Stick Tripod</a></li><li><a href="https://amzn.to/3ZMgRdv">Roost Laptop Stand</a></li><li><a href="https://amzn.to/3ZJ0dLU">LG Gram+View</a></li><li><a href="https://amzn.to/3VTwmPH">Macbook Pro 16</a></li><li><a href="https://amzn.to/404Efo4">Apple Magic Keyboard</a></li><li><a href="https://amzn.to/3VQKOrM">Logitech G703 Mouse</a></li></ul><p><em>Note: Some of the links in this article are affiliate links. If you choose to use them, I may earn a small commission at no additional cost to you. Thank you for supporting my work!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac9ae57f04f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Pass Arguments to a HiltViewModel from Compose]]></title>
            <link>https://medium.com/@cgaisl/how-to-pass-arguments-to-a-hiltviewmodel-from-compose-97c74a75f772?source=rss-abf795a50df------2</link>
            <guid isPermaLink="false">https://medium.com/p/97c74a75f772</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[compose-ui]]></category>
            <dc:creator><![CDATA[Christian Gaisl]]></dc:creator>
            <pubDate>Sat, 20 Jan 2024 16:15:57 GMT</pubDate>
            <atom:updated>2025-02-11T09:13:05.580Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvwpSjggi8JjFcUelDqTzw.png" /></figure><p>Passing arguments to a ViewModel is common in mobile app development. The most prominent example would be a detail screen that has a ViewModel that takes an ID and fetches the remaining information it needs from a repository using that ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*uV1eoDp3Oyv5V7mPIfvcHQ.jpeg" /><figcaption>A typical recipe app. The RecipeSearchScreen navigates to the RecipeDetailScreen and passes recipe_id along. RecipeDetailScreen has a RecipeDetailViewModel, which needs access to recipe_id</figcaption></figure><p>I recently joined an existing Android app project, which was in the process of introducing Jetpack Compose into the codebase. The project used Hilt for dependency injection, meaning that all ViewModels had to be HiltViewModels. It turned out that something as simple as passing arguments to a HiltViewModel from Compose was not as straightforward as it should have been.</p><h3>Why This Is Even a Problem</h3><p>The whole app UI in Android development lives inside Fragments and Activities. These get destroyed and recreated on configuration changes, like device rotation, Locale change, dark/light mode transitions, and many more. To save the state of the UI, we use Android ViewModels, which survive configuration changes. However, in Android, we don’t instantiate our ViewModels ourselves. Instead, they are created and managed by a ViewModelStore, which takes care of persistence through configuration changes.</p><p>What this leads to is that we don’t call the constructor of a ViewModel in our UI directly. Instead, we provide our ViewModelStore with a factory to tell it how to create our ViewModel for us. This looks something like this:</p><pre>@Composable<br>fun MyScreen(<br>    argument: String,<br>) {<br>    val myViewModel = viewModel(<br>        factory = MyViewModelFactory(argument)<br>    )<br><br>    ...<br>}<br><br>class MyViewModel(<br>    val argument: String<br>) : ViewModel() {<br>    ...<br>}<br><br>class MyViewModelFactory(<br>    private val argument: String,<br>) : ViewModelProvider.NewInstanceFactory() {<br>    override fun &lt;T : ViewModel&gt; create(modelClass: Class&lt;T&gt;): T {<br>        return MyViewModel(argument) as T<br>    }<br>}</pre><p>A problem comes up when using Hilt for dependency injection. Hilt injects dependencies into our @HiltViewModel annotated ViewModels by providing its own ViewModelFactories, meaning we can’t use custom factories to pass arguments to our ViewModel at runtime.</p><h3>Some Ways to Pass Arguments to HiltViewModels</h3><h4>SavedStateHandle</h4><p>The codebase I joined used Fragments, XMLs, and Jetpack Navigation. The way arguments were handled was through Jetpack Navigation arguments and SavedStateHandle. HiltViewModels have access to the current SavedStateHandle automatically through Hilt Injection.</p><pre>@HiltViewModel<br>class DetailViewModel @Inject constructor(<br>    savedStateHandle: SavedStateHandle,<br>) : ViewModel() {<br>    private val navArgs = DetailFragmentArgs.fromSavedStateHandle(savedStateHandle)<br>}</pre><p>This has several problems. It ties the ViewModel to Jetpack Navigation with its use of SavedStateHandle. What if we wanted to use a different kind of Navigation, especially with Compose?</p><p>It also ties our ViewModel to our DetailFragment. What if we wanted to reuse this ViewModel with a Compose Screen in other parts of our app or even in different Fragments or Activities?</p><p>With SavedStateHandle, we are also limited to arguments that can be put into a Bundle, meaning functions are out of the question. And, although Android Studio has some good tooling to fix this issue, your arguments are stringly typed somewhere in your code.</p><pre>&lt;!-- Stringly Typed. To be avoided. --&gt;<br>&lt;fragment<br>    android:id=&quot;@+id/detail&quot;<br>    android:name=&quot;com.example.DetailFragment&quot;<br>    android:label=&quot;detail&quot;<br>    tools:layout=&quot;@layout/fragment_detail&quot;&gt;<br><br>    &lt;argument<br>        android:name=&quot;id&quot;<br>        android:defaultValue=&quot;0L&quot;<br>        app:argType=&quot;long&quot; /&gt;<br>&lt;/fragment&gt;</pre><h4>CreationExtras</h4><p>AndroidX Fragment KTX’s viewModel() function allows you to pass an extrasProducer as an argument. With that, you can add additional arguments to SavedStateHandle without relying on a particular navigation library.</p><pre>val viewModel by viewModels&lt;MyViewModel&gt;(extrasProducer = {<br>  MutableCreationExtras(defaultViewModelCreationExtras).apply {<br>    set(DEFAULT_ARGS_KEY, bundleOf(&quot;someId&quot; to someId))<br>  }<br>})</pre><p>As in the previous example, you can extract those arguments from the SavedStateHandle in the HiltViewModel. This comes with all the same disadvantages. Additionally, Androids Fragment KTX’s viewModel function is only available in Fragments, meaning there is no support for Compose.</p><h4>Assisted Inject</h4><p>When I first saw AssistedInject, I thought it would be precisely what I was looking for. Dagger defines Assisted Injection as follows:</p><blockquote>Assisted injection is a dependency injection (DI) pattern that is used to construct an object where some parameters may be provided by the DI framework and others must be passed in at creation time (a.k.a “assisted”) by the user.</blockquote><p>In principle, this works by using the .withCreationCallback() function on the defaultViewModelCreationExtras typed to your <a href="http://twitter.com/AssistedFactory">@AssistedFactory</a> ViewModel factory. However, this again only works inside of Fragments, as only they allow you to pass an extras producer here. This doesn’t work for Composables.</p><pre>@HiltViewModel(assistedFactory = DetailViewModel.DetailViewModelFactory::class)<br>class DetailViewModel @AssistedInject constructor(<br>    @Assisted private val id: String,<br>    val exampleRepository: ExampleRepository,<br>) : ViewModel() {<br><br>    @AssistedFactory<br>    interface DetailViewModelFactory {<br>        fun create(id: String): DetailViewModel<br>    }<br>}<br><br><br>@AndroidEntryPoint<br>class DetailFragment : Fragment() {<br><br>    private val navArgs by navArgs&lt;DetailFragmentArgs&gt;()<br><br>    private val detailViewModel: DetailViewModel by viewModels {<br>        extrasProducer = {<br>              defaultViewModelCreationExtras<br>                  .withCreationCallback&lt;DetailViewModel.DetailViewModelFactory&gt; { factory -&gt;<br>                      factory.create(navArgs.id)<br>                  }<br>        }<br>    }<br>}</pre><p>That’s a lot of code to pass an argument to a ViewModel 🧐. ExtrasProducer, DefaultViewModelCreationExtras, withCreationCallback, factory, <a href="http://twitter.com/AssistedInject">@AssistedInject</a>, <a href="http://twitter.com/Assisted">@Assisted</a>, <a href="http://twitter.com/AssistedFactory">@AssistedFactory</a>, … 😵‍💫</p><h3>The Solution — How to Pass Arguments to a HiltViewModel from Compose</h3><p>Since December 13th, 2023, it is finally possible to use Assisted Inject when using pure Compose. With the release of version 1.2.0-alpha01 of the <a href="https://mvnrepository.com/artifact/androidx.hilt/hilt-navigation-compose/1.2.0-alpha01">Hilt Navigation Compose library</a> comes a new composable <em>hiltViewModel()</em> function, which takes a callback with our AssistedFactory with which we can initialize our HiltViewModel with runtime parameters.</p><pre>@HiltViewModel(assistedFactory = DetailViewModel.DetailViewModelFactory::class)<br>class DetailViewModel @AssistedInject constructor(<br>    @Assisted val id: String,<br>    val exampleRepository: ExampleRepository,<br>) : ViewModel() {<br><br>    @AssistedFactory<br>    interface DetailViewModelFactory {<br>        fun create(id: String): DetailViewModel<br>    }<br>}<br><br>@Composable<br>fun DetailScreen(<br>    id: String,<br>) {<br>    val viewModel = hiltViewModel&lt;DetailViewModel, DetailViewModel.DetailViewModelFactory&gt; { factory -&gt;<br>        factory.create(id)<br>    }<br>}</pre><p>Also, be sure to use the latest version of Dagger, as version ≤ 2.48 will give you an error when using @AssistedInject for a HiltViewModel.</p><h3>Conclusion</h3><p>There are a lot of hoops to jump through when passing an argument to a HiltViewModel from Compose. Having to use the latest Alpha release of a navigation library that I otherwise do not need is a bit disappointing. The resulting code is somewhat concise but uses four different annotations to get to the finish line. Surprisingly, this wasn’t even possible at all when Compose came out more than two years ago.</p><p>I’ve had much better experiences using something like Koin for dependency injection in the past. It’s much more straightforward and does not slow down my build times like Hilt. And you can also use it in Kotlin Multiplatform projects. In my opinion, Hilt is to be avoided.</p><p>Have you enjoyed this article? Feel free to give me a clap 👏, write a comment, and follow me here on Medium to catch all my latest articles. Thanks 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97c74a75f772" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>