Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
Expand Up @@ -176,6 +176,7 @@ fun FeaturedGameCard(
bottomEnd = 16.dp
)
),
isFeatured = true,
onClick = onClick
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
Expand All @@ -57,6 +58,7 @@ fun GameCard(
sportIcon: Painter,
topCornerRound: Boolean,
modifier: Modifier = Modifier,
isFeatured: Boolean = false,
onClick: () -> Unit
) {
val cardShape = if (topCornerRound) {
Expand Down Expand Up @@ -116,7 +118,9 @@ fun GameCard(
Text(
text = team,
style = heading2,
color = GrayPrimary
color = GrayPrimary,
maxLines = if (isFeatured) 1 else Int.MAX_VALUE,
overflow = if (isFeatured) TextOverflow.Ellipsis else TextOverflow.Clip
)
}
Row(
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/com/cornellappdev/score/model/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,13 @@ fun List<GameDetailsBoxScore>.toScoreEvents(teamLogo: String): List<ScoreEvent>
description = boxScore.description
)
}
}
}

val validSports = setOf(
"Baseball", "Basketball", "Field Hockey",
"Football", "Ice Hockey", "Lacrosse", "Soccer"
)

fun isValidSport(sportName: String): Boolean {
return sportName in validSports
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.cornellappdev.score.model.GenderDivision
import com.cornellappdev.score.model.ScoreRepository
import com.cornellappdev.score.model.Sport
import com.cornellappdev.score.model.SportSelection
import com.cornellappdev.score.model.isValidSport
import com.cornellappdev.score.model.map
import com.cornellappdev.score.model.toGameCardData
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -23,13 +24,23 @@ data class HomeUiState(
get() = when (loadedState) {
is ApiResponse.Success -> loadedState.data.filter { game ->
(selectedGender == GenderDivision.ALL || game.gender == selectedGender.displayName) &&
(sportSelect is SportSelection.All || (sportSelect is SportSelection.SportSelect && game.sport == sportSelect.sport.displayName))
(sportSelect is SportSelection.All ||
(sportSelect is SportSelection.SportSelect && game.sport == sportSelect.sport.displayName)) &&
isValidSport(game.sport)
}

ApiResponse.Loading -> emptyList()
ApiResponse.Error -> emptyList()
}
val upcomingGames: List<GameCardData> = filteredGames.take(3)
val upcomingGames: List<GameCardData>
get() = when (loadedState) {
is ApiResponse.Success -> loadedState.data.filter { game ->
isValidSport(game.sport)
}

ApiResponse.Loading -> emptyList()
ApiResponse.Error -> emptyList()
}.take(3)
}

@HiltViewModel
Expand All @@ -39,7 +50,10 @@ class HomeViewModel @Inject constructor(
HomeUiState(
selectedGender = GenderDivision.ALL,
sportSelect = SportSelection.All,
selectionList = Sport.getSportSelectionList(GenderDivision.ALL),
selectionList = Sport.getSportSelectionList(GenderDivision.ALL).filter {
it is SportSelection.All ||
(it is SportSelection.SportSelect && isValidSport(it.sport.displayName))
},
loadedState = ApiResponse.Loading
)
) {
Expand Down Expand Up @@ -72,7 +86,10 @@ class HomeViewModel @Inject constructor(
applyMutation {
copy(
selectedGender = gender,
selectionList = Sport.getSportSelectionList(gender)
selectionList = Sport.getSportSelectionList(gender).filter {
it is SportSelection.All ||
(it is SportSelection.SportSelect && isValidSport(it.sport.displayName))
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.cornellappdev.score.model.GenderDivision
import com.cornellappdev.score.model.ScoreRepository
import com.cornellappdev.score.model.Sport
import com.cornellappdev.score.model.SportSelection
import com.cornellappdev.score.model.isValidSport
import com.cornellappdev.score.model.map
import com.cornellappdev.score.model.toGameCardData
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -23,13 +24,23 @@ data class PastGamesUiState(
get() = when (loadedState) {
is ApiResponse.Success -> loadedState.data.filter { game ->
(selectedGender == GenderDivision.ALL || game.gender == selectedGender.displayName) &&
(sportSelect is SportSelection.All || (sportSelect is SportSelection.SportSelect && game.sport == sportSelect.sport.displayName))
(sportSelect is SportSelection.All ||
(sportSelect is SportSelection.SportSelect && game.sport == sportSelect.sport.displayName)) &&
isValidSport(game.sport)
}

ApiResponse.Loading -> emptyList()
ApiResponse.Error -> emptyList()
}
val pastGames: List<GameCardData> = filteredGames.take(3)
val pastGames: List<GameCardData>
get() = when (loadedState) {
is ApiResponse.Success -> loadedState.data.filter { game ->
isValidSport(game.sport)
}

ApiResponse.Loading -> emptyList()
ApiResponse.Error -> emptyList()
}.take(3)
}

@HiltViewModel
Expand All @@ -39,7 +50,10 @@ class PastGamesViewModel @Inject constructor(
PastGamesUiState(
selectedGender = GenderDivision.ALL,
sportSelect = SportSelection.All,
selectionList = Sport.getSportSelectionList(GenderDivision.ALL),
selectionList = Sport.getSportSelectionList(GenderDivision.ALL).filter {
it is SportSelection.All ||
(it is SportSelection.SportSelect && isValidSport(it.sport.displayName))
},
loadedState = ApiResponse.Loading
)
) {
Expand Down Expand Up @@ -71,7 +85,10 @@ class PastGamesViewModel @Inject constructor(
applyMutation {
copy(
selectedGender = gender,
selectionList = Sport.getSportSelectionList(gender)
selectionList = Sport.getSportSelectionList(gender).filter {
it is SportSelection.All ||
(it is SportSelection.SportSelect && isValidSport(it.sport.displayName))
},
)
}
}
Expand Down
Loading