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

[QUESTION] Adding section item to section that is empty, ie, has an orphan header #230

Closed
ahmedkhan23 opened this issue Nov 15, 2016 · 4 comments
Labels

Comments

@ahmedkhan23
Copy link

Are the following limitations ?

  1. We drag items out of a section so that we now have an orphan header. Can we drag items back into this section [that currently has no items] ?

  2. Can we swap items of different types ? Both items extend AbstractSectionableItem.

@davideas
Copy link
Owner

davideas commented Nov 15, 2016

@ahmedkhan23, yes, check the demo app, example Headers and Sections. This is what I call auto-linkage.
There are methods and callbacks that you need to override/implement to follow your use case of non swapping/dragging.

Pay attention that the support of Orphan headers, as I intended, is going to be deprecated soon with the next pre-release. Read issue #200 more more information.

@ahmedkhan23
Copy link
Author

Will v5.0.0 b8 always be available in the repo for future access ?
If you are able to tell me which methods to override that would be great.

Also, in general [and perhaps particular to your lib]: what determines the stable ID for any particular ViewHolder ? I ran into an IllegalStateException earlier when trying to swap/drag views with the message that 2 ViewHolders had the same stable ID.

@davideas
Copy link
Owner

davideas commented Nov 16, 2016

Will v5.0.0 b8 always be available in the repo for future access ?

Yes, 5.0.0-b8, like older pre-releases as well, remains available at JCentral.

What determines the stable ID for any particular ViewHolder ?

As far as I know, stable ids should be used in conjunction only with notifyDataSetChanged() to animate differences, otherwise if items have no stable ids, that method won't run any animations by definition.
In this library, the only way to call that method is to pass animate=false as parameter to updateDataSet(), otherwise single notifications are the normality called everywhere.
Now, notifyDataSetChanged() is very fast when updating the data set but, as said, it comes with no animations, it also rebinds all items again. With stable ids it should make the binding only for the real one that changed.
The items have stable ids if their id is unique, so you should implement hashCode() too and return the hash code of the id of your item in accordance with equals()!
Finally, depending on your business information, if you have thousands of items and you are going to use updateDataSet() with animate=false, is always a good choice to provide stableIds=true in the Adapter constructor, so items will animate however.

You can read more about it, by googling it.

@davideas
Copy link
Owner

davideas commented Nov 16, 2016

Ragarding the methods for dragging, there's a listener OnItemMoveListener with the methods shouldMoveItem() and onItemMove(), read the javaDoc.
Exists OnItemSwipeListener for swiping too, but I still didn't use them in a real project, somebody did it, so I don't know exactly the needs for new methods if these are not enough.

There's also shouldMove() in the Adapter method that can be overridden but it simply wraps the call to the listener that is better to implement.
ItemTouchHelperCallback is the originator of the calls, that class can be completely customized by the user and set to Adapter. You can extends the existing one, because I wrote some basic code that works for everyone.
The demoApp has the left swiping unfinished, by the way, I need some help for background click and to restore back the swiping automatically if user undoes the action. That I don't know how to do.

Then the FlexibleViewHolder has specific settings for dragging and swiping you might want to enable.

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

No branches or pull requests

2 participants