Skip to content

Commit

Permalink
fix backstack by historyChangesAfterListenerCall() flow test
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuinden committed Jan 16, 2017
1 parent 05f8056 commit 08584fc
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public class Backstack {
public static final int REATTACH = 1;
//

private final List<Parcelable> initialParameters;
private final List<Parcelable> originalStack = new ArrayList<>();

private ArrayList<Parcelable> stack = new ArrayList<>();
private final List<Parcelable> initialParameters;
private List<Parcelable> stack = originalStack;

private LinkedList<PendingStateChange> queuedStateChanges = new LinkedList<>();

Expand Down Expand Up @@ -71,6 +72,7 @@ public void setStateChanger(StateChanger stateChanger, @StateChangerRegisterMode
}
ArrayList<Parcelable> newHistory = new ArrayList<>();
newHistory.addAll(stack.isEmpty() ? initialParameters : stack);
stack = initialParameters;
enqueueStateChange(newHistory, StateChange.Direction.REPLACE, true);
}
}
Expand Down Expand Up @@ -172,9 +174,12 @@ public void stateChangeComplete() {
}

private void completeStateChange(StateChange stateChange) {
if(!stateChange.previousState.isEmpty() || (stateChange.previousState.isEmpty() && stack.isEmpty())) {
this.stack.clear();
this.stack.addAll(stateChange.newState);
if(!stateChange.previousState.isEmpty() || (stateChange.previousState.isEmpty() && initialParameters == stack)) {
if(initialParameters == stack) {
stack = originalStack;
}
stack.clear();
stack.addAll(stateChange.newState);
}

PendingStateChange pendingStateChange = queuedStateChanges.remove(0);
Expand Down

0 comments on commit 08584fc

Please sign in to comment.