コード例 #1
0
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_library_category, container, false);
    ButterKnife.bind(this, view);

    adapter = new LibraryCategoryAdapter(this);
    recycler.setHasFixedSize(true);
    recycler.setAdapter(adapter);

    if (getLibraryFragment().getActionMode() != null) {
      setMode(FlexibleAdapter.MODE_MULTI);
    }

    Preference<Integer> columnsPref =
        getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
            ? getLibraryPresenter().preferences.portraitColumns()
            : getLibraryPresenter().preferences.landscapeColumns();

    numColumnsSubscription =
        columnsPref
            .asObservable()
            .doOnNext(recycler::setSpanCount)
            .skip(1)
            // Set again the adapter to recalculate the covers height
            .subscribe(count -> recycler.setAdapter(adapter));

    if (savedState != null) {
      adapter.onRestoreInstanceState(savedState);

      if (adapter.getMode() == FlexibleAdapter.MODE_SINGLE) {
        adapter.clearSelection();
      }
    }

    searchSubscription =
        getLibraryPresenter()
            .searchSubject
            .subscribe(
                text -> {
                  adapter.setSearchText(text);
                  adapter.updateDataSet();
                });

    return view;
  }
コード例 #2
0
 public void setMode(int mode) {
   adapter.setMode(mode);
   if (mode == FlexibleAdapter.MODE_SINGLE) {
     adapter.clearSelection();
   }
 }