Hello everyone! I have a question about collecting...
# android-architecture
s
Hello everyone! I have a question about collecting data from multiple data sources into one list. I have two sources: remote and local. Models for these items almost the same except several fields. It's okay to merge them into one source for viewmodel? In that case new shared model will have several null fields. Or I should collect data separately and not merge models? In the list local items always placed first. Thanks.
1
m
You can get data from remote, save them into your db and only work with local data
👍 1
👀 1
w
Assuming you're using Kotlin, this sounds like a great use case for a sealed class. Have a sealed class representing your data (possibly with the common values between the two of them), then extend it with local and remote.
2
👍 2
k
In that case new shared model will have several null fields
Would possibly be a smell, as your contract does not fit. If you merge them, can you have a domain model that will not contain unnecessary properties?
m
To the view, the source of the data (local/remote) should not matter. Only the nature of the data should. Data of X nature should correspond to an X class. Unless you are showing different, yet similar things (like dogs and cats), the only difference should be the degree of completion between different instances of the object.
And you should have an unified data layer where the completion happens.
👍 1