Skip to content

Commit

Permalink
[FIX]#111: Toast 공통화
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Aug 19, 2024
1 parent fba99f0 commit 680fc2a
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 80 deletions.
19 changes: 7 additions & 12 deletions app/src/main/kotlin/com/bff/wespot/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import com.bff.wespot.analytic.AnalyticsHelper
import com.bff.wespot.analytic.LocalAnalyticsHelper
import com.bff.wespot.designsystem.R
import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.theme.StaticTypeScale
import com.bff.wespot.designsystem.theme.WeSpotTheme
import com.bff.wespot.designsystem.theme.WeSpotThemeManager
Expand All @@ -65,6 +64,7 @@ import com.bff.wespot.model.ToastState
import com.bff.wespot.model.notification.NotificationType
import com.bff.wespot.model.notification.convertNotificationType
import com.bff.wespot.navigation.Navigator
import com.bff.wespot.ui.TopToast
import com.bff.wespot.state.MainAction
import com.bff.wespot.viewmodel.MainViewModel
import com.ramcosta.composedestinations.dynamic.within
Expand Down Expand Up @@ -227,17 +227,12 @@ private fun MainScreen(
navigateScreenFromNavArgs(navArgs, navController)
}

if (toast.show) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
WSToast(
text = stringResource(toast.message),
showToast = toast.show,
toastType = toast.type,
closeToast = {
toast = toast.copy(show = false)
},
)
}
TopToast(
message = stringResource(toast.message),
toastType = toast.type,
showToast = toast.show
) {
toast = toast.copy(show = false)
}

LaunchedEffect(Unit) {
Expand Down
3 changes: 2 additions & 1 deletion core/ui/src/main/kotlin/com/bff/wespot/model/ToastState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ data class ToastState(
@StringRes val message: Int,
val type: WSToastType,
) {
constructor() : this(false, -1, WSToastType.Success)
constructor() :
this(false, com.bff.wespot.designsystem.R.string.cancel, WSToastType.Success)
}
33 changes: 33 additions & 0 deletions core/ui/src/main/kotlin/com/bff/wespot/ui/TopToast.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.bff.wespot.ui

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.component.indicator.WSToastType

@Composable
fun TopToast(
message: String,
toastType: WSToastType,
showToast: Boolean,
closeToast: () -> Unit,
) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(top = 12.dp),
contentAlignment = Alignment.TopCenter
) {
WSToast(
text = message,
showToast = showToast,
toastType = toastType,
closeToast = closeToast,
)
}
}
17 changes: 7 additions & 10 deletions feature/auth/src/main/kotlin/com/bff/wespot/auth/AuthActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import android.view.ViewTreeObserver
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import com.bff.wespot.auth.screen.AuthNavGraph
Expand All @@ -29,7 +27,6 @@ import com.bff.wespot.auth.screen.destinations.SchoolScreenDestination
import com.bff.wespot.auth.state.AuthAction
import com.bff.wespot.auth.state.AuthSideEffect
import com.bff.wespot.auth.viewmodel.AuthViewModel
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.component.indicator.WSToastType
import com.bff.wespot.designsystem.theme.WeSpotTheme
import com.bff.wespot.model.constants.LoginState
Expand All @@ -39,6 +36,7 @@ import com.bff.wespot.navigation.util.EXTRA_TARGET_ID
import com.bff.wespot.navigation.util.EXTRA_TOAST_MESSAGE
import com.bff.wespot.navigation.util.EXTRA_TYPE
import com.bff.wespot.ui.LoadingAnimation
import com.bff.wespot.ui.TopToast
import com.ramcosta.composedestinations.DestinationsNavHost
import com.ramcosta.composedestinations.navigation.dependency
import com.ramcosta.composedestinations.navigation.navigate
Expand Down Expand Up @@ -130,13 +128,12 @@ class AuthActivity : ComponentActivity() {
}

if (toastMessage != null) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
WSToast(
text = toastMessage,
toastType = WSToastType.Success,
showToast = showToast,
closeToast = { showToast = false },
)
TopToast(
message = toastMessage,
toastType = WSToastType.Success,
showToast = showToast,
) {
showToast = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import com.bff.wespot.auth.viewmodel.AuthViewModel
import com.bff.wespot.designsystem.component.button.WSButton
import com.bff.wespot.designsystem.component.button.WSOutlineButton
import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.component.indicator.WSToastType
import com.bff.wespot.designsystem.theme.StaticTypeScale
import com.bff.wespot.designsystem.theme.WeSpotThemeManager
import com.bff.wespot.ui.TopToast
import com.bff.wespot.ui.WSBottomSheet
import com.ramcosta.composedestinations.annotation.Destination
import org.orbitmvi.orbit.compose.collectAsState
Expand Down Expand Up @@ -113,13 +113,12 @@ fun GradeScreen(
}
}

Box(modifier = Modifier.fillMaxSize().padding(it), contentAlignment = Alignment.TopCenter) {
WSToast(
text = stringResource(id = R.string.more_than_14_to_register),
toastType = WSToastType.Error,
showToast = toast,
closeToast = { toast = false },
)
TopToast(
message = stringResource(id = R.string.more_than_14_to_register),
toastType = WSToastType.Error,
showToast = toast
) {
toast = false
}

if (state.gradeBottomSheet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.bff.wespot.designsystem.component.button.WSButton
import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.component.indicator.WSToastType
import com.bff.wespot.designsystem.component.input.WsTextField
import com.bff.wespot.designsystem.component.input.WsTextFieldType
Expand All @@ -62,6 +61,7 @@ import com.bff.wespot.navigation.Navigator
import com.bff.wespot.navigation.util.WebLink
import com.bff.wespot.ui.LetterCountIndicator
import com.bff.wespot.ui.LoadingAnimation
import com.bff.wespot.ui.TopToast
import com.bff.wespot.util.hexToColor
import com.ramcosta.composedestinations.annotation.Destination
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -102,6 +102,7 @@ fun ProfileEditScreen(
toast = it.toastState
focusManager.clearFocus()
}

else -> {}
}
}
Expand Down Expand Up @@ -212,7 +213,7 @@ fun ProfileEditScreen(
action(EntireEditAction.OnIntroductionEditDoneButtonClicked)
},
enabled =
isEdited &&
isEdited &&
state.hasProfanity.not() &&
state.introductionInput.length in 1..20,
text = stringResource(id = R.string.edit_done),
Expand All @@ -230,17 +231,12 @@ fun ProfileEditScreen(
}
}

