title: How to update data from Retrofit periodically in MVVM using WorkManager?
body: <p>Help me out please.<br>
  I have a simpe <code>Retrofit</code>-><code>Repository</code>-><code>MVVM</code>-><code>Fragment</code> app.<br>
  What it does is provides current weather from OpenWeatherApi.<br>
  I have my <code>LiveData</code> in my <code>ViewModel</code> observed via <code>Data Binding</code>.<br>
  It all works fine.<br>
  <strong>Issue:</strong><br>
  Now I want a background service which updates weather data every 20 minutes.<br>
  Im trying to implement this with <code>WorkManager</code>.<br>
  And the problem is that I don’t know how to access my <code>ViewModel</code> and how to update <code>LiveData</code> there.<br>
  <strong>Main question:</strong><br>
  How can I update data from Retrofit periodically in MVVM using WorkManager?<br>
  Here is my code:<br>
  ViewModel:  </p>
  
  <pre><code>class CurrentViewModel(application: Application) : AndroidViewModel(application) {
          val repo = mRepository.getInstance(application)
          val context = application
          //This is data i am observing by Data Binding
          var currentWeather: LiveData&lt;CurrentWeather&gt;? = repo.getCurrentWeather()
          //This method does not seem work when called explicitly btw.
          fun updateWeather(){
              currentWeather = repo.getCurrentWeather()
          }
      }
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>class mRepository private constructor(private val context: Context) {
      val retrofitClient = RetrofitResponseProvider()
      //From here I receive LiveData
      fun getCurrentWeather(): LiveData&lt;CurrentWeather&gt;? {
          return retrofitClient.getCurrentWeather()
      }
  }
  </code></pre>
  
  <p>Retrofit:</p>
  
  <pre><code>class RetrofitResponseProvider {
      fun getCurrentWeather(): LiveData&lt;CurrentWeather&gt;? {
          val currentWeatherLivedata: MutableLiveData&lt;CurrentWeather&gt; by lazy {
              MutableLiveData&lt;CurrentWeather&gt;()
          }
          val forecast = RetrofitClientInstanceProvider.getRetrofitInstance()?.create(WeatherApiService::class.java)
          val call = forecast?.getCurrentWeather()
          call?.enqueue(object : Callback&lt;CurrentWeather&gt; {
              override fun onResponse(call: Call&lt;CurrentWeather&gt;, response: Response&lt;CurrentWeather&gt;) {
                  currentWeatherLivedata.value = response.body()
              }
              override fun onFailure(call: Call&lt;CurrentWeather&gt;, t: Throwable) {
              }
          })
          return currentWeatherLivedata
      }
  
  </code></pre>
  
  <p>WorkManager:</p>
  
  <pre><code>class MyWorker(val context: Context, val workerParams: WorkerParameters) :
      Worker(context, workerParams) {
      override fun doWork(): Result {
          //This is what I want it to do somehow
          viewModel.updateWeatherData()
          return Result.success()
      }
  
  }
  
  </code></pre>