Adopting MVVM

Feb. 23, 2021

Model — View — ViewModel

android  architecture  design  java  kotlin

Continuing from the post about Kotlin, this post talks about the migration process and the new architecture of the project.

For the initial migration, I used Java to Kotlin migration tool that Intellij IDEA has. It is useful for getting things started. It renames source files and gives us a glimpse of how the finished code will look like. The next step is to fix everything that it will break because it will break a lot of things.

Somewhat unnecessarily, I moved a few libraries separated from the source code (with the hope that I would use them in my other projects) back into the project because I never used them in any other way. I also replaced a very old database library with Room, but that needed me to create Room equaivalent classes first.

Now it is time to remodel the codebase. Being aware of my previous mistakes and with seperation of concerns in mind, I started creating new classes from my God1 ListFragment class which was handling all the business logic, and UI elements and was providing sorting, ordering, and other similar functionalities. In other words, it was blocking me from creating unique UI elements and was limiting the project's growth. So, it had to go.

After completing that, I created Repositories and ViewModels around the UI and business logic in line with the MVVM design pattern, enabling me to create unique UI structures using existing components.

For dependencies, I used Hilt. It made pulling them into the different parts of the UI a lot easier. It worked especially great with ViewModels. For the UI, I used Databinding, and I haven't experienced any issue other than needing to write some BindingAdapters.

I think this is everything for now. Up next, I will remove AsyncTask and Executors in favor of Coroutines.

Series 2.0

This post is part of a series. This section shows other posts in the same series.

TrebleShot Completed

June 20, 2020

An Open Content Exchange Standard

Let's create an open standard enabling users and developers to do more with what they have!

reading

Feb. 23, 2021

Adopting MVVM

Continuing from the post about Kotlin, this post talks about the migration process and the new architecture of the project.