Skip to content

Commit

Permalink
0.9.2: remove isPending, added Backstack.isStateChangePending()
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuinden committed Feb 11, 2017
1 parent 910e748 commit 0623594
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change log

-Simple Stack 0.9.2 (2017-02-11)
---------------------------------
- BREAKING CHANGE(?): `CompletionListener` no longer receives `isPending` parameter.

- ADDED: `Backstack.isStateChangePending()` to replace `isPending`.

- ENHANCEMENT: Added some missing `@NonNull` and `@Nullable` annotations.

- ADDED: Apache license notes, and improved the README.

-Simple Stack 0.9.1 (2017-02-09)
---------------------------------
- BREAKING CHANGE(!): `BackstackDelegate` has a new method which **must be called**: `backstackDelegate.onDestroy()`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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:0.9.1'
compile 'com.github.Zhuinden:simple-stack:0.9.2'

## How does it work?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void goTo(@NonNull Parcelable newKey) {
}

public boolean goBack() {
if(!queuedStateChanges.isEmpty() && queuedStateChanges.get(0).getStatus() != PendingStateChange.Status.COMPLETED) {
if(isStateChangePending()) {
return true;
}
if(stack.size() <= 1) {
Expand Down Expand Up @@ -151,6 +151,10 @@ public List<Parcelable> getHistory() {
return Collections.unmodifiableList(copy);
}

public boolean isStateChangePending() {
return !queuedStateChanges.isEmpty();
}

private void enqueueStateChange(List<Parcelable> newHistory, int direction, boolean initialization) {
PendingStateChange pendingStateChange = new PendingStateChange(newHistory, direction, initialization);
queuedStateChanges.add(pendingStateChange);
Expand All @@ -168,7 +172,7 @@ private List<Parcelable> selectActiveHistory() {
}

private boolean beginStateChangeIfPossible() {
if(hasStateChanger() && !queuedStateChanges.isEmpty()) {
if(hasStateChanger() && isStateChangePending()) {
PendingStateChange pendingStateChange = queuedStateChanges.get(0);
if(pendingStateChange.getStatus() == PendingStateChange.Status.ENQUEUED) {
pendingStateChange.setStatus(PendingStateChange.Status.IN_PROGRESS);
Expand Down Expand Up @@ -220,7 +224,7 @@ private void completeStateChange(StateChange stateChange) {

// completion listeners
public interface CompletionListener {
void stateChangeCompleted(@NonNull StateChange stateChange, boolean isPending);
void stateChangeCompleted(@NonNull StateChange stateChange);
}

private LinkedList<CompletionListener> completionListeners = new LinkedList<>();
Expand All @@ -240,9 +244,8 @@ public void removeCompletionListener(@NonNull CompletionListener completionListe
}

private void notifyCompletionListeners(StateChange stateChange) {
boolean isPending = !queuedStateChanges.isEmpty();
for(CompletionListener completionListener : completionListeners) {
completionListener.stateChangeCompleted(stateChange, isPending);
completionListener.stateChangeCompleted(stateChange);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ protected void clearStatesNotIn(@NonNull List<Parcelable> keys) {
}

@Override
public void stateChangeCompleted(@NonNull StateChange stateChange, boolean isPending) {
if(!isPending) {
public void stateChangeCompleted(@NonNull StateChange stateChange) {
if(!backstack.isStateChangePending()) {
clearStatesNotIn(stateChange.getNewState());
}
}
Expand Down

0 comments on commit 0623594

Please sign in to comment.