luizgrp / SectionedRecyclerViewAdapter

An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.
MIT License
1.68k stars 372 forks source link

Can we have isHeaderPositionInSection and isFooterPositionInSection in SectionedRecyclerViewAdapter #109

Closed yccheok closed 6 years ago

yccheok commented 6 years ago

In conjunction with https://github.com/luizgrp/SectionedRecyclerViewAdapter/issues/108 , given an absolute position in RecyclerViewAdapter, we would like to know whether the absolute position is referring to header/footer of a Section.

Can we provide the following 2 functions - isHeaderPositionInSection and isFooterPositionInSection?

My first thought of their implementations would be

public boolean isHeaderPositionInSection(int position) {
    return getPositionInSection(position) == -1;
}

public boolean isFooterPositionInSection(int position) {
    Section section = getSectionForPosition(position);

    if (!section.hasFooter()) {
        return false;
    }

    return getPositionInSection(position) == section.getSectionItemsTotal() - 1;
}
luizgrp commented 6 years ago

Sounds good 👍

luizgrp commented 6 years ago

Hi @yccheok,

I think these methods are redundant, given you can use getSectionItemViewType(position) and check if the value is VIEW_TYPE_HEADER or VIEW_TYPE_FOOTER.

What do you think?

yccheok commented 6 years ago

You are right. I re-check my application code again. I don't find a valid use case anymore for my previous request.