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
package net.bradball.android.androidapptemplate.ui.theme | |
import androidx.compose.foundation.isSystemInDarkTheme | |
import androidx.compose.material.* | |
import androidx.compose.runtime.* | |
import androidx.compose.ui.graphics.Color | |
private val DarkColorPalette = AppColors( | |
materialColors = darkColors( | |
primary = purple200, |
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
/** | |
A class that makes api calls to the backend, process responses, and returns proper data models | |
*/ | |
class NetworkLayer(val api: CdiApi) { | |
fun fetchProgramData(track: String, race: Number): List<ProgramEntry> { | |
// Get a ProgramResponse object (the network model) back from the api | |
val response: ProgramResponse = api.fetchProgram(track, race) | |
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
override fun onConfigurationChanged(newConfig: Configuration) { | |
super.onConfigurationChanged(newConfig) | |
val isLandscape = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE | |
if (isLandscape) { | |
supportActionBar?.hide() | |
supportActionBar?.setDisplayShowTitleEnabled(false) | |
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN) | |
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN) | |
} else { // turn OFF full screen | |
supportActionBar?.show() |
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 | |
} |
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 val viewModel: MainActivityViewModel by viewModels() | |
private val videoPlayerCallbacks = object: ControlledVideoView.IVideoListener { | |
override fun onPipToggleClicked() { | |
viewModel.onPipToggled() | |
} | |
override fun onVideoCloseClicked() { |
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() { | |
val videoUrl = "https://video-dev.github.io/streams/x36xhzz/x36xhzz.m3u8" | |
enum class VideoPlaybackState { | |
STOPPED, | |
PLAYING | |
} | |
enum class VideoLayoutState { |
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 val orientationHandler = Handler() | |
private var orientationLock: Int = Configuration.ORIENTATION_UNDEFINED | |
fun onDeviceOrientationChange(deviceOrientation: Int, activityOrientation: Int?) { | |
currentOrientation = when (deviceOrientation) { | |
in 0..20, in 160..200, in 340..359 -> Configuration.ORIENTATION_PORTRAIT |
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() { | |
lateinit var orientationListener: OrientationEventListener | |
override fun onCreate(savedInstanceState: Bundle?) { | |
orientationListener = object: OrientationEventListener(this) { | |
override fun onOrientationChanged(orientation: Int) { | |
viewModel.onOrientationChange(orientation, resources.configuration.orientation) | |
} | |
}.apply { disable() } |
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) | |
title = getString(R.string.app_name) | |
setupVideo() | |
} | |
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 |
NewerOlder