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

Please provide getSectionCount() and getSection(position) #295

Closed
ghost opened this issue Sep 26, 2019 · 5 comments
Closed

Please provide getSectionCount() and getSection(position) #295

ghost opened this issue Sep 26, 2019 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 26, 2019

Please, correct me, if I'm doing something wrong. I have sections with header and items. Each section has id. When I need to add\remove\update item in this section I do:

for (s in 0 until adapter.groupCount) {
	val section = adapter.getGroup(s) as DFLineSection
	if (section.sectionKey != tournamentId) continue
	val groupCount = section.groupCount
	for (i in 1 until groupCount) { // 1 to ignore header
		val item = section.getGroup(i) as DFLineItem
		if (item.event.key != serverMarket.key.eventId) continue
...

The problem - adapter.groupCount returns number of all items I have in the list, not sections. adapter.getGroup(s) works almost correctly - for each s it returns correct section, but as many times as many items this section has.
What I believe would be very useful - possibility to get number of and then navigate directly by sections.

Also I would like to have adapter.removeSection(position) and section.removeItem(position), now it is only possible to remove using section\item as argument.

@ghost ghost added enhancement waiting for owners Waiting on an answer by project owners labels Sep 26, 2019
@ValCanBuild
Copy link
Collaborator

ValCanBuild commented Sep 26, 2019

A Section is a subclass of a Group and GroupAdapter already provides methods for removing Groups. You've got remove(Group) and removeGroup(index) which you can use.

Groupie is built with composability in mind. Your adapter could be built from many sections, each with subsections and subsubsections etc. If you want to keep a track of a particular Group/Section you want to update then store a reference to it and just directly update it.

@ValCanBuild ValCanBuild removed the waiting for owners Waiting on an answer by project owners label Sep 26, 2019
@ghost
Copy link
Author

ghost commented Sep 26, 2019

Well, but then there is non obvious point:
adapter.groupCount returns sections count, but adapter.getGroup(position) returns group containing item with raw position
Let's imagine situation

section1
   item
section2
   item

adapter.groupCount returns 2
but adapter.getGroup(1) returns section1
Finally I managed to understand what is happening, but I believe it should be better explained in docs.

@ValCanBuild
Copy link
Collaborator

@AlexMatiash agreed on that point. Those methods need to be named better. Perhaps it'll be useful to have a getTopLevelGroup(topLevelGroupPosition) type method. I agree the current naming is confusing.

I'll explore for the next release

@ValCanBuild
Copy link
Collaborator

@AlexMatiash PR opened #296

ValCanBuild pushed a commit that referenced this issue Oct 2, 2019
Update method names in GroupAdapter and add javadoc to better document what they do
@ValCanBuild
Copy link
Collaborator

Now deployed in 2.7.0

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

1 participant