Skip to content

Commit 078ad0b

Browse files
shahdDaghashcopybara-github
authored andcommitted
Do not show Snackbar message for automatically added items
When the main page becomes visible on the screen, 4 items are automatically added to the seqeuence(s). With each added item, we present a snackbar message to signal adding it. However, the snackbar message doesn't matter much for these items, and we'd need to wait for them to be disappear before we click on preview. PiperOrigin-RevId: 781091774
1 parent 70d6221 commit 078ad0b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

demos/composition/src/main/java/androidx/media3/demo/composition/CompositionPreviewViewModel.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ class CompositionPreviewViewModel(application: Application, val compositionLayou
121121
for (i in titles.indices) {
122122
mediaItemOptions.add(Item(titles[i], uris[i], durations[i].toLong(), mutableStateOf(false)))
123123
}
124-
// Load initial media item selections
125-
addItem(0)
126-
addItem(0)
127-
addItem(0)
128-
addItem(0)
124+
// Load initial media item selections. No need to show the Snackbar message at this point
125+
addItem(0, showSnackbarMessage = false)
126+
addItem(0, showSnackbarMessage = false)
127+
addItem(0, showSnackbarMessage = false)
128+
addItem(0, showSnackbarMessage = false)
129129
}
130130

131131
override fun onCleared() {
@@ -140,9 +140,11 @@ class CompositionPreviewViewModel(application: Application, val compositionLayou
140140
DebugTraceUtil.enableTracing = enable
141141
}
142142

143-
fun addItem(index: Int) {
143+
fun addItem(index: Int, showSnackbarMessage: Boolean = true) {
144144
selectedMediaItems.add(mediaItemOptions[index].copy(applyEffects = mutableStateOf(false)))
145-
snackbarMessage = "Added item: ${mediaItemOptions[index].title}"
145+
if (showSnackbarMessage) {
146+
snackbarMessage = "Added item: ${mediaItemOptions[index].title}"
147+
}
146148
}
147149

148150
fun removeItem(index: Int) {

0 commit comments

Comments
 (0)