Created
January 24, 2019 15:41
-
-
Save wellingtoncosta/e78ddbd923cca99bb6b83a10f19f81fd 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(MAIN_ACTIVITY_SUBJECT, FRAGMENT_ONE_TAG) | |
} | |
private fun observeEvents() { | |
RxBus.instance.subscribe(MAIN_ACTIVITY_SUBJECT, this) { | |
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() | |
} | |
} | |
} | |
override fun onDestroy() { | |
super.onDestroy() | |
RxBus.instance.unregister(this) | |
} | |
companion object { | |
const val MAIN_ACTIVITY_SUBJECT = "MAIN_ACTIVITY_SUBJECT" | |
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