The Android guy

Some quick notes on Dark Mode

The dark mode, perhaps is one of the easiest functionality to implement without breaking literally anything in existing project. However, it has it’s own hidden costs, tricks. Before implementing the Dark mode, what is most important is that your project must be ready for dark mode. What I had: What I wanted to achieve: The setup: The only thing you need to do to get your app ready for dark mode is the themes tag and the AppCompatDelegate class.

How to produce the SavedStateHandle in your ViewModel using AssistedInject

One of my previous article Dagger Multibinding Saved My Time “claimed” to have found the right practice for providing ViewModels without producing a ViewModel Factory for each ViewModel. Apparently, I was wrong. There are 2 main problems with that approach: 1 - I might forget to add a ViewModel in the Map graph. 2 - With the new SavedStateHandle which stays uniqely in each ViewModel I can’t use a generic ViewModel Factory.

Solving Room "cannot find setter for field" error in build time

Room persistence library is one of the easiest one to set up. However, when using data classes for your Room entities, you might face some small problem, which on the first look doesn’t really make any sense. Let’s try to compile this class: @Entity(tableName = "users") data class User( @PrimaryKey @ColumnInfo(name = "id") val number: Int, @ColumnInfo(name = "user_name") val userName: String, @ColumnInfo(name = "user_status") val userStatus: String, @Ignore val englishNameMeaning: UserGrade ) The problem:

Let's get beyond null safety

_Inspired by myself and perhaps some other people, who coded Java style in Kotlin. I have seen tones of articles which (mostly) highlight Kotlins null safety and nothing more. So that’s it? If it was only for that I swear I would be still using Java with some null checks. Therefore, this article suggest what to use best in Kotlin as well as droping some everyday Java habits. _

Dagger Multibindings saved my time

While the Android architecture made development simpler, we should always be aware of the Lifecycle and with that, the right way to provide ViewModels. Creating one ViewModel factory for each Fragment and ViewModel you have is really expensive, bad architecture, and too much unnecessary code. Not to mention the fact that you should care about scopes, dependencies, components modules when using Dagger for DI. You can have a simple “generic” ViewModel factory for all your app as a Singleton, with the help of Kotlin Reflection and Daggers Multibinding.

Getting hands dirty with KotlinJs

Although web development hasn’t been my thing since I started programming, I was really attracted the way Kotlin does solve things. So I did give a try to KotlinJS. **This is how to set up a KotlinJs page in less than an hour. ** Note: Chose to use the simplest set up without gradle or maven. You are free to chose what you like. First of all, you start with a new project in your IntelliJ and choose Kotlin -> Javascript.