Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 705f871d authored by George Lin's avatar George Lin
Browse files

Fix clock carousel flash position

1. Check if the job is active before updating the position
2. Remove the delay since settings clocks is not comparatively light

Test: manuelly tested no more flash
Bug: 281916104
Change-Id: Ieeb3821a6f94f6ddc732a3d3e07e836fd3c66ab7
parent 1fb9b229
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -63,7 +63,9 @@ constructor(
            .flatMapLatest { allClockIds ->
                interactor.selectedClockId.map { selectedClockId ->
                    val index = allClockIds.indexOf(selectedClockId)
                    if (index >= 0) {
                    /** Making sure there is no active [setSelectedClockJob] */
                    val isSetClockIdJobActive = setSelectedClockJob?.isActive == true
                    if (index >= 0 && !isSetClockIdJobActive) {
                        index
                    } else {
                        null
@@ -85,10 +87,7 @@ constructor(
    fun setSelectedClock(clockId: String) {
        setSelectedClockJob?.cancel()
        setSelectedClockJob =
            viewModelScope.launch(backgroundDispatcher) {
                delay(SET_SELECTED_CLOCK_DELAY_MILLIS)
                interactor.setSelectedClock(clockId)
            }
            viewModelScope.launch(backgroundDispatcher) { interactor.setSelectedClock(clockId) }
    }

    class Factory(
@@ -107,9 +106,5 @@ constructor(

    companion object {
        const val CLOCKS_EVENT_UPDATE_DELAY_MILLIS: Long = 100

        // In the case if the user scroll the clock carousel frequently, we make a delay for
        // setting the selected clock to avoid too many heavy calls.
        const val SET_SELECTED_CLOCK_DELAY_MILLIS: Long = 650
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -77,7 +77,6 @@ class ClockCarouselViewModelTest {
        val observedSelectedIndex = collectLastValue(underTest.selectedIndex)
        advanceTimeBy(ClockCarouselViewModel.CLOCKS_EVENT_UPDATE_DELAY_MILLIS)
        underTest.setSelectedClock(FakeClockPickerRepository.fakeClocks[2].clockId)
        advanceTimeBy(ClockCarouselViewModel.SET_SELECTED_CLOCK_DELAY_MILLIS)
        assertThat(observedSelectedIndex()).isEqualTo(2)
    }