Last active
May 8, 2018 07:08
-
-
Save vinaysshenoy/41a0ac57ae72418848f0b48ae5e9df1b to your computer and use it in GitHub Desktop.
MVP-Rx-Kotlin
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 PresenterToViewMsg | |
data class Msg1(val prop: Int): PresenterToViewMsg() | |
data class Msg2(val prop: String): PresenterToViewMsg() | |
sealed class ViewToPresenterMsg | |
data class Msg3(val prop: Int): ViewToPresenterMsg() | |
data class Msg4(val prop: String): ViewToPresenterMsg() |
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
class Presenter { | |
val messages = PublishSubject.create<PresenterToViewMsg>() as Observable<PresenterToViewMsg> | |
fun onViewReady(view) { | |
view.messages.subscribe { | |
when(it) { | |
is Msg3 -> messages.onNext(Msg1(4)) | |
is Msg4 -> messages.onNext(Msg2("Test")) | |
} | |
} | |
} | |
} |
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
class MyActivity: AppCompatActivity { | |
val messages = PublishSubject.create<ViewToPresenterMsg>() as Observable<PresenterToViewMsg> | |
val presenter = Presenter() | |
onStart() { | |
presenter.messages.subscribe { | |
when(it) { | |
is Msg1 -> tv_1.visibility = View.VISIBLE | |
is Msg2 -> tv_1.visibility = VIEW.GONE | |
} | |
} | |
presenter.onViewReady(this) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment