Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a FlexibleViewHolder #14

Closed
danielpassos opened this issue Dec 5, 2015 · 4 comments
Closed

Add a FlexibleViewHolder #14

danielpassos opened this issue Dec 5, 2015 · 4 comments
Milestone

Comments

@danielpassos
Copy link
Contributor

I was think about add a new utility class FlexibleViewHolder it will help developers it alwasy need to implements the View.OnClickListener and View.OnLongClickListener

public abstract class FlexibleViewHolder extends RecyclerView.ViewHolder
        implements View.OnClickListener, View.OnLongClickListener {

    private final FlexibleAdapter adapter;
    private final OnListItemClickListener onListItemClickListener;

    public FlexibleViewHolder(View itemView,FlexibleAdapter adapter,
                              OnListItemClickListener onListItemClickListener) {
        super(itemView);
        this.adapter = adapter;

        this.onListItemClickListener = onListItemClickListener;

        this.itemView.setOnClickListener(this);
        this.itemView.setOnLongClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (onListItemClickListener.onListItemClick(getAdapterPosition())) {
            toggleActivation();
        }
    }

    @Override
    public boolean onLongClick(View view) {
        onListItemClickListener.onListItemLongClick(getAdapterPosition());
        toggleActivation();
        return true;
    }

    protected void toggleActivation() {
        itemView.setActivated(adapter.isSelected(getAdapterPosition()));
    }

    public interface OnListItemClickListener {
        boolean onListItemClick(int position);
        void onListItemLongClick(int position);
    }

}

So you can easily override the toggleActivation to add whatever you want and implements the OnListItemClickListener on your Activiy/Fragment

@davideas
Copy link
Owner

davideas commented Dec 5, 2015

Yes, this can be useful, indeed. I need to try it.

@danielpassos
Copy link
Contributor Author

@davideas I have that in my locally version of this library, let me send a PR to that ;)

@davideas davideas added this to the 5.0.0 milestone Dec 6, 2015
@davideas
Copy link
Owner

davideas commented Jan 3, 2016

Available from 5.0.0-b1.

@davideas
Copy link
Owner

FlexibleViewHolder is heavily revisited in 5.0.0-b2 in order to support drag&drop and swipe actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants