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

Bring back old pre-2.7.0 methods and mark them as deprecated. #303

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions library/src/main/java/com/xwray/groupie/GroupAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ public int getItemCountForGroup(int groupIndex) {
return groups.get(groupIndex).getItemCount();
}

/**
* This returns the total number of items contained in the top level group at the passed index
* @deprecated This method has been deprecated in favour of {@link #getItemCountForGroup(int)}. Please use that method instead.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would have been awesome if we had this file in Kotlin - we could have used the @ReplaceWith annotation like described here: https://hackernoon.com/how-kotlins-deprecated-relieves-pain-of-colossal-refactoring-8577545aaed.

This should work for now though!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would have indeed. I have explored converting the library to Kotlin but the benefit of a direct conversion isn't that great over just keeping it in Java. It'll be worth it more if we decide to do a larger API overhaul that leverages Kotlin features a lot more.

*/
@Deprecated
public int getItemCount(int groupIndex) {
return getItemCountForGroup(groupIndex);
}

public void clear() {
for (Group group : groups) {
group.unregisterGroupDataObserver(this);
Expand Down Expand Up @@ -367,6 +376,16 @@ public void removeGroupAtAdapterPosition(int position) {
remove(position, group);
}

/**
* Remove a Group at a raw adapter position.
* @param adapterPosition raw adapter position of Group to remove.
* @deprecated This method has been deprecated in favor of {@link #removeGroupAtAdapterPosition(int)}. Please use that method instead.
*/
@Deprecated
public void removeGroup(int adapterPosition) {
removeGroupAtAdapterPosition(adapterPosition);
}

private void remove(int position, @NonNull Group group) {
int itemCountBeforeGroup = getItemCountBeforeGroup(position);
group.unregisterGroupDataObserver(this);
Expand All @@ -391,13 +410,13 @@ public void add(int index, @NonNull Group group) {
*/
@SuppressWarnings("WeakerAccess")
@NonNull
public Group getGroup(int position) {
public Group getTopLevelGroup(int position) {
return groups.get(position);
}

/**
* Get group, given a raw adapter position. If you want to get a top level group by position
* then use {@link #getGroup(int)}
* then use {@link #getTopLevelGroup(int)}
*
* @param position raw adapter position
* @return Group at that position or throws {@link IndexOutOfBoundsException}
Expand All @@ -415,6 +434,20 @@ public Group getGroupAtAdapterPosition(int position) {
"but there are only " + previous + " items");
}

/**
* Get group, given a raw adapter position. If you want to get a top level group by position
* then use {@link #getTopLevelGroup(int)}
*
* @param adapterPosition raw adapter position
* @return Group at that position or throws {@link IndexOutOfBoundsException}
* @deprecated This method is deprecated and has been replaced with {@link #getGroupAtAdapterPosition(int)}. Please use that method instead.
*/
@Deprecated
@NonNull
public Group getGroup(int adapterPosition) {
return getGroupAtAdapterPosition(adapterPosition);
}

/**
* Returns the Group which contains this item or throws an {@link IndexOutOfBoundsException} if not present.
* This is the item's <b>direct</b> parent, not necessarily one of the top level groups present in this adapter.
Expand Down