Repository: Automattic/pocket-casts-android
File: modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/SleepFragment.kt (Kotlin)

Code before:
        viewModel.sleepTimerAddExtraMins(mins = 1)
        analyticsTracker.track(AnalyticsEvent.PLAYER_SLEEP_TIMER_EXTENDED, mapOf(AMOUNT_KEY to TimeUnit.MILLISECONDS.toSeconds(1.minutes())))
        viewModel.timeLeftInSeconds()?.let { timeLeft ->
            binding?.root?.announceAccessibility("1 minute added to sleep timer. ${timeLeft / 60} minutes ${timeLeft % 60} seconds remaining")
        }
    }

    private fun startCustomTimer() {
        viewModel.sleepTimerAfter(mins = viewModel.sleepCustomTimeInMinutes)
        binding?.root?.announceAccessibility("Sleep timer set for ${viewModel.sleepCustomTimeInMinutes} minutes")
        analyticsTracker.track(AnalyticsEvent.PLAYER_SLEEP_TIMER_ENABLED, mapOf(TIME_KEY to TimeUnit.MILLISECONDS.toSeconds(viewModel.sleepCustomTimeInMinutes.minutes())))
        close()
    }

    private fun plusButtonClicked() {
        if (viewModel.sleepCustomTimeInMinutes < 5) {
            viewModel.sleepCustomTimeInMinutes += 1
        } else {
            viewModel.sleepCustomTimeInMinutes += 5
        }
        binding?.root?.announceAccessibility("Custom sleep time ${viewModel.sleepCustomTimeInMinutes}")
    }

    private fun plusEndOfEpisodeButtonClicked() {
        viewModel.setSleepEndOfEpisodes(viewModel.getSleepEndOfEpisodes() + 1)
        binding?.root?.announceAccessibility("Sleep time end of episode ${viewModel.getSleepEndOfEpisodes()}")
    }

    private fun plusEndOfChapterButtonClicked() {
        viewModel.setSleepEndOfChapters(viewModel.getSleepEndOfChapters() + 1)
        binding?.root?.announceAccessibility("Sleep time chapter ${viewModel.getSleepEndOfChapters()}")
    }

    private fun minusButtonClicked() {
        if (viewModel.sleepCustomTimeInMinutes <= 5) {
            viewModel.sleepCustomTimeInMinutes -= 1
        } else {
            viewModel.sleepCustomTimeInMinutes -= 5
        }
        binding?.root?.announceAccessibility("Custom sleep time ${viewModel.sleepCustomTimeInMinutes}")
    }

    private fun minusEndOfEpisodeButtonClicked() {
        val endOfEpisodes = viewModel.getSleepEndOfEpisodes()
        if (endOfEpisodes > 1) {
            viewModel.setSleepEndOfEpisodes(endOfEpisodes - 1)
        }
        binding?.root?.announceAccessibility("Sleep time end of episode ${viewModel.getSleepEndOfEpisodes() }")
    }

    private fun minusEndOfChapterButtonClicked() {

Review comment (suggestion):
I'm not sure this is working the same way.

Before

https://github.com/user-attachments/assets/b391aef1-2f5c-494f-ad72-92a58004167d

After

https://github.com/user-attachments/assets/fd8923a9-ffe0-45dd-af41-42f087927de9

Code after:
    private fun startCustomTimer() {
        viewModel.sleepTimerAfter(mins = viewModel.sleepCustomTimeInMinutes)
        analyticsTracker.track(AnalyticsEvent.PLAYER_SLEEP_TIMER_ENABLED, mapOf(TIME_KEY to TimeUnit.MILLISECONDS.toSeconds(viewModel.sleepCustomTimeInMinutes.minutes())))
        close()
    }

    private fun plusButtonClicked() {
        if (viewModel.sleepCustomTimeInMinutes < 5) {
            viewModel.sleepCustomTimeInMinutes += 1
        } else {
            viewModel.sleepCustomTimeInMinutes += 5
        }
    }

    private fun plusEndOfEpisodeButtonClicked() {
        viewModel.setSleepEndOfEpisodes(viewModel.getSleepEndOfEpisodes() + 1)
    }

    private fun plusEndOfChapterButtonClicked() {
        viewModel.setSleepEndOfChapters(viewModel.getSleepEndOfChapters() + 1)
    }

    private fun minusButtonClicked() {
        if (viewModel.sleepCustomTimeInMinutes <= 5) {
            viewModel.sleepCustomTimeInMinutes -= 1
        } else {
            viewModel.sleepCustomTimeInMinutes -= 5
        }
    }

    private fun minusEndOfEpisodeButtonClicked() {
        val endOfEpisodes = viewModel.getSleepEndOfEpisodes()
        if (endOfEpisodes > 1) {
            viewModel.setSleepEndOfEpisodes(endOfEpisodes - 1)
        }
    }

    private fun minusEndOfChapterButtonClicked() {
        val endOfChapters = viewModel.getSleepEndOfChapters()
        if (endOfChapters > 1) {
            viewModel.setSleepEndOfChapters(endOfChapters - 1)
        }
    }

    private fun startTimerEndOfEpisode(episodes: Int) {
        viewModel.sleepTimerAfterEpisode(episodes)
        close()
    }

    private fun startTimerEndOfChapter(chapters: Int) {
        viewModel.sleepTimerAfterChapter(chapters)