From 8f517dbba98d7c326d00ad4510f97a85d53db719 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Sun, 22 Sep 2024 15:41:20 +0900 Subject: [PATCH 01/15] =?UTF-8?q?[UI/#61]=20=EB=A6=AC=EB=93=AC=EB=B7=B0=20?= =?UTF-8?q?UI=20=EC=88=98=EC=A0=95=EC=82=AC=ED=95=AD=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ect.xml => shape_gray200_fill_17_rect.xml} | 2 +- .../drawable/shape_green50_fill_17_rect.xml | 5 ++ ...ct.xml => shape_purple50_fill_17_rect.xml} | 2 +- .../res/drawable/shape_sky50_fill_17_rect.xml | 5 ++ .../shape_white_fill_gray600_line_17_rect.xml | 7 +++ .../main/res/layout/bottom_sheet_rhythm.xml | 20 +++---- .../src/main/res/layout/fragment_rhythm.xml | 60 ++++++++++++------- 7 files changed, 69 insertions(+), 32 deletions(-) rename presentation/src/main/res/drawable/{shape_gray200_fill_16_rect.xml => shape_gray200_fill_17_rect.xml} (80%) create mode 100644 presentation/src/main/res/drawable/shape_green50_fill_17_rect.xml rename presentation/src/main/res/drawable/{shape_purple50_fill_16_rect.xml => shape_purple50_fill_17_rect.xml} (80%) create mode 100644 presentation/src/main/res/drawable/shape_sky50_fill_17_rect.xml create mode 100644 presentation/src/main/res/drawable/shape_white_fill_gray600_line_17_rect.xml diff --git a/presentation/src/main/res/drawable/shape_gray200_fill_16_rect.xml b/presentation/src/main/res/drawable/shape_gray200_fill_17_rect.xml similarity index 80% rename from presentation/src/main/res/drawable/shape_gray200_fill_16_rect.xml rename to presentation/src/main/res/drawable/shape_gray200_fill_17_rect.xml index b5ed002..04bed02 100644 --- a/presentation/src/main/res/drawable/shape_gray200_fill_16_rect.xml +++ b/presentation/src/main/res/drawable/shape_gray200_fill_17_rect.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/shape_green50_fill_17_rect.xml b/presentation/src/main/res/drawable/shape_green50_fill_17_rect.xml new file mode 100644 index 0000000..4d0745f --- /dev/null +++ b/presentation/src/main/res/drawable/shape_green50_fill_17_rect.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/shape_purple50_fill_16_rect.xml b/presentation/src/main/res/drawable/shape_purple50_fill_17_rect.xml similarity index 80% rename from presentation/src/main/res/drawable/shape_purple50_fill_16_rect.xml rename to presentation/src/main/res/drawable/shape_purple50_fill_17_rect.xml index fe33df5..b6ebfad 100644 --- a/presentation/src/main/res/drawable/shape_purple50_fill_16_rect.xml +++ b/presentation/src/main/res/drawable/shape_purple50_fill_17_rect.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/shape_sky50_fill_17_rect.xml b/presentation/src/main/res/drawable/shape_sky50_fill_17_rect.xml new file mode 100644 index 0000000..8dd401b --- /dev/null +++ b/presentation/src/main/res/drawable/shape_sky50_fill_17_rect.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/shape_white_fill_gray600_line_17_rect.xml b/presentation/src/main/res/drawable/shape_white_fill_gray600_line_17_rect.xml new file mode 100644 index 0000000..083a944 --- /dev/null +++ b/presentation/src/main/res/drawable/shape_white_fill_gray600_line_17_rect.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/layout/bottom_sheet_rhythm.xml b/presentation/src/main/res/layout/bottom_sheet_rhythm.xml index 09f6f2f..687fa56 100644 --- a/presentation/src/main/res/layout/bottom_sheet_rhythm.xml +++ b/presentation/src/main/res/layout/bottom_sheet_rhythm.xml @@ -60,13 +60,13 @@ android:layout_column="0" android:layout_columnWeight="1" android:layout_margin="8dp" - android:background="@{vm.tempBit == 2 ? @drawable/shape_purple50_fill_16_rect : @drawable/shape_gray200_fill_16_rect}" + android:background="@{vm.tempBit == 2 ? @drawable/shape_purple50_fill_17_rect : @drawable/shape_gray200_fill_17_rect}" android:gravity="center" android:onClick="@{() -> vm.setTempBit(2)}" android:paddingVertical="12dp" android:text="2 비트" android:textColor="@{vm.tempBit == 2 ? @color/white : @color/gray_600}" - tools:background="@drawable/shape_gray200_fill_16_rect" /> + tools:background="@drawable/shape_gray200_fill_17_rect" /> + tools:background="@drawable/shape_gray200_fill_17_rect" /> + tools:background="@drawable/shape_gray200_fill_17_rect" /> + tools:background="@drawable/shape_gray200_fill_17_rect" /> + tools:background="@drawable/shape_gray200_fill_17_rect" /> diff --git a/presentation/src/main/res/layout/fragment_rhythm.xml b/presentation/src/main/res/layout/fragment_rhythm.xml index 0527d6a..2b3de5f 100644 --- a/presentation/src/main/res/layout/fragment_rhythm.xml +++ b/presentation/src/main/res/layout/fragment_rhythm.xml @@ -11,21 +11,6 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - + app:layout_constraintTop_toTopOf="parent" /> + + + + + app:layout_constraintHorizontal_chainStyle="packed" + app:layout_constraintStart_toEndOf="@id/tv_rhythm_bpm" + tools:text="000 걸음" /> Date: Sun, 22 Sep 2024 15:55:07 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[FEAT/#61]=20bit,=20bpm=20=EB=B3=80?= =?UTF-8?q?=EB=8F=99=20=EC=8B=9C=20UI=20=EB=8C=80=EC=9D=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/rhythm/RhythmFragment.kt | 55 ++++++++++--------- .../main/rhythm/RhythmViewModel.kt | 4 +- presentation/src/main/res/values/strings.xml | 4 +- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index 9e89fa6..b5dc09b 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -20,6 +20,8 @@ import com.google.android.gms.wearable.DataEventBuffer import com.google.android.gms.wearable.DataMapItem import com.google.android.gms.wearable.Wearable import com.kkkk.core.base.BaseFragment +import com.kkkk.core.extension.colorOf +import com.kkkk.core.extension.drawableOf import com.kkkk.core.extension.setOnSingleClickListener import com.kkkk.core.extension.setStatusBarColor import com.kkkk.core.extension.stringOf @@ -59,10 +61,11 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy ) { super.onViewCreated(view, savedInstanceState) - initChangeLevelBtnListener() + initChangeRhythmBtnListener() initPlayBtnListener() initStopBtnListener() initWearableSyncBtnListener() + setUiWithCurrentRhythm() observeStepCount() observeRhythmChanged() observeRhythmUrlState() @@ -71,7 +74,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy setStatusBarColor(R.color.white) } - private fun initChangeLevelBtnListener() { + private fun initChangeRhythmBtnListener() { binding.btnChangeLevel.setOnSingleClickListener { rhythmBottomSheet = RhythmBottomSheet() rhythmBottomSheet?.show(parentFragmentManager, BOTTOM_SHEET_CHANGE_LEVEL) @@ -117,8 +120,8 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy } private fun observeStepCount() { - viewModel.stepCount.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { level -> - binding.tvRhythmStep.text = viewModel.stepCount.value.toString() + viewModel.stepCount.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { + binding.tvRhythmStep.text = getString(R.string.rhythm_tv_step, viewModel.stepCount.value) }.launchIn(lifecycleScope) } @@ -130,15 +133,15 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy mediaPlayer.pause() switchPlayingState(false) } - setUiWithCurrentLevel() + setUiWithCurrentRhythm() viewModel.resetRhythmChangedState() viewModel.postToGetRhythmUrlFromServer() } }.launchIn(lifecycleScope) } - private fun setUiWithCurrentLevel() { - val color = when (viewModel.bit.rem(3)) { + private fun setUiWithCurrentRhythm() { + val color = when (viewModel.bit) { 2 -> COLOR_PURPLE 3 -> COLOR_SKY 4 -> COLOR_GREEN @@ -146,25 +149,25 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy 8 -> COLOR_SKY else -> return } -// with(binding) { -// tvRhythmLevel.apply { -// text = getString(R.string.rhythm_tv_level, viewModel.rhythmLevel.value) -// setTextColor(colorOf(getResource("${color}_50", COLOR))) -// background = -// drawableOf(getResource("shape_white_fill_${color}50_line_17_rect", DRAWABLE)) -// } -// tvRhythmStep.apply { -// setTextColor(colorOf(getResource("${color}_50", COLOR))) -// background = -// drawableOf(getResource("shape_white_fill_${color}50_line_17_rect", DRAWABLE)) -// } -// ivRhythmBg.setImageResource(getResource("img_rhythm_bg_$color", DRAWABLE)) -// lottieRhythmBg.apply { -// setAnimation(getResource("stempo_rhythm_$color", RAW)) -// speed = viewModel.bpm / FLOAT_120 -// playAnimation() -// } -// } + with(binding) { + tvRhythmBpm.apply { + text = getString(R.string.rhythm_tv_bpm, viewModel.bpm) + setTextColor(colorOf(getResource("${color}_50", COLOR))) + background = + drawableOf(getResource("shape_white_fill_${color}50_line_17_rect", DRAWABLE)) + } + tvRhythmBit.apply { + text = getString(R.string.rhythm_tv_bit, viewModel.bit) + background = + drawableOf(getResource("shape_${color}50_fill_17_rect", DRAWABLE)) + } + ivRhythmBg.setImageResource(getResource("img_rhythm_bg_$color", DRAWABLE)) + lottieRhythmBg.apply { + setAnimation(getResource("stempo_rhythm_$color", RAW)) + speed = viewModel.bpm / FLOAT_120 + playAnimation() + } + } } private fun getResource(name: String, defType: String) = diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt index a3bdaef..eee078e 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt @@ -106,7 +106,9 @@ constructor( } fun resetRhythmChangedState() { - _isRhythmChanged.resetReplayCache() + viewModelScope.launch { + _isRhythmChanged.emit(false) + } } fun postToGetRhythmUrlFromServer() { diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index a4a7cdb..868fa75 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -21,7 +21,9 @@ 학습 마이 - %d단계 리듬 + %d비트 + %dbpm + %d걸음 리듬에 맞춰 걸어주세요! 단계 변경하기 완료하기 From 419b9891bac696e394ee1128921104163bdf4519 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Sun, 22 Sep 2024 15:57:58 +0900 Subject: [PATCH 03/15] =?UTF-8?q?[FIX/#61]=20=EA=B8=80=EC=94=A8=20?= =?UTF-8?q?=ED=81=AC=EA=B8=B0=20=EA=B3=A0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/res/values/appearances.xml | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/presentation/src/main/res/values/appearances.xml b/presentation/src/main/res/values/appearances.xml index fe344b8..68363df 100644 --- a/presentation/src/main/res/values/appearances.xml +++ b/presentation/src/main/res/values/appearances.xml @@ -11,50 +11,50 @@ From 32926f91eb1a2a980eae4ae76c4e1c99df70ae2a Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 00:25:29 +0900 Subject: [PATCH 04/15] =?UTF-8?q?[UI/#61]=20=EC=8A=A4=ED=8A=B8=EB=9E=98?= =?UTF-8?q?=EC=B9=AD=EB=B7=B0=20UI=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/rhythm/StretchFragment.kt | 2 + .../src/main/res/layout/fragment_rhythm.xml | 15 ++- .../src/main/res/layout/fragment_stretch.xml | 102 ++++++++++++++++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt create mode 100644 presentation/src/main/res/layout/fragment_stretch.xml diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt new file mode 100644 index 0000000..930f993 --- /dev/null +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt @@ -0,0 +1,2 @@ +package com.kkkk.presentation.main.rhythm + diff --git a/presentation/src/main/res/layout/fragment_rhythm.xml b/presentation/src/main/res/layout/fragment_rhythm.xml index 2b3de5f..b6ee58b 100644 --- a/presentation/src/main/res/layout/fragment_rhythm.xml +++ b/presentation/src/main/res/layout/fragment_rhythm.xml @@ -11,12 +11,25 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From fcc94e1103cd40b973aa52652f26b00477cd0b4d Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 01:34:55 +0900 Subject: [PATCH 05/15] =?UTF-8?q?[FEAT/#61]=20=EC=8A=A4=ED=8A=B8=EB=A0=88?= =?UTF-8?q?=EC=B9=AD=EB=B7=B0=20navigate=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kkkk/presentation/main/MainActivity.kt | 26 +++++++++++++++++ .../main/rhythm/RhythmFragment.kt | 7 +++++ .../main/rhythm/RhythmViewModel.kt | 10 +++++++ .../main/rhythm/StretchFragment.kt | 29 +++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt b/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt index 43c890d..821fb15 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt @@ -4,22 +4,34 @@ import android.os.Bundle import androidx.fragment.app.Fragment import androidx.fragment.app.commit import androidx.fragment.app.replace +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.flowWithLifecycle +import androidx.lifecycle.lifecycleScope import com.kkkk.core.base.BaseActivity import com.kkkk.presentation.main.profile.ProfileFragment import com.kkkk.presentation.main.record.RecordFragment import com.kkkk.presentation.main.rhythm.RhythmFragment +import com.kkkk.presentation.main.rhythm.RhythmViewModel +import com.kkkk.presentation.main.rhythm.StretchFragment import com.kkkk.presentation.main.study.StudyFragment import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.onEach import kr.genti.presentation.R import kr.genti.presentation.databinding.ActivityMainBinding @AndroidEntryPoint class MainActivity : BaseActivity(R.layout.activity_main) { + + private lateinit var rhythmViewModel: RhythmViewModel + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) initBnvItemIconTintList() initBnvItemSelectedListener() + initViewModelProvider() + observeStretchViewNavigate() } private fun initBnvItemIconTintList() { @@ -56,4 +68,18 @@ class MainActivity : BaseActivity(R.layout.activity_main) { replace(R.id.fcv_main, T::class.java.canonicalName) } } + + private fun initViewModelProvider() { + rhythmViewModel = ViewModelProvider(this)[RhythmViewModel::class.java] + } + + private fun observeStretchViewNavigate() { + rhythmViewModel.isStretchView.flowWithLifecycle(lifecycle).onEach { isStretch -> + if (isStretch) { + navigateTo() + } else { + navigateTo() + } + }.launchIn(lifecycleScope) + } } diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index b5dc09b..656a5f4 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -62,6 +62,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy super.onViewCreated(view, savedInstanceState) initChangeRhythmBtnListener() + initStretchNavigateBtnListener() initPlayBtnListener() initStopBtnListener() initWearableSyncBtnListener() @@ -81,6 +82,12 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy } } + private fun initStretchNavigateBtnListener() { + binding.btnStretch.setOnSingleClickListener { + viewModel.navigateToStretchView(true) + } + } + private fun initPlayBtnListener() { binding.btnRhythmPlay.setOnSingleClickListener { if (::mediaPlayer.isInitialized) { diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt index eee078e..7aaf6f2 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt @@ -31,6 +31,9 @@ constructor( var isBpmMinusAvailable = MutableLiveData(false) var isBpmPlusAvailable = MutableLiveData(true) + private val _isStretchView = MutableSharedFlow() + val isStretchView: SharedFlow = _isStretchView + private val _isRhythmChanged = MutableSharedFlow() val isRhythmChanged: SharedFlow = _isRhythmChanged @@ -111,6 +114,13 @@ constructor( } } + fun navigateToStretchView(isStretch: Boolean) { + viewModelScope.launch { + _isStretchView.emit(isStretch) + _isStretchView.resetReplayCache() + } + } + fun postToGetRhythmUrlFromServer() { _rhythmUrlState.value = UiState.Loading viewModelScope.launch { diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt index 930f993..0cefe52 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt @@ -1,2 +1,31 @@ package com.kkkk.presentation.main.rhythm +import android.os.Bundle +import android.view.View +import androidx.fragment.app.activityViewModels +import com.kkkk.core.base.BaseFragment +import com.kkkk.core.extension.setOnSingleClickListener +import dagger.hilt.android.AndroidEntryPoint +import kr.genti.presentation.R +import kr.genti.presentation.databinding.FragmentStretchBinding + +@AndroidEntryPoint +class StretchFragment : BaseFragment(R.layout.fragment_stretch) { + + private val viewModel by activityViewModels() + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { + super.onViewCreated(view, savedInstanceState) + + initRhythmNavigateBtnListener() + } + + private fun initRhythmNavigateBtnListener() { + binding.btnRhythm.setOnSingleClickListener { + viewModel.navigateToStretchView(false) + } + } + +} \ No newline at end of file From 7de930762f703e48527ed53adf0c5632533f8f60 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 01:45:31 +0900 Subject: [PATCH 06/15] =?UTF-8?q?[UI/#61]=20=EB=A6=AC=EB=93=AC=EB=B7=B0=20?= =?UTF-8?q?=ED=86=A0=EA=B8=80=20UI=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/rhythm/RhythmFragment.kt | 5 +- .../main/rhythm/StretchFragment.kt | 2 +- .../drawable/shape_gray200_fill_26_rect.xml | 5 ++ .../res/drawable/shape_white_fill_26_rect.xml | 5 ++ .../src/main/res/layout/fragment_rhythm.xml | 47 ++++++++++++---- .../src/main/res/layout/fragment_stretch.xml | 55 +++++++++++++------ 6 files changed, 88 insertions(+), 31 deletions(-) create mode 100644 presentation/src/main/res/drawable/shape_gray200_fill_26_rect.xml create mode 100644 presentation/src/main/res/drawable/shape_white_fill_26_rect.xml diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index 656a5f4..f05c7c7 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -83,7 +83,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy } private fun initStretchNavigateBtnListener() { - binding.btnStretch.setOnSingleClickListener { + binding.btnStretchMode.setOnSingleClickListener { viewModel.navigateToStretchView(true) } } @@ -128,7 +128,8 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy private fun observeStepCount() { viewModel.stepCount.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { - binding.tvRhythmStep.text = getString(R.string.rhythm_tv_step, viewModel.stepCount.value) + binding.tvRhythmStep.text = + getString(R.string.rhythm_tv_step, viewModel.stepCount.value) }.launchIn(lifecycleScope) } diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt index 0cefe52..e58557d 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt @@ -23,7 +23,7 @@ class StretchFragment : BaseFragment(R.layout.fragment_s } private fun initRhythmNavigateBtnListener() { - binding.btnRhythm.setOnSingleClickListener { + binding.btnRhythmMode.setOnSingleClickListener { viewModel.navigateToStretchView(false) } } diff --git a/presentation/src/main/res/drawable/shape_gray200_fill_26_rect.xml b/presentation/src/main/res/drawable/shape_gray200_fill_26_rect.xml new file mode 100644 index 0000000..dcf8162 --- /dev/null +++ b/presentation/src/main/res/drawable/shape_gray200_fill_26_rect.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/shape_white_fill_26_rect.xml b/presentation/src/main/res/drawable/shape_white_fill_26_rect.xml new file mode 100644 index 0000000..e972e75 --- /dev/null +++ b/presentation/src/main/res/drawable/shape_white_fill_26_rect.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/presentation/src/main/res/layout/fragment_rhythm.xml b/presentation/src/main/res/layout/fragment_rhythm.xml index b6ee58b..d28a164 100644 --- a/presentation/src/main/res/layout/fragment_rhythm.xml +++ b/presentation/src/main/res/layout/fragment_rhythm.xml @@ -11,30 +11,53 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent"> + + + + + + + app:layout_constraintTop_toBottomOf="@id/toggle_rhythm_mode" /> - + app:layout_constraintTop_toTopOf="parent"> + + + + + + + app:layout_constraintTop_toBottomOf="@id/toggle_rhythm_mode" /> + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" /> From 8d8e7462b5b058943206ab10df3c51ddc16cc3b6 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 01:50:30 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[FIX/#61]=20=ED=94=84=EB=9E=98=EA=B7=B8?= =?UTF-8?q?=EB=A8=BC=ED=8A=B8=20=EB=B7=B0=20=EB=86=92=EC=9D=B4=20=ED=86=B5?= =?UTF-8?q?=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- presentation/src/main/res/layout/fragment_record.xml | 2 +- presentation/src/main/res/layout/fragment_study.xml | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/presentation/src/main/res/layout/fragment_record.xml b/presentation/src/main/res/layout/fragment_record.xml index 301c549..a7bc526 100644 --- a/presentation/src/main/res/layout/fragment_record.xml +++ b/presentation/src/main/res/layout/fragment_record.xml @@ -23,7 +23,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="18dp" - android:layout_marginTop="32dp" + android:layout_marginTop="16dp" android:onClick="@{() -> vm.setIsChangingMonth()}" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" diff --git a/presentation/src/main/res/layout/fragment_study.xml b/presentation/src/main/res/layout/fragment_study.xml index 95f17fc..9ae8d33 100644 --- a/presentation/src/main/res/layout/fragment_study.xml +++ b/presentation/src/main/res/layout/fragment_study.xml @@ -1,7 +1,6 @@ @@ -22,10 +21,10 @@ style="@style/TextAppearance.Stempo.Head2" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="16dp" android:text="과제" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - margin:layout_marginTop="16dp" /> + app:layout_constraintTop_toTopOf="parent" /> Date: Mon, 23 Sep 2024 02:13:04 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[FEAT/#61]=20=EC=8A=A4=ED=8A=B8=EB=A0=88?= =?UTF-8?q?=EC=B9=AD=EB=B7=B0=20=EB=AF=B8=EB=94=94=EC=96=B4=20=ED=94=8C?= =?UTF-8?q?=EB=A0=88=EC=9D=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/rhythm/RhythmFragment.kt | 14 +++-- .../main/rhythm/RhythmViewModel.kt | 1 + .../main/rhythm/StretchFragment.kt | 58 +++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index f05c7c7..8bc1f36 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -66,7 +66,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy initPlayBtnListener() initStopBtnListener() initWearableSyncBtnListener() - setUiWithCurrentRhythm() + initExistingRhythm() observeStepCount() observeRhythmChanged() observeRhythmUrlState() @@ -126,6 +126,11 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy } } + private fun initExistingRhythm() { + setUiWithCurrentRhythm() + viewModel.postToGetRhythmUrlFromServer() + } + private fun observeStepCount() { viewModel.stepCount.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { binding.tvRhythmStep.text = @@ -134,7 +139,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy } private fun observeRhythmChanged() { - viewModel.isRhythmChanged.flowWithLifecycle(lifecycle).distinctUntilChanged() + viewModel.isRhythmChanged.flowWithLifecycle(lifecycle) .onEach { isChanged -> if (isChanged) { if (::mediaPlayer.isInitialized) { @@ -236,10 +241,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy if (::mediaPlayer.isInitialized) mediaPlayer.release() mediaPlayer = MediaPlayer().apply { setDataSource( - File( - requireContext().filesDir, - viewModel.filename - ).absolutePath + File(requireContext().filesDir, viewModel.filename).absolutePath ) prepare() } diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt index 7aaf6f2..590c6da 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt @@ -60,6 +60,7 @@ constructor( init { initRhythmLevelFromDataStore() + } private fun initRhythmLevelFromDataStore() { diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt index e58557d..1e73b9f 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt @@ -1,18 +1,26 @@ package com.kkkk.presentation.main.rhythm +import android.media.MediaPlayer import android.os.Bundle import android.view.View +import android.view.WindowManager +import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels import com.kkkk.core.base.BaseFragment import com.kkkk.core.extension.setOnSingleClickListener +import com.kkkk.core.extension.stringOf +import com.kkkk.core.extension.toast import dagger.hilt.android.AndroidEntryPoint import kr.genti.presentation.R import kr.genti.presentation.databinding.FragmentStretchBinding +import java.io.File @AndroidEntryPoint class StretchFragment : BaseFragment(R.layout.fragment_stretch) { private val viewModel by activityViewModels() + private lateinit var mediaPlayer: MediaPlayer + override fun onViewCreated( view: View, savedInstanceState: Bundle?, @@ -20,6 +28,9 @@ class StretchFragment : BaseFragment(R.layout.fragment_s super.onViewCreated(view, savedInstanceState) initRhythmNavigateBtnListener() + initPlayBtnListener() + initStopBtnListener() + setMediaPlayer() } private fun initRhythmNavigateBtnListener() { @@ -28,4 +39,51 @@ class StretchFragment : BaseFragment(R.layout.fragment_s } } + private fun initPlayBtnListener() { + binding.btnStretchPlay.setOnSingleClickListener { + if (::mediaPlayer.isInitialized) { + mediaPlayer.start() + switchPlayingState(true) + requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } else { + toast(stringOf(R.string.error_msg)) + } + } + } + + private fun initStopBtnListener() { + binding.btnStretchStop.setOnSingleClickListener { + if (::mediaPlayer.isInitialized) { + mediaPlayer.pause() + switchPlayingState(false) + requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + } + } + + private fun switchPlayingState(start: Boolean) { + with(binding) { + btnStretchPlay.isVisible = !start + btnStretchStop.isVisible = start + lottieStretchBg.isVisible = start + } + } + + private fun setMediaPlayer() { + if (File(requireContext().filesDir, STRETCH_WAV_FILE).exists()) { + if (::mediaPlayer.isInitialized) mediaPlayer.release() + mediaPlayer = MediaPlayer().apply { + setDataSource( + File(requireContext().filesDir, STRETCH_WAV_FILE).absolutePath + ) + prepare() + } + } else { + toast(stringOf(R.string.error_msg)) + } + } + + companion object { + const val STRETCH_WAV_FILE = "stempo_bpm_65_bit_2" + } } \ No newline at end of file From 219ca443cb6d57bd951a3f30e6d1d26c95c069e7 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 02:29:22 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[FIX/#64]=20=EB=A6=AC=EB=93=AC=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20API=20domain=20=EB=AA=A8=EB=93=88=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kkkk/domain/entity/request/RhythmRequestModel.kt | 6 ++++++ .../kotlin/com/kkkk/domain/repository/RhythmRepository.kt | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 domain/src/main/kotlin/com/kkkk/domain/entity/request/RhythmRequestModel.kt diff --git a/domain/src/main/kotlin/com/kkkk/domain/entity/request/RhythmRequestModel.kt b/domain/src/main/kotlin/com/kkkk/domain/entity/request/RhythmRequestModel.kt new file mode 100644 index 0000000..fb93fef --- /dev/null +++ b/domain/src/main/kotlin/com/kkkk/domain/entity/request/RhythmRequestModel.kt @@ -0,0 +1,6 @@ +package com.kkkk.domain.entity.request + +data class RhythmRequestModel( + val bpm: Int, + val bit: Int, +) \ No newline at end of file diff --git a/domain/src/main/kotlin/com/kkkk/domain/repository/RhythmRepository.kt b/domain/src/main/kotlin/com/kkkk/domain/repository/RhythmRepository.kt index fde666a..247d794 100644 --- a/domain/src/main/kotlin/com/kkkk/domain/repository/RhythmRepository.kt +++ b/domain/src/main/kotlin/com/kkkk/domain/repository/RhythmRepository.kt @@ -1,10 +1,11 @@ package com.kkkk.domain.repository import com.kkkk.domain.entity.request.RecordRequestModel +import com.kkkk.domain.entity.request.RhythmRequestModel interface RhythmRepository { suspend fun postToGetRhythmUrl( - bpm: Int + request: RhythmRequestModel ): Result suspend fun getRhythmWav( From 70516cad59e475e920b7c48b8670e0c9e7cb90f3 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 02:33:55 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[FIX/#64]=20=EB=A6=AC=EB=93=AC=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20API=20data=20=EB=AA=A8=EB=93=88=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kkkk/data/dataSource/RhythmDataSource.kt | 3 ++- .../data/dataSourceImpl/RhythmDataSourceImpl.kt | 5 +++-- .../kkkk/data/dto/request/RhythmRequestDto.kt | 17 +++++++++++++++++ .../data/repositoryImpl/RhythmRepositoryImpl.kt | 6 ++++-- .../java/com/kkkk/data/service/RhythmService.kt | 6 +++--- .../presentation/main/rhythm/RhythmViewModel.kt | 3 ++- 6 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 data/src/main/java/com/kkkk/data/dto/request/RhythmRequestDto.kt diff --git a/data/src/main/java/com/kkkk/data/dataSource/RhythmDataSource.kt b/data/src/main/java/com/kkkk/data/dataSource/RhythmDataSource.kt index 3d0d6e5..605271b 100644 --- a/data/src/main/java/com/kkkk/data/dataSource/RhythmDataSource.kt +++ b/data/src/main/java/com/kkkk/data/dataSource/RhythmDataSource.kt @@ -2,11 +2,12 @@ package com.kkkk.data.dataSource import com.kkkk.data.dto.BaseResponse import com.kkkk.data.dto.request.RecordRequestDto +import com.kkkk.data.dto.request.RhythmRequestDto import okhttp3.ResponseBody interface RhythmDataSource { suspend fun postToGetRhythmUrl( - bpm: Int + request: RhythmRequestDto ): BaseResponse suspend fun getRhythmWav( diff --git a/data/src/main/java/com/kkkk/data/dataSourceImpl/RhythmDataSourceImpl.kt b/data/src/main/java/com/kkkk/data/dataSourceImpl/RhythmDataSourceImpl.kt index 14a62cd..63bf101 100644 --- a/data/src/main/java/com/kkkk/data/dataSourceImpl/RhythmDataSourceImpl.kt +++ b/data/src/main/java/com/kkkk/data/dataSourceImpl/RhythmDataSourceImpl.kt @@ -3,6 +3,7 @@ package com.kkkk.data.dataSourceImpl import com.kkkk.data.dataSource.RhythmDataSource import com.kkkk.data.dto.BaseResponse import com.kkkk.data.dto.request.RecordRequestDto +import com.kkkk.data.dto.request.RhythmRequestDto import com.kkkk.data.service.RhythmService import okhttp3.ResponseBody import javax.inject.Inject @@ -13,8 +14,8 @@ constructor( private val rhythmService: RhythmService ) : RhythmDataSource { - override suspend fun postToGetRhythmUrl(bpm: Int): BaseResponse = - rhythmService.postToGetRhythmUrl(bpm) + override suspend fun postToGetRhythmUrl(request: RhythmRequestDto): BaseResponse = + rhythmService.postToGetRhythmUrl(request) override suspend fun getRhythmWav(url: String): ResponseBody = rhythmService.getRhythmWav(url) diff --git a/data/src/main/java/com/kkkk/data/dto/request/RhythmRequestDto.kt b/data/src/main/java/com/kkkk/data/dto/request/RhythmRequestDto.kt new file mode 100644 index 0000000..7a6e442 --- /dev/null +++ b/data/src/main/java/com/kkkk/data/dto/request/RhythmRequestDto.kt @@ -0,0 +1,17 @@ +package com.kkkk.data.dto.request + +import com.kkkk.domain.entity.request.RhythmRequestModel +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class RhythmRequestDto( + @SerialName("bpm") + val bpm: Int, + @SerialName("bit") + val bit: Int, +) { + companion object { + fun RhythmRequestModel.toDto() = RhythmRequestDto(bpm, bit) + } +} \ No newline at end of file diff --git a/data/src/main/java/com/kkkk/data/repositoryImpl/RhythmRepositoryImpl.kt b/data/src/main/java/com/kkkk/data/repositoryImpl/RhythmRepositoryImpl.kt index e5c3a8a..e6bfa74 100644 --- a/data/src/main/java/com/kkkk/data/repositoryImpl/RhythmRepositoryImpl.kt +++ b/data/src/main/java/com/kkkk/data/repositoryImpl/RhythmRepositoryImpl.kt @@ -2,7 +2,9 @@ package com.kkkk.data.repositoryImpl import com.kkkk.data.dataSource.RhythmDataSource import com.kkkk.data.dto.request.RecordRequestDto.Companion.toDto +import com.kkkk.data.dto.request.RhythmRequestDto.Companion.toDto import com.kkkk.domain.entity.request.RecordRequestModel +import com.kkkk.domain.entity.request.RhythmRequestModel import com.kkkk.domain.repository.RhythmRepository import javax.inject.Inject @@ -12,9 +14,9 @@ constructor( private val rhythmDataSource: RhythmDataSource, ) : RhythmRepository { - override suspend fun postToGetRhythmUrl(bpm: Int): Result = + override suspend fun postToGetRhythmUrl(request: RhythmRequestModel): Result = runCatching { - rhythmDataSource.postToGetRhythmUrl(bpm).data + rhythmDataSource.postToGetRhythmUrl(request.toDto()).data } override suspend fun getRhythmWav(url: String): Result = diff --git a/data/src/main/java/com/kkkk/data/service/RhythmService.kt b/data/src/main/java/com/kkkk/data/service/RhythmService.kt index d0631db..9292fa9 100644 --- a/data/src/main/java/com/kkkk/data/service/RhythmService.kt +++ b/data/src/main/java/com/kkkk/data/service/RhythmService.kt @@ -2,17 +2,17 @@ package com.kkkk.data.service import com.kkkk.data.dto.BaseResponse import com.kkkk.data.dto.request.RecordRequestDto +import com.kkkk.data.dto.request.RhythmRequestDto import okhttp3.ResponseBody import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST -import retrofit2.http.Path import retrofit2.http.Url interface RhythmService { - @POST("/api/v1/rhythm/{bpm}") + @POST("/api/v1/rhythm") suspend fun postToGetRhythmUrl( - @Path("bpm") bpm: Int, + @Body request: RhythmRequestDto, ): BaseResponse @GET diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt index 590c6da..e188531 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.kkkk.core.state.UiState import com.kkkk.domain.entity.request.RecordRequestModel +import com.kkkk.domain.entity.request.RhythmRequestModel import com.kkkk.domain.repository.RhythmRepository import com.kkkk.domain.repository.UserRepository import dagger.hilt.android.lifecycle.HiltViewModel @@ -125,7 +126,7 @@ constructor( fun postToGetRhythmUrlFromServer() { _rhythmUrlState.value = UiState.Loading viewModelScope.launch { - rhythmRepository.postToGetRhythmUrl(bpm) + rhythmRepository.postToGetRhythmUrl(RhythmRequestModel(bpm, bit)) .onSuccess { _rhythmUrlState.value = UiState.Success(it) } From 52eba8cde9493f06214b0995c9cb8be0710b9469 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 02:53:28 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[FEAT/#64]=20=EC=95=B1=20=EA=BA=BC?= =?UTF-8?q?=EC=A7=80=EB=A9=B4=20=EB=AF=B8=EB=94=94=EC=96=B4=20=EC=A0=95?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kkkk/presentation/main/rhythm/RhythmFragment.kt | 10 ++++++++++ .../kkkk/presentation/main/rhythm/StretchFragment.kt | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index 8bc1f36..bf28942 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -112,6 +112,15 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy } } + override fun onStop() { + super.onStop() + if (::mediaPlayer.isInitialized) { + mediaPlayer.pause() + switchPlayingState(false) + requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + } + private fun switchPlayingState(start: Boolean) { with(binding) { btnRhythmPlay.isVisible = !start @@ -243,6 +252,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy setDataSource( File(requireContext().filesDir, viewModel.filename).absolutePath ) + isLooping = true prepare() } setLoadingView(false) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt index 1e73b9f..3ba6dbf 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt @@ -61,6 +61,15 @@ class StretchFragment : BaseFragment(R.layout.fragment_s } } + override fun onStop() { + super.onStop() + if (::mediaPlayer.isInitialized) { + mediaPlayer.pause() + switchPlayingState(false) + requireActivity().window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + } + private fun switchPlayingState(start: Boolean) { with(binding) { btnStretchPlay.isVisible = !start @@ -76,6 +85,7 @@ class StretchFragment : BaseFragment(R.layout.fragment_s setDataSource( File(requireContext().filesDir, STRETCH_WAV_FILE).absolutePath ) + isLooping = true prepare() } } else { From f6faa4d5f73a099030cdb41a9e927b35b0d3e940 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 03:07:09 +0900 Subject: [PATCH 12/15] =?UTF-8?q?[ADD/#64]=20=EB=AF=B8=EB=94=94=EC=96=B4?= =?UTF-8?q?=20init=20=EC=A0=84=EC=97=90=20=ED=94=8C=EB=A0=88=EC=9D=B4=20?= =?UTF-8?q?=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/rhythm/RhythmFragment.kt | 48 ++++++++++--------- .../main/rhythm/RhythmViewModel.kt | 2 + 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index bf28942..2d3e2c1 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -90,12 +90,14 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy private fun initPlayBtnListener() { binding.btnRhythmPlay.setOnSingleClickListener { - if (::mediaPlayer.isInitialized) { - mediaPlayer.start() - switchPlayingState(true) - requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - } else { - toast(stringOf(R.string.error_msg)) + if (!viewModel.isLoading) { + if (::mediaPlayer.isInitialized) { + mediaPlayer.start() + switchPlayingState(true) + requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } else { + toast(stringOf(R.string.error_msg)) + } } } } @@ -148,18 +150,18 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy } private fun observeRhythmChanged() { - viewModel.isRhythmChanged.flowWithLifecycle(lifecycle) - .onEach { isChanged -> - if (isChanged) { - if (::mediaPlayer.isInitialized) { - mediaPlayer.pause() - switchPlayingState(false) - } - setUiWithCurrentRhythm() - viewModel.resetRhythmChangedState() - viewModel.postToGetRhythmUrlFromServer() + viewModel.isRhythmChanged.flowWithLifecycle(lifecycle).onEach { isChanged -> + if (isChanged) { + setLoadingView(true) + if (::mediaPlayer.isInitialized) { + mediaPlayer.pause() + switchPlayingState(false) } - }.launchIn(lifecycleScope) + setUiWithCurrentRhythm() + viewModel.resetRhythmChangedState() + viewModel.postToGetRhythmUrlFromServer() + } + }.launchIn(lifecycleScope) } private fun setUiWithCurrentRhythm() { @@ -201,6 +203,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy when (state) { is UiState.Success -> { if (File(requireContext().filesDir, viewModel.filename).exists()) { + setLoadingView(false) setMediaPlayer() } else { setLoadingView(true) @@ -237,13 +240,11 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy outputStream.write(byteArray) outputStream.flush() } + }.onSuccess { + setMediaPlayer() + }.onFailure { + toast(stringOf(R.string.error_msg)) } - .onSuccess { - setMediaPlayer() - } - .onFailure { - toast(stringOf(R.string.error_msg)) - } } private fun setMediaPlayer() { @@ -260,6 +261,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy private fun setLoadingView(isLoading: Boolean) { binding.layoutLoading.isVisible = isLoading + viewModel.isLoading = isLoading if (isLoading) { setStatusBarColor(R.color.transparent_50) } else { diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt index e188531..b180a3b 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmViewModel.kt @@ -32,6 +32,8 @@ constructor( var isBpmMinusAvailable = MutableLiveData(false) var isBpmPlusAvailable = MutableLiveData(true) + var isLoading = false + private val _isStretchView = MutableSharedFlow() val isStretchView: SharedFlow = _isStretchView From 4597ff6fe33c10bacd6b4144d5ed0031faf33a0b Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 03:27:37 +0900 Subject: [PATCH 13/15] =?UTF-8?q?[FEAT/#64]=20=EA=B8=B0=EB=A1=9D=EB=B7=B0?= =?UTF-8?q?=20=EB=A1=9C=EB=94=A9=EB=B7=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/record/RecordFragment.kt | 30 +++++++++++++---- .../main/record/RecordViewModel.kt | 6 +--- .../src/main/res/layout/fragment_record.xml | 32 +++++++++++++++++-- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/record/RecordFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/record/RecordFragment.kt index a3c6b31..cc54777 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/record/RecordFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/record/RecordFragment.kt @@ -18,7 +18,6 @@ import com.kkkk.core.extension.stringOf import com.kkkk.core.extension.toast import com.kkkk.core.state.UiState import dagger.hilt.android.AndroidEntryPoint -import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kr.genti.presentation.R @@ -39,6 +38,7 @@ class RecordFragment : BaseFragment(R.layout.fragment_rec observeReportMonth() observeChartEntry() setStatusBarColor(R.color.white) + viewModel.setGraphWithDate() } private fun observeReportMonth() { @@ -53,11 +53,11 @@ class RecordFragment : BaseFragment(R.layout.fragment_rec } private fun observeChartEntry() { - viewModel.chartEntry.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { state -> + viewModel.chartEntry.flowWithLifecycle(lifecycle).onEach { state -> when (state) { is UiState.Success -> { - binding.ivChartLoading.isVisible = false - binding.layoutChart.isVisible = true + setLoadingView(false) + binding.ivChartEmpty.isVisible = false binding.chartReport.apply { data = LineData(LineDataSet(state.data, CHART_RECORD).setDataSettings()) invalidate() @@ -66,17 +66,33 @@ class RecordFragment : BaseFragment(R.layout.fragment_rec } is UiState.Failure -> { - binding.ivChartLoading.isVisible = true + setLoadingView(false) + binding.ivChartEmpty.isVisible = true toast(stringOf(R.string.error_msg)) } - is UiState.Loading -> binding.ivChartLoading.isVisible = false + is UiState.Loading -> setLoadingView(true) - is UiState.Empty -> binding.ivChartLoading.isVisible = true + is UiState.Empty -> { + setLoadingView(false) + binding.ivChartEmpty.isVisible = true + } } }.launchIn(lifecycleScope) } + private fun setLoadingView(isLoading: Boolean) { + binding.layoutLoading.isVisible = isLoading + if (isLoading) { + binding.layoutChart.visibility = View.INVISIBLE + setStatusBarColor(R.color.transparent_50) + } else { + binding.layoutChart.visibility = View.VISIBLE + setStatusBarColor(R.color.white) + } + } + + private fun LineDataSet.setDataSettings(): LineDataSet { this.apply { color = colorOf(R.color.purple_50) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/record/RecordViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/main/record/RecordViewModel.kt index 7cf2917..0f11e3e 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/record/RecordViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/record/RecordViewModel.kt @@ -34,10 +34,6 @@ constructor( var startDate = "" var endDate = "" - init { - setGraphWithDate() - } - fun setIsChangingMonth() { isChangingMonth.value = isChangingMonth.value?.not() ?: false } @@ -48,7 +44,7 @@ constructor( setGraphWithDate() } - private fun setGraphWithDate() { + fun setGraphWithDate() { endDate = DATE_FORMAT.format(Date()) DATE_FORMAT.parse(endDate)?.let { date -> val postCalendar = Calendar.getInstance().apply { diff --git a/presentation/src/main/res/layout/fragment_record.xml b/presentation/src/main/res/layout/fragment_record.xml index a7bc526..f50f9cd 100644 --- a/presentation/src/main/res/layout/fragment_record.xml +++ b/presentation/src/main/res/layout/fragment_record.xml @@ -152,9 +152,10 @@ + app:layout_constraintTop_toTopOf="@id/layout_chart" /> + + + + + + \ No newline at end of file From 759001618f7bbc29b93bd4b60a7baa30da3cb8ba Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 03:30:47 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[FIX/#64]=20=EC=8A=A4=ED=8A=B8=EB=9E=98?= =?UTF-8?q?=EC=B9=AD=EB=B7=B0=20=EB=A6=AC=EB=93=AC=20=EB=8F=99=EA=B8=B0?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/kkkk/presentation/main/rhythm/StretchFragment.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt index 3ba6dbf..3d3850a 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/StretchFragment.kt @@ -79,11 +79,11 @@ class StretchFragment : BaseFragment(R.layout.fragment_s } private fun setMediaPlayer() { - if (File(requireContext().filesDir, STRETCH_WAV_FILE).exists()) { + if (File(requireContext().filesDir, viewModel.filename).exists()) { if (::mediaPlayer.isInitialized) mediaPlayer.release() mediaPlayer = MediaPlayer().apply { setDataSource( - File(requireContext().filesDir, STRETCH_WAV_FILE).absolutePath + File(requireContext().filesDir, viewModel.filename).absolutePath ) isLooping = true prepare() @@ -92,8 +92,4 @@ class StretchFragment : BaseFragment(R.layout.fragment_s toast(stringOf(R.string.error_msg)) } } - - companion object { - const val STRETCH_WAV_FILE = "stempo_bpm_65_bit_2" - } } \ No newline at end of file From 05cc115e433c40345c14443ec78e4140cc2a3da4 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Mon, 23 Sep 2024 03:36:52 +0900 Subject: [PATCH 15/15] =?UTF-8?q?[FIX/#64]=20=EB=A6=AC=EB=93=AC=EB=B7=B0?= =?UTF-8?q?=20=EC=A7=84=EC=9E=85=20=EC=8B=9C=20=EB=AF=B8=EB=94=94=EC=96=B4?= =?UTF-8?q?=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=20=EB=8C=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index 2d3e2c1..82e857b 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -61,6 +61,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy ) { super.onViewCreated(view, savedInstanceState) + setLoadingView(true) initChangeRhythmBtnListener() initStretchNavigateBtnListener() initPlayBtnListener() @@ -72,7 +73,6 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy observeRhythmUrlState() observeDownloadState() observeRecordSaveState() - setStatusBarColor(R.color.white) } private fun initChangeRhythmBtnListener() {