Kotlin Flow tips for ViewModel

Many months have passed since I last wrote about Kotlin Flow: Domain Model’s StateFlow Sharing. So, let’s take a look at something related to Flow handling in a ViewModel. StateIn shortcut Usually, you want a StateFlow‘s state to survive a configuration change. AndroidX’s default time limit is 5 seconds — but only if it’s subscribed. … Read more

Does Jetpack Navigation meet Type Safety?

You may have heard that Jetpack Navigation has a new API for type-safe navigation. This new official solution brings navigation with a “destination object” instead of simple manual URL building. Previously, I developed kiwicom/navigation-compose-typed library that did the same and was an inspiration for the official solution. The official solution makes navigation easier than before, … Read more

Page Objects for E2E Android UI testing

Android end-to-end UI testing is not that difficult, but we have observed that the official API/tooling doesn’t scale much if you have a big app. “Page Object” is a design pattern abstraction over a particular screen: it provides access to read the screen’s data and provides an API to interact with the screen. You may … Read more

Rewriting Android App’s Back-Handling Logic

Our Kiwi.com app is quite old and vast. It is in development for about 7 years; each year we’re adding more features and code, each year the app is being worked on by more developers. We evolved to a custom back-aware logic in our activities and fragments. Basically, back press was handled in the activity … Read more

Domain Model’s StateFlow Sharing

A lot of applications have an app-wide state defined in its domain model. Making it correctly reactive may not be so trivial. Let’s explore. Apps have state all over the source code. ViewModels have their screen’s state. Storage has the app’s state, and sometimes we need to keep an app-wide state in our domain model … Read more

Exposing ktlint report as GitHub PR annotations

GitHub is awesome! One of the great features is PR annotations – your tool may simply not only check your code, but also post an annotation that is shown in the diff. ktlint is awesome! No more bikesheedding about coding style. Simply run ktlint, ideally let ktlint format your code and don’t let reviewers to … Read more

Retrieving reified generic arguments

Kotlin has a great feature that will allow you to preserve generic type T for further work, not only type resolution. So how much we can utilize it? This simple code does not take any “normal” argument, but it takes one generic argument – the T. Usually, we can just pass the T around to … Read more

Success & logic error propagation in Kotlin

In Kotlin, the expected code-flow should not use exceptions. The non-success code flow should be propagated through return type to be well-documented, strictly & statically typed. This post should be a practical guide after you have read Elizarov’s great post on Kotlin and Exceptions. Be aware that this post talks about domain errors, as described … Read more

Variance

A lot was written about variance and its application in generics. This is another trial to explain variance and its practical usage. Let’s explore this using Kotlin. This article expects basic knowledge about generics. Variance is a powerful way to allow your code to do more. It is most obvious when you consider generics with … Read more