private void loadAndShowEpisodes(Category category) {
   Observable.from(category.episodeUrls)
       .flatMap(itemUrl -> apiAdapter.getEpisode(itemUrl))
       .map(episode -> new Episode(episode.title))
       .toList()
       .filter(episodes -> !episodes.isEmpty())
       .compose(RxUtils.<List<Episode>>applySchedulers())
       .compose(RxLifecycle.bindUntilActivityEvent(lifecycle(), ActivityEvent.PAUSE))
       .doOnSubscribe(() -> progressBar.setVisibility(View.VISIBLE))
       .doOnCompleted(() -> progressBar.setVisibility(View.GONE))
       .doOnError(throwable -> progressBar.setVisibility(View.GONE))
       .subscribe(
           episodeItems -> {
             episodeAdapter.setEpisodes(episodeItems);
             episodeAdapter.setDividers(category.dividers);
           },
           throwable -> {
             Snackbar.make(rvEpisodes, R.string.error_loading_episodes, Snackbar.LENGTH_INDEFINITE)
                 .setAction(R.string.action_retry, v -> loadAndShowEpisodes(category))
                 .show();
           });
 }
  private void initUI(Category category) {
    // Get view references
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    final ImageView ivCategory = (ImageView) findViewById(R.id.iv_category);
    progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    final TextView tvSummary = (TextView) findViewById(R.id.tv_summary);

    // Set title
    toolbar.setTitle(category.title);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Set summary if available
    if (category.summary.isEmpty()) {
      tvSummary.setVisibility(View.GONE);
    } else {
      tvSummary.setText(category.summary);
    }

    // Setup recyclerview
    rvEpisodes = (RecyclerView) findViewById(R.id.rv_episodes);
    final RecyclerView.LayoutManager layoutManager =
        new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    rvEpisodes.setLayoutManager(layoutManager);
    episodeAdapter = new EpisodeAdapter(getApplicationContext());
    rvEpisodes.setAdapter(episodeAdapter);
    episodeAdapter.setOnEpisodeClickListener(
        v -> Snackbar.make(rvEpisodes, R.string.play_video, Snackbar.LENGTH_SHORT).show());

    // Load category image
    Glide.with(this)
        .load(category.imageUrl)
        .placeholder(ContextCompat.getDrawable(this, R.drawable.placeholder))
        .centerCrop()
        .into(ivCategory);
  }