From a73b34b8a1d3c63ae131a8b2a7177205a5b19c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaquim=20St=C3=A4hli?= Date: Thu, 2 Nov 2023 13:33:25 +0100 Subject: [PATCH] Add a small debounce --- .../pillarbox/demo/ui/integrationLayer/SearchViewModel.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchViewModel.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchViewModel.kt index c0320fa5a..d8bdb44b1 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchViewModel.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchViewModel.kt @@ -21,9 +21,11 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map +import kotlin.time.Duration.Companion.milliseconds /** * Search view model to search media for the chosen bu @@ -46,7 +48,7 @@ class SearchViewModel(private val ilRepository: ILRepository) : ViewModel() { */ val query: StateFlow = _query - private val config = combine(bu, query) { bu, query -> Config(bu, query) } + private val config = combine(bu, query) { bu, query -> Config(bu, query) }.debounce(600.milliseconds) /** * Result of the search trigger by [bu] and [query]