Adopting MVVM

23 Şubat 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.

Dizi 2.0

Bu gönderi bir dizinin parçasıdır. Bu bölüm aynı dizideki diğer gönderileri gösterir.

TrebleShot  /  Bitmiş

en

An Open Content Exchange Standard

20 Haziran 2020

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

okuyorsun en

Adopting MVVM

23 Şubat 2021

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