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

Duplicate item #96

Closed
mdtuyen opened this issue Jun 3, 2016 · 10 comments
Closed

Duplicate item #96

mdtuyen opened this issue Jun 3, 2016 · 10 comments

Comments

@mdtuyen
Copy link

mdtuyen commented Jun 3, 2016

I make a example with Expandable only have two class i tem is ExpandableHeaderItem ad ExpanableItem:

public class ExpandableHeaderItem
        extends AbstractModelItem<ExpandableHeaderViewHolder>
        implements IExpandable<ExpandableHeaderViewHolder, ExpandableItem>,
        IHeader<ExpandableHeaderViewHolder> 

public class ExpandableItem extends AbstractModelItem<ExpandableItem.ParentViewHolder>
        implements ISectionable<ExpandableItem.ParentViewHolder, ExpandableHeaderItem> ,IExpandable<ExpandableItem.ParentViewHolder, ExpandableItem>, IFilterable, Serializable 

However ExpandableItem have been duplicate.

And I have a question:
I make endless for Expandable item, how to make item expand when it added to recyclerview.

@davideas
Copy link
Owner

davideas commented Jun 3, 2016

Hello @mdtuyen, there's an open issue for this kind of duplication by bornest #95.
What you want to achieve is an expandableHeader of expandables n-levels?

What do you return in the method getExpansionLevel() for ExpandableItem?
You put ExpandableItem as subItem of itself.

@mdtuyen
Copy link
Author

mdtuyen commented Jun 3, 2016

I want to make a Item class for all, Then I will put a layout and a bindView to update for each item type as this library

@davideas
Copy link
Owner

davideas commented Jun 3, 2016

Wait, you are not adopting his method right? the RV is exactly a view recycler, it means the ViewHolder is not scrapped but it is re-used so there's no findViewById that the app is making again.
Clarified this, I created the item interfaces to split bindView for each type, so what you are doing is not properly complaint with this architecture.
Maybe can you explain better?

@mdtuyen
Copy link
Author

mdtuyen commented Jun 3, 2016

Sorry, I only borrow idea from that library that make a wrapper for Item and only change once when init Adapter.

I found that because I fix issue #79 by clear all mItems in animateTo function then readd, call notificationDataSetChanged(). So that initializeItems call twice => duplicate

I use the new fix of you for #79 but issue with sticker not occur but endless not work.

@mdtuyen
Copy link
Author

mdtuyen commented Jun 3, 2016

I use:

HeaderItem expandableHeader = DatabaseService.newExpandableSectionItem(id);
                                    expandableHeader.setHidden(false);
                                    expandableHeader.setExpanded(true);
                                    expandableHeader.setSelectable(false);
                                    newItems.add(expandableHeader);

getExpansionLevel() return 0.
But new item not expanded when loadmore. And if I setHidden(true) => issue duplicate

@davideas
Copy link
Owner

davideas commented Jun 4, 2016

@mdtuyen, new items are not expanded automatically, not yet, I'm now testing if this feature can be added.

Then, what is not working in the endless?
Also, can you give me the part of the code with all the calls of the Adapter?

@davideas
Copy link
Owner

davideas commented Jun 5, 2016

@mdtuyen, I added the new feature to expand item automatically when are added on load more, but I'm not sure to keep it, since it's something very specific.

@mdtuyen
Copy link
Author

mdtuyen commented Jun 6, 2016

Hi, I apply new feature to my code. And:

  • Issue duplicate still occur (old fixed). item added no issue.
  • Refresh -> header missing -> continue refresh header showed.

@davideas
Copy link
Owner

davideas commented Jun 6, 2016

@mdtuyen, duplicated issue I have now also in my demo App, but please write me the code here. Also don't just write "there is an issue doing this", describe how I can reproduce it, your use case, which function you are calling, eventually enable logs, etc...
Thanks. Davide

@mdtuyen
Copy link
Author

mdtuyen commented Jun 6, 2016

Hi, This is my code:

new Builder(mAdapter)
        .setAnimationOnScrolling(false)
        .setAnimationOnReverseScrolling(false)
        .setAutoScrollOnExpand(true)
        .setRemoveOrphanHeaders(true)
        //.setUnlinkAllItemsOnRemoveHeaders(true)
        .setExpandItemsAtStartUp()
        .setDisplayHeadersAtStartUp(true)
        .setActionModeHelper(SelectableAdapter.MODE_IDLE, null)
        .setStickyHeaders(true)
        .setSwipeEnabled(true)
        .setFastScroller(null)
        .setOnDataChangedListender(new OnDataChangedListender() {
            @Override
            public void onRefresh() {
                mAdapter.updateDataSet(DatabaseService.getInstance().getDatabaseList());
            }

            @Override
            public void onLoadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        final List<AbstractFlexibleItem> newItems = new ArrayList<>(2);

                        //Simulating success/failure
                        int id = mAdapter.getItemCountOfTypes(R.layout.recycler_expandable_header_item) + 1;
                        int count = new Random().nextInt(3);
                        for (int i = 0; i < count; i++) {
                            HeaderItem expandableHeader = DatabaseService.newExpandableSectionItem(id);
                            newItems.add(expandableHeader);
                            id++;
                        }
                        //int count = new Random().nextInt(7);
                        //int totalItemsOfType = mAdapter.getItemCountOfTypes(R.layout.recycler_expandable_item);
                        //for (int i = 1; i <= count; i++) {
                        //  newItems.add(DatabaseService.newSimpleItem(totalItemsOfType + i, null));
                        //}
                        //Callback the Adapter to notify the change
                        //Items will be added to the end of the list
                        mAdapter.onLoadMoreComplete(newItems);
                        String message = (newItems.size() > 0 ?
                                "Simulated: " + newItems.size() + " new items arrived :-)" :
                                "Simulated: No more items to load :-(");
                        Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
                    }
                }, 3000);
            }
        })
        .initData(DatabaseService.getInstance().createExpandableSectionsDatabase());

Builder class only a wrapper I use to enable each option for the adapter.

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