Skip to content

Commit

Permalink
1.4.3: fix reusing cleared backstack after restoring with manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuinden committed Mar 25, 2017
1 parent daefb7c commit 96b2295
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

-Simple Stack 1.4.3 (2017-03-25)
--------------------------------
- FIX: Fixed a bug that if a restored backstack is cleared and an initialize state change is triggered,
then the restored keys were used instead of the initial key
(this only surfaced if you attempt to use multiple backstacks, and a cleared backstack is re-used)

-Simple Stack 1.4.2 (2017-03-20)
--------------------------------
- CHANGE: Decreased minSDK to 1.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ In order to use Simple Stack, you need to add jitpack to your project root gradl

and add the compile dependency to your module level gradle.

compile 'com.github.Zhuinden:simple-stack:1.4.2'
compile 'com.github.Zhuinden:simple-stack:1.4.3'

## How does it work?

Expand Down
16 changes: 12 additions & 4 deletions simple-stack/src/main/java/com/zhuinden/simplestack/Backstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static <T> T getKey(Context context) {

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

private final List<Object> initialKeys;
private List<Object> initialParameters;
private List<Object> stack = originalStack;

Expand All @@ -68,7 +69,8 @@ public Backstack(@NonNull Object... initialKeys) {
if(initialKeys == null || initialKeys.length <= 0) {
throw new IllegalArgumentException("At least one initial key must be defined");
}
initialParameters = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(initialKeys)));
this.initialKeys = Collections.unmodifiableList(new ArrayList<>(Arrays.asList(initialKeys)));
setInitialParameters(new ArrayList<>(this.initialKeys));
}

/**
Expand All @@ -83,14 +85,15 @@ public Backstack(@NonNull List<?> initialKeys) {
if(initialKeys.size() <= 0) {
throw new IllegalArgumentException("Initial key list should contain at least one element");
}
initialParameters = Collections.unmodifiableList(new ArrayList<>(initialKeys));
this.initialKeys = Collections.unmodifiableList(new ArrayList<>(initialKeys));
setInitialParameters(new ArrayList<>(this.initialKeys));
}

void setInitialParameters(List<?> initialKeys) {
if(initialKeys == null || initialKeys.size() <= 0) {
throw new IllegalArgumentException("At least one initial key must be defined");
}
this.initialParameters = Collections.unmodifiableList(new ArrayList<>(initialKeys));
this.initialParameters = new ArrayList<>(initialKeys);
}

/**
Expand Down Expand Up @@ -173,7 +176,7 @@ public boolean goBack() {
return true;
}
if(stack.size() <= 1) {
stack.clear();
resetBackstack();
return false;
}
ArrayList<Object> newHistory = new ArrayList<>();
Expand All @@ -186,6 +189,11 @@ public boolean goBack() {
return true;
}

private void resetBackstack() {
stack.clear();
initialParameters = new ArrayList<>(initialKeys);
}

/**
* Sets the provided state list as the new active history.
*
Expand Down

0 comments on commit 96b2295

Please sign in to comment.