At this point we can congratulate ourselves on a good and functional app – current weather and the location are all working properly. What kind of a forecast app would this be though, if it didn’t have a future weather screen? That’s why in this part we’re going to finally start implementing it.
In order to get the future weather working, we need to add the classes to store it in when we fetch the data from the API and we need to store the future weather in the local database. That’s what this part will be about. Then we also have to get the UI working which will be the content of the next part!
?Get the code from this tutorial?
Thanks for the awesome series. I’ve followed it all the way through so far but something is bothering me.
Storing a deferred in the viewModel is problematic. First, it places the responsibility of actually fetching the data back on the fragment via the call to await(). Second, the use of lazy is ok but the LiveData is immutable. While that works, supposed we wanted to listen for changes in settings. There’s no way to update the UI because we’d need to call back to the repository to get the unit specific data and replace the value in our LiveData. We can’t do that because it’s immutable. And then even if we modified that, we still have the issue that it returns a deferred instead of a LiveData object.
Perhaps, we should take a more traditional path by using coroutines in the ViewModel instead of the fragment. If we did that, then we could introduce an OnPreferenceChangeListener in the fragment and then when isMetric changes, update the UI by making a call to viewModel to refetch the data to match the isMetric preference.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.