Fix bet confirmation
continuous-integration/drone/push Build is passing Details

pull/5/head
avalin 1 year ago
parent 527577677a
commit c32c4ab561

@ -14,7 +14,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.Icon
@ -29,11 +30,12 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.scale
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
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.unit.sp
@ -112,17 +114,22 @@ fun BetConfirmationBottomSheetAnswer(
text = text.uppercase(),
color = contentColor ?: color,
style = AllInTheme.typography.h1,
fontSize = 30.sp,
fontSize = 35.sp,
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Center)
maxLines = 2,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.align(Alignment.Center)
.padding(horizontal = 64.dp)
)
AllInCard(
radius = 50.dp,
backgroundColor = contentColor ?: AllInColorToken.allInPurple,
modifier = Modifier.align(Alignment.CenterEnd)
Box(
modifier = Modifier
.align(Alignment.CenterEnd)
.clip(RoundedCornerShape(50.dp))
.background(contentColor ?: AllInColorToken.allInPurple)
.padding(vertical = 4.dp, horizontal = 8.dp)
) {
Box(Modifier.padding(vertical = 4.dp, horizontal = 8.dp)) {
Text(
text = "x${odds.formatToSimple(locale)}",
color = backColor,
@ -131,7 +138,6 @@ fun BetConfirmationBottomSheetAnswer(
}
}
}
}
}
@Composable
@ -141,14 +147,20 @@ fun ConfirmationAnswers(
onClick: (String) -> Unit
) {
val configuration = LocalConfiguration.current
val locale =
remember { ConfigurationCompat.getLocales(configuration).get(0) ?: Locale.getDefault() }
val locale = remember { ConfigurationCompat.getLocales(configuration).get(0) ?: Locale.getDefault() }
val possibleAnswers = remember {
when (val bet = betDetail.bet) {
is CustomBet -> bet.possibleAnswers
is MatchBet -> listOf(bet.nameTeam1, bet.nameTeam2)
is YesNoBet -> listOf(YES_VALUE, NO_VALUE)
}
}
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
when (betDetail.bet) {
is CustomBet -> items((betDetail.bet as CustomBet).possibleAnswers) {
itemsIndexed(possibleAnswers) { idx, it ->
betDetail.getAnswerOfResponse(it)?.let {
val opacity by animateFloatAsState(
targetValue = if (selectedAnswer != null && selectedAnswer != it.response) .5f else 1f,
@ -159,102 +171,17 @@ fun ConfirmationAnswers(
text = it.response,
odds = it.odds,
locale = locale,
color = if (possibleAnswers.size == 2 && idx == 1) {
AllInColorToken.allInBarPink
} else {
AllInColorToken.allInBlue
},
onClick = { onClick(it.response) },
isSelected = selectedAnswer == it.response,
modifier = Modifier.alpha(opacity)
)
}
}
is MatchBet -> {
val bet = (betDetail.bet as MatchBet)
item {
betDetail.getAnswerOfResponse(bet.nameTeam1)?.let {
val opacity by animateFloatAsState(
targetValue = if (selectedAnswer != null && selectedAnswer != it.response) .5f else 1f,
label = ""
)
BetConfirmationBottomSheetAnswer(
text = it.response,
odds = it.odds,
locale = locale,
onClick = { onClick(it.response) },
isSelected = selectedAnswer == it.response,
modifier = Modifier.alpha(opacity)
)
}
}
item {
betDetail.getAnswerOfResponse(bet.nameTeam2)?.let {
val opacity by animateFloatAsState(
targetValue = if (selectedAnswer != null && selectedAnswer != it.response) .5f else 1f,
label = ""
)
BetConfirmationBottomSheetAnswer(
text = it.response,
color = AllInColorToken.allInBarPink,
odds = it.odds,
locale = locale,
onClick = { onClick(it.response) },
isSelected = selectedAnswer == it.response,
modifier = Modifier
.alpha(opacity)
)
}
}
}
is YesNoBet -> {
item {
betDetail.getAnswerOfResponse(YES_VALUE)?.let {
val opacity by animateFloatAsState(
targetValue = if (selectedAnswer != null && selectedAnswer != it.response) .5f else 1f,
label = ""
)
val scale by animateFloatAsState(
targetValue = if (selectedAnswer != null && selectedAnswer != it.response) .95f else 1f,
label = ""
)
BetConfirmationBottomSheetAnswer(
text = it.response,
odds = it.odds,
locale = locale,
onClick = { onClick(it.response) },
isSelected = selectedAnswer == it.response,
modifier = Modifier
.alpha(opacity)
.scale(scale)
)
}
}
item {
betDetail.getAnswerOfResponse(NO_VALUE)?.let {
val opacity by animateFloatAsState(
targetValue = if (selectedAnswer != null && selectedAnswer != it.response) .5f else 1f,
label = ""
)
val scale by animateFloatAsState(
targetValue = if (selectedAnswer != null && selectedAnswer != it.response) .95f else 1f,
label = ""
)
BetConfirmationBottomSheetAnswer(
text = it.response,
color = AllInColorToken.allInBarPink,
odds = it.odds,
locale = locale,
onClick = { onClick(it.response) },
isSelected = selectedAnswer == it.response,
modifier = Modifier
.alpha(opacity)
.scale(scale)
)
}
}
}
}
}
}
@ -326,7 +253,7 @@ fun BetConfirmationBottomSheetContent(
}
}
Text(
text = "Ce bet est arrivé à la date de fin. Vous devez à présent distribuer les gains en validant le pari gagnant.",
text = stringResource(id = R.string.bet_confirmation_text),
color = AllInColorToken.allInLightGrey200,
style = AllInTheme.typography.p2,
textAlign = TextAlign.Center
@ -335,8 +262,8 @@ fun BetConfirmationBottomSheetContent(
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "Veuillez choisir la réponse finale :",
fontSize = 20.sp,
text = stringResource(id = R.string.bet_confirmation_choose_response),
fontSize = 18.sp,
color = AllInColorToken.white,
style = AllInTheme.typography.h1,
modifier = Modifier.fillMaxWidth()
@ -374,7 +301,7 @@ private fun BetConfirmationBottomSheetContentPreview() {
endBetDate = ZonedDateTime.now(),
isPublic = true,
betStatus = BetStatus.FINISHED,
creator = "creator",
creator = "creator"
),
answers = listOf(
BetAnswerDetail(
@ -389,7 +316,7 @@ private fun BetConfirmationBottomSheetContentPreview() {
totalStakes = 150,
totalParticipants = 1,
highestStake = 150,
odds = 2.0f
odds = 2.255f
)
),
participations = emptyList(),

@ -2,6 +2,7 @@ package fr.iut.alldev.allin.ui.main
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.background
@ -48,7 +49,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import timber.log.Timber
const val EVENT_DISMISS_DELAY_MS = 300L
const val EVENT_DISMISS_DELAY_MS = 150L
private val topLevelDestinations = listOf(
TopLevelDestination.PublicBets,
@ -208,8 +209,8 @@ fun MainScreen(
var dailyRewardVisible by remember { mutableStateOf(true) }
AnimatedVisibility(
visible = dailyRewardVisible,
enter = fadeIn(),
exit = fadeOut()
enter = fadeIn(tween(EVENT_DISMISS_DELAY_MS.toInt())),
exit = fadeOut(tween(EVENT_DISMISS_DELAY_MS.toInt()))
) {
(events.firstOrNull() as? DailyReward)?.let {
it.Display(

@ -134,6 +134,10 @@
<string name="bet_history_status_won">%s [icon] gagnés !</string>
<string name="bet_history_status_lost">%s [icon] perdus !</string>
<!--Bet confirmation-->
<string name="bet_confirmation_text">Ce bet est arrivé à la date de fin. Vous devez à présent distribuer les gains en validant le pari gagnant.</string>
<string name="bet_confirmation_choose_response">Veuillez choisir la réponse finale :</string>
<!--Bet result-->
<string name="bet_result_congratulations">FÉLICITATIONS</string>
<string name="bet_result_you_win">Vous remportez</string>

@ -133,6 +133,10 @@
<string name="bet_history_status_won">%s [icon] won !</string>
<string name="bet_history_status_lost">%s [icon] lost !</string>
<!--Bet confirmation-->
<string name="bet_confirmation_text">This bet has now ended. You may now distribute the winnings by selecting the right answer.</string>
<string name="bet_confirmation_choose_response">Please select the final answer :</string>
<!--Bet result-->
<string name="bet_result_congratulations">CONGRATULATIONS</string>
<string name="bet_result_you_win">You win</string>

Loading…
Cancel
Save