Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.puzzle.designsystem.component

import androidx.annotation.DrawableRes
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -12,23 +13,34 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults.cardColors
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
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.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.puzzle.common.ui.SnackBarState
import com.puzzle.designsystem.R
import com.puzzle.designsystem.foundation.PieceTheme
import kotlinx.coroutines.delay

@Composable
fun PieceDialog(
Expand Down Expand Up @@ -294,9 +306,24 @@ fun PieceImageDialog(
buttonLabel: String,
onDismissRequest: () -> Unit,
onApproveClick: () -> Unit = {},
isPuzzleUsed: Boolean = false,
isApproveButtonShow: Boolean = true,
buttonEnabled: Boolean = true,
) {

val context = LocalContext.current
val message = context.getString(R.string.puzzle_used, 1)

var showToast by remember { mutableStateOf(isPuzzleUsed) }

LaunchedEffect(isPuzzleUsed) {
if (isPuzzleUsed) {
showToast = true
delay(2000L)
showToast = false
}
}

Dialog(
onDismissRequest = onDismissRequest,
properties = DialogProperties(usePlatformDefaultWidth = false),
Expand All @@ -312,6 +339,38 @@ fun PieceImageDialog(
.padding(start = 20.dp, end = 20.dp),
)

Crossfade(
targetState = showToast,
label = "ToastCrossfade",
modifier = Modifier
.align(Alignment.TopCenter)
.padding(top = 64.35.dp)
) { isVisible ->
if (isVisible) {
Row(
modifier = Modifier
.wrapContentWidth()
.clip(RoundedCornerShape(12.dp))
.background(PieceTheme.colors.primaryDefault)
.padding(horizontal = 20.dp, vertical = 8.dp),
) {
Image(
painter = painterResource(R.drawable.ic_toast_matching),
contentDescription = null,
modifier = Modifier.padding(end = 8.dp),
)

Text(
text = message,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
style = PieceTheme.typography.bodySM,
color = PieceTheme.colors.white,
)
}
}
}

PieceImage(
model = imageUri,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ internal fun MatchingDetailScreen(
MatchingDetailPage.ValuePickPage -> "value_pick"
MatchingDetailPage.ValueTalkPage -> "value_talk"
},
isPuzzleUsed = state.isPuzzleUsedForImage,
onDismissRequest = onDismissDialogClick,
onApproveClick = { onConfirmDialogClick(PROFILE_IMAGE_DETAIL) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class MatchingDetailViewModel @Inject constructor(
is MatchingDetailIntent.OnReportClick -> onReportClick()
is MatchingDetailIntent.OnShowDialog -> showDialog(intent.dialogType)
is MatchingDetailIntent.OnConfirmDialogClick -> processConfirmDialog(intent.dialogType)
MatchingDetailIntent.OnDismissDialogClick -> setState { copy(isShowDialog = false) }
MatchingDetailIntent.OnDismissDialogClick -> setState { copy(isShowDialog = false, isPuzzleUsedForImage = false) }
MatchingDetailIntent.OnShowOpponentImageClick -> onShowOpponentImageClick()
MatchingDetailIntent.OnAcceptMatchingClick -> onAcceptMatchingClick()
}
Expand Down Expand Up @@ -230,18 +230,12 @@ class MatchingDetailViewModel @Inject constructor(
suspendRunCatching {
matchingRepository.postOpponentProfile(matchId = matchId)
}.onSuccess {
_sideEffect.send(
SnackBarSideEffect.Matching(
R.string.puzzle_used,
PUZZLE_COUNT_CHECK_PICTURE
)
)

setState {
copy(
profile = profile?.copy(
isImageViewed = true,
)
),
isPuzzleUsedForImage = true
)
}
loadProfileImage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.puzzle.matching.graph.detail.common.constant.MatchingDetailDialogType
@Immutable
data class MatchingDetailState(
val isLoading: Boolean = false,
val isPuzzleUsedForImage: Boolean = false,
val currentPage: MatchingDetailPage = MatchingDetailPage.BasicInfoPage,
val remainWaitingTimeInSec : Long = 0L,
val imageUrl: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ internal fun ProfileImageDialog(
imageUri: String?,
matchStatus: MatchStatus?,
entryRoute: String,
isPuzzleUsed: Boolean = false,
onDismissRequest: () -> Unit,
onApproveClick: () -> Unit,
) {
Expand All @@ -31,6 +32,7 @@ internal fun ProfileImageDialog(
)
},
onDismissRequest = onDismissRequest,
isPuzzleUsed = isPuzzleUsed
)

TrackScreenViewEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ internal fun MatchingRoute(
LifecycleStartEffect(viewModel) {
viewModel.fetchMatchInfo()
viewModel.fetchFreeMatch()
viewModel.fetchPuzzleCount()
viewModel.fetchNotificationsCount()

onStopOrDispose { viewModel.stopTimerList() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,12 @@ class MatchingViewModel @Inject constructor(
}
}

internal fun fetchPuzzleCount() = viewModelScope.launch(dispatcher) {

if (currentState.userRole != UserRole.USER) return@launch
private suspend fun fetchPuzzleCount() = suspendRunCatching {
userRepository.getUserPuzzle()
}.onSuccess {
setState { copy(puzzleCount = it.count) }
}.onFailure { handleMatchingError(it) }

suspendRunCatching {
userRepository.getUserPuzzle()
}.onSuccess {
setState { copy(puzzleCount = it.count) }
}.onFailure { handleMatchingError(it) }
}

internal fun fetchNotificationsCount() = viewModelScope.launch(dispatcher) {
suspendRunCatching {
Expand All @@ -130,6 +126,8 @@ class MatchingViewModel @Inject constructor(
isApprovalExpired = userInfo.isApprovalExpired
setState { copy(userRole = userInfo.userRole) }

if (userInfo.userRole == UserRole.USER) fetchPuzzleCount()

when {
userInfo.profileStatus == ProfileStatus.REJECTED -> getRejectReason()
userInfo.userRole == UserRole.USER -> getMatchInfoList()
Expand Down Expand Up @@ -204,7 +202,7 @@ class MatchingViewModel @Inject constructor(
setState { copy(isRefreshing = true) }

try {
joinAll(fetchMatchInfo(), fetchFreeMatch(), fetchPuzzleCount(), fetchNotificationsCount())
joinAll(fetchMatchInfo(), fetchFreeMatch(), fetchNotificationsCount())
} finally {
setState { copy(isRefreshing = false) }
}
Expand Down Expand Up @@ -279,11 +277,14 @@ class MatchingViewModel @Inject constructor(
if (throwable is HttpResponseException) {
when (throwable.errorCode) {
PieceErrorCode.NOT_ENOUGH_USER_FOR_INSTANT_MATCH -> {
val type = if (isFree) MatchingPoolEmptyType.Basic else MatchingPoolEmptyType.New
val type =
if (isFree) MatchingPoolEmptyType.Basic else MatchingPoolEmptyType.New
showDialog(MatchingDialogType.MatchingPoolEmpty(type))
}

PieceErrorCode.EXPIRED_TOKEN, PieceErrorCode.NOT_ENOUGH_PUZZLE -> errorHelper.sendError(throwable)
PieceErrorCode.EXPIRED_TOKEN, PieceErrorCode.NOT_ENOUGH_PUZZLE -> errorHelper.sendError(
throwable
)

else -> _sideEffect.send(SnackBarSideEffect.TextOnly(R.string.unknown_error))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.puzzle.analytics.LocalAnalyticsHelper
import com.puzzle.common.ui.clickable
import com.puzzle.common.ui.throttledClickable
import com.puzzle.designsystem.R
import com.puzzle.designsystem.foundation.PieceTheme
import com.puzzle.domain.model.match.MatchInfo
Expand All @@ -49,6 +50,8 @@ import com.puzzle.domain.model.match.MatchStatus.RESPONDED
import com.puzzle.domain.model.match.MatchStatus.WAITING
import com.puzzle.domain.model.match.MatchType

private const val NEW_MATCHING_CARD_CLICK_THROTTLE_MS = 500L

@Composable
internal fun NewMatchingCard(
modifier: Modifier = Modifier,
Expand All @@ -57,7 +60,7 @@ internal fun NewMatchingCard(
) {
Row(
modifier = modifier
.clickable(onClick = onNewMatchingCardClick)
.throttledClickable(throttleTime = NEW_MATCHING_CARD_CLICK_THROTTLE_MS, onClick = onNewMatchingCardClick)
.fillMaxWidth()
.clip(RoundedCornerShape(12.dp))
.background(PieceTheme.colors.white)
Expand Down