diff --git a/data/src/main/java/com/kkkk/data/local/UserSharedPref.kt b/data/src/main/java/com/kkkk/data/local/UserSharedPref.kt index fa51649..20618a8 100644 --- a/data/src/main/java/com/kkkk/data/local/UserSharedPref.kt +++ b/data/src/main/java/com/kkkk/data/local/UserSharedPref.kt @@ -4,6 +4,7 @@ interface UserSharedPref { var accessToken: String var refreshToken: String var deviceToken: String + var bpmLevel: Int fun clearInfo() } diff --git a/data/src/main/java/com/kkkk/data/local/UserSharedPrefImpl.kt b/data/src/main/java/com/kkkk/data/local/UserSharedPrefImpl.kt index 1e98b68..ad9904d 100644 --- a/data/src/main/java/com/kkkk/data/local/UserSharedPrefImpl.kt +++ b/data/src/main/java/com/kkkk/data/local/UserSharedPrefImpl.kt @@ -5,30 +5,34 @@ import androidx.core.content.edit import javax.inject.Inject class UserSharedPrefImpl - @Inject - constructor( - private val dataStore: SharedPreferences, - ) : UserSharedPref { - override var accessToken: String - get() = dataStore.getString(ACCESS_TOKEN, "").orEmpty() - set(value) = dataStore.edit { putString(ACCESS_TOKEN, value) } +@Inject +constructor( + private val dataStore: SharedPreferences, +) : UserSharedPref { + override var accessToken: String + get() = dataStore.getString(ACCESS_TOKEN, "").orEmpty() + set(value) = dataStore.edit { putString(ACCESS_TOKEN, value) } - override var refreshToken: String - get() = dataStore.getString(REFRESH_TOKEN, "").orEmpty() - set(value) = dataStore.edit { putString(REFRESH_TOKEN, value) } + override var refreshToken: String + get() = dataStore.getString(REFRESH_TOKEN, "").orEmpty() + set(value) = dataStore.edit { putString(REFRESH_TOKEN, value) } - override var deviceToken: String - get() = dataStore.getString(DEVICE_TOKEN, "").orEmpty() - set(value) = dataStore.edit { putString(DEVICE_TOKEN, value) } + override var deviceToken: String + get() = dataStore.getString(DEVICE_TOKEN, "").orEmpty() + set(value) = dataStore.edit { putString(DEVICE_TOKEN, value) } - override fun clearInfo() { - dataStore.edit().clear().apply() - } + override var bpmLevel: Int + get() = dataStore.getInt(BPM_LEVEL, 1) + set(value) = dataStore.edit { putInt(BPM_LEVEL, value) } - companion object { - private const val ACCESS_TOKEN = "ACCESS_TOKEN" - private const val REFRESH_TOKEN = "REFRESH_TOKEN" - private const val DEVICE_TOKEN = "DEVICE_TOKEN" - private const val USER_ID = "USER_ID" - } + override fun clearInfo() { + dataStore.edit().clear().apply() } + + companion object { + 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" + } +} diff --git a/data/src/main/java/com/kkkk/data/repositoryImpl/UserRepositoryImpl.kt b/data/src/main/java/com/kkkk/data/repositoryImpl/UserRepositoryImpl.kt index 22df334..a0c6314 100644 --- a/data/src/main/java/com/kkkk/data/repositoryImpl/UserRepositoryImpl.kt +++ b/data/src/main/java/com/kkkk/data/repositoryImpl/UserRepositoryImpl.kt @@ -13,6 +13,10 @@ constructor( override fun getRefreshToken(): String = userSharedPref.refreshToken + override fun getBpmLevel(): Int = userSharedPref.bpmLevel + + override fun getDeviceToken(): String = userSharedPref.deviceToken + override fun setTokens( accessToken: String, refreshToken: String, @@ -21,7 +25,9 @@ constructor( userSharedPref.refreshToken = refreshToken } - override fun getDeviceToken(): String = userSharedPref.deviceToken + override fun setBpmLevel(bpmLevel: Int) { + userSharedPref.bpmLevel = bpmLevel + } override fun setDeviceToken(deviceToken: String) { userSharedPref.deviceToken = deviceToken diff --git a/domain/src/main/kotlin/com/kkkk/domain/repository/UserRepository.kt b/domain/src/main/kotlin/com/kkkk/domain/repository/UserRepository.kt index 8ed0401..0ec4592 100644 --- a/domain/src/main/kotlin/com/kkkk/domain/repository/UserRepository.kt +++ b/domain/src/main/kotlin/com/kkkk/domain/repository/UserRepository.kt @@ -5,11 +5,15 @@ interface UserRepository { fun getRefreshToken(): String + fun getBpmLevel(): Int + fun setTokens( accessToken: String, refreshToken: String, ) + fun setBpmLevel(bpmLevel: Int) + fun getDeviceToken(): String fun setDeviceToken(deviceToken: String) diff --git a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt index db7f7a3..4166d19 100644 --- a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt +++ b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingActivity.kt @@ -11,11 +11,13 @@ import androidx.lifecycle.lifecycleScope import com.kkkk.core.base.BaseActivity import com.kkkk.core.extension.navigateToScreenClear import com.kkkk.presentation.main.MainActivity +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.ActivityOnboardingBinding +@AndroidEntryPoint class OnboardingActivity : BaseActivity(R.layout.activity_onboarding) { private lateinit var timer: CountDownTimer private val viewModel by viewModels() @@ -49,11 +51,14 @@ class OnboardingActivity : BaseActivity(R.layout.acti } private fun startTimer() { - timer = object : CountDownTimer(60000, 1000) { + timer = object : CountDownTimer(TIME, INTERVAL) { override fun onTick(millisUntilFinished: Long) {} override fun onFinish() { - viewModel.setState(OnboardingState.END) + with(viewModel) { + setBpmLevel() + setState(OnboardingState.END) + } } }.start() } @@ -70,4 +75,9 @@ class OnboardingActivity : BaseActivity(R.layout.acti replace(R.id.fcv_onboarding, T::class.java.canonicalName) } } + + companion object { + private const val TIME = 60000L + private const val INTERVAL = 1000L + } } diff --git a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt index be8c9fd..8253f67 100644 --- a/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt +++ b/presentation/src/main/java/com/kkkk/presentation/onboarding/onbarding/OnboardingViewModel.kt @@ -1,6 +1,7 @@ package com.kkkk.presentation.onboarding.onbarding import androidx.lifecycle.ViewModel +import com.kkkk.domain.repository.UserRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -8,6 +9,7 @@ import javax.inject.Inject @HiltViewModel class OnboardingViewModel @Inject constructor( + private val userRepository: UserRepository ) : ViewModel() { private val _state = MutableStateFlow(OnboardingState.START) val state: StateFlow = _state @@ -16,7 +18,6 @@ class OnboardingViewModel @Inject constructor( val stepCount: StateFlow = _stepCount private val _speed = MutableStateFlow(0f) - val speed: StateFlow = _speed private val _lastStepTime = MutableStateFlow(0L) val lastStepTime: StateFlow = _lastStepTime @@ -37,6 +38,22 @@ class OnboardingViewModel @Inject constructor( _state.value = newState } + fun setBpmLevel() { + val level = when (_speed.value / (_stepCount.value / SPEED_CALC_INTERVAL)) { + in 55f..65f -> 2 + in 65f..75f -> 3 + in 75f..85f -> 4 + in 85f..95f -> 5 + in 95f..105f -> 6 + in 15f..115f -> 7 + in 115f..125f -> 8 + in 125f..Float.MAX_VALUE -> 9 + else -> 1 + } + + userRepository.setBpmLevel(level) + } + companion object { const val SPEED_CALC_INTERVAL = 10 } diff --git a/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt b/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt index 3312690..817f035 100644 --- a/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt +++ b/presentation/src/main/java/com/kkkk/presentation/onboarding/splash/SplashActivity.kt @@ -12,7 +12,7 @@ import com.kkkk.core.extension.setNavigationBarColorFromResource import com.kkkk.core.extension.setStatusBarColorFromResource import com.kkkk.core.extension.toast import com.kkkk.presentation.main.MainActivity -import com.kkkk.presentation.main.onboarding.onbarding.OnboardingActivity +import com.kkkk.presentation.onboarding.onbarding.OnboardingActivity import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach