This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ActivityScoped | |
class SuccessPresenter @Inject constructor(val dispatcher: Dispatcher) : | |
BasePresenter<SuccessMVPView>() { | |
override fun attachView(mvpView: SuccessMVPView, lifecycle: Lifecycle) { | |
super.attachView(mvpView, lifecycle) | |
dispatcher.showingSuccess() | |
.subscribe({ bindData((it as Showing.Success).successMetaData) }, | |
{ Timber.e(it) }) | |
dispatcher | |
.showing() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API.submit(request) } | |
.subscribeOn(Schedulers.io()) | |
.observeOn(Schedulers.io()) | |
.subscribe({ | |
Timber.e("Submit:Success:" + it.success) | |
if (it.success) { | |
dispatcher.dispatchShow(Showing.Success(resultData)) | |
} else { | |
dispatcher.dispatchShow(Showing.Failure(resultData)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
disposables.add(dispatcher.arTargetFound() | |
.subscribeOn(Schedulers.io()) | |
.observeOn(scheduler) | |
.subscribe({ mvpView.targetAcquired() }, { Timber.e(it) })) | |
disposables.add(dispatcher.arTargetLost() | |
.subscribeOn(Schedulers.io()) | |
.observeOn(scheduler) | |
.subscribe({ mvpView.targetLost() }, { Timber.e(it) })) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
disposables.add(dispatcher.showingArView() | |
.subscribeOn(scheduler) | |
.observeOn(scheduler) | |
.subscribe({ mvpView.show() }, { Timber.e(it) })) | |
disposables.add(dispatcher | |
.showing() | |
.filter{(it !is Showing.ArView)} | |
.observeOn(scheduler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun attachView(mvpView: AR, lifecycle: Lifecycle) { | |
super.attachView(mvpView, lifecycle) | |
disposables.add(dispatcher.showingArView() | |
.subscribeOn(scheduler) | |
.subscribe({ mvpView.showArView() }, { Timber.e(it) })) | |
disposables.add(dispatcher | |
.showing() | |
.filter{(it !is Showing.ArView)} | |
.observeOn(scheduler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class State { | |
data class ResolvingTarget(var resolveRequestData: ResolveRequestData) : State() | |
object BackStackEmpty : State() | |
object BeginCameraReveal: State() | |
} | |
sealed class Showing : State() { | |
object Landing : Showing() | |
object ArView : Showing() | |
data class NoNetwork(var resolveRequestData: ResolveRequestData) : Showing() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class Dispatcher @Inject | |
constructor(val stateSubject: PublishSubject<State>) { | |
val showEvents: Stack<State> = Stack() | |
fun dispatch(state: State) = stateSubject.onNext(state) | |
fun dispatchShow(state: State) { | |
showEvents.push(state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun attachView(mvpView: NoNetworkMVPView, lifecycle: Lifecycle) { | |
super.attachView(mvpView, lifecycle) | |
dispatcher.noNetwork() | |
.observeOn(scheduler) | |
.subscribe { mvpView.show() } | |
dispatcher | |
.showing() | |
.filter { it !is Showing.NoNetwork } | |
.subscribe { mvpView.hide() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) | |
override fun detachView() { | |
disposables.clear() | |
mvpView = null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun attachView(mvpView: NoNetworkMVPView, lifecycle: Lifecycle){ | |
lifecycle.addObserver(this) | |
... | |
} |