@@ -27,13 +27,15 @@ import androidx.activity.viewModels
2727import androidx.appcompat.app.AppCompatActivity
2828import androidx.compose.foundation.background
2929import androidx.compose.foundation.border
30+ import androidx.compose.foundation.clickable
3031import androidx.compose.foundation.layout.Arrangement
3132import androidx.compose.foundation.layout.Box
3233import androidx.compose.foundation.layout.Column
3334import androidx.compose.foundation.layout.Row
3435import androidx.compose.foundation.layout.Spacer
3536import androidx.compose.foundation.layout.fillMaxSize
3637import androidx.compose.foundation.layout.fillMaxWidth
38+ import androidx.compose.foundation.layout.height
3739import androidx.compose.foundation.layout.heightIn
3840import androidx.compose.foundation.layout.padding
3941import androidx.compose.foundation.lazy.LazyColumn
@@ -45,17 +47,15 @@ import androidx.compose.foundation.shape.RoundedCornerShape
4547import androidx.compose.foundation.verticalScroll
4648import androidx.compose.material.icons.Icons
4749import androidx.compose.material.icons.filled.Add
48- import androidx.compose.material.icons.filled.Star
4950import androidx.compose.material.icons.twotone.Delete
50- import androidx.compose.material.icons.twotone.Star
5151import androidx.compose.material3.Button
5252import androidx.compose.material3.Card
53+ import androidx.compose.material3.Checkbox
5354import androidx.compose.material3.ElevatedButton
5455import androidx.compose.material3.FilledIconButton
5556import androidx.compose.material3.HorizontalDivider
5657import androidx.compose.material3.Icon
5758import androidx.compose.material3.IconButton
58- import androidx.compose.material3.IconToggleButton
5959import androidx.compose.material3.MaterialTheme
6060import androidx.compose.material3.OutlinedButton
6161import androidx.compose.material3.RadioButton
@@ -361,13 +361,24 @@ class CompositionPreviewActivity : AppCompatActivity() {
361361
362362 @Composable
363363 fun VideoSequenceList (viewModel : CompositionPreviewViewModel ) {
364- var showDialog by remember { mutableStateOf(false ) }
364+ var selectedMediaItemIndex by remember { mutableStateOf<Int ?>(null ) }
365+ var showEditMediaItemsDialog by remember { mutableStateOf(false ) }
365366
366- if (showDialog ) {
367+ if (showEditMediaItemsDialog ) {
367368 VideoSequenceDialog (
368- { showDialog = false },
369- viewModel.mediaItemOptions,
370- { index -> viewModel.addItem(index) },
369+ onDismissRequest = { showEditMediaItemsDialog = false },
370+ itemOptions = viewModel.mediaItemOptions,
371+ addSelectedVideo = { index -> viewModel.addItem(index) },
372+ )
373+ }
374+
375+ selectedMediaItemIndex?.let { index ->
376+ val item = viewModel.selectedMediaItems[index]
377+ EffectSelectionDialog (
378+ onDismissRequest = { selectedMediaItemIndex = null },
379+ effectOptions = viewModel.availableEffectNames,
380+ currentSelections = item.selectedEffects.value,
381+ onEffectsSelected = { newEffects -> viewModel.updateEffectsForItem(index, newEffects) },
371382 )
372383 }
373384
@@ -396,33 +407,27 @@ class CompositionPreviewActivity : AppCompatActivity() {
396407 Row (
397408 horizontalArrangement = Arrangement .SpaceBetween ,
398409 verticalAlignment = Alignment .CenterVertically ,
399- modifier = Modifier .fillMaxWidth(),
410+ modifier = Modifier .fillMaxWidth().clickable { selectedMediaItemIndex = index } ,
400411 ) {
401- Text (
402- text = " ${index + 1 } . ${item.title} " ,
403- modifier = Modifier .textPadding().weight(1f ),
404- )
405- Row (horizontalArrangement = Arrangement .spacedBy(2 .dp)) {
406- IconToggleButton (
407- checked = item.applyEffects.value,
408- onCheckedChange = { checked -> viewModel.updateEffects(index, checked) },
409- ) {
410- Icon (
411- imageVector =
412- if (item.applyEffects.value) Icons .Filled .Star else Icons .TwoTone .Star ,
413- contentDescription = " Apply effects to item ${index + 1 } " ,
414- )
415- }
416- IconButton ({ viewModel.removeItem(index) }) {
417- Icon (Icons .TwoTone .Delete , contentDescription = " Remove item ${index + 1 } " )
418- }
412+ Column (modifier = Modifier .textPadding().weight(1f )) {
413+ Text (text = " ${index + 1 } . ${item.title} " )
414+ val effectsText = item.selectedEffects.value.joinToString().ifEmpty { " None" }
415+ Text (
416+ text = " Effect: $effectsText " ,
417+ fontSize = 12 .sp,
418+ fontStyle = FontStyle .Italic ,
419+ color = MaterialTheme .colorScheme.onSecondaryContainer.copy(alpha = 0.8f ),
420+ )
421+ }
422+ IconButton ({ viewModel.removeItem(index) }) {
423+ Icon (Icons .TwoTone .Delete , contentDescription = " Remove item ${index + 1 } " )
419424 }
420425 }
421426 }
422427 }
423428 HorizontalDivider (thickness = 1 .dp, color = MaterialTheme .colorScheme.secondary)
424429 ElevatedButton (
425- onClick = { showDialog = true },
430+ onClick = { showEditMediaItemsDialog = true },
426431 modifier = Modifier .align(Alignment .CenterHorizontally ),
427432 ) {
428433 Text (text = stringResource(R .string.edit))
@@ -533,6 +538,68 @@ class CompositionPreviewActivity : AppCompatActivity() {
533538 }
534539 }
535540
541+ @Composable
542+ fun EffectSelectionDialog (
543+ onDismissRequest : () -> Unit ,
544+ effectOptions : List <String >,
545+ currentSelections : Set <String >,
546+ onEffectsSelected : (Set <String >) -> Unit ,
547+ ) {
548+ var selectedOptions by remember { mutableStateOf(currentSelections) }
549+
550+ Dialog (onDismissRequest = onDismissRequest) {
551+ Card (shape = RoundedCornerShape (16 .dp)) {
552+ Column (modifier = Modifier .padding(MaterialTheme .spacing.standard)) {
553+ Text (
554+ text = stringResource(R .string.select_effects),
555+ fontWeight = FontWeight .Bold ,
556+ modifier = Modifier .padding(bottom = MaterialTheme .spacing.small),
557+ )
558+ Column {
559+ effectOptions.forEach { effectName ->
560+ Row (
561+ Modifier .fillMaxWidth()
562+ .clickable {
563+ selectedOptions =
564+ if (selectedOptions.contains(effectName)) {
565+ selectedOptions - effectName
566+ } else {
567+ selectedOptions + effectName
568+ }
569+ }
570+ .padding(vertical = MaterialTheme .spacing.mini),
571+ verticalAlignment = Alignment .CenterVertically ,
572+ ) {
573+ Checkbox (checked = selectedOptions.contains(effectName), onCheckedChange = null )
574+ Text (
575+ text = effectName,
576+ modifier = Modifier .padding(start = MaterialTheme .spacing.small),
577+ )
578+ }
579+ }
580+ }
581+ Spacer (modifier = Modifier .height(MaterialTheme .spacing.standard))
582+ Row (modifier = Modifier .fillMaxWidth(), horizontalArrangement = Arrangement .End ) {
583+ OutlinedButton (
584+ onClick = onDismissRequest,
585+ modifier = Modifier .padding(end = MaterialTheme .spacing.small),
586+ ) {
587+ Text (stringResource(R .string.cancel))
588+ }
589+ Button (
590+ onClick = {
591+ onEffectsSelected(selectedOptions)
592+ onDismissRequest()
593+ }
594+ ) {
595+ Text (stringResource(R .string.ok))
596+ }
597+ }
598+ }
599+ }
600+ }
601+ }
602+
536603 companion object {
537604 private const val TAG = " CompPreviewActivity"
538605
0 commit comments