Skip to content

Commit

Permalink
[TNT-190] Merge branch 'develop' into feature/TNT-190
Browse files Browse the repository at this point in the history
# Conflicts:
#	feature/trainee/signup/src/main/java/co/kr/tnt/trainee/signup/TraineeSignUpViewModel.kt
#	feature/trainer/signup/src/main/java/co/kr/tnt/trainer/signup/TrainerSignUpViewModel.kt
  • Loading branch information
SeonJeongk committed Feb 14, 2025
2 parents c7e63ad + c5baa66 commit 9b6a12e
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fun TnTSnackbar(

@Preview(showBackground = true)
@Composable
private fun TnTToastPreview() {
private fun TnTSnackbarPreview() {
TnTTheme {
TnTSnackbar(
snackbarData = object : SnackbarData {
Expand Down
1 change: 1 addition & 0 deletions core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dependencies {
implementation(projects.domain)

implementation(libs.accompanist.permissions)
implementation(libs.androidx.compose.navigation)
}
33 changes: 33 additions & 0 deletions core/ui/src/main/java/co/kr/tnt/ui/component/TnTLoading.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package co.kr.tnt.ui.component

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import co.kr.tnt.designsystem.theme.TnTTheme

@Composable
fun TnTLoadingScreen(modifier: Modifier = Modifier) {
Surface(
modifier = modifier.fillMaxSize(),
color = Color.Black.copy(alpha = 0.4f),
) {
TnTLoading(modifier = Modifier.fillMaxSize())
}
}

@Composable
fun TnTLoading(modifier: Modifier) {
Box(
modifier = modifier,
contentAlignment = Alignment.Center,
) {
CircularProgressIndicator(
color = TnTTheme.colors.redColors.Red500,
)
}
}
12 changes: 12 additions & 0 deletions core/ui/src/main/java/co/kr/tnt/ui/extensions/NavController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package co.kr.tnt.ui.extensions

import androidx.navigation.NavController

/**
* Back button 연속 클릭 μ‹œ 빈 화면이 좜λ ₯λ˜λŠ” ν˜„μƒ 방지
*/
fun NavController.safePopBackStack() {
if (currentBackStackEntry?.lifecycle?.currentState == androidx.lifecycle.Lifecycle.State.RESUMED) {
popBackStack()
}
}
23 changes: 23 additions & 0 deletions core/ui/src/main/java/co/kr/tnt/ui/utils/Throttle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package co.kr.tnt.ui.utils

import android.os.SystemClock
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue

@Composable
inline fun throttled(
throttleTime: Long = 1500L,
crossinline onClick: () -> Unit,
): () -> Unit {
var lastTimeClicked by remember { mutableLongStateOf(0L) }
return {
val now = SystemClock.uptimeMillis()
if (now - lastTimeClicked >= throttleTime) {
lastTimeClicked = now
onClick()
}
}
}
9 changes: 9 additions & 0 deletions feature/login/src/main/java/co/kr/tnt/login/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal class LoginViewModel @Inject constructor(
}

this@LoginViewModel.loginResult = loginResult
clearAllChecks()
sendEffect(LoginSideEffect.ShowTermBottomSheet)
}.onFailure {
// TODO resource
Expand Down Expand Up @@ -89,6 +90,14 @@ internal class LoginViewModel @Inject constructor(
}
}

private fun clearAllChecks() {
updateState {
copy(
terms = terms.keys.associateWith { false },
)
}
}

private fun navigateToSignup() {
loginResult?.let { loginResult ->
sendEffect(LoginSideEffect.NavigateToSignup(loginResult))
Expand Down
15 changes: 8 additions & 7 deletions feature/main/src/main/java/co/kr/tnt/main/ui/TnTNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import co.kr.tnt.trainer.main.navigation.navigateToTrainerMain
import co.kr.tnt.trainer.main.navigation.trainerMainScreen
import co.kr.tnt.trainer.signup.navigation.navigateToTrainerSignUp
import co.kr.tnt.trainer.signup.navigation.trainerSignUpScreen
import co.kr.tnt.ui.extensions.safePopBackStack
import co.kr.tnt.webview.navigateToWebView
import co.kr.tnt.webview.webViewScreen

Expand Down Expand Up @@ -65,29 +66,29 @@ fun TnTNavHost(
navigateToTrainerSignUp = navController::navigateToTrainerSignUp,
)
trainerSignUpScreen(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
navigateToInvite = navController::navigateToTrainerInvite,
)
traineeSignUpScreen(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
navigateToConnect = {
navController.navigateToTraineeConnect(isSkippable = true)
},
)
trainerInviteScreen(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
navigateToHome = { navController.navigateToTrainerMain(clearBackStack = true) },
)
trainerConnectScreen(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
navigateToHome = { navController.navigateToTrainerMain(clearBackStack = true) },
)
traineeConnectScreen(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
navigateToHome = { navController.navigateToTraineeMain(clearBackStack = true) },
)
traineeMealRecordScreen(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
)
trainerMainScreen(
navigateToConnect = navController::navigateToTrainerConnect,
Expand All @@ -103,7 +104,7 @@ fun TnTNavHost(
navigateToMealDetail = navController::navigateToTraineeMealRecordDetail,
)
webViewScreen(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import co.kr.tnt.designsystem.component.TnTTopBarWithBackButton
import co.kr.tnt.designsystem.component.button.TnTBottomButton
import co.kr.tnt.designsystem.theme.TnTTheme
import co.kr.tnt.feature.trainee.connect.R
import co.kr.tnt.ui.component.TnTLoadingScreen
import co.kr.tnt.ui.utils.throttled
import java.time.LocalDate
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand All @@ -44,6 +46,7 @@ internal fun PTSessionFormPage(
sessionStartDate: LocalDate?,
completedSessionCount: String,
totalSessionCount: String,
isLoading: Boolean,
onChangeSessionStartDate: (date: LocalDate) -> Unit,
onChangeCompletedSessionCount: (count: String) -> Unit,
onChangeTotalSessionCount: (count: String) -> Unit,
Expand Down Expand Up @@ -198,10 +201,14 @@ internal fun PTSessionFormPage(
text = stringResource(uiResource.string.next),
modifier = Modifier.align(Alignment.BottomCenter),
enabled = isFormValid,
onClick = onNextClick,
onClick = throttled { onNextClick() },
)
}
}

if (isLoading) {
TnTLoadingScreen()
}
}

/**
Expand Down Expand Up @@ -294,6 +301,7 @@ private fun PTSessionFormPagePreview() {
sessionStartDate = LocalDate.now(),
completedSessionCount = "15",
totalSessionCount = "10",
isLoading = false,
onNextClick = { },
onBackClick = { },
onChangeSessionStartDate = { },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class TraineeConnectContract {
val trainerImage: String = "",
val traineeName: String = "",
val traineeImage: String = "",
val isLoading: Boolean = false,
) : UiState

sealed interface TraineeConnectUiEvent : UiEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private fun TraineeConnectScreen(
sessionStartDate = state.sessionStartDate,
completedSessionCount = state.completedSessionCount,
totalSessionCount = state.totalSessionCount,
isLoading = state.isLoading,
onChangeSessionStartDate = onChangeSessionStartDate,
onChangeCompletedSessionCount = onChangeCompletedSessionCount,
onChangeTotalSessionCount = onChangeTotalSessionCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ internal class TraineeConnectViewModel @Inject constructor(

private fun requestConnect() {
viewModelScope.launch {
updateState { copy(isLoading = true) }
runCatching {
currentState.run {
connectRepository.connectRequest(
Expand All @@ -100,6 +101,8 @@ internal class TraineeConnectViewModel @Inject constructor(
navigateToNext()
}.onFailure {
sendEffect(TraineeConnectSideEffect.ShowToast("μ„œλ²„ μš”μ²­μ— μ‹€νŒ¨ν–ˆμ–΄μš”"))
}.also {
updateState { copy(isLoading = false) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import co.kr.tnt.trainee.home.navigation.traineeHomeNavGraph
import co.kr.tnt.trainee.mypage.navigation.traineeMyPageNavGraph
import co.kr.tnt.trainee.notification.navigation.navigateToTraineeNotification
import co.kr.tnt.trainee.notification.navigation.traineeNotification
import co.kr.tnt.ui.extensions.safePopBackStack

@Composable
internal fun TraineeMainRoute(
Expand Down Expand Up @@ -74,7 +75,7 @@ private fun TraineeMainScreen(
navigateToConnect = { navigateToConnect(false) },
) {
traineeNotification(
navigateToPrevious = navController::popBackStack,
navigateToPrevious = navController::safePopBackStack,
)
}
traineeMyPageNavGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class TraineeMealRecordContract {
val isMealRecordValid: Boolean = false,
val showWarning: Boolean = false,
val dialogState: DialogState = DialogState.NONE,
val isLoading: Boolean = false,
) : UiState {
enum class DialogState {
NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ import co.kr.tnt.trainee.mealrecord.record.TraineeMealRecordContract.TraineeMeal
import co.kr.tnt.trainee.mealrecord.record.TraineeMealRecordContract.TraineeMealRecordUiState
import co.kr.tnt.trainee.mealrecord.record.TraineeMealRecordContract.TraineeMealRecordUiState.DialogState
import co.kr.tnt.ui.coil.ResizeTransformation
import co.kr.tnt.ui.component.TnTLoadingScreen
import co.kr.tnt.ui.model.RecordChip
import co.kr.tnt.ui.utils.throttled
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import com.kizitonwose.calendar.compose.rememberCalendarState
Expand Down Expand Up @@ -219,7 +221,7 @@ private fun TraineeMealRecordScreen(
size = ButtonSize.XLarge,
type = ButtonType.Primary,
enabled = state.isMealRecordValid,
onClick = onClickSaveButton,
onClick = throttled { onClickSaveButton() },
)
},
) { innerPadding ->
Expand Down Expand Up @@ -275,6 +277,10 @@ private fun TraineeMealRecordScreen(
}
}
}

if (state.isLoading) {
TnTLoadingScreen()
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ internal class TraineeMealRecordViewModel @Inject constructor(
}

private fun postMealRecord(context: Context) {
updateState { copy(isLoading = true) }

viewModelScope.launch {
val state = currentState
val imageFile: File? = state.image?.toFile(context)?.let { file ->
Expand All @@ -112,6 +114,8 @@ internal class TraineeMealRecordViewModel @Inject constructor(
updateState { copy(dialogState = DialogState.COMPLETED) }
}.onFailure {
sendEffect(TraineeMealRecordSideEffect.ShowToast("식단 기둝에 μ‹€νŒ¨ν–ˆμ–΄μš”"))
}.also {
updateState { copy(isLoading = false) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import co.kr.tnt.ui.extensions.moveToAppSetting
import co.kr.tnt.ui.model.DefaultUserProfile
import co.kr.tnt.ui.permission.PermissionRequestDialog
import co.kr.tnt.ui.permission.TnTPermission
import co.kr.tnt.ui.utils.throttled
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import com.google.accompanist.permissions.ExperimentalPermissionsApi
Expand Down Expand Up @@ -178,11 +179,10 @@ private fun TraineeMyPageScreen(
text = stringResource(coreR.string.app_push_notification),
verticalPadding = 12.dp,
enabled = false,
onClick = { },
trailingComponent = {
TnTSwitch(
checked = state.isEnablePushNotification,
onClick = onTogglePushNotification,
onClick = throttled(throttleTime = 500L) { onTogglePushNotification() },
)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import co.kr.tnt.designsystem.component.button.TnTBottomButton
import co.kr.tnt.designsystem.theme.TnTTheme
import co.kr.tnt.feature.trainee.signup.R
import co.kr.tnt.trainee.signup.TraineeSignUpContract.TraineeSignUpUiState
import co.kr.tnt.ui.component.TnTLoadingScreen
import co.kr.tnt.ui.model.DefaultUserProfile
import co.kr.tnt.ui.utils.throttled
import coil.compose.rememberAsyncImagePainter
import co.kr.tnt.core.ui.R as uiResource

Expand Down Expand Up @@ -77,11 +79,15 @@ internal fun TraineeSignUpCompletePage(
}
TnTBottomButton(
text = stringResource(uiResource.string.start),
onClick = { onNextClick(state.image) },
onClick = throttled { onNextClick(state.image) },
modifier = Modifier.align(Alignment.BottomCenter),
)
}
}

if (state.isLoading) {
TnTLoadingScreen()
}
}

@Preview(showBackground = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class TraineeSignUpContract {
val weight: String? = null,
val ptPurpose: List<String> = emptyList(),
val caution: String? = "",
val isLoading: Boolean = false,
) : UiState {
val isNameValid get() = name.length <= MAX_NAME_LENGTH

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ internal class TraineeSignUpViewModel @Inject constructor(
authType: String,
) {
viewModelScope.launch {
updateState { copy(isLoading = true) }

val state = currentState
val profileImageFile: File? = imageUri?.toFile(context)?.let { file ->
if (!isAllowedImageFormat(file)) {
Expand Down Expand Up @@ -85,7 +87,9 @@ internal class TraineeSignUpViewModel @Inject constructor(
}.onSuccess {
sendEffect(TraineeSignUpEffect.NavigateToConnect)
}.onFailure {
sendEffect(TraineeSignUpEffect.ShowToast("μ„œλ²„ μš”μ²­μ— μ‹€νŒ¨ν–ˆμ–΄μš”"))
sendEffect(TraineeSignUpEffect.ShowToast("μ„œλ²„ μš”μ²­μ— μ‹€νŒ¨ν–ˆμ–΄μš”."))
}.also {
updateState { copy(isLoading = false) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal class AddPtSessionContract {
val memo: String = "",
val dialogState: DialogState = DialogState.NONE,
val sheetType: BottomSheetType = BottomSheetType.NONE,
val isLoading: Boolean = false,
) : UiState {
val totalSessionMinute: Int?
get() {
Expand Down
Loading

0 comments on commit 9b6a12e

Please sign in to comment.