Skip to content

Commit

Permalink
[Merge] fix-run-vibration -> develop
Browse files Browse the repository at this point in the history
[FIX] setOnlyAlertOnce 추가를 통한 소리/진동 제한
  • Loading branch information
unam98 authored Dec 13, 2023
2 parents 3d45ced + 4dc009f commit 8010f30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import com.runnect.runnect.data.dto.TimerData
import com.runnect.runnect.databinding.ActivityRunBinding
import com.runnect.runnect.presentation.endrun.EndRunActivity
import com.runnect.runnect.presentation.run.TimerService.Companion.EXTRA_TIMER_VALUE
import com.runnect.runnect.presentation.run.TimerService.Companion.TIMER_UPDATE_ACTION
import com.runnect.runnect.util.extension.round

class RunActivity : BindingActivity<ActivityRunBinding>(R.layout.activity_run),
Expand Down Expand Up @@ -123,7 +124,7 @@ class RunActivity : BindingActivity<ActivityRunBinding>(R.layout.activity_run),
override fun onStart() {
super.onStart()
// Timer 결과값을 받기 위해 브로드캐스트 리시버 등록
registerReceiver(timerReceiver, IntentFilter(TimerService.TIMER_UPDATE_ACTION))
registerReceiver(timerReceiver, IntentFilter(TIMER_UPDATE_ACTION))
}

override fun onStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class TimerService : Service() {
return START_STICKY
}

fun notifyStartRun() {
if (player == null) {
player = MediaPlayer.create(this@TimerService, R.raw.start_run)
player?.setOnCompletionListener { mediaPlayer ->
mediaPlayer.release() // 재생이 끝나면 MediaPlayer 객체를 해제합니다.
}
}
player?.start()
}

fun startTimer() {
timer = Timer()
timer?.scheduleAtFixedRate(object : TimerTask() {
Expand Down Expand Up @@ -86,6 +96,7 @@ class TimerService : Service() {
.setColor(ContextCompat.getColor(this@TimerService, R.color.M1))
.setContentTitle("러닝")
.setContentText("00:00:00")
.setOnlyAlertOnce(true)
.setOngoing(true) // true 일 경우 알림 리스트에서 클릭하거나 좌우로 드래그해도 사라지지 않음

val notificationIntent = Intent(this@TimerService, RunActivity::class.java)
Expand Down Expand Up @@ -119,16 +130,6 @@ class TimerService : Service() {
startForeground(NOTI_ID, notification)
}

fun notifyStartRun() {
if (player == null) {
player = MediaPlayer.create(this@TimerService, R.raw.start_run)
player?.setOnCompletionListener { mediaPlayer ->
mediaPlayer.release() // 재생이 끝나면 MediaPlayer 객체를 해제합니다.
}
}
player?.start()
}

companion object {
const val TIMER_UPDATE_ACTION = "TIMER_UPDATE_ACTION"
const val EXTRA_TIMER_VALUE = "EXTRA_TIMER_VALUE"
Expand Down

0 comments on commit 8010f30

Please sign in to comment.