Skip to content

Instantly share code, notes, and snippets.

@Bradleycorn
Last active January 22, 2019 01:36
Show Gist options
  • Save Bradleycorn/0f4ab5476e33638be038edee9fa9a539 to your computer and use it in GitHub Desktop.
Save Bradleycorn/0f4ab5476e33638be038edee9fa9a539 to your computer and use it in GitHub Desktop.
class MainActivityViewModel: ViewModel() {
val videoUrl = "https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8"
enum class VideoPlaybackState {
STOPPED,
PLAYING
}
enum class VideoLayoutState {
EMBEDDED,
FULLSCREEN,
PIP
}
private var showInPipMode = false
private var currentOrientation: Int = Configuration.ORIENTATION_UNDEFINED
private val _playbackState = MutableLiveData<VideoPlaybackState>().apply {
value = VideoPlaybackState.STOPPED
}
val playbackState: LiveData<VideoPlaybackState> = _playbackState
private val _layoutState = MutableLiveData<VideoLayoutState>().apply {
value = VideoLayoutState.EMBEDDED
}
val layoutState: LiveData<VideoLayoutState> = Transformations.map(_layoutState) { newState ->
showInPipMode = when (newState) {
VideoLayoutState.PIP -> true
VideoLayoutState.EMBEDDED -> false
else -> showInPipMode
}
return@map newState
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment