Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. package ;
  2.  
  3. import java.util.LinkedList;
  4.  
  5. import javax.annotation.Nonnull;
  6.  
  7. import rx.functions.Action1;
  8.  
  9. public class ViewState<V extends ViewState.View> {
  10. public interface View {}
  11.  
  12. private final LinkedList<Action1<V>> mActions = new LinkedList<>();
  13. private V mView;
  14.  
  15. public void attach(V view) {
  16. mView = view;
  17. processUnfinishedActions();
  18. }
  19.  
  20. public void detach() {
  21. mView = null;
  22. }
  23.  
  24. public void apply(@Nonnull Action1<V> action) {
  25. if (mView == null) {
  26. mActions.add(action);
  27. } else {
  28. action.call(mView);
  29. }
  30. }
  31.  
  32. private void processUnfinishedActions() {
  33. if (mActions.size() == 0) return;
  34.  
  35. while (mActions.peek() != null) {
  36. mActions.pop().call(mView);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement