Skip to content

Instantly share code, notes, and snippets.

@ekursakov
Created March 22, 2017 17:47
Show Gist options
  • Save ekursakov/110b057789a7eaad4f4a983076492ee3 to your computer and use it in GitHub Desktop.
Save ekursakov/110b057789a7eaad4f4a983076492ee3 to your computer and use it in GitHub Desktop.
import com.arellomobile.mvp.MvpView
import com.arellomobile.mvp.viewstate.ViewCommand
import com.arellomobile.mvp.viewstate.strategy.StateStrategy
class AddToEndSingleWithTagStrategy : StateStrategy {
override fun <View : MvpView> beforeApply(currentState: MutableList<ViewCommand<View>>,
incomingCommand: ViewCommand<View>) {
val iterator = currentState.iterator()
while (iterator.hasNext()) {
val entry = iterator.next()
if (entry.tag == incomingCommand.tag) {
iterator.remove()
break
}
}
currentState.add(incomingCommand)
}
override fun <View : MvpView> afterApply(currentState: List<ViewCommand<View>>,
incomingCommand: ViewCommand<View>) {
// pass
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment