<commit_before>/*
 * Copyright (C) 2021, <NAME>
 * All rights reserved.
 */
package tm.alashow.datmusic.ui.playback

import androidx.compose.material.BottomSheetState
import androidx.compose.material.BottomSheetValue
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.rememberBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import tm.alashow.base.util.toast
import tm.alashow.common.compose.rememberFlowWithLifecycle
import tm.alashow.datmusic.playback.NONE_PLAYBACK_STATE
import tm.alashow.datmusic.playback.PlaybackConnection

val LocalPlaybackConnection = staticCompositionLocalOf<PlaybackConnection> {
    error("No LocalPlaybackConnection provided")
}

@OptIn(ExperimentalMaterialApi::class)
val LocalPlaybackSheetState = staticCompositionLocalOf<BottomSheetState> {
    error("No LocalPlaybackSheetState provided")
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun PlaybackHost(
    viewModel: PlaybackViewModel = hiltViewModel(),
    content: @Composable () -> Unit
) {
    val context = LocalContext.current

    val playbackState by rememberFlowWithLifecycle(viewModel.playbackConnection.playbackState).collectAsState(NONE_PLAYBACK_STATE)
    LaunchedEffect(playbackState.errorCode) {
        playbackState.errorMessage?.apply { context.toast("Playback error: ${playbackState.errorMessage}") }
    }

    val playbackBottomSheetState = rememberBottomSheetState(BottomSheetValue.Expanded)

    CompositionLocalProvider(
        LocalPlaybackConnection provides viewModel.playbackConnection,
        LocalPlaybackSheetState provides playbackBottomSheetState,
    ) {<commit_msg>Playback: change initial playback sheet to collapsed<commit_after>/*
 * Copyright (C) 2021, <NAME>
 * All rights reserved.
 */
package tm.alashow.datmusic.ui.playback

import androidx.compose.material.BottomSheetState
import androidx.compose.material.BottomSheetValue
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.rememberBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.platform.LocalContext
import androidx.hilt.navigation.compose.hiltViewModel
import tm.alashow.base.util.toast
import tm.alashow.common.compose.rememberFlowWithLifecycle
import tm.alashow.datmusic.playback.NONE_PLAYBACK_STATE
import tm.alashow.datmusic.playback.PlaybackConnection

val LocalPlaybackConnection = staticCompositionLocalOf<PlaybackConnection> {
    error("No LocalPlaybackConnection provided")
}

@OptIn(ExperimentalMaterialApi::class)
val LocalPlaybackSheetState = staticCompositionLocalOf<BottomSheetState> {
    error("No LocalPlaybackSheetState provided")
}

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun PlaybackHost(
    viewModel: PlaybackViewModel = hiltViewModel(),
    content: @Composable () -> Unit
) {
    val context = LocalContext.current

    val playbackState by rememberFlowWithLifecycle(viewModel.playbackConnection.playbackState).collectAsState(NONE_PLAYBACK_STATE)
    LaunchedEffect(playbackState.errorCode) {
        playbackState.errorMessage?.apply { context.toast("Playback error: ${playbackState.errorMessage}") }
    }

    val playbackBottomSheetState = rememberBottomSheetState(BottomSheetValue.Collapsed)

    CompositionLocalProvider(
        LocalPlaybackConnection provides viewModel.playbackConnection,
        LocalPlaybackSheetState provides playbackBottomSheetState,
    ) {
{'fraction_non_alphanumeric': 0.07713293650793651, 'fraction_numerical': 0.001984126984126984, 'mean_word_length': 6.681904761904762, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5454566', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1112, 'n_words': 180}