I\'m using Android MVVM architecture with LiveData. I have an object like this
public class User {
private String firstName;
private String lastName;
How can I make sure when some filed in user object changes observers get notified? BTW it is important to me to keep this data in the separate object and not use primary values like Strings in my ViewModel.
You can use androidx.lifecyle.Transformation class to monitor for individual fields.
val user = MutableLiveData();
//to monitor for User.Name
val firstName: LiveData = Transformations.map {it.firstName}
val lastName: LiveData = Transformations.map {it.lastName}
you update user as per normal, and listen for firstname/lastname to monitor for changes in those fields.