Skip to content

5. PlayerViewHelper: Toro's right hand

Nam Nguyen Hoai edited this page Oct 23, 2016 · 2 revisions

A powerful Helper, support every RecyclerView's child ViewHolder by connect it to Toro's powerful API. Any custom ViewHolder which extends ToroViewHolder are supported by default. Users should create new final instance in their own custom ViewHolder:

public class MySimpleViewHolder extends ToroAdapter.ViewHolder implements ToroPlayer, View.OnLongClickListener {

  private final RecyclerViewItemHelper mHelper;

  public MySimpleViewHolder(View itemView) {
    super(itemView);
    mHelper = new RecyclerViewItemHelper();

    // if user wants to support long press on this ViewHolder, it's recommended that user call super method for full support
    super.setOnItemLongClickListener(this);
  }

  @Override public void onAttachedToParent() {
    mHelper.onAttachedToParent(this, itemView, itemView.getParent());
  }

  @Override public void onDetachedFromParent() {
    mHelper.onDetachedFromParent(this, itemView, itemView.getParent());
  }

  @Override public boolean onLongClick(View v) {
    return mHelper.onItemLongClick(this, itemView, itemView.getParent());
  }
}

Clone this wiki locally