Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public abstract class AbstractSlideExpandableListAdapter extends WrapperListAdap

private boolean froyoOrAbove;

/**
* Determines if adapter should collapse the last expanded View before expanding a new one
*/
private boolean collapseLastExpanded = true;

public void setCollapseLastExpanded (boolean value){
collapseLastExpanded = value;
}

public AbstractSlideExpandableListAdapter(ListAdapter wrapped) {
super(wrapped);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
Expand Down Expand Up @@ -148,7 +157,7 @@ public View getView(int position, View view, ViewGroup viewGroup) {
* A listener will be attached to the button which will
* either expand or collapse the expandable view
*
* @see #getExpandableView(View)
* @see #getExpandableView(android.view.View)
* @param parent the list view item
* @ensure return!=null
* @return a child of parent which is a button
Expand All @@ -165,7 +174,7 @@ public View getView(int position, View view, ViewGroup viewGroup) {
* return parent.findViewById(R.id.expandable)
* </pre>
*
* @see #getExpandToggleButton(View)
* @see #getExpandToggleButton(android.view.View)
* @param parent the list view item
* @ensure return!=null
* @return a child of parent which is a view (or often ViewGroup)
Expand Down Expand Up @@ -214,7 +223,6 @@ public void enableFor(View parent, int position) {
itemToolbar.requestLayout();
}


private void enableFor(final View button, final View target, final int position) {
if(target == lastOpen && position!=lastOpenPosition) {
// lastOpen is recycled, so its reference is false
Expand All @@ -238,10 +246,9 @@ private void enableFor(final View button, final View target, final int position)
public void onClick(final View view) {

Animation a = target.getAnimation();

if (a != null && a.hasStarted() && !a.hasEnded()) {

a.setAnimationListener(new Animation.AnimationListener() {
a.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
Expand All @@ -257,7 +264,6 @@ public void onAnimationRepeat(Animation animation) {
});

} else {

target.setAnimation(null);

int type = target.getVisibility() == View.VISIBLE
Expand All @@ -270,22 +276,25 @@ public void onAnimationRepeat(Animation animation) {
} else {
openItems.set(position, false);
}
// check if we need to collapse a different view
if (type == ExpandCollapseAnimation.EXPAND) {
if (lastOpenPosition != -1 && lastOpenPosition != position) {
if (lastOpen != null) {
animateView(lastOpen, ExpandCollapseAnimation.COLLAPSE);
notifiyExpandCollapseListener(
ExpandCollapseAnimation.COLLAPSE,
lastOpen, lastOpenPosition);
}
openItems.set(lastOpenPosition, false);
}
lastOpen = target;
lastOpenPosition = position;
} else if (lastOpenPosition == position) {
lastOpenPosition = -1;
}

if(collapseLastExpanded){
// check if we need to collapse a different view
if (type == ExpandCollapseAnimation.EXPAND) {
if (lastOpenPosition != -1 && lastOpenPosition != position) {
if (lastOpen != null) {
animateView(lastOpen, ExpandCollapseAnimation.COLLAPSE);
notifiyExpandCollapseListener(
ExpandCollapseAnimation.COLLAPSE,
lastOpen, lastOpenPosition);
}
openItems.set(lastOpenPosition, false);
}
lastOpen = target;
lastOpenPosition = position;
} else if (lastOpenPosition == position) {
lastOpenPosition = -1;
}
}
animateView(target, type);
notifiyExpandCollapseListener(type, target, position);
}
Expand Down Expand Up @@ -447,8 +456,8 @@ public void writeToParcel(Parcel out, int flags) {
}

//required field that makes Parcelables from a Parcel
public static final Parcelable.Creator<SavedState> CREATOR =
new Parcelable.Creator<SavedState>() {
public static final Creator<SavedState> CREATOR =
new Creator<SavedState>() {
public SavedState createFromParcel(Parcel in) {
return new SavedState(in);
}
Expand Down