if (toast.show) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
WSToast(
text = stringResource(toast.message),
showToast = toast.show,
toastType = toast.type,
closeToast = {
toast = toast.copy(show = false)
},
)
}
TopToast(
message = stringResource(toast.message),
toastType = toast.type,
showToast = toast.show
) {
toast = toast.copy(show = false)
}

if (state.isLoading) {
Expand Down Expand Up @@ -338,9 +334,11 @@ fun ProfileIntroductionItem(
content.length > INTRODUCTION_MAX_LENGTH -> {
stringResource(R.string.introduction_limit)
}

hasProfanity -> {
stringResource(com.bff.wespot.designsystem.R.string.has_profanity)
}

else -> ""
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bff.wespot.message.screen

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -17,14 +16,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.bff.wespot.designsystem.R.string
import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.component.indicator.WSToastType
import com.bff.wespot.designsystem.theme.StaticTypeScale
import com.bff.wespot.designsystem.theme.WeSpotThemeManager
Expand All @@ -35,6 +32,7 @@ import com.bff.wespot.message.state.send.SendAction
import com.bff.wespot.message.viewmodel.MessageViewModel
import com.bff.wespot.message.viewmodel.SendViewModel
import com.bff.wespot.ui.ReservedMessageItem
import com.bff.wespot.ui.TopToast
import com.ramcosta.composedestinations.annotation.Destination
import org.orbitmvi.orbit.compose.collectAsState

Expand Down Expand Up @@ -107,20 +105,12 @@ fun ReservedMessageScreen(
}
}

if (showToast) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(top = 8.dp),
contentAlignment = Alignment.TopCenter,
) {
WSToast(
text = stringResource(id = R.string.edit_done),
toastType = WSToastType.Success,
showToast = showToast,
closeToast = { showToast = false },
)
}
TopToast(
message = stringResource(id = R.string.edit_done),
toastType = WSToastType.Success,
showToast = showToast,
) {
showToast = false
}

LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.bff.wespot.designsystem.component.button.HeightRange
import com.bff.wespot.designsystem.component.button.WSButton
import com.bff.wespot.designsystem.component.button.WSButtonType
import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.component.indicator.WSToastType
import com.bff.wespot.designsystem.component.modal.WSDialog
import com.bff.wespot.designsystem.component.toggle.WSSwitch
Expand All @@ -46,6 +45,7 @@ import com.bff.wespot.message.state.send.SendSideEffect
import com.bff.wespot.message.viewmodel.SendViewModel
import com.bff.wespot.ui.LetterCountIndicator
import com.bff.wespot.ui.LoadingAnimation
import com.bff.wespot.ui.TopToast
import com.ramcosta.composedestinations.annotation.Destination
import org.orbitmvi.orbit.compose.collectAsState
import org.orbitmvi.orbit.compose.collectSideEffect
Expand Down Expand Up @@ -261,17 +261,15 @@ fun MessageEditScreen(
}
}

if (toast) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
WSToast(
text = stringResource(R.string.toast_error_name_edit),
toastType = WSToastType.Error,
showToast = toast,
closeToast = { toast = false },
)
}
TopToast(
message = stringResource(R.string.toast_error_name_edit),
toastType = WSToastType.Error,
showToast = toast
) {
toast = false
}


LaunchedEffect(Unit) {
action(SendAction.OnMessageEditScreenEntered(navArgs.isReservedMessage, navArgs.messageId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import com.bff.wespot.designsystem.component.button.WSOutlineButton
import com.bff.wespot.designsystem.component.button.WSOutlineButtonType
import com.bff.wespot.designsystem.component.button.WSTextButton
import com.bff.wespot.designsystem.component.header.WSTopBar
import com.bff.wespot.designsystem.component.indicator.WSToast
import com.bff.wespot.designsystem.component.indicator.WSToastType
import com.bff.wespot.designsystem.component.modal.WSDialog
import com.bff.wespot.designsystem.theme.StaticTypeScale
import com.bff.wespot.navigation.Navigator
import com.bff.wespot.ui.LoadingAnimation
import com.bff.wespot.ui.ReportBottomSheet
import com.bff.wespot.ui.TopToast
import com.bff.wespot.util.hexToColor
import com.bff.wespot.vote.R
import com.bff.wespot.vote.state.voting.VotingAction
Expand Down Expand Up @@ -156,17 +156,15 @@ fun VotingScreen(
}
}

Box(
modifier = Modifier
.fillMaxSize()
.padding(top = 8.dp),
contentAlignment = Alignment.TopCenter,
TopToast(
message = toastMessage,
toastType = WSToastType.Success,
showToast = toast,
) {
WSToast(text = toastMessage, toastType = WSToastType.Success, showToast = toast) {
toast = false
}
toast = false
}


if (state.loading) {
LoadingAnimation()
}
Expand Down

0 comments on commit 680fc2a

Please sign in to comment.