Comments (5)
Good point
We could change it to use the generated string for the section as key, but then this method getAdapterForSection(Section) would have to loop through the sections to find the tag before returning the SectionAdapter.
Or we could just not store any SectionAdapter and have them created on the go by the getAdapterForSection methods. In this case we would also have loop through the sections to check if the Section passed as parameter is valid. So not much benefit in relation to the previous option, as it will also have to instantiate a class on top of looping through the sections.
Both options above will and an extra loop through the sections, so I feel like we could compromise and keep the current solution.
What do you think? Do you have any other ideas?
from sectionedrecyclerviewadapter.
Hem...
I just feel that, having a class instance, for every Section
, to perform a set of "helper function operation", doesn't look very good to me. It just smell redundant, and not efficient.
Usually, for "helper functions", I prefer to design them as public static
set of functions.
But, such design would put burden on caller. We would need to have
public static int getPositionInSection(SectionedRecyclerViewAdapter sectionedAdapter, Section section, final int position)
instead
public int getPositionInSection(final int position)
My understanding is that, you wish to move out all "helper functions" implementation out from SectionedRecyclerViewAdapter class ?
Do you want to consider using default
function feature of interface
?
Something which looks like
interface SectionPositionIdentifier {
SectionedRecyclerViewAdapter getSectionedRecyclerViewAdapter();
// All helper functions implementation will go into SectionPositionIdentifier's default functions.
default int getPositionInSection(final int position) {
SectionedRecyclerViewAdapter sectionedRecyclerViewAdapter = getSectionedRecyclerViewAdapter();
// Perform some computation based on sectionedRecyclerViewAdapter.
return 0;
}
}
public class SectionedRecyclerViewAdapter implements SectionPositionIdentifier {
@Override
public SectionedRecyclerViewAdapter getSectionedRecyclerViewAdapter() {
return this;
}
}
from sectionedrecyclerviewadapter.
I agree with you. They are helper methods and I considered to build them as static methods, but then decided to make it convenient instead.
My understanding is that, you wish to move out all "helper functions" implementation out from SectionedRecyclerViewAdapter class ?
Reasoning is described in this pull request #153
Do you want to consider using default function feature of interface?
That would address items 1 and 3 of the "Pros" described in that pull request, but not items 2 and 4.
Also, the idea was to distinguish between an adapter to manipulate sections and another to manipulate items from a specific section.
Let me know your thoughts..
from sectionedrecyclerviewadapter.
You are right. The proposed default interface method doesn't address item 2 and 4.
In such case, your current HashMap
might be the best available option.
But, I feel maybe we can have the following improvement in the following line?
Check the returned value of
sectionAdapters.put(section, new SectionAdapter(this, section));
It should return null. If not, throw runtime exception as this might imply the caller overrides equals
and hashCode
methods. Such action will cause 2 different instance of Sections returning same value in equals
and hashCode
methods.
This is kind of defensive way, to have early detection on problematic implementation.
Thanks.
from sectionedrecyclerviewadapter.
sounds good
from sectionedrecyclerviewadapter.
Related Issues (20)
- Is it possible to support Paging concept introduced in recent year? HOT 6
- Error adding to dependecies HOT 1
- How can I bind the Header view? HOT 1
- How can I get the Section header position? HOT 5
- Suggestion to add example-code on how to use empty-views HOT 2
- OnClick in onBindItemViewHolder does not work HOT 1
- How to get header position? HOT 1
- swipe to delete... HOT 3
- Design suggestion based on the following use case HOT 1
- Can we have SectionedRecyclerViewAdapter.getSectionItemViewTypeForAdapterViewType as static method? HOT 2
- Optimize onCreateViewHolder
- removeAllSections HOT 2
- How can I get position group of recyclerview? HOT 2
- FirstVisibleItem not change after I use notifyDataSetChange
- Collapse when section when open new one
- Is there a way to set section background,like a cardview style
- how to Expand first item by default ?
- New versions changelog addition. HOT 1
- How Section Support ItemTouchHelper for drag & drop DataItem
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sectionedrecyclerviewadapter.