Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#75
Browse files Browse the repository at this point in the history
  • Loading branch information
chattymin authored Oct 3, 2024
2 parents 372c70a + 69ea03b commit c038182
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ constructor(
DATE_FORMAT.parse(record.date)?.let { DISPLAY_DATE_FORMAT.format(it) } ?: ""
}
_chartEntry.value = UiState.Success(
recordList.mapIndexed { index, record ->
Entry(index.toFloat(), record.accuracy.toFloat())
}.toMutableList()
(if (recordList.size == 1) {
listOf(Entry(0f, 0f)) + recordList.mapIndexed { index, record ->
Entry((index + 1).toFloat(), record.accuracy.toFloat())
}
} else {
recordList.mapIndexed { index, record ->
Entry(index.toFloat(), record.accuracy.toFloat())
}
}).toMutableList()
)
}
.onFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.media.MediaPlayer
import android.media.PlaybackParams
import android.media.SoundPool
import android.os.Bundle
import android.view.View
Expand Down Expand Up @@ -84,10 +85,16 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
}

private fun initChangeRhythmBtnListener() {
binding.btnChangeLevel.setOnSingleClickListener {
rhythmBottomSheet = RhythmBottomSheet()
rhythmBottomSheet?.show(parentFragmentManager, BOTTOM_SHEET_CHANGE_LEVEL)
}
with(binding) {
btnChangeLevel.setOnSingleClickListener { startRhythmBottomSheet()}
tvRhythmBpm.setOnSingleClickListener { startRhythmBottomSheet()}
tvRhythmBit.setOnSingleClickListener { startRhythmBottomSheet()}
}
}

private fun startRhythmBottomSheet() {
rhythmBottomSheet = RhythmBottomSheet()
rhythmBottomSheet?.show(parentFragmentManager, BOTTOM_SHEET_CHANGE_LEVEL)
}

private fun initStretchNavigateBtnListener() {
Expand All @@ -112,19 +119,25 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
private suspend fun playSoundPoolAndMediaPlayer() {
lifecycleScope.launch {
listOf(
async { playMediaPlayerWithSpeed() },
async { playOrResumeSoundPool() },
async { mediaPlayer.start() }
).awaitAll()
switchPlayingState(true)
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
}

private fun playMediaPlayerWithSpeed() {
mediaPlayer.apply {
setPlaybackParams(PlaybackParams().setSpeed(findSpeedByBpm(viewModel.bpm)))
}.start()
}

private fun playOrResumeSoundPool() {
if (beatStream != 0) {
soundPool.resume(beatStream)
} else {
beatStream = soundPool.play(beatSound, 1f, 1f, 1, -1, 1f)
beatStream = soundPool.play(beatSound, 10f, 10f, 1, -1, 1f)
}
}

Expand All @@ -136,7 +149,7 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy

override fun onStop() {
super.onStop()
pauseMusic(false)
if (::mediaPlayer.isInitialized && ::soundPool.isInitialized) pauseMusic(false)
}

private fun pauseMusic(isButton: Boolean) {
Expand Down Expand Up @@ -305,6 +318,7 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
if (::mediaPlayer.isInitialized) mediaPlayer.release()
mediaPlayer = MediaPlayer.create(requireContext(), findMusicByBpm(viewModel.bpm)).apply {
isLooping = true
setVolume(0.2f, 0.2f)
setOnPreparedListener {
continuation.resume(Unit)
}
Expand All @@ -316,10 +330,18 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy

private fun setLoadingView(isLoading: Boolean) {
binding.layoutLoading.isVisible = isLoading

if (isLoading) {
setStatusBarColor(R.color.transparent_50)
requireActivity().window.setFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
)
} else {
setStatusBarColor(R.color.white)
requireActivity().window.clearFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
)
}
}

Expand Down Expand Up @@ -444,15 +466,20 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy

private const val SUCCESS_CODE = 200

fun findMusicByBpm(bpm: Int) =
when (bpm) {
60, 65 -> R.raw.music_bpm_60
70, 75 -> R.raw.music_bpm_70
80, 85 -> R.raw.music_bpm_80
90, 95 -> R.raw.music_bpm_90
100, 105 -> R.raw.music_bpm_100
110, 115 -> R.raw.music_bpm_110
else -> R.raw.music_bpm_120
}
fun findMusicByBpm(bpm: Int) = when (bpm / 20) {
3 -> R.raw.music_bpm_60
4 -> R.raw.music_bpm_80
5 -> R.raw.music_bpm_100
6 -> R.raw.music_bpm_120
else -> R.raw.music_bpm_60
}

fun findSpeedByBpm(bpm: Int) = when (bpm % 20) {
0 -> 1.0f
5 -> 1.08f
10 -> 1.16f
15 -> 1.25f
else -> 1.0f
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class StretchFragment : BaseFragment<FragmentStretchBinding>(R.layout.fragment_s
private suspend fun playSoundPoolAndMediaPlayer() {
lifecycleScope.launch {
listOf(
async { mediaPlayer.start() },
async { playOrResumeSoundPool() },
async { mediaPlayer.start() }
).awaitAll()
switchPlayingState(true)
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
Expand Down Expand Up @@ -124,34 +124,30 @@ class StretchFragment : BaseFragment<FragmentStretchBinding>(R.layout.fragment_s
}

private suspend fun setSoundPoolAsync() = suspendCancellableCoroutine { continuation ->
if (File(requireContext().filesDir, viewModel.filename).exists()) {
if (::soundPool.isInitialized) soundPool.release()
soundPool = SoundPool.Builder().setMaxStreams(1).build().apply {
setOnLoadCompleteListener { _, sampleId, status ->
if (status == 0 && sampleId == beatSound) {
continuation.resume(Unit)
}
if (::soundPool.isInitialized) soundPool.release()
soundPool = SoundPool.Builder().setMaxStreams(1).build().apply {
setOnLoadCompleteListener { _, sampleId, status ->
if (status == 0 && sampleId == beatSound) {
continuation.resume(Unit)
}
}
beatSound =
soundPool.load(File(requireContext().filesDir, viewModel.filename).absolutePath, 1)
} else {
toast(stringOf(R.string.error_msg))
continuation.resume(Unit)
}
beatSound = soundPool.load(requireContext(), R.raw.rhythm_stretch, 1)
continuation.invokeOnCancellation {
if (::soundPool.isInitialized) soundPool.release()
}
}

private suspend fun setMediaPlayerAsync() = suspendCancellableCoroutine { continuation ->
if (::mediaPlayer.isInitialized) mediaPlayer.release()
mediaPlayer = MediaPlayer.create(requireContext(), findMusicByBpm(viewModel.bpm)).apply {
mediaPlayer = MediaPlayer.create(requireContext(), R.raw.music_stretch).apply {
isLooping = true
setVolume(0.2f, 0.2f)
setOnPreparedListener {
continuation.resume(Unit)
}
}
binding.lottieStretchBg.speed = 0.75f
continuation.invokeOnCancellation {
if (::mediaPlayer.isInitialized) mediaPlayer.release()
}
Expand Down
14 changes: 7 additions & 7 deletions presentation/src/main/res/layout/bottom_sheet_rhythm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="14dp"
android:text="비트 선택"
android:text="박자 선택"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_handler" />
Expand Down Expand Up @@ -64,7 +64,7 @@
android:gravity="center"
android:onClick="@{() -> vm.setTempBit(2)}"
android:paddingVertical="12dp"
android:text="2 비트"
android:text="2 박자"
android:textColor="@{vm.tempBit == 2 ? @color/white : @color/gray_600}"
tools:background="@drawable/shape_gray200_fill_17_rect" />

Expand All @@ -79,7 +79,7 @@
android:gravity="center"
android:onClick="@{() -> vm.setTempBit(3)}"
android:paddingVertical="12dp"
android:text="3 비트"
android:text="3 박자"
android:textColor="@{vm.tempBit == 3 ? @color/white : @color/gray_600}"
tools:background="@drawable/shape_gray200_fill_17_rect" />

Expand All @@ -94,7 +94,7 @@
android:gravity="center"
android:onClick="@{() -> vm.setTempBit(4)}"
android:paddingVertical="12dp"
android:text="4 비트"
android:text="4 박자"
android:textColor="@{vm.tempBit == 4 ? @color/white : @color/gray_600}"
tools:background="@drawable/shape_gray200_fill_17_rect" />

Expand All @@ -109,7 +109,7 @@
android:gravity="center"
android:onClick="@{() -> vm.setTempBit(6)}"
android:paddingVertical="12dp"
android:text="6 비트"
android:text="6 박자"
android:textColor="@{vm.tempBit == 6 ? @color/white : @color/gray_600}"
tools:background="@drawable/shape_gray200_fill_17_rect" />

Expand All @@ -124,7 +124,7 @@
android:gravity="center"
android:onClick="@{() -> vm.setTempBit(8)}"
android:paddingVertical="12dp"
android:text="8 비트"
android:text="8 박자"
android:textColor="@{vm.tempBit == 8 ? @color/white : @color/gray_600}"
tools:background="@drawable/shape_gray200_fill_17_rect" />

Expand All @@ -149,7 +149,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="8dp"
android:text="BPM 선택"
android:text="빠르기 선택"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/border_rhythm" />
Expand Down
Binary file modified presentation/src/main/res/raw/music_bpm_100.mp3
Binary file not shown.
Binary file removed presentation/src/main/res/raw/music_bpm_110.mp3
Binary file not shown.
Binary file modified presentation/src/main/res/raw/music_bpm_120.mp3
Binary file not shown.
Binary file modified presentation/src/main/res/raw/music_bpm_60.mp3
Binary file not shown.
Binary file removed presentation/src/main/res/raw/music_bpm_70.mp3
Binary file not shown.
Binary file modified presentation/src/main/res/raw/music_bpm_80.mp3
Binary file not shown.
Binary file removed presentation/src/main/res/raw/music_bpm_90.mp3
Binary file not shown.
Binary file added presentation/src/main/res/raw/music_stretch.mp3
Binary file not shown.
Binary file added presentation/src/main/res/raw/rhythm_stretch.mp3
Binary file not shown.
4 changes: 2 additions & 2 deletions presentation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<string name="menu_study">과제</string>
<string name="menu_profile">마이</string>

<string name="rhythm_tv_bit">%d비트</string>
<string name="rhythm_tv_bpm">%dbpm</string>
<string name="rhythm_tv_bit">%d박자</string>
<string name="rhythm_tv_bpm">%d빠르기</string>
<string name="rhythm_tv_step">%03d걸음</string>
<string name="rhythm_tv_title">리듬에 맞춰 걸어주세요!</string>
<string name="rhythm_btn_change_level">단계 변경하기</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.kkkk.stempo.presentation

import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.CompositionLocalProvider
Expand Down Expand Up @@ -74,6 +75,8 @@ class WatchActivity : ComponentActivity(), DataClient.OnDataChangedListener {
val bpm = getInt(KEY_BPM)
Timber.tag("okhttp").d("LISTENER : DATA RECEIVED : $bpm")
VIBRATION_INTERVAL = 60_000L / bpm
Toast.makeText(this@WatchActivity, "동기화에 성공했습니다.", Toast.LENGTH_SHORT)
.show()
}
}
}
Expand Down

0 comments on commit c038182

Please sign in to comment.