Skip to content

Instantly share code, notes, and snippets.

Mike Nakhimovich digitalbuddha

Block or report user

Report or block digitalbuddha

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Router.kt
data class Transition(toAnim:Animation=null, fromAnim:Animation,
direction:String=Forward, shouldDispatch=true)
sealed class Screen : State() {
data class MyScreen(var data: Data, layoutID:Int, transition:Transition) : Screen()
data class Ar(var data: Data, layoutID:Int, transition:Transition) : Screen()
}
View MultiPresenters.kt
class ScreenModule(){
@Binds
@IntoSet
Presenter()=LandingPresenter;
@Binds
@IntoSet
Presenter()=SuccessPresenter;
}
View Activity.kt
dispatcher.backStackEmpty().subscribe { finish() }
...
override fun onBackPressed() {
dispatcher.goBack()
}
View GoBack.kt
fun Dispatcher.goBack() {
popLastShowingState()//current state is what we are currently showing
dispatchShow(popLastShowingState())
}
fun popLastShowingState(): State {
if(!showEvents.empty()) Timber.d("popping "+showEvents.peek())
return if (showEvents.isEmpty()) State.BackStackEmpty else showEvents.pop()
}
View SuccessFailure.kt
@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()
View Submit.kt
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))
}
View OverlayPresenter2.kt
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) }))
View OverlayPresenter.kt
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)
View CameraPresenter.kt
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)
View State.kt
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()
You can’t perform that action at this time.