Skip to content

Instantly share code, notes, and snippets.

@wellingtoncosta
Last active January 24, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wellingtoncosta/5e6d0b895ec14f6b4dad3489faabfbe3 to your computer and use it in GitHub Desktop.
Save wellingtoncosta/5e6d0b895ec14f6b4dad3489faabfbe3 to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
observeEvents()
RxBus.instance.publish(FRAGMENT_ONE_TAG)
}
private fun observeEvents() {
RxBus.instance.subscribe {
when (it as String) {
FRAGMENT_ONE_TAG -> {
supportFragmentManager.transaction {
replace(R.id.frame_layout, FragmentOne(), FRAGMENT_ONE_TAG)
}
}
FRAGMENT_TWO_TAG -> {
supportFragmentManager.transaction {
replace(R.id.frame_layout, FragmentTwo(), FRAGMENT_TWO_TAG)
}
}
FINISH_APP_TAG -> this.finish()
}
}
}
companion object {
const val FRAGMENT_ONE_TAG = "FRAGMENT_ONE"
const val FRAGMENT_TWO_TAG = "FRAGMENT_TWO"
const val FINISH_APP_TAG = "FINISH_APP"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment