private void setupAdapter() {

    GridLayoutManager gridLayoutManager = new GridLayoutManager(SearchActivity.this, 5);
    gridLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    gridLayoutManager.setSmoothScrollbarEnabled(true);

    searchAdapter = new SearchAdapter(this);
    searchAdapter.setCallback(SearchActivity.this);

    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(searchAdapter);
    recyclerView.addItemDecoration(new MarginDecoration(SearchActivity.this, R.dimen.material_4dp));
  }
Example #2
0
  private void setupAdapter() {

    this.swipeRefreshLayout.setColorSchemeResources(Constants.colors);

    this.compositeSubscription.add(
        RxSwipeRefreshLayout.refreshes(swipeRefreshLayout)
            .compose(ListActivity.this.<Void>bindUntilEvent(ActivityEvent.DESTROY))
            .subscribe(
                new SimpleObserver<Void>() {
                  @Override
                  public void onNext(Void o) {
                    /*refresh*/
                    listPresenter.loadData();
                  }
                }));

    gridLayoutManager = new GridLayoutManager(ListActivity.this, 2);
    gridLayoutManager.setSmoothScrollbarEnabled(true);

    gridLayoutManager.setSpanSizeLookup(
        new GridLayoutManager.SpanSizeLookup() {
          @Override
          public int getSpanSize(int position) {
            /*position == 0*/
            return forecastAdapter.isHeader(position) ? gridLayoutManager.getSpanCount() : 1;
          }
        });

    forecastAdapter = new ForecastAdapter(ListActivity.this);
    forecastAdapter.setCallback(ListActivity.this);

    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(forecastAdapter);
    recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    recyclerView.addItemDecoration(new GridDecoration(ListActivity.this));
  }