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

Sticky Header doesn't update selected view state correct for MODE_SINGLE #347

Closed
vladyslav-zh opened this issue Apr 19, 2017 · 11 comments
Closed

Comments

@vladyslav-zh
Copy link

vladyslav-zh commented Apr 19, 2017

I have sticky headers

public class MyHeader extends AbstractFlexibleItem<HeaderViewHolder>
        implements  IHeader<HeaderViewHolder>...

And simple items

public class SimpleViewModel extends AbstractFlexibleItem<HeaderViewHolder>
 implements ISectionable<HeaderViewHolder, IHeader>`

and my adapter is initialized like this:

mAdapter = new FlexibleAdapter<>(data, this);
mAdapter.enableStickyHeaders();
//or 
mAdapter.setStickyHeaders(true);
mAdapter.setDisplayHeadersAtStartUp(true);
mAdapter.showAllHeaders();
mAdapter.expandItemsAtStartUp();
mAdapter.setMode(MODE_SINGLE);
mRecyclerView.setAdapter(mAdapter);

and all activation logic like in wiki example

@Override
public boolean onItemClick(int position) {
	if (position != mActivatedPosition) setActivatedPosition(position);
	return true;//Important!
}
//Optional
private void setActivatedPosition(int position) {
	mActivatedPosition = position;
	mAdapter.toggleSelection(position);//Important!
}

But sometime's two headers are highlighted 1 view is not updated correctly. OnClick functions are call.
It happens when i have 2 headers coherently without children and first header is half-scrolled. After scroll it fix.

How i can fix this issue?

@davideas
Copy link
Owner

@vladislav-z, following your code is quite difficult, could you please make a video (not public) and post it on your Youtube, so I can better understand your situation?

Few notes:

  • showAllHeaders() and expandItemsAtStartUp() you don't need to call.
  • if you use rc1 version data must be a copy (new ArrayList<>(data)), if you use the snapshot version (next rc2) copy is done internally.
  • If you don't have particular needs, maybe you can simply extends AbstractHeaderItem and AbstractSectionableItem, also be sure to have correctly implemented equals in the items, most of the time it is the cause.

@vladyslav-zh
Copy link
Author

@davideas
Hello, thank you for the answer, I removed these methods, but it didn't fix, so I recorded video, like you wanted.

single mode video.zip

@davideas
Copy link
Owner

@vladislav-z, I start to understand, I would like to try it out without recreating the app. Could you share the demo code in your Github project?

@davideas
Copy link
Owner

davideas commented May 1, 2017

@vladislav-z, I can't help you more if I can't see the code.

@vladyslav-zh
Copy link
Author

@davideas Hello, i added sample https://github.com/Vladislav-Z/flexiblebug

@davideas
Copy link
Owner

davideas commented May 3, 2017

@vladislav-z, this should now be resolved, thanks for the demo bug.

@vladyslav-zh
Copy link
Author

vladyslav-zh commented May 4, 2017

@davideas Thank you! And remove please final from public final void onBindViewHolder

@davideas
Copy link
Owner

davideas commented May 4, 2017

@vladislav-z, as explained in the migration page, from rc2 the classic method to bind VH becomes superfluous, since we will delegate to the items to bind themself to VH. Now the 3 methods in the IFlexible are declared abstract, therefore onBindViewHolder won't ever be used.

Do you actually use it? how and in which occasion you should use it?

@vladyslav-zh
Copy link
Author

@davideas yes, we actually use it because we are using RxJava and pass a PublishSubject to a viewholder in this method to pass touch events outside the adapter. This is related to the fact that we use MVP architecture so each viewholder also has a presenter which is "bound" to the view in the onBindViewHolder() method. I have tried to do it in the onViewAttachedToWindow() but this method is called later than onBindViewHolder() so it wouldn't work.

@davideas
Copy link
Owner

davideas commented May 4, 2017

Ok I see, but the presenter cannot be used inside of each item? why is necessary to call that method since it will skip all the super implementation?!

@davideas
Copy link
Owner

davideas commented May 7, 2017

For the moment, I've removed some final methods in the Snapshot. I will analyse better this point for final release.

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