title: Combining RxJava with LiveData
body: <p>I have data in JSON file and I want to write ItemRepository class using RxJava (I'm new on this topic), because I've read that using LiveData in repository isn't good idea. Repository should allow to fetch all items (on create view) or filtered by name (later by sarchBar). I don't know how to combine the Repo's Rx stuff with LiveData which is used to set data in RecyclerView's adapter. I know about LiveDataReactiveStreams, but I'm not sure how to use it. I also think that it might be good idea to process the file asynchronous and store the result cached to not re-read the file every method call. What i've got now is:</p>
  <p>Fragment:</p>
  <pre><code>itemAdapter = new ItemAdapter();
  recyclerView = rootView.findViewById(R.id.recyclerView);
  recyclerView.setAdapter(itemAdapter);
  recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
  mViewModel.getItemsMutableLiveData().observe(getViewLifecycleOwner(), items -&gt; {
      itemAdapter.setItems(items);
  });
  mViewModel.loadItems();
  
  </code></pre>
  <p>ViewModel:</p>
  <pre><code>public class MainViewModel extends ViewModel {
      ItemRepository repository = new ItemRepository();
      private MutableLiveData&lt;List&lt;Item&gt;&gt; itemsMutableLiveData = new MutableLiveData&lt;&gt;();
  
      public void loadItems(){
          repository.findAll()
                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe((items, throwable) -&gt; itemsMutableLiveData.setValue(items));
      }
  
      public void searchByName(String name){
          //repository.findByName(name);
      }
  
      public MutableLiveData&lt;List&lt;Item&gt;&gt; getItemsMutableLiveData() {
          return itemsMutableLiveData;
      }
  }
  </code></pre>
  <p>Repo:</p>
  <pre><code>public class ItemRepository {
      public Single&lt;List&lt;Item&gt;&gt; findAll(){
          return Single.fromCallable(ReaderAndParser::processFiles);
      }
  
      public Observable&lt;List&lt;Item&gt;&gt; findByName(String name){
          /*return Observable.fromCallable(ReaderAndParser::processFiles)
                  .flatMap(Observable::fromIterable)
                  .filter(item -&gt; item.getName().contains(name))
                  .toList()
                  */
          return null;
      }
  }
  
  class ReaderAndParser{
      static List&lt;Item&gt; processFiles(){
          //Some reading and parsing
          List&lt;Item&gt; items = new ArrayList&lt;&gt;();
          items.add(new Item(&quot;A&quot;));
          items.add(new Item(&quot;B&quot;));
          items.add(new Item(&quot;C&quot;));
          return  items;
      }
  }
  </code></pre>
  <p>Could you give me any tips or examples? Thank you.</p>
  <p><br>EDIT The question is: how to do the Repository class using RxJava properly (maybe using async for reading file and caching the result) and how to handle the results in ViewModel's LiveData so I can update an UI.</p>