[text] test

Viewer

  1. @ExperimentalSnapperApi
  2. @Composable
  3. fun SongsBottomSheetCollapsed(navController: NavController, application: Application) {
  4.     val viewModel = MyMusicViewModel(application = application)
  5.     val configuration = LocalConfiguration.current
  6.     val screenWidth = configuration.screenWidthDp
  7.     
  8.     val lazyListState = rememberLazyListState()
  9.     val coroutineScope = rememberCoroutineScope()
  10.     
  11.     LazyRow(
  12.         state = lazyListState,
  13.         flingBehavior = rememberSnapperFlingBehavior(lazyListState),
  14.     ) {
  15.  
  16.         items(selectedFilteredSongs.size) { index ->
  17.  
  18.             coroutineScope.launch {
  19.                 if (scrollToSongCollapse) {
  20.                     lazyListState.scrollToItem(currentSongIndex)
  21.                     currentSongIndex = lazyListState.firstVisibleItemIndex
  22.                 }
  23.  
  24.                 sheetPeakHeight = 50.dp
  25.                 sheetPeakHeight = 110.dp
  26.  
  27.                 scrollToSongCollapse = false
  28.             }
  29.  
  30.             coroutineScope.launch {
  31.                 if (currentSongIndex != lazyListState.firstVisibleItemIndex && !lazyListState.isScrollInProgress && !scrollToSongCollapse) {
  32.                     try {
  33.                         viewModel.updateVariables(
  34.                             songIndex = index,
  35.                             songID = viewModel.getFilteredSelectedSongID(index)
  36.                         )
  37.                         Variable.mp?.release()
  38.                         Variable.mp = MediaPlayer().apply {
  39.                             setAudioAttributes(
  40.                                 AudioAttributes.Builder()
  41.                                     .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
  42.                                     .setUsage(AudioAttributes.USAGE_MEDIA)
  43.                                     .build()
  44.                             )
  45.                             setDataSource(viewModel.getFilteredSelectedSongFile(currentSongIndex))
  46.                             prepareAsync()
  47.                             setOnPreparedListener {
  48.                                 if (Variable.mpIsPlaying) {
  49.                                     start()
  50.                                 }
  51.                             }
  52.                         }
  53.                         viewModel.showToast("Started new song", "short")
  54.                     } catch (e: IOException) {
  55.                         viewModel.showToast("An error occurred", "long")
  56.                         e.printStackTrace()
  57.                     }
  58.                 }
  59.             }
  60.  
  61.             Card(
  62.                 modifier = Modifier
  63.                     .width(50.dp)
  64.                     .height(50.dp),
  65.                 shape = RoundedCornerShape(0)
  66.             ) {
  67.                 Image(
  68.                     painter = rememberImagePainter(
  69.                         data = viewModel.getFilteredSelectedSongImage(index)
  70.                     ),
  71.                     contentScale = ContentScale.Crop,
  72.                     contentDescription = null
  73.                 )
  74.             }
  75.  
  76.             Spacer(modifier = Modifier.width(10.dp))
  77.  
  78.             Column(
  79.                 modifier = Modifier
  80.             ) {
  81.                 Text(
  82.                     text = viewModel.getFilteredSelectedSongTitle(index),
  83.                     modifier = Modifier
  84.                         .width(screenWidth.dp - 60.dp)
  85.                         .padding(horizontal = 5.dp, vertical = 2.dp),
  86.                     fontSize = 16.sp
  87.                 )
  88.  
  89.                 Text(
  90.                     text = viewModel.getFilteredSelectedSongArtist(index),
  91.                     modifier = Modifier.padding(horizontal = 5.dp),
  92.                     fontSize = 14.sp,
  93.                     color = Color.Gray
  94.                 )
  95.             }
  96.         }
  97.     }
  98.  
  99. }

Editor

You can edit this paste and save as new: