title: Sync between Local Database/Location and Network using Repository
body: <p>I am implementing a weather app, that gets the forecast from DarkSky through Retrofit and location from GoogleFusedLocationClient. My goal is to save UI data through app closure and configuration change. I achieved it using Room+ViewModel+LiveData and Repository model. But I am getting my location and forecast in my fragment and not in the repository, the goal is to move it to repository.<br>
  So that the repository looks into the database and if it's empty fetches data from network.<br>
  My current Repository:</p>
  
  <pre><code>public class UIRepository {
  
      private UIDao mUIDao;
      private LiveData&lt;List&lt;UIData&gt;&gt; mAllUIData;
  
      UIRepository(Application application) {
          PhotoDatabase db = PhotoDatabase.getDatabase(application);
          mUIDao = db.uiDao();
          mAllUIData = mUIDao.getAllUIData();
      }
  
      LiveData&lt;List&lt;UIData&gt;&gt; getAllUIData() {
          return mAllUIData;
      }
  
      public void insert(UIData uiData) {
          new insertAsyncTask(mUIDao).execute(uiData);
      }
  
      private static class insertAsyncTask extends AsyncTask&lt;UIData, Void, Void&gt; {
  
          private UIDao mAsyncDao;
  
          insertAsyncTask(UIDao uiDao) {
              mAsyncDao = uiDao;
          }
  
          @Override
          protected Void doInBackground(UIData... uiData) {
              mAsyncDao.insert(uiData[0]);
              return null;
          }
      }
  } 
  </code></pre>
  
  <p>My separate class for getting the location can be found <a href="https://codereview.stackexchange.com/questions/189987/getting-location-using-livedata-and-fusedlocationproviderclient">here</a>. And for the forecast it's just Retrofit.<br>
  How would I go about combining those elements in the repository?</p>