Ejemplo n.º 1
0
 public void setMangas(List<Manga> mangas) {
   if (mangas != null) {
     adapter.setItems(mangas);
   } else {
     adapter.clear();
   }
 }
Ejemplo n.º 2
0
  private void toggleSelection(int position) {
    LibraryFragment f = getLibraryFragment();

    adapter.toggleSelection(position, false);
    f.getPresenter().setSelection(adapter.getItem(position), adapter.isSelected(position));

    int count = f.getPresenter().selectedMangas.size();
    if (count == 0) {
      f.destroyActionModeIfNeeded();
    } else {
      f.setContextTitle(count);
      f.invalidateActionMode();
    }
  }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 4
0
 @Override
 public boolean onListItemClick(int position) {
   if (getLibraryFragment().getActionMode() != null && position != -1) {
     toggleSelection(position);
     return true;
   } else {
     openManga(adapter.getItem(position));
     return false;
   }
 }
Ejemplo n.º 5
0
 public void setMode(int mode) {
   adapter.setMode(mode);
   if (mode == FlexibleAdapter.MODE_SINGLE) {
     adapter.clearSelection();
   }
 }
Ejemplo n.º 6
0
 @Override
 public void onSaveInstanceState(Bundle outState) {
   adapter.onSaveInstanceState(outState);
   super.onSaveInstanceState(outState);
 }