Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI/#54] 리듬뷰 / 바텀시트 UI 수정사항 대응 #60

Merged
merged 12 commits into from
Sep 22, 2024
Merged
1 change: 1 addition & 0 deletions data/src/main/java/com/kkkk/data/local/UserSharedPref.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface UserSharedPref {
var refreshToken: String
var deviceToken: String
var bpm: Int
var bit : Int

fun clearInfo()
}
11 changes: 8 additions & 3 deletions data/src/main/java/com/kkkk/data/local/UserSharedPrefImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ constructor(
set(value) = dataStore.edit { putString(DEVICE_TOKEN, value) }

override var bpm: Int
get() = dataStore.getInt(BPM_LEVEL, 50)
set(value) = dataStore.edit { putInt(BPM_LEVEL, value) }
get() = dataStore.getInt(BPM, 65)
set(value) = dataStore.edit { putInt(BPM, value) }

override var bit: Int
get() = dataStore.getInt(BIT, 2)
set(value) = dataStore.edit { putInt(BIT, value) }

override fun clearInfo() {
dataStore.edit().clear().apply()
Expand All @@ -33,6 +37,7 @@ constructor(
private const val ACCESS_TOKEN = "ACCESS_TOKEN"
private const val REFRESH_TOKEN = "REFRESH_TOKEN"
private const val DEVICE_TOKEN = "DEVICE_TOKEN"
private const val BPM_LEVEL = "BPM_LEVEL"
private const val BPM = "BPM"
private const val BIT = "BIT"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ constructor(

override fun getRefreshToken(): String = userSharedPref.refreshToken

override fun getDeviceToken(): String = userSharedPref.deviceToken

override fun getBpm(): Int = userSharedPref.bpm

override fun getDeviceToken(): String = userSharedPref.deviceToken
override fun getBit(): Int = userSharedPref.bit

override fun setTokens(
accessToken: String,
Expand All @@ -25,12 +27,16 @@ constructor(
userSharedPref.refreshToken = refreshToken
}

override fun setDeviceToken(deviceToken: String) {
userSharedPref.deviceToken = deviceToken
}

override fun setBpm(bpm: Int) {
userSharedPref.bpm = bpm
}

override fun setDeviceToken(deviceToken: String) {
userSharedPref.deviceToken = deviceToken
override fun setBit(bit: Int) {
userSharedPref.bit = bit
}

override fun clearInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ interface UserRepository {

fun getRefreshToken(): String

fun getDeviceToken(): String

fun getBpm(): Int

fun getBit(): Int

fun setTokens(
accessToken: String,
refreshToken: String,
)

fun setBpm(bpm: Int)
fun setDeviceToken(deviceToken: String)

fun getDeviceToken(): String
fun setBpm(bpm: Int)

fun setDeviceToken(deviceToken: String)
fun setBit(bit: Int)

fun clearInfo()
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.kkkk.presentation.main.rhythm

import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import androidx.fragment.app.activityViewModels
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.kkkk.core.base.BaseBottomSheet
import com.kkkk.core.extension.setOnSingleClickListener
import kr.genti.presentation.R
Expand All @@ -16,7 +18,19 @@ class RhythmBottomSheet :

override fun onStart() {
super.onStart()
dialog?.window?.setBackgroundDrawableResource(R.color.transparent)
dialog?.apply {
window?.setBackgroundDrawableResource(R.color.transparent)
findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)?.let {
it.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
override fun onGlobalLayout() {
it.viewTreeObserver.removeOnGlobalLayoutListener(this)
it.layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT
BottomSheetBehavior.from(it).state = BottomSheetBehavior.STATE_EXPANDED
it.requestLayout()
}
})
}
}
}

override fun onViewCreated(
Expand All @@ -26,18 +40,14 @@ class RhythmBottomSheet :
super.onViewCreated(view, savedInstanceState)

binding.vm = viewModel
viewModel.setRhythmToTemp()
initSubmitBtnListener()
}

private fun initSubmitBtnListener() {
binding.btnSubmitLevel.setOnSingleClickListener {
viewModel.setRhythmLevel()
viewModel.setTempToRhythm()
dismiss()
}
}

override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
viewModel.resetTempRhythmLevel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ 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
import com.kkkk.core.extension.toast
import com.kkkk.core.state.UiState
import com.kkkk.presentation.main.rhythm.RhythmViewModel.Companion.LEVEL_UNDEFINED
import com.kkkk.presentation.manager.PhoneDataManager
import com.kkkk.presentation.manager.PhoneDataManager.Companion.KEY_BPM
import com.kkkk.presentation.manager.PhoneDataManager.Companion.PATH_BPM
import com.kkkk.presentation.onboarding.onbarding.OnboardingViewModel.Companion.SPEED_CALC_INTERVAL
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
Expand Down Expand Up @@ -68,7 +64,7 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
initStopBtnListener()
initWearableSyncBtnListener()
observeStepCount()
observeRhythmLevel()
observeRhythmChanged()
observeRhythmUrlState()
observeDownloadState()
observeRecordSaveState()
Expand Down Expand Up @@ -116,7 +112,7 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy

private fun initWearableSyncBtnListener() {
binding.tvRhythmTitle.setOnSingleClickListener {
phoneDataManager.sendIntToWearable(PATH_BPM, KEY_BPM, viewModel.getBpmFromDataStore())
phoneDataManager.sendIntToWearable(PATH_BPM, KEY_BPM, viewModel.bpm)
}
}

Expand All @@ -126,44 +122,49 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy
}.launchIn(lifecycleScope)
}

private fun observeRhythmLevel() {
viewModel.rhythmLevel.flowWithLifecycle(lifecycle).distinctUntilChanged().onEach { level ->
if (level == LEVEL_UNDEFINED) return@onEach
if (::mediaPlayer.isInitialized) {
mediaPlayer.pause()
switchPlayingState(false)
}
setUiWithCurrentLevel()
viewModel.postToGetRhythmUrlFromServer()
}.launchIn(lifecycleScope)
private fun observeRhythmChanged() {
viewModel.isRhythmChanged.flowWithLifecycle(lifecycle).distinctUntilChanged()
.onEach { isChanged ->
if (isChanged) {
if (::mediaPlayer.isInitialized) {
mediaPlayer.pause()
switchPlayingState(false)
}
setUiWithCurrentLevel()
viewModel.resetRhythmChangedState()
viewModel.postToGetRhythmUrlFromServer()
}
}.launchIn(lifecycleScope)
}

private fun setUiWithCurrentLevel() {
val color = when (viewModel.rhythmLevel.value.rem(3)) {
1 -> COLOR_PURPLE
2 -> COLOR_SKY
0 -> COLOR_GREEN
val color = when (viewModel.bit.rem(3)) {
2 -> COLOR_PURPLE
3 -> COLOR_SKY
4 -> COLOR_GREEN
6 -> COLOR_PURPLE
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) {
// 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()
// }
// }
}

private fun getResource(name: String, defType: String) =
Expand Down Expand Up @@ -245,12 +246,12 @@ class RhythmFragment : BaseFragment<FragmentRhythmBinding>(R.layout.fragment_rhy

private fun observeRecordSaveState() {
viewModel.isRecordSaved.flowWithLifecycle(lifecycle).onEach { isSuccess ->
if (isSuccess) {
toast(stringOf(R.string.rhythm_toast_save_success))
} else {
toast(stringOf(R.string.error_msg))
}
}.launchIn(lifecycleScope)
if (isSuccess) {
toast(stringOf(R.string.rhythm_toast_save_success))
} else {
toast(stringOf(R.string.error_msg))
}
}.launchIn(lifecycleScope)
}

override fun onDestroyView() {
Expand Down
Loading
Loading