Last active
January 22, 2019 01:39
-
-
Save Bradleycorn/695540ce54a134241f5d803fff58bc76 to your computer and use it in GitHub Desktop.
MotionLayout - ViewModel
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 MainActivityViewModel: ViewModel() { | |
//... | |
private fun setOrientation(requestedOrientation: Int = -1) { | |
val newOrientation = requestedOrientation.takeUnless { it == -1 } ?: currentOrientation | |
_layoutState.value = when (newOrientation) { | |
Configuration.ORIENTATION_LANDSCAPE -> VideoLayoutState.FULLSCREEN | |
else -> { | |
if (showInPipMode) { | |
VideoLayoutState.PIP | |
} else { | |
VideoLayoutState.EMBEDDED | |
} | |
} | |
} | |
} | |
fun onOrientationForced(orientation: Int) { | |
setOrientation(orientation) | |
} | |
fun onVideoToggled() { | |
val newState = when (_playbackState.value) { | |
VideoPlaybackState.STOPPED -> VideoPlaybackState.PLAYING | |
else -> VideoPlaybackState.STOPPED | |
} | |
_playbackState.value = newState | |
} | |
fun onVideoClosed() { | |
if (_layoutState.value == VideoLayoutState.FULLSCREEN) { | |
_layoutState.value = if (showInPipMode) VideoLayoutState.PIP else VideoLayoutState.EMBEDDED | |
} | |
_playbackState.value = VideoPlaybackState.STOPPED | |
} | |
fun onPipToggled() { | |
_layoutState.value = when (_layoutState.value) { | |
VideoLayoutState.PIP -> VideoLayoutState.EMBEDDED | |
else -> VideoLayoutState.PIP | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment