Closed sgelb closed 6 years ago
I just checked and this is actually not due to createDefault()
. With createDefault()
a MaybeNull
instance is added to that observable but it is null
. So the first invocation of updateUserViewContent()
(out of three) is returning in the first if: UserFragment.java#L218
The issue here is really that when loading a user with mUserRepository.get()
we might get two responses: The first one is the cached version from the database/cache and the second one the freshly loaded one from the network. They can be distinguished by Resource::isLoading()
. Maybe we should check here whether the new user is the same than the one already in mUser
.
But you have a point: mUser
should be of type BehaviorSubject<User>
and initialized with BehaviorSubject.create()
.
Due to initialization of
mUser
withcreateDefault()
, an additional user is emitted. As a result,updateUserViewContent
(including the download of the user image) is called twice.