Skip to content

Commit e6a4ab0

Browse files
committed
Style : apply 와 return 을 활용해 코드 수정
1 parent 54df48c commit e6a4ab0

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

presentation/src/main/java/com/stop/SoundService.kt

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,28 @@ class SoundService : LifecycleService() {
3333
getAlarmUseCase.getAlarm().collectLatest { alarmData ->
3434
alarmData?.let {
3535
if (it.alarmMethod) {
36-
mediaPlayer = MediaPlayer.create(this@SoundService, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
37-
mediaPlayer?.setWakeMode(this@SoundService, PowerManager.PARTIAL_WAKE_LOCK)
38-
mediaPlayer?.isLooping = true
39-
mediaPlayer?.start()
40-
} else {
41-
val pattern = longArrayOf(100, 200, 100, 200, 100, 200)
42-
val amplitude = intArrayOf(0, 50, 0, 100, 0, 200)
43-
if (isUnderOreo()) {
44-
vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
45-
vibrator?.vibrate(pattern, 0)
46-
} else if (isMoreThanOreoUnderRedVelVet()) {
47-
vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
48-
val effect = VibrationEffect.createWaveform(pattern, amplitude, 0)
49-
vibrator?.vibrate(effect)
50-
} else if (isMoreThanSnow()) {
51-
vibratorManager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
52-
val effect = VibrationEffect.createWaveform(pattern, amplitude, 0)
53-
val combinedVibration = CombinedVibration.createParallel(effect)
54-
vibratorManager?.vibrate(combinedVibration)
36+
mediaPlayer = MediaPlayer.create(this@SoundService, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).apply {
37+
setWakeMode(this@SoundService, PowerManager.PARTIAL_WAKE_LOCK)
38+
isLooping = true
39+
start()
5540
}
41+
return@let
42+
}
43+
44+
val pattern = longArrayOf(100, 200, 100, 200, 100, 200)
45+
val amplitude = intArrayOf(0, 50, 0, 100, 0, 200)
46+
if (isUnderOreo()) {
47+
vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
48+
vibrator?.vibrate(pattern, 0)
49+
} else if (isMoreThanOreoUnderRedVelVet()) {
50+
vibrator = getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
51+
val effect = VibrationEffect.createWaveform(pattern, amplitude, 0)
52+
vibrator?.vibrate(effect)
53+
} else if (isMoreThanSnow()) {
54+
vibratorManager = getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
55+
val effect = VibrationEffect.createWaveform(pattern, amplitude, 0)
56+
val combinedVibration = CombinedVibration.createParallel(effect)
57+
vibratorManager?.vibrate(combinedVibration)
5658
}
5759
}
5860
}

0 commit comments

Comments
 (0)