Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ;
- import java.util.LinkedList;
- import javax.annotation.Nonnull;
- import rx.functions.Action1;
- public class ViewState<V extends ViewState.View> {
- public interface View {}
- private final LinkedList<Action1<V>> mActions = new LinkedList<>();
- private V mView;
- public void attach(V view) {
- mView = view;
- processUnfinishedActions();
- }
- public void detach() {
- mView = null;
- }
- public void apply(@Nonnull Action1<V> action) {
- if (mView == null) {
- mActions.add(action);
- } else {
- action.call(mView);
- }
- }
- private void processUnfinishedActions() {
- if (mActions.size() == 0) return;
- while (mActions.peek() != null) {
- mActions.pop().call(mView);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement