Tabnine Logo
FastAdapter
Code IndexAdd Tabnine to your IDE (free)

How to use
FastAdapter
in
com.mikepenz.fastadapter

Best Java code snippets using com.mikepenz.fastadapter.FastAdapter (Showing top 20 results out of 315)

origin: mikepenz/MaterialDrawer

/**
 * get the adapter (null safe)
 *
 * @return the FastAdapter used with this drawer
 */
protected FastAdapter<IDrawerItem> getAdapter() {
  if (mAdapter == null) {
    mAdapter = FastAdapter.with(Arrays.asList(mHeaderAdapter, mItemAdapter, mFooterAdapter), Arrays.<IAdapterExtension<IDrawerItem>>asList(mExpandableExtension));
    mAdapter.withSelectable(true);
    mAdapter.withMultiSelect(false);
    mAdapter.withAllowDeselection(false);
    mAdapter.setHasStableIds(mHasStableIds);
  }
  return mAdapter;
}
origin: mikepenz/FastAdapter

/**
 * Gets all items (including sub items) from the FastAdapter
 *
 * @param fastAdapter the FastAdapter
 * @return a list of all items including the whole subItem hirachy
 */
public static <Item extends IItem> List<Item> getAllItems(FastAdapter<Item> fastAdapter) {
  int size = fastAdapter.getItemCount();
  List<Item> items = new ArrayList<>(size);
  for (int i = 0; i < size; i++) {
    Item item = fastAdapter.getItem(i);
    items.add(item);
    addAllSubItems(item, items);
  }
  return items;
}
origin: mikepenz/FastAdapter

public ActionModeHelper(FastAdapter<Item> fastAdapter, int cabMenu, ActionMode.Callback callback) {
  this.mFastAdapter = fastAdapter;
  this.mCabMenu = cabMenu;
  this.mCallback = callback;
  this.mInternalCallback = new ActionBarCallBack();
  this.mSelectExtension = fastAdapter.getExtension(SelectExtension.class);
  if (mSelectExtension == null) {
    throw new IllegalStateException("The provided FastAdapter requires the `SelectExtension` or `withSelectable(true)`");
  }
}
origin: mikepenz/MaterialDrawer

/**
 * Define a custom Adapter which will be used in the drawer
 * NOTE: this is not recommender
 * WARNING: if you do this after adding items you will loose those!
 *
 * @param adapter the FastAdapter to use with this drawer
 * @return this
 */
public DrawerBuilder withAdapter(@NonNull FastAdapter<IDrawerItem> adapter) {
  this.mAdapter = adapter;
  //we have to rewrap as a different FastAdapter was provided
  adapter.addAdapter(0, mHeaderAdapter);
  adapter.addAdapter(1, mItemAdapter);
  adapter.addAdapter(2, mFooterAdapter);
  adapter.addExtension(mExpandableExtension);
  return this;
}
origin: mikepenz/MaterialDrawer

/**
 * set the selection of the MiniDrawer
 *
 * @param identifier the identifier of the item which should be selected (-1 for none)
 */
public void setSelection(long identifier) {
  if (identifier == -1) {
    mAdapter.deselect();
  }
  int count = mAdapter.getItemCount();
  for (int i = 0; i < count; i++) {
    IDrawerItem item = mAdapter.getItem(i);
    if (item.getIdentifier() == identifier && !item.isSelected()) {
      mAdapter.deselect();
      mAdapter.select(i);
    }
  }
}
origin: mikepenz/FastAdapter

mFastAdapter = FastAdapter.with(Arrays.asList(headerAdapter, itemAdapter));
mFastAdapter.setHasStableIds(true);
mFastAdapter.withSelectable(true);
mFastAdapter.withMultiSelect(true);
mFastAdapter.withSelectOnLongClick(true);
mFastAdapter.withSelectionListener(new ISelectionListener<SimpleItem>() {
  @Override
  public void onSelectionChanged(SimpleItem item, boolean selected) {
mFastAdapter.withOnPreClickListener(new OnClickListener<SimpleItem>() {
  @Override
  public boolean onClick(View v, IAdapter<SimpleItem> adapter, @NonNull SimpleItem item, int position) {
mFastAdapter.withOnClickListener(new OnClickListener<SimpleItem>() {
  @Override
  public boolean onClick(View v, IAdapter<SimpleItem> adapter, @NonNull SimpleItem item, int position) {
mFastAdapter.withOnPreLongClickListener(new OnLongClickListener<SimpleItem>() {
  @Override
  public boolean onLongClick(View v, IAdapter<SimpleItem> adapter, SimpleItem item, int position) {
mFastAdapter.withSavedInstanceState(savedInstanceState);
origin: mikepenz/MaterialDrawer

mAdapter.withMultiSelect(mMultiSelect);
if (mMultiSelect) {
  mAdapter.withSelectOnLongClick(false);
  mAdapter.withAllowDeselection(true);
  mSelectedItemPosition = 1;
mAdapter.deselect();
mAdapter.select(mSelectedItemPosition);
mAdapter.withOnClickListener(new OnClickListener<IDrawerItem>() {
  @Override
  public boolean onClick(final View view, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
mAdapter.withOnLongClickListener(new OnLongClickListener<IDrawerItem>() {
  @Override
  public boolean onLongClick(View view, IAdapter<IDrawerItem> adapter, final IDrawerItem item, final int position) {
    mAdapter.deselect();
    mAdapter.withSavedInstanceState(mSavedInstance, Drawer.BUNDLE_SELECTION);
    DrawerUtils.setStickyFooterSelection(this, mSavedInstance.getInt(Drawer.BUNDLE_STICKY_FOOTER_SELECTION, -1), null);
  } else {
    mAdapter.deselect();
    mAdapter.withSavedInstanceState(mSavedInstance, Drawer.BUNDLE_SELECTION_APPENDED);
    DrawerUtils.setStickyFooterSelection(this, mSavedInstance.getInt(Drawer.BUNDLE_STICKY_FOOTER_SELECTION_APPENDED, -1), null);
  int selection = mAdapter.getSelections().size() == 0 ? -1 : mAdapter.getSelections().iterator().next();
  mOnDrawerItemClickListener.onItemClick(null, selection, getDrawerItem(selection));
origin: mikepenz/FastAdapter

mFastAdapter = FastAdapter.with(Arrays.asList(mHeaderAdapter, mItemAdapter), Arrays.<IAdapterExtension<IItem>>asList(mExpandableExtension));
mFastAdapter.withSelectable(true);
mFastAdapter.withMultiSelect(true);
mFastAdapter.withSelectOnLongClick(true);
mFastAdapter.withOnPreClickListener(new OnClickListener<IItem>() {
  @Override
  public boolean onClick(View v, IAdapter adapter, @NonNull IItem item, int position) {
mFastAdapter.withOnPreLongClickListener(new OnLongClickListener<IItem>() {
  @Override
  public boolean onLongClick(View v, IAdapter adapter, IItem item, int position) {
mFastAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
  @Override
  public void onChanged() {
mFastAdapter.withSavedInstanceState(savedInstanceState);
origin: mikepenz/FastAdapter

fastAdapter = FastAdapter.with(itemAdapter);
fastAdapter.withSelectable(true);
fastAdapter.withOnClickListener(new OnClickListener<SimpleItem>() {
  @Override
  public boolean onClick(View v, IAdapter<SimpleItem> adapter,
fastAdapter.withSavedInstanceState(savedInstanceState);
origin: mikepenz/FastAdapter

mFastAdapter = FastAdapter.with(Arrays.asList(mItemAdapter));
mFastAdapter.withSelectable(true);
mFastAdapter.withMultiSelect(true);
mFastAdapter.withSelectOnLongClick(false);
selectExtension = mFastAdapter.getExtension(SelectExtension.class);
origin: mikepenz/FastAdapter

/**
 * make sure we return the Item from the FastAdapter so we retrieve the item from all adapters
 *
 * @param position
 * @return
 */
public Item getItem(int position) {
  return mFastAdapter.getItem(position);
}
origin: mikepenz/FastAdapter

fastAdapter = FastAdapter.with(Arrays.asList(itemAdapter));
fastAdapter.withSelectable(true);
fastAdapter.withSavedInstanceState(savedInstanceState);
origin: mikepenz/FastAdapter

identifier = it.next();
pos = fastAdapter.getPosition(identifier);
item = fastAdapter.getItem(pos);
  parentPos = fastAdapter.getPosition(parent);
  boolean success = ((IExpandable) parent).getSubItems().remove(item);
    fastAdapter.notifyAdapterItemChanged(parentPos);
  IAdapter adapter = fastAdapter.getAdapter(pos);
  boolean success = false;
  if (adapter instanceof IItemAdapter) {
    success = ((IItemAdapter) adapter).remove(pos) != null;
    if (success) {
      fastAdapter.notifyAdapterItemRemoved(pos);
origin: mikepenz/FastAdapter

/**
 * @param position the global position of the current item
 * @return a set with the global positions of all expanded items on the root level
 */
public int[] getExpandedItemsRootLevel(int position) {
  int[] expandedItems;
  ArraySet<Integer> expandedItemsList = new ArraySet<>();
  Item item = mFastAdapter.getItem(position);
  for (int i = 0, size = mFastAdapter.getItemCount(); i < size; i++) {
    Item currItem = mFastAdapter.getItem(i);
    if (currItem instanceof ISubItem) {
      IItem parent = ((ISubItem) currItem).getParent();
      if (parent instanceof IExpandable && ((IExpandable) parent).isExpanded()) {
        i += ((IExpandable) parent).getSubItems().size();
        if (parent != item)
          expandedItemsList.add(mFastAdapter.getPosition((Item) parent));
      }
    }
  }
  int expandedItemsListLength = expandedItemsList.size();
  expandedItems = new int[expandedItemsListLength];
  for (int i = 0; i < expandedItemsListLength; i++) {
    expandedItems[i] = expandedItemsList.valueAt(i);
  }
  return expandedItems;
}
origin: mikepenz/FastAdapter

fastAdapter = FastAdapter.with(Arrays.asList(headerAdapter, itemAdapter));
fastAdapter.withSelectable(true);
fastAdapter.setHasStableIds(true);
fastAdapter.withSavedInstanceState(savedInstanceState);
origin: mikepenz/FastAdapter

/**
 * creates a new FastAdapter with the provided adapters
 * if adapters is null, a default ItemAdapter is defined
 *
 * @param adapters the adapters which this FastAdapter should use
 * @return a new FastAdapter
 */
public static <Item extends IItem, A extends IAdapter> FastAdapter<Item> with(@Nullable Collection<A> adapters) {
  return with(adapters, null);
}
origin: mikepenz/FastAdapter

  @Override
  public void onClick(View v, int position, FastAdapter<RadioButtonSampleItem> fastAdapter, RadioButtonSampleItem item) {
    if (!item.isSelected()) {
      Set<Integer> selections = fastAdapter.getSelections();
      if (!selections.isEmpty()) {
        int selectedPosition = selections.iterator().next();
        fastAdapter.deselect();
        fastAdapter.notifyItemChanged(selectedPosition);
      }
      fastAdapter.select(position);
    }
  }
}
origin: mikepenz/FastAdapter

@Test
public void select() throws Exception {
  adapter.withSelectable(true);
  itemAdapter.set(TestDataGenerator.genTestItemList(100));
  assertThat(adapter.getSelectedItems().size()).isEqualTo(0);
  assertThat(adapter.getSelections().size()).isEqualTo(0);
  adapter.select(10);
  assertThat(adapter.getSelectedItems().size()).isEqualTo(1);
  assertThat(adapter.getSelectedItems().iterator().next().getIdentifier()).isEqualTo(10);
  assertThat(adapter.getSelections().size()).isEqualTo(1);
  assertThat(adapter.getSelections().iterator().next()).isEqualTo(10);
}
origin: mikepenz/FastAdapter

.withSelectable(true)
.withMultiSelect(true)
.withSelectOnLongClick(true)
.withOnPreClickListener(new OnClickListener<IItem>() {
  @Override
  public boolean onClick(View v, IAdapter<IItem> adapter, @NonNull IItem item, int position) {
.withOnClickListener(new OnClickListener<IItem>() {
  @Override
  public boolean onClick(View v, IAdapter<IItem> adapter, @NonNull IItem item, int position) {
.withOnPreLongClickListener(new OnLongClickListener<IItem>() {
  @Override
  public boolean onLongClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
origin: mikepenz/FastAdapter

/**
 * opens the expandable item at the given position
 *
 * @param position          the global position
 * @param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false
 */
public void expand(int position, boolean notifyItemChanged) {
  Item item = mFastAdapter.getItem(position);
  if (item != null && item instanceof IExpandable) {
    IExpandable expandable = (IExpandable) item;
    //if this item is not already expanded and has sub items we go on
    if (!expandable.isExpanded() && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) {
      IAdapter<Item> adapter = mFastAdapter.getAdapter(position);
      if (adapter != null && adapter instanceof IItemAdapter) {
        ((IItemAdapter<?, Item>) adapter).addInternal(position + 1, expandable.getSubItems());
      }
      //remember that this item is now opened (not collapsed)
      expandable.withIsExpanded(true);
      //we need to notify to get the correct drawable if there is one showing the current state
      if (notifyItemChanged) {
        mFastAdapter.notifyItemChanged(position);
      }
    }
  }
}
com.mikepenz.fastadapterFastAdapter

Javadoc

The `FastAdapter` class is the core managing class of the `FastAdapter` library, it handles all `IAdapter` implementations, keeps track of the item types which can be displayed and correctly provides the size and position and identifier information to the RecyclerView.

It also comes with IAdapterExtension allowing to further modify its behaviour. Additionally it allows to attach various different listener's, and also EventHooks on per item and view basis.

See the sample application for more details

Most used methods

  • with
    creates a new FastAdapter with the provided adapters if adapters is null, a default ItemAdapter is d
  • getItem
    gets the IItem by a position, from all registered adapters
  • getItemCount
    calculates the total ItemCount over all registered adapters
  • getExtension
  • getAdapter
    Gets the adapter for the given position
  • getPosition
    Searches for the given item and calculates its global position
  • getSelections
  • withSelectable
    Set to true if you want the items to be selectable. By default, no items are selectable
  • addExtension
  • getPreItemCountByOrder
    calculates the item count up to a given (excluding this) order number
  • getRelativeInfo
    Internal method to get the Item as ItemHolder which comes with the relative position within its adap
  • notifyItemChanged
  • getRelativeInfo,
  • notifyItemChanged,
  • saveInstanceState,
  • select,
  • withSavedInstanceState,
  • addAdapter,
  • getItemId,
  • getItemViewType,
  • getPreItemCount,
  • getSelectedItems

Popular in Java

  • Reading from database using SQL prepared statement
  • putExtra (Intent)
  • getSystemService (Context)
  • setScale (BigDecimal)
  • Menu (java.awt)
  • String (java.lang)
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Join (org.hibernate.mapping)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now