From a51886870e97fbf199cfd91a8c1be49dc418ea74 Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Mon, 21 Aug 2023 22:57:28 +0300 Subject: [PATCH] adjust initial alarm volume before media player starts playing. --- .../clock/activities/ReminderActivity.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt index 530a4a1..3380bbc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/ReminderActivity.kt @@ -22,8 +22,8 @@ import com.simplemobiletools.commons.helpers.* class ReminderActivity : SimpleActivity() { private val INCREASE_VOLUME_DELAY = 300L - private val increaseVolumeHandler = Handler() - private val maxReminderDurationHandler = Handler() + private val increaseVolumeHandler = Handler(Looper.getMainLooper()) + private val maxReminderDurationHandler = Handler(Looper.getMainLooper()) private val swipeGuideFadeHandler = Handler() private val vibrationHandler = Handler(Looper.getMainLooper()) private var isAlarmReminder = false @@ -198,19 +198,19 @@ class ReminderActivity : SimpleActivity() { } if (config.increaseVolumeGradually) { - scheduleVolumeIncrease(maxVol) + scheduleVolumeIncrease(maxVol, 0) } } catch (e: Exception) { } } } - private fun scheduleVolumeIncrease(maxVolume: Float) { + private fun scheduleVolumeIncrease(maxVolume: Float, delay: Long) { increaseVolumeHandler.postDelayed({ lastVolumeValue = (lastVolumeValue + 0.1f).coerceAtMost(maxVolume) audioManager?.setStreamVolume(AudioManager.STREAM_ALARM, lastVolumeValue.toInt(), 0) - scheduleVolumeIncrease(maxVolume) - }, INCREASE_VOLUME_DELAY) + scheduleVolumeIncrease(maxVolume, INCREASE_VOLUME_DELAY) + }, delay) } override fun onNewIntent(intent: Intent?) {