Repository navigation
[1/2] Add highlights networking and data layer #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| query Highlights($sportsType: String) { | ||
| articles(sportsType: $sportsType) { | ||
| title | ||
| image | ||
| sportsType | ||
| publishedAt | ||
| url | ||
| } | ||
| youtubeVideos { | ||
| title | ||
| thumbnail | ||
| url | ||
| publishedAt | ||
| duration | ||
| sportsType | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
app/src/main/java/com/cornellappdev/score/components/highlights/ExternalLink.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 68 additions & 6 deletions
74
app/src/main/java/com/cornellappdev/score/model/Highlights.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,95 @@ | ||
| package com.cornellappdev.score.model | ||
|
|
||
| import com.cornellappdev.score.util.formatDateTimeDisplay | ||
| import com.cornellappdev.score.util.isValidSport | ||
| import com.cornellappdev.score.util.outputFormatter | ||
| import com.cornellappdev.score.util.parseDateTimeOrNull | ||
| import com.cornellappdev.score.util.parseIsoDateToLocalDateOrNull | ||
| import com.example.score.HighlightsQuery | ||
| import java.time.LocalDate | ||
|
|
||
| data class VideoHighlightData( | ||
| val title: String, | ||
| val thumbnailImageUrl: String, | ||
| val videoUrl: String, | ||
| val date: String, | ||
| val sport: Sport, | ||
| val gender: GenderDivision, | ||
| val gender: GenderDivision?, | ||
| val duration: String? = null, | ||
| val finalScore: String? = null, | ||
| val photoCredit: String? = null | ||
| val photoCredit: String? = null, | ||
| val date: LocalDate?, | ||
| val dateString: String, | ||
| val sport: Sport?, | ||
| ) | ||
|
|
||
| data class ArticleHighlightData( | ||
| val title: String, | ||
| val imageUrl: String, | ||
| val articleUrl: String, | ||
| val date: String, | ||
| val sport: Sport | ||
| val date: LocalDate?, | ||
| val dateString: String, | ||
| val sport: Sport? | ||
| ) | ||
|
|
||
| sealed class HighlightData { | ||
| abstract val title: String | ||
| abstract val date: LocalDate? | ||
|
|
||
| abstract val dateString: String | ||
| abstract val sport: Sport? | ||
|
|
||
| data class Video(val data: VideoHighlightData) : HighlightData() { | ||
| override val title = data.title | ||
| override val date = data.date | ||
| override val dateString = data.dateString | ||
| override val sport = data.sport | ||
| } | ||
|
|
||
| data class Article(val data: ArticleHighlightData) : HighlightData() { | ||
| override val title = data.title | ||
| override val date = data.date | ||
| override val dateString = data.dateString | ||
| override val sport = data.sport | ||
| } | ||
| } | ||
|
|
||
| fun HighlightsQuery.YoutubeVideo.toHighlightData(): HighlightData? { | ||
| val sportName = sportsType ?: return null | ||
| if (!isValidSport(sportName)) return null | ||
|
|
||
| val date = parseIsoDateToLocalDateOrNull(publishedAt) | ||
|
|
||
| return HighlightData.Video( | ||
| VideoHighlightData( | ||
| title = title, | ||
| thumbnailImageUrl = thumbnail, | ||
| videoUrl = url, | ||
| date = date, | ||
| dateString = date?.format(outputFormatter) ?: "-/-/-", | ||
| sport = Sport.fromDisplayName(sportName), | ||
| gender = if (title.contains("Men's")) { | ||
| GenderDivision.MALE | ||
| } else { | ||
| GenderDivision.FEMALE | ||
| }, | ||
| duration = duration | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| fun HighlightsQuery.Article.toHighlightData(): HighlightData? { | ||
| val sportName = sportsType | ||
| if (!isValidSport(sportName)) return null | ||
|
|
||
| val date = parseIsoDateToLocalDateOrNull(publishedAt) | ||
|
|
||
| return HighlightData.Article( | ||
| ArticleHighlightData( | ||
| title = title, | ||
| imageUrl = image ?: return null, | ||
| articleUrl = url, | ||
| date = date, | ||
| dateString = date?.format(outputFormatter) ?: "-/-/-", | ||
| sport = Sport.fromDisplayName(sportName) | ||
| ) | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not default every unmatched title to female.
A title such as
"Late Goal Lifts No. 6 Men’s Hockey Over Brown"uses a curly apostrophe. This condition does not match it, so the converter assignsGenderDivision.FEMALE. Lowercase"men's"and titles without a gender marker also receive the female icon.Normalize case and apostrophes before checking explicit men's and women's markers. Use
nullwhen the title does not identify a gender; the card already supports that value.