Repository navigation
Create initial Compose components #28
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
caleb-bit
wants to merge
7
commits into
master
Choose a base branch
from
caleb/compose-foundation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
986037f
Add Compose dependencies and some components
caleb-bit 7a06e64
Share preview fixtures across components
caleb-bit ed1540c
Split TrackButton into TrackButton and RemoveButton
caleb-bit 6c26dda
Remove comments
caleb-bit 8a7fc66
Use a darker secondary text color on white surfaces
caleb-bit bfc5459
Remove added docstrings
caleb-bit 00e5b71
Make CourseRow's actions slot optional
caleb-bit 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
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/cornellappdev/coursegrab/ui/components/CoursePreviewData.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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.cornellappdev.coursegrab.ui.components | ||
|
|
||
| import com.cornellappdev.coursegrab.models.Course | ||
| import com.cornellappdev.coursegrab.models.SearchResult | ||
|
|
||
| internal fun sampleCourse( | ||
| catalogNum: Int = 10032, | ||
| subjectCode: String = "CS", | ||
| courseNum: Int = 1998, | ||
| title: String = "Intro to Android Development", | ||
| section: String = "LEC 001 / M 7:30PM", | ||
| isOpen: Boolean = true, | ||
| isTracking: Boolean = false, | ||
| numTracking: Int = 12 | ||
| ): Course = Course( | ||
| catalogNum = catalogNum, | ||
| courseNum = courseNum, | ||
| section = section, | ||
| instructors = listOf(SAMPLE_INSTRUCTOR), | ||
| isTracking = isTracking, | ||
| status = if (isOpen) STATUS_OPEN else STATUS_CLOSED, | ||
| subjectCode = subjectCode, | ||
| title = title, | ||
| numTracking = numTracking | ||
| ) | ||
|
|
||
| internal fun sampleSearchResult( | ||
| subjectCode: String = "CS", | ||
| courseNum: Int = 1998, | ||
| title: String = "Intro to Android Development", | ||
| sections: List<Course> = listOf(sampleCourse()) | ||
| ): SearchResult = SearchResult( | ||
| subjectCode = subjectCode, | ||
| courseNum = courseNum, | ||
| title = title, | ||
| sections = sections | ||
| ) | ||
|
|
||
| internal const val SAMPLE_INSTRUCTOR = "Adrian Sampson (als485)" | ||
|
|
||
| private const val STATUS_OPEN = "OPEN" | ||
| private const val STATUS_CLOSED = "CLOSED" |
133 changes: 133 additions & 0 deletions
133
app/src/main/java/com/cornellappdev/coursegrab/ui/components/CourseRow.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 |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| package com.cornellappdev.coursegrab.ui.components | ||
|
|
||
| import androidx.compose.foundation.BorderStroke | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.RowScope | ||
| import androidx.compose.foundation.layout.fillMaxHeight | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.CardDefaults | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.OutlinedCard | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.style.TextOverflow | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.cornellappdev.coursegrab.R | ||
| import com.cornellappdev.coursegrab.models.Course | ||
| import com.cornellappdev.coursegrab.ui.theme.CardBorder | ||
| import com.cornellappdev.coursegrab.ui.theme.CourseGrabTheme | ||
| import com.cornellappdev.coursegrab.ui.theme.PrimaryText | ||
| import java.util.Locale | ||
|
|
||
| @Composable | ||
| fun CourseRow( | ||
| course: Course, | ||
| onClick: () -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| actions: (@Composable RowScope.() -> Unit)? = null | ||
| ) { | ||
| OutlinedCard( | ||
| modifier = modifier | ||
| .fillMaxWidth() | ||
| .clickable(onClick = onClick), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| shape = RoundedCornerShape(6.dp), | ||
| border = BorderStroke(1.dp, CardBorder), | ||
| colors = CardDefaults.outlinedCardColors( | ||
| containerColor = MaterialTheme.colorScheme.surface | ||
| ) | ||
| ) { | ||
| Column( | ||
| modifier = Modifier.padding(16.dp), | ||
| verticalArrangement = Arrangement.spacedBy(12.dp) | ||
| ) { | ||
| Row(verticalAlignment = Alignment.Top) { | ||
| Text( | ||
| text = stringResource( | ||
| R.string.course_title_format, | ||
| course.subjectCode, | ||
| course.courseNum, | ||
| course.title | ||
| ), | ||
| style = MaterialTheme.typography.titleMedium, | ||
| maxLines = 2, | ||
| overflow = TextOverflow.Ellipsis, | ||
| modifier = Modifier.weight(1f) | ||
| ) | ||
| StatusIndicator(isOpen = course.isOpen, modifier = Modifier.padding(start = 12.dp)) | ||
| } | ||
|
|
||
| Row(verticalAlignment = Alignment.CenterVertically) { | ||
| Text( | ||
| text = course.section.uppercase(Locale.ROOT), | ||
| style = MaterialTheme.typography.bodyLarge, | ||
| color = PrimaryText, | ||
| maxLines = 1, | ||
| overflow = TextOverflow.Ellipsis, | ||
| modifier = Modifier.weight(1f) | ||
| ) | ||
| Text( | ||
| text = course.catalogNum.toString(), | ||
| style = MaterialTheme.typography.bodyLarge, | ||
| color = PrimaryText, | ||
| modifier = Modifier.padding(start = 12.dp) | ||
| ) | ||
| } | ||
| if (actions != null) { | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .padding(top = 4.dp) | ||
| .height(BUTTON_ROW_HEIGHT), | ||
| horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| content = actions | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private val BUTTON_ROW_HEIGHT = 44.dp | ||
|
|
||
| @Preview(showBackground = true, widthDp = 360) | ||
| @Composable | ||
| private fun CourseRowOpenPreview() { | ||
| CourseGrabTheme { | ||
| CourseRow(course = sampleCourse(), onClick = {}) { | ||
| TrackButton( | ||
| onClick = {}, | ||
| modifier = Modifier | ||
| .weight(1f) | ||
| .fillMaxHeight() | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true, widthDp = 360) | ||
| @Composable | ||
| private fun CourseRowClosedPreview() { | ||
| CourseGrabTheme { | ||
| CourseRow( | ||
| course = sampleCourse(isOpen = false, isTracking = true), | ||
| onClick = {} | ||
| ) { | ||
| RemoveButton( | ||
| onClick = {}, | ||
| modifier = Modifier | ||
| .weight(1f) | ||
| .fillMaxHeight() | ||
| ) | ||
| } | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/cornellappdev/coursegrab/ui/components/EmptyState.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 |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package com.cornellappdev.coursegrab.ui.components | ||
|
|
||
| import androidx.annotation.DrawableRes | ||
| import androidx.annotation.StringRes | ||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| 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.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.text.style.TextAlign | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.cornellappdev.coursegrab.R | ||
| import com.cornellappdev.coursegrab.ui.theme.CourseGrabTheme | ||
|
|
||
| @Composable | ||
| fun EmptyState( | ||
| @DrawableRes icon: Int, | ||
| @StringRes title: Int, | ||
| @StringRes subtitle: Int, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| Column( | ||
| modifier = modifier | ||
| .fillMaxWidth() | ||
| .padding(horizontal = 32.dp, vertical = 48.dp), | ||
| horizontalAlignment = Alignment.CenterHorizontally, | ||
| verticalArrangement = Arrangement.spacedBy(12.dp) | ||
| ) { | ||
| Image( | ||
| painter = painterResource(icon), | ||
| contentDescription = null, | ||
| modifier = Modifier.size(ICON_SIZE) | ||
| ) | ||
| Text( | ||
| text = stringResource(title), | ||
| style = MaterialTheme.typography.titleLarge, | ||
| textAlign = TextAlign.Center | ||
| ) | ||
| Text( | ||
| text = stringResource(subtitle), | ||
| style = MaterialTheme.typography.bodyLarge, | ||
| color = MaterialTheme.colorScheme.onSurfaceVariant, | ||
| textAlign = TextAlign.Center | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private val ICON_SIZE = 96.dp | ||
|
|
||
| @Preview(showBackground = true, widthDp = 360) | ||
| @Composable | ||
| private fun EmptyStateNoResultsPreview() { | ||
| CourseGrabTheme { | ||
| EmptyState( | ||
| icon = R.drawable.ic_status_closed, | ||
| title = R.string.no_courses_alert, | ||
| subtitle = R.string.no_results_alert_subtext_try_another | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true, widthDp = 360) | ||
| @Composable | ||
| private fun EmptyStateFailedPreview() { | ||
| CourseGrabTheme { | ||
| EmptyState( | ||
| icon = R.drawable.ic_status_warning, | ||
| title = R.string.search_failed, | ||
| subtitle = R.string.search_failed_subtext | ||
| ) | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/cornellappdev/coursegrab/ui/components/StatusIndicator.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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package com.cornellappdev.coursegrab.ui.components | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import com.cornellappdev.coursegrab.R | ||
| import com.cornellappdev.coursegrab.ui.theme.CourseGrabTheme | ||
|
|
||
| @Composable | ||
| fun StatusIndicator(isOpen: Boolean, modifier: Modifier = Modifier) { | ||
| Image( | ||
| painter = painterResource( | ||
| if (isOpen) R.drawable.ic_status_open else R.drawable.ic_status_closed | ||
| ), | ||
| contentDescription = stringResource( | ||
| if (isOpen) R.string.status_open else R.string.status_closed | ||
| ), | ||
| modifier = modifier | ||
| ) | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun StatusIndicatorPreview() { | ||
| CourseGrabTheme { StatusIndicator(isOpen = true) } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun StatusIndicatorClosedPreview() { | ||
| CourseGrabTheme { StatusIndicator(isOpen = false) } | ||
| } |
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.
nit: the other new versions are pulled into
ext. could we do the same here? or maybe share alifecycle_versionwith the other lifecycle deps?