Skip to content

Commit 7f202c7

Browse files
committed
add debounce on main tab search
1 parent 1e6f997 commit 7f202c7

File tree

1 file changed

+8
-2
lines changed
  • features/feature_running_records/src/main/java/com/example/util/simpletimetracker/feature_running_records/viewModel

1 file changed

+8
-2
lines changed

features/feature_running_records/src/main/java/com/example/util/simpletimetracker/feature_running_records/viewModel/RunningRecordsViewModel.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class RunningRecordsViewModel @Inject constructor(
8787

8888
private var timerJob: Job? = null
8989
private var updateJob: Job? = null
90+
private var searchJob: Job? = null
9091
private var completeTypeJob: Job? = null
9192
private var completeTypeIds: Set<Long> = emptySet()
9293
private var navBarHeightDp: Int = 0
@@ -315,8 +316,13 @@ class RunningRecordsViewModel @Inject constructor(
315316

316317
fun onSearchTextChange(text: String) {
317318
if (text != searchText) {
318-
searchText = text
319-
updateRunningRecords(fromValueChange = true)
319+
searchJob?.cancel()
320+
searchJob = viewModelScope.launch {
321+
searchText = text
322+
// Do not delay on clear.
323+
if (text.isNotEmpty()) delay(500)
324+
updateRunningRecords(fromValueChange = true)
325+
}
320326
}
321327
}
322328

0 commit comments

Comments
 (0)