Пример #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
 private void subscribeToChanges() {
   RxSharedPreferences prefs =
       RxSharedPreferences.create(PreferenceManager.getDefaultSharedPreferences(mAppContext));
   Preference<Integer> lastPage = prefs.getInteger(Constants.PREF_LAST_PAGE);
   Observable.merge(
           mBookmarkModel.tagsObservable(),
           mBookmarkModel.bookmarksObservable(),
           lastPage.asObservable())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           new Action1<Object>() {
             @Override
             public void call(Object o) {
               if (mFragment != null) {
                 requestData(false);
               } else {
                 mCachedData = null;
               }
             }
           });
 }