Skip to content

Commit

Permalink
Merge pull request #12 from prochazkajp/master
Browse files Browse the repository at this point in the history
Dirty flag for redraw
  • Loading branch information
jakubkinst authored May 8, 2017
2 parents cce6135 + e9d4e29 commit 1a846f3
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class StatefulLayout extends FrameLayout {
private String mState;
private OnStateChangeListener mOnStateChangeListener;
private boolean mInitialized;
private boolean mDirtyFlag = false;


public interface OnStateChangeListener {
Expand Down Expand Up @@ -86,6 +87,7 @@ public void setStateView(String state, View view) {
addView(view);
}
view.setVisibility(GONE);
mDirtyFlag = true;
}


Expand All @@ -97,10 +99,10 @@ public String getState() {

public void setState(String state) {
if(getStateView(state) == null) {
throw new IllegalStateException(String.format("Cannot switch to state \"%s\". This state was not defined or the view for this state is null."));
throw new IllegalStateException(String.format("Cannot switch to state \"%s\". This state was not defined or the view for this state is null.", state));
}

if(mState != null && mState.equals(state))
if(mState != null && mState.equals(state) && !mDirtyFlag)
return;

mState = state;
Expand All @@ -110,6 +112,8 @@ public void setState(String state) {

if(mOnStateChangeListener != null)
mOnStateChangeListener.onStateChange(state);

mDirtyFlag = false;
}


Expand Down

0 comments on commit 1a846f3

Please sign in to comment.