Skip to content

Instantly share code, notes, and snippets.

View halilozercan's full-sized avatar
🏛️
Learning

Halil Ozercan halilozercan

🏛️
Learning
View GitHub Profile
@Composable
fun CalendarView(
modifier: Modifier = Modifier,
selectedDay: CalendarDay = CalendarDay.create(),
onSelectedDayChange: (CalendarDay) -> Unit = {},
visibleMonth: CalendarDay = CalendarDay.create(),
onVisibleMonthChange: (CalendarDay) -> Unit = {},
today: CalendarDay = CalendarDay.create(),
events: Set<CalendarDay> = emptySet()
) {
/**
* This interface marks the class for use of `Rizalt` library.
*/
interface Rizalt<P: Parcelable>
/**
* Creates a unique request key for given Fragment class. Key can be left empty
* to create a default instance.
*/
fun <T, P: Parcelable> KClass<T>.getRequestKeyNameFor(key: String): String where T: Fragment, T: Rizalt<P> {
> Task :app:compileDebugKotlin FAILED
w: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+NonParenthesizedAnnotationsOnFunctionalTypes
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
object MediaControlButtons {
private val HIDDEN = "hidden"
private val VISIBLE = "visible"
private val alpha = FloatPropKey()
private val transitionDef by lazy {
transitionDefinition {
state(HIDDEN) {
this[alpha] = 0f
private val _isPlaying = MutableStateFlow(true)
val isPlaying: StateFlow<Boolean> = _isPlaying
private val _playbackState = MutableStateFlow(ExoPlayer.STATE_IDLE)
val playbackState: StateFlow<Int> = _playbackState
private val exoPlayer by lazy {
SimpleExoPlayer.Builder(context).build().apply {
addListener(object: Player.EventListener {
override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
@Composable
fun PlayPauseButton(modifier: Modifier = Modifier) {
val controller = PlayerControllerAmbient.current
val isPlaying by controller.isPlaying.collectAsState()
val playbackState by controller.playbackState.collectAsState()
IconButton(
onClick = { controller.playPause() },
modifier = Modifier + modifier
@Composable
fun MediaControlButtons(modifier: Modifier = Modifier) {
val controller = PlayerControllerAmbient.current
Stack(modifier = Modifier + modifier) {
Box(modifier = Modifier.gravity(Alignment.Center).fillMaxSize().clickable(indication = null) {
controller.setControlsVisible(false)
})
PlayPauseButton(modifier = Modifier.gravity(Alignment.Center))
@Composable
fun PlayerSurface() {
val playerController = PlayerControllerAmbient.current
AndroidView(resId = R.layout.surface) {
val exoPlayerView = it.findViewById<PlayerView>(R.id.player_view)
playerController.setPlayerView(exoPlayerView)
}
}
class PlayerController(
private val context: Context
) {
private val exoPlayer by lazy {
SimpleExoPlayer.Builder(context).build()
}
fun prepare(sourceUrl: String) {
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(context,
@Composable
fun VideoPlayer(sourceUrl: String) {
// This is the official way to access current context from Composable functions
val context = LocalContext.current
// Do not recreate the player everytime this Composable commits
val exoPlayer = remember {
SimpleExoPlayer.Builder(context).build()
}