Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -2,6 +2,7 @@ package com.cornellappdev.score.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -123,6 +124,7 @@ private fun FeaturedGameCardPreview() = ScorePreview {

@Composable
fun FeaturedGameCard(
id: String,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never require an id to show a Composable, the only parameters Composables should take are things related to its view state, or click methods. So really, this composable should have an onClick: () -> Unit method. Then we would write:

onClick = { 
                    onClick(game.id)
                }

And pass it through like that. Lmk if that makes sense.

leftTeamLogo: Painter,
rightTeamLogo: String,
team: String,
Expand All @@ -137,11 +139,12 @@ fun FeaturedGameCard(
modifier: Modifier = Modifier,
headerModifier: Modifier = Modifier,
leftScore: Int? = null,
rightScore: Int? = null
rightScore: Int? = null,
onClick: (String) -> Unit = {}
) {
Column(
modifier = modifier
.fillMaxWidth()
.fillMaxWidth().clickable { onClick(id) }
) {

FeaturedGameHeader(
Expand All @@ -156,6 +159,7 @@ fun FeaturedGameCard(
)

GameCard(
id = id,
teamLogo = rightTeamLogo,
team = team,
date = date,
Expand All @@ -172,7 +176,8 @@ fun FeaturedGameCard(
bottomStart = 16.dp,
bottomEnd = 16.dp
)
)
),
onClick = onClick
)
}
}
Expand All @@ -181,6 +186,7 @@ fun FeaturedGameCard(
@Composable
private fun GameScheduleScreen() = ScorePreview {
FeaturedGameCard(
id = "1",
leftTeamLogo = painterResource(R.drawable.cornell_logo),
rightTeamLogo = "https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max",//painterResource(R.drawable.penn_logo),
leftScore = 32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import com.cornellappdev.score.theme.saturatedGreen

@Composable
fun GameCard(
id: String,
teamLogo: String,
team: String,
date: String,
Expand All @@ -57,7 +58,7 @@ fun GameCard(
sportIcon: Painter,
topCornerRound: Boolean,
modifier: Modifier = Modifier,
onClick: (Boolean) -> Unit = {}
onClick: (String) -> Unit
) {
val cardShape = if (topCornerRound) {
RoundedCornerShape(16.dp) // Rounded all
Expand Down Expand Up @@ -89,7 +90,7 @@ fun GameCard(
)
}
)
.clickable { onClick(false) }
.clickable { onClick(id) }
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -210,6 +211,7 @@ fun GameCard(
private fun GameCardPreview() = ScorePreview {
Column {
GameCard(
id = "1",
teamLogo = "https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max", //painterResource(id = R.drawable.penn_logo),
team = "Penn",
date = "5/20/2024",
Expand All @@ -219,6 +221,7 @@ private fun GameCardPreview() = ScorePreview {
sportIcon = painterResource(id = R.drawable.ic_baseball),
topCornerRound = false,
modifier = Modifier.padding(16.dp),
onClick = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.cornellappdev.score.theme.CrimsonPrimary
import com.cornellappdev.score.theme.GrayLight
import com.cornellappdev.score.theme.GrayPrimary
import com.cornellappdev.score.theme.Style.heading1
import com.cornellappdev.score.theme.White
import com.cornellappdev.score.util.gameList

@Composable
Expand Down Expand Up @@ -60,7 +59,8 @@ fun DotIndicator(
fun GamesCarousel(
games: List<GameCardData>,
variant: GamesCarouselVariant,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
onClick: (String) -> Unit,
) {
val pagerState = rememberPagerState(pageCount = { games.size })
Column(
Expand All @@ -81,6 +81,7 @@ fun GamesCarousel(
) { page ->
val game = games[page]
FeaturedGameCard(
id = game.id,
leftTeamLogo = painterResource(R.drawable.cornell_logo),
rightTeamLogo = game.teamLogo,
team = game.team,
Expand All @@ -93,7 +94,8 @@ fun GamesCarousel(
modifier = Modifier,
headerModifier = Modifier,
gradientColor1 = CornellRed,
gradientColor2 = game.teamColor
gradientColor2 = game.teamColor,
onClick = onClick
)
}

Expand All @@ -110,5 +112,5 @@ fun GamesCarousel(
@Composable
@Preview
private fun GamesCarouselPreview() = ScorePreview {
GamesCarousel(gameList, GamesCarouselVariant.UPCOMING)
GamesCarousel(gameList, GamesCarouselVariant.UPCOMING, onClick = {})
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import java.time.LocalDate
fun PastGameCard(
data: GameCardData,
modifier: Modifier = Modifier,
onClick: (Boolean) -> Unit = {}
onClick: (String) -> Unit = {}
) {
Card(
colors = CardDefaults.cardColors(containerColor = Color.White),
Expand All @@ -58,7 +58,7 @@ fun PastGameCard(
Modifier
.border(width = 1.dp, color = GrayStroke, RoundedCornerShape(16.dp))
)
.clickable { onClick(true) }
.clickable { onClick(data.id) }
) {
Row(
modifier = Modifier
Expand Down Expand Up @@ -201,6 +201,7 @@ private fun TeamScore(
@Composable
private fun PastGameCardPreview() = ScorePreview {
val gameCard = GameCardData(
id = "1",
teamLogo = "https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max",
team = "University of Pennsylvania",
teamColor = Color.Red,
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/cornellappdev/score/model/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import java.time.LocalDateTime
// TODO Refactor to make easier to filter... actual gender, etc.

data class Game(
val id: String,
val teamName: String,
val teamLogo: String,
val teamColor: Color,
Expand Down Expand Up @@ -71,6 +72,7 @@ data class GameDetailsGame(

// Data for HomeScreen game displays
data class GameCardData(
val id: String,
val teamLogo: String,
val team: String,
val teamColor: Color,
Expand Down Expand Up @@ -202,6 +204,7 @@ enum class GamesCarouselVariant {

fun Game.toGameCardData(): GameCardData {
return GameCardData(
id = id,
teamLogo = teamLogo,
team = teamName,
teamColor = teamColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ScoreRepository @Inject constructor(
val otherScore = scores?.getOrNull(1)?.toNumberOrNull()
game?.team?.image?.let {
Game(
id = game.id ?: "", // Should never be null
teamLogo = it,
teamName = game.team.name,
teamColor = parseColor(game.team.color).copy(alpha = 0.4f * 255),
Expand Down Expand Up @@ -90,6 +91,7 @@ class ScoreRepository @Inject constructor(
fun getGameById(id: String) = appScope.launch {
_currentGameFlow.value = ApiResponse.Loading
try {
Log.d("ScoreRepository", "getGameById: ${id}")
val result = (apolloClient.query(GameByIdQuery(id)).execute()).toResult()
result.getOrNull()?.game?.let {
_currentGameFlow.value = ApiResponse.Success(it.toGameDetails())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,20 @@ fun RootNavigation(
) {
composable<ScoreRootScreens.Home> {
HomeScreen(navigateToGameDetails = {
navController.navigate(ScoreRootScreens.GameDetailsPage(""))
navController.navigate(ScoreRootScreens.GameDetailsPage(it))
})
}

composable<ScoreRootScreens.GameDetailsPage> {
GameDetailsScreen(onBackArrow = {
navController.navigateUp()
})
composable<ScoreRootScreens.GameDetailsPage> {
GameDetailsScreen(onBackArrow = {
navController.navigateUp()
})

}

composable<ScoreRootScreens.ScoresScreen> {
PastGamesScreen(navigateToGameDetails = {
navController.navigate(ScoreRootScreens.GameDetailsPage(""))
navController.navigate(ScoreRootScreens.GameDetailsPage(it))
})
}
}
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/com/cornellappdev/score/screen/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -42,7 +40,7 @@ import com.cornellappdev.score.viewmodel.HomeViewModel
@Composable
fun HomeScreen(
homeViewModel: HomeViewModel = hiltViewModel(),
navigateToGameDetails: (Boolean) -> Unit = {}
navigateToGameDetails: (String) -> Unit = {}
) {
val uiState = homeViewModel.collectUiStateValue()

Expand All @@ -51,7 +49,6 @@ fun HomeScreen(
modifier = Modifier
.background(Color.White)
) {
Button(onClick = { navigateToGameDetails(true) }) { }
when (uiState.loadedState) {
is ApiResponse.Loading -> {
LoadingScreen("Loading Upcoming...", "Loading Schedules...")
Expand Down Expand Up @@ -79,11 +76,15 @@ private fun HomeContent(
uiState: HomeUiState,
onGenderSelected: (GenderDivision) -> Unit,
onSportSelected: (SportSelection) -> Unit,
navigateToGameDetails: (Boolean) -> Unit = {}
navigateToGameDetails: (String) -> Unit = {}
) {
LazyColumn(contentPadding = PaddingValues(top = 24.dp, start = 24.dp, end = 24.dp)) {
item {
GamesCarousel(uiState.upcomingGames, GamesCarouselVariant.UPCOMING)
GamesCarousel(
uiState.upcomingGames,
GamesCarouselVariant.UPCOMING,
onClick = navigateToGameDetails
)
}
stickyHeader {
Column(modifier = Modifier.background(White)) {
Expand All @@ -110,6 +111,7 @@ private fun HomeContent(
items(uiState.filteredGames) {
val game = it
GameCard(
id = game.id,
teamLogo = game.teamLogo,
team = game.team,
date = game.dateString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import com.cornellappdev.score.viewmodel.PastGamesViewModel
@Composable
fun PastGamesScreen(
pastGamesViewModel: PastGamesViewModel = hiltViewModel(),
navigateToGameDetails: (Boolean) -> Unit = {}
navigateToGameDetails: (String) -> Unit = {}
) {
val uiState = pastGamesViewModel.collectUiStateValue()

Expand Down Expand Up @@ -74,11 +74,15 @@ private fun PastGamesContent(
uiState: PastGamesUiState,
onGenderSelected: (GenderDivision) -> Unit,
onSportSelected: (SportSelection) -> Unit,
navigateToGameDetails: (Boolean) -> Unit = {}
navigateToGameDetails: (String) -> Unit = {}
) {
LazyColumn(contentPadding = PaddingValues(top = 24.dp, start = 24.dp, end = 24.dp)) {
item {
GamesCarousel(uiState.pastGames, GamesCarouselVariant.PAST)
GamesCarousel(
uiState.pastGames,
GamesCarouselVariant.PAST,
onClick = navigateToGameDetails
)
}
stickyHeader {
Column(modifier = Modifier.background(White)) {
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/cornellappdev/score/util/TestingConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.cornellappdev.score.model.TeamScore
import java.time.LocalDate

val PENN_GAME = GameCardData(
id = "1",
teamLogo = "https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max",
team = "Penn",
teamColor = Color(0x66B31B1B),
Expand All @@ -28,6 +29,7 @@ val PENN_GAME = GameCardData(
)

val PRINCETON_GAME = GameCardData(
id = "1",
teamLogo = "https://cornellbigred.com/images/logos/Princeton_Tigers.png?width=80&height=80&mode=max",
team = "Princeton",
teamColor = Color(0x66FF6000),
Expand Down Expand Up @@ -68,8 +70,14 @@ val teamScore2 = TeamScore(

val gameData = GameData(teamScores = Pair(teamScore1, teamScore2))

val team3 = TeamGameSummary(name = "Cornell", "https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max")
val team4 = TeamGameSummary(name = "Yale", "https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max")
val team3 = TeamGameSummary(
name = "Cornell",
"https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max"
)
val team4 = TeamGameSummary(
name = "Yale",
"https://cornellbigred.com/images/logos/penn_200x200.png?width=80&height=80&mode=max"
)
val scoreEvents1 = listOf(
ScoreEvent(
id = 1,
Expand Down