Android Kotlin: Forecast App 04 – Abstracting Retrofit Network Calls – MVVM Tutorial Course

Up until now we’ve created a Retrofit service to communicate with the weather API, we also created all of the pieces needed for a local database using the Room library. So, we basically have all of the data components of our app implemented, right? We can fetch data and then cache it locally, so all that’s left to do is to put it all in a repository to somehow centralize network and local data calls.

Well, while we’re really close to creating a repository, we still have one important step unfinished. We need to wrap the retrofit weather API service into a special class to create an abstraction and to give the code making network calls a better structure.

?Get the code from this tutorial?


Matej Rešetár

Matej is an app developer with a knack for teaching others. If he's not programming, making tutorials or doing other business, he's mostly working out, listening to audiobooks and taking cold showers.

  • Sina says:

    what’s the name of the theme that you are using in the android studio?!
    I’ve searched and installed many material themes for that, but none of them was like the one that you are using! 😀

  • JoeyA says:

    In this tutorial how would you be able to handle network call callbacks like for events when there is a success call, onerrors (httperror), any throwable failures.
    What you did was handle the no network error in the DataSourceImpl, and only use Log.e

    But developers will need to get a handle on that event and do UI changes, for ex. showing error messages.

    For the success calls, I guess it will trigger the observer and pass the LiveData
    But how do you handle the different error scenarios?


  • >