Last active
January 24, 2019 14:25
-
-
Save wellingtoncosta/5e6d0b895ec14f6b4dad3489faabfbe3 to your computer and use it in GitHub Desktop.
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 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