Mock API and Bet participation bottom sheet
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
3c5545bdb6
commit
2432599726
@ -0,0 +1,9 @@
|
||||
package fr.iut.alldev.allin.ext
|
||||
|
||||
import java.text.DecimalFormat
|
||||
import java.text.DecimalFormatSymbols
|
||||
import java.util.Locale
|
||||
|
||||
fun Float.formatToSimple(locale: Locale): String {
|
||||
return DecimalFormat("0.##", DecimalFormatSymbols.getInstance(locale)).format(this)
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package fr.iut.alldev.allin.ext
|
||||
|
||||
import java.text.DecimalFormat
|
||||
import java.text.DecimalFormatSymbols
|
||||
import java.util.Locale
|
||||
|
||||
fun String.verifyIsFloat(locale: Locale): String? {
|
||||
val pattern = Regex("^\\d+(\\.|\\,)?\\d*\$")
|
||||
val decimalSeparator = DecimalFormatSymbols.getInstance(locale).decimalSeparator.toString()
|
||||
|
||||
return if (this.matches(pattern)) {
|
||||
this.replace(Regex("[.,]"), decimalSeparator).format()
|
||||
} else if (this.isEmpty()) {
|
||||
this
|
||||
} else null
|
||||
}
|
||||
|
||||
fun String.toFloatOrNull(locale: Locale): Float? {
|
||||
val format = DecimalFormat("0.##", DecimalFormatSymbols.getInstance(locale))
|
||||
return format.parse(this)?.toFloat()
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package fr.iut.alldev.allin.ui.betStatus.components
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.material3.Text
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.sp
|
||||
import fr.iut.alldev.allin.R
|
||||
import fr.iut.alldev.allin.data.model.bet.Bet
|
||||
import fr.iut.alldev.allin.data.model.bet.CustomBet
|
||||
import fr.iut.alldev.allin.data.model.bet.MatchBet
|
||||
import fr.iut.alldev.allin.data.model.bet.NO_VALUE
|
||||
import fr.iut.alldev.allin.data.model.bet.YES_VALUE
|
||||
import fr.iut.alldev.allin.data.model.bet.YesNoBet
|
||||
import fr.iut.alldev.allin.theme.AllInTheme
|
||||
import fr.iut.alldev.allin.ui.preview.BetPreviewProvider
|
||||
|
||||
private val participationAnswerFontSize = 25.sp
|
||||
|
||||
@Composable
|
||||
fun Bet.getParticipationAnswers(): List<@Composable RowScope.() -> Unit> =
|
||||
when (this) {
|
||||
is CustomBet -> this.possibleAnswers.map {
|
||||
{
|
||||
Text(
|
||||
text = it,
|
||||
color = AllInTheme.colors.allInBlue,
|
||||
style = AllInTheme.typography.h1,
|
||||
fontSize = participationAnswerFontSize
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is MatchBet -> listOf(
|
||||
{
|
||||
Text(
|
||||
text = this@getParticipationAnswers.nameTeam1,
|
||||
color = AllInTheme.colors.allInBlue,
|
||||
style = AllInTheme.typography.h1,
|
||||
fontSize = participationAnswerFontSize
|
||||
)
|
||||
},
|
||||
{
|
||||
Text(
|
||||
text = this@getParticipationAnswers.nameTeam2,
|
||||
color = AllInTheme.colors.allInBarPink,
|
||||
style = AllInTheme.typography.h1,
|
||||
fontSize = participationAnswerFontSize
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
is YesNoBet -> listOf(
|
||||
{
|
||||
Text(
|
||||
text = stringResource(id = R.string.Yes).uppercase(),
|
||||
color = AllInTheme.colors.allInBlue,
|
||||
style = AllInTheme.typography.h1,
|
||||
fontSize = participationAnswerFontSize
|
||||
)
|
||||
},
|
||||
{
|
||||
Text(
|
||||
text = stringResource(id = R.string.No).uppercase(),
|
||||
color = AllInTheme.colors.allInBarPink,
|
||||
style = AllInTheme.typography.h1,
|
||||
fontSize = participationAnswerFontSize
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun Bet.getAnswerFromParticipationIdx(idx: Int) =
|
||||
when (this) {
|
||||
is CustomBet -> this.possibleAnswers.getOrElse(idx) { "" }
|
||||
is MatchBet -> when (idx) {
|
||||
0 -> this.nameTeam1
|
||||
1 -> this.nameTeam2
|
||||
else -> ""
|
||||
}
|
||||
|
||||
is YesNoBet -> when (idx) {
|
||||
0 -> YES_VALUE
|
||||
1 -> NO_VALUE
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Composable
|
||||
private fun ParticipationAnswersPreview(
|
||||
@PreviewParameter(BetPreviewProvider::class) bet: Bet,
|
||||
) {
|
||||
AllInTheme {
|
||||
Column {
|
||||
bet.getParticipationAnswers().forEach {
|
||||
Row(Modifier.fillMaxWidth()) { it() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package fr.iut.alldev.allin.data.api
|
||||
|
||||
import fr.iut.alldev.allin.data.api.interceptors.AllInAPIException
|
||||
import fr.iut.alldev.allin.data.api.model.CheckUser
|
||||
import fr.iut.alldev.allin.data.api.model.RequestBet
|
||||
import fr.iut.alldev.allin.data.api.model.RequestUser
|
||||
import fr.iut.alldev.allin.data.api.model.ResponseBet
|
||||
import fr.iut.alldev.allin.data.api.model.ResponseUser
|
||||
import fr.iut.alldev.allin.data.model.bet.NO_VALUE
|
||||
import fr.iut.alldev.allin.data.model.bet.YES_VALUE
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.UUID
|
||||
|
||||
class MockAllInApi : AllInApi {
|
||||
override suspend fun login(body: CheckUser): ResponseUser {
|
||||
return users.find { it.first.username == body.login && it.second == body.password }?.first
|
||||
?: throw AllInAPIException("Invalid login/password.")
|
||||
}
|
||||
|
||||
override suspend fun login(token: String): ResponseUser {
|
||||
return users.find { it.first.token == token }?.first
|
||||
?: throw AllInAPIException("Invalid token")
|
||||
}
|
||||
|
||||
override suspend fun register(body: RequestUser): ResponseUser {
|
||||
val response = ResponseUser(
|
||||
id = UUID.randomUUID().toString(),
|
||||
username = body.username,
|
||||
email = body.email,
|
||||
nbCoins = body.nbCoins,
|
||||
token = "${body.username} ${users.size}"
|
||||
) to body.password
|
||||
users.add(response)
|
||||
return response.first
|
||||
}
|
||||
|
||||
override suspend fun createBet(token: String, body: RequestBet) {
|
||||
mockBets.add(
|
||||
ResponseBet(
|
||||
id = UUID.randomUUID().toString(),
|
||||
theme = body.theme,
|
||||
sentenceBet = body.sentenceBet,
|
||||
endRegistration = body.endRegistration,
|
||||
endBet = body.endBet,
|
||||
isPrivate = body.isPrivate,
|
||||
response = body.response,
|
||||
createdBy = ""
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun getAllBets(): List<ResponseBet> = mockBets.toList()
|
||||
}
|
||||
|
||||
private val users = mutableListOf(
|
||||
ResponseUser(
|
||||
id = "UUID 1",
|
||||
username = "User 1",
|
||||
email = "john@doe.fr",
|
||||
nbCoins = 250,
|
||||
token = "token 1"
|
||||
) to "psswrd"
|
||||
)
|
||||
|
||||
private val mockBets = mutableListOf(
|
||||
ResponseBet(
|
||||
id = "UUID1",
|
||||
theme = "Études",
|
||||
sentenceBet = "Dave va arriver en retard demain matin ?",
|
||||
endRegistration = ZonedDateTime.now().plusDays(3),
|
||||
endBet = ZonedDateTime.now().plusDays(4),
|
||||
isPrivate = false,
|
||||
response = listOf(YES_VALUE, NO_VALUE),
|
||||
createdBy = "Armure"
|
||||
),
|
||||
ResponseBet(
|
||||
id = "UUID2",
|
||||
theme = "Études",
|
||||
sentenceBet = "Dave va arriver en retard demain matin ?",
|
||||
endRegistration = ZonedDateTime.now().plusDays(3),
|
||||
endBet = ZonedDateTime.now().plusDays(4),
|
||||
isPrivate = false,
|
||||
response = listOf("Answer 1", "Answer 2", "Answer 3", "Answer 4"),
|
||||
createdBy = "User 2"
|
||||
),
|
||||
ResponseBet(
|
||||
id = "UUID3",
|
||||
theme = "Sport",
|
||||
sentenceBet = "Nouveau record du monde ?",
|
||||
endRegistration = ZonedDateTime.now().plusDays(3),
|
||||
endBet = ZonedDateTime.now().plusDays(4),
|
||||
isPrivate = false,
|
||||
response = listOf(YES_VALUE, NO_VALUE),
|
||||
createdBy = "Armure"
|
||||
)
|
||||
)
|
Loading…
Reference in new issue