Last active
January 22, 2019 02:26
-
-
Save Bradleycorn/e14a1ce0c0b645f653a2046459208222 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() { | |
private var currentPlaybackState: MainActivityViewModel.VideoPlaybackState? = null | |
private var currentLayoutState: MainActivityViewModel.VideoLayoutState? = null | |
override fun onCreateOptionsMenu(menu: Menu?): Boolean { | |
super.onCreateOptionsMenu(menu) | |
menuInflater.inflate(R.menu.options_menu, menu) | |
return true | |
} | |
override fun onPrepareOptionsMenu(menu: Menu?): Boolean { | |
super.onPrepareOptionsMenu(menu) | |
val playVideoItem = menu?.findItem(R.id.option_play_video) | |
val stopVideoItem = menu?.findItem(R.id.option_stop_video) | |
playVideoItem?.isVisible = currentPlaybackState == MainActivityViewModel.VideoPlaybackState.STOPPED | |
stopVideoItem?.isVisible = currentPlaybackState == MainActivityViewModel.VideoPlaybackState.PLAYING | |
return true | |
} | |
override fun onOptionsItemSelected(item: MenuItem?): Boolean { | |
return when (item?.itemId) { | |
R.id.option_play_video -> { | |
viewModel.onVideoToggled() | |
true | |
} | |
R.id.option_stop_video -> { | |
viewModel.onVideoToggled() | |
true | |
} | |
else -> super.onOptionsItemSelected(item) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment