Skip to content

Commit

Permalink
Adding a swiss stage row item to demonstrate how a team preformed. (#443
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AdamMc331 authored Jan 28, 2024
1 parent 5cbb1d9 commit 016954b
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.adammcneilly.pocketleague.core.displaymodels.GameDetailDisplayModel
import com.adammcneilly.pocketleague.core.displaymodels.GameTeamResultDisplayModel
import com.adammcneilly.pocketleague.core.displaymodels.MatchDetailDisplayModel
import com.adammcneilly.pocketleague.core.displaymodels.MatchTeamResultDisplayModel
import com.adammcneilly.pocketleague.core.displaymodels.SwissTeamResultDisplayModel
import com.adammcneilly.pocketleague.core.displaymodels.TeamOverviewDisplayModel
import com.adammcneilly.pocketleague.core.displaymodels.ThemedImageURL
import com.adammcneilly.pocketleague.core.displaymodels.toDisplayModel
Expand Down Expand Up @@ -116,4 +117,22 @@ object TestDisplayModel {
lan = false,
liquipedia = "liquipediaURL",
)

val qualifiedSwiss = SwissTeamResultDisplayModel(
team = g2,
overline = "Qualified",
subtitle = "3-0 | 9-1 | +8",
)

val inProgressSwiss = SwissTeamResultDisplayModel(
team = g2,
overline = "",
subtitle = "1-0 | 3-0 | +3",
)

val eliminatedSwiss = SwissTeamResultDisplayModel(
team = g2,
overline = "Eliminated",
subtitle = "0-3 | 1-9 | -8",
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.adammcneilly.pocketleague.core.displaymodels

/**
* User friendly explanation of how a [team] preformed in a Swiss stage.
*
* @property[team] The team information for the players in this swiss result.
* @property[overline] Describes if the team is qualified or eliminated. Should be empty if neither of those.
* @property[subtitle] States how the team preformed in the swiss stage, with match and game records and game differential.
* example: 3-0 | 9-0 | +9
*/
data class SwissTeamResultDisplayModel(
val team: TeamOverviewDisplayModel,
val overline: String,
val subtitle: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.adammcneilly.pocketleague.shared.ui.swiss

import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.adammcneilly.pocketleague.core.displaymodels.SwissTeamResultDisplayModel
import com.adammcneilly.pocketleague.shared.ui.components.ListItemDividerCard

/**
* [ListItemDividerCard] implementation for a set of [teamResults].
*/
@Composable
fun SwissTeamResultListCard(
teamResults: List<SwissTeamResultDisplayModel>,
modifier: Modifier = Modifier,
) {
ListItemDividerCard(
items = teamResults,
modifier = modifier,
) { teamResult ->
SwissTeamResultListItem(
displayModel = teamResult,
modifier = Modifier
.padding(8.dp),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.adammcneilly.pocketleague.shared.ui.swiss

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.adammcneilly.pocketleague.core.displaymodels.SwissTeamResultDisplayModel
import com.adammcneilly.pocketleague.shared.ui.components.CircleTeamLogo
import com.adammcneilly.pocketleague.shared.ui.theme.PocketLeagueTheme

/**
* User friendly representation of a [SwissTeamResultDisplayModel].
*/
@Composable
fun SwissTeamResultListItem(
displayModel: SwissTeamResultDisplayModel,
modifier: Modifier = Modifier,
) {
val colorToUse = if (displayModel.overline == "Qualified") {
Color.Green
} else {
Color.Red
}

Row(
modifier = Modifier
.height(IntrinsicSize.Min),
) {
Box(
modifier = Modifier
.background(color = colorToUse)
.width(4.dp)
.fillMaxHeight(),
)

Row(
modifier = modifier,
horizontalArrangement = Arrangement.spacedBy(PocketLeagueTheme.sizes.listItemSpacing),
verticalAlignment = Alignment.CenterVertically,
) {
CircleTeamLogo(
displayModel = displayModel.team,
modifier = Modifier
.size(36.dp),
)

Column(
modifier = Modifier
.weight(1F),
) {
// Text(
// text = displayModel.overline,
// style = MaterialTheme.typography.labelSmall,
// fontWeight = FontWeight.Bold,
// )

Text(
text = displayModel.team.name,
style = MaterialTheme.typography.bodyLarge,
)

Text(
text = displayModel.subtitle,
style = MaterialTheme.typography.bodySmall,
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package com.adammcneilly.pocketleague.shared.ui.swiss

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.ui.unit.dp
import app.cash.paparazzi.Paparazzi
import com.adammcneilly.pocketleague.core.displaymodels.SwissTeamResultDisplayModel
import com.adammcneilly.pocketleague.core.displaymodels.test.TestDisplayModel
import com.adammcneilly.pocketleague.shared.ui.snapshotScreen
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.runner.RunWith
import kotlin.test.Test

@RunWith(TestParameterInjector::class)
class SwissTeamResultListCardPaparazziTest {
@get:Rule
val paparazzi = Paparazzi()

@TestParameter
val useDarkTheme: Boolean = false

@Test
fun render() {
val displayModels = testDisplayModels()

paparazzi.snapshotScreen(
useDarkTheme = useDarkTheme,
screenPaddingDp = 0,
) {
LazyColumn(
contentPadding = PaddingValues(16.dp),
) {
item {
SwissTeamResultListCard(displayModels)
}
}
}
}
}

@Suppress("LongMethod")
private fun testDisplayModels() =
listOf(
makeResult(
teamName = "G2 Esports",
overline = "Qualified",
subtitle = "3-0 | 12-3 | +9",
),
makeResult(
teamName = "Team Falcons",
overline = "Qualified",
subtitle = "3-0 | 12-5 | +7",
),
makeResult(
teamName = "KRÜ Esports",
overline = "Qualified",
subtitle = "3-1 | 14-8 | +6",
),
makeResult(
teamName = "Spacestation Gaming",
overline = "Qualified",
subtitle = "3-0 | 15-9 | +6",
),
makeResult(
teamName = "Complexity Gaming",
overline = "Qualified",
subtitle = "3-0 | 12-7 | +5",
),
makeResult(
teamName = "Moist Esports",
overline = "Qualified",
subtitle = "3-2 | 16-10 | +6",
),
makeResult(
teamName = "Twisted Minds",
overline = "Qualified",
subtitle = "3-2 | 15-11 | +4",
),
makeResult(
teamName = "Team Secret",
overline = "Qualified",
subtitle = "3-2 | 14-12 | +2",
),
makeResult(
teamName = "PWR",
overline = "Eliminated",
subtitle = "2-3 | 13-13 | 0",
),
makeResult(
teamName = "G1",
overline = "Eliminated",
subtitle = "2-3 | 13-13 | 0",
),
makeResult(
teamName = "Elevate",
overline = "Eliminated",
subtitle = "2-3 | 10-16 | -6",
),
makeResult(
teamName = "Pioneers",
overline = "Eliminated",
subtitle = "1-3 | 8-12 | -4",
),
makeResult(
teamName = "Oxygen Esports",
overline = "Eliminated",
subtitle = "1-3 | 10-14 | -4",
),
makeResult(
teamName = "Limitless",
overline = "Eliminated",
subtitle = "1-3 | 4-12 | -8",
),
makeResult(
teamName = "Valiant",
overline = "Eliminated",
subtitle = "0-3 | 1-12 | -11",
),
makeResult(
teamName = "Gaimin Gladiators",
overline = "Eliminated",
subtitle = "0-3 | 0-12 | -12",
),
)

private fun makeResult(
teamName: String,
overline: String,
subtitle: String,
): SwissTeamResultDisplayModel {
val team = TestDisplayModel.g2.copy(
name = teamName,
)

return SwissTeamResultDisplayModel(
team = team,
overline = overline,
subtitle = subtitle,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.adammcneilly.pocketleague.shared.ui.swiss

import app.cash.paparazzi.Paparazzi
import com.adammcneilly.pocketleague.core.displaymodels.test.TestDisplayModel.eliminatedSwiss
import com.adammcneilly.pocketleague.core.displaymodels.test.TestDisplayModel.inProgressSwiss
import com.adammcneilly.pocketleague.core.displaymodels.test.TestDisplayModel.qualifiedSwiss
import com.adammcneilly.pocketleague.shared.ui.snapshotScreen
import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import org.junit.Rule
import org.junit.runner.RunWith
import kotlin.test.Test

@RunWith(TestParameterInjector::class)
class SwissTeamResultListItemPaparazziTest {
@get:Rule
val paparazzi = Paparazzi()

@TestParameter
val useDarkTheme: Boolean = false

@Test
fun renderQualified() {
paparazzi.snapshotScreen(
useDarkTheme = useDarkTheme,
screenPaddingDp = 0,
) {
SwissTeamResultListItem(
displayModel = qualifiedSwiss,
)
}
}

@Test
fun renderInProgress() {
paparazzi.snapshotScreen(
useDarkTheme = useDarkTheme,
screenPaddingDp = 0,
) {
SwissTeamResultListItem(
displayModel = inProgressSwiss,
)
}
}

@Test
fun renderEliminated() {
paparazzi.snapshotScreen(
useDarkTheme = useDarkTheme,
screenPaddingDp = 0,
) {
SwissTeamResultListItem(
displayModel = eliminatedSwiss,
)
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 016954b

Please sign in to comment.