Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save horse315/8de8efc66519152515fa47f40703f1a9 to your computer and use it in GitHub Desktop.
Save horse315/8de8efc66519152515fa47f40703f1a9 to your computer and use it in GitHub Desktop.
import java.util.Iterator;
import java.util.List;
import com.arellomobile.mvp.MvpView;
import com.arellomobile.mvp.viewstate.ViewCommand;
import com.arellomobile.mvp.viewstate.strategy.StateStrategy;
public class AddToEndSingleByTagStateStrategy implements StateStrategy {
@Override
public <View extends MvpView> void beforeApply(List<ViewCommand<View>> currentState, ViewCommand<View> incomingCommand) {
Iterator<ViewCommand<View>> iterator = currentState.iterator();
while (iterator.hasNext()) {
ViewCommand<View> entry = iterator.next();
if (entry.getClass().equals(incomingCommand.getClass()) && entry.getTag().equals(incomingCommand.getTag())) {
iterator.remove();
break;
}
}
currentState.add(incomingCommand);
}
@Override
public <View extends MvpView> void afterApply(List<ViewCommand<View>> currentState, ViewCommand<View> incomingCommand) {
// pass
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment