I’m starting to like MVVM more and more. Though I don’t regret using MVP (we’re rocking the architecture), it’s impossible to not appreciate the simplicity of the things that come with MVVM. Today I discovered MediatorLiveData, where I’ve used it is for validating data, but the use-cases are many! This is the code block:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
val isPersonValid = MediatorLiveData<Boolean>() val socialSecurityNumber = MutableLiveData<String>() val name = MutableLiveData<String>() init { isPersonValid.addSource(socialSecurityNumber) { isPersonValid() } isPersonValid.addSource(name) { isPersonValid() } } fun isPersonValid(): Boolean { val isSsnValid = socialSecurityNumber.value?.length ?: 0 == 9 val isNameValid = name.value.length?.isNotEmpty() == true return isSsnValid && isNameValid } |
[…]
By: Adrian Coman
Working closer with MVVM, I got to the point where I got to use Transformations.
1 2 3 4 5 |
val phoneNumber = MutableLiveData<string>() val isPhoneNumberValid: LiveData = Transformations.map(phoneNumber) { phone -> phone.isPhoneNumberValid() } </string> |
What this basically does is: Whenever the phoneNumber variable changed, the function from the Transformation.map is triggered and isPhoneNumberValid changes. Basically if isPhoneNumberValid is observed (and only if it’s observed), it will change to true or false based on […]
By: Adrian Coman
Some time ago we got to the conclusion that we should migrate from our MVP architecture to a MVVM one. There were a lot of things to learn and discover. Expect that the following bytes will focus more on this. One of the problems that I faced was that sometimes I would like the View […]
By: Adrian Coman
Some time ago, a tweet caught my attention in which someone said they created an Android app with no “Base” activity/fragment class. Looking at my apps, I thought that was impossible to do because of the duplicate code you would have. It would have been a nightmare even only for the analytics functions that I […]
By: Adrian Coman
Working as a developer one of the things that helped me grow was the ability to discover what’s blocking me from achieving my goals and constantly assessing how to have a continuous stream of work. I’m a freelancer and I get paid by the hour, so an hour of waiting for someone to answer a […]
By: Adrian Coman
Some time ago I had some free time and was looking over the codebase of one of the apps I’m working on and something caught my eye, the constructor looked something like:
1 2 3 4 5 |
class SomeScreen( val fromOnboarding: Boolean, val fromSignup: Boolean, val fromLogin: Boolean ) |
From this code, you would get the impression that you could have 8 possible states of the class, but that wasn’t the […]
By: Adrian Coman
I recently started to use MotionLayout in a more extensive way in one of the apps I’m working on. One of the issues I faced was that once I released my finger from the view the snapping animation was too slow and I needed it to be way faster. GIF It’s not very intuitive, but […]
By: Adrian Coman
Stii sa scrii was my first app that I build for Android. And we’ve finally launched it again! New design, new game mode, new questions. It’s basically an app that tests your Romanian grammar knowledge. It has only one pack available at the moment with 50 types of questions and 150 different questions. We already have a […]
By: Adrian Coman
While working on the chat app and knowing that the backend will be done in about 3-4 weeks, I decided that I will not wait that long to test my server connection and responses. Especially, because the flow of the app is pretty complex. Thus, I started to look on how to somehow mock the […]
By: Adrian Coman
For about a week, I started to document myself to build a chat app for Android. I’ve done something similar one year ago, only that I had a few problems while building it because of the complexity. This time, I decided to be a little bit smarter and, in the process, push my limits and […]
By: Adrian Coman