-
Notifications
You must be signed in to change notification settings - Fork 0
Highlights Search Screen UI #90
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
Changes from 10 commits
bce211d
6a04011
7859639
289f4e4
de3f5f8
82b1a32
b8bab79
1b3d9ec
e34db06
cba8227
69eac9d
a597341
250559d
edf83c0
1ad57cd
91c976f
5dc83ea
917f1da
b8dd80c
3910d80
f2df140
638cc52
d2d881f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.cornellappdev.score.components.highlights | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.lazy.LazyColumn | ||
| import androidx.compose.foundation.lazy.items | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.cornellappdev.score.components.ScorePreview | ||
| import com.cornellappdev.score.model.HighlightData | ||
| import com.cornellappdev.score.util.highlightsList | ||
|
|
||
| @Composable | ||
| fun HighlightsCardLazyColumn( | ||
| highlightsList: List<HighlightData> | ||
| ) { | ||
| LazyColumn( | ||
| modifier = Modifier.padding(top = 16.dp), | ||
| verticalArrangement = Arrangement.spacedBy(16.dp) | ||
| ) { | ||
| items(highlightsList) { item -> | ||
| when (item) { | ||
| is HighlightData.Video -> VideoHighlightCard(item.data, true) | ||
| is HighlightData.Article -> ArticleHighlightCard(item.data, true) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
amjiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Composable | ||
| private fun HighlightsCardLazyColumnPreview() { | ||
| ScorePreview { | ||
| HighlightsCardLazyColumn(highlightsList) | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package com.cornellappdev.score.components.highlights | ||
|
|
||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| 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.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.focus.FocusRequester | ||
| import androidx.compose.ui.focus.onFocusChanged | ||
| import androidx.compose.ui.platform.LocalFocusManager | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.cornellappdev.score.components.ScorePreview | ||
| import com.cornellappdev.score.model.Sport | ||
| import com.cornellappdev.score.theme.Style.bodyMedium | ||
| import com.cornellappdev.score.util.sportList | ||
|
|
||
| @Composable | ||
| fun HighlightsScreenSearchFilterBar( | ||
| sportList: List<Sport>, | ||
| focusRequester: FocusRequester | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| val focusManager = LocalFocusManager.current | ||
| var isActive by remember { mutableStateOf(true) } | ||
|
||
| Column(modifier = Modifier.fillMaxWidth()) { | ||
| Row( | ||
| modifier = Modifier | ||
| .padding(horizontal = 24.dp) | ||
| .clip(shape = RoundedCornerShape(100.dp)) | ||
| .clickable(onClick = {/*todo clear the highlight rows and show recent searches*/ }), | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| horizontalArrangement = Arrangement.spacedBy(12.dp), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| HighlightsSearchBar( | ||
| onSearchClick = { | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isActive = true | ||
| focusRequester.requestFocus() | ||
| }, | ||
| focusRequester = focusRequester, | ||
| modifier = Modifier | ||
| .weight(1f) | ||
| .onFocusChanged { state -> | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // When the search bar loses focus, hide cancel | ||
| if (!state.isFocused) { | ||
| isActive = !isActive | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| if (isActive) { | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Box( | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| modifier = Modifier.clickable { | ||
| isActive = true; | ||
| focusManager.clearFocus(force = true) | ||
| /*todo: clear the text in the search bar*/ | ||
| } | ||
| ) { | ||
| Text("Cancel", style = bodyMedium) | ||
| } | ||
| } | ||
| } | ||
| Spacer(modifier = Modifier.height(16.dp)) | ||
| HighlightsFilterRow(sportList, {/*todo on filter selected*/ }) | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun HighlightsScreenSearchFilterBarActivePreview() { | ||
| ScorePreview { | ||
| HighlightsScreenSearchFilterBar(sportList, FocusRequester()) | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun HighlightsScreenSearchFilterBarInactivePreview() { | ||
| ScorePreview { | ||
| HighlightsScreenSearchFilterBar(sportList, FocusRequester()) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,9 @@ import androidx.compose.runtime.setValue | |
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.focus.FocusRequester | ||
| import androidx.compose.ui.focus.focusRequester | ||
| import androidx.compose.ui.focus.onFocusChanged | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.text.input.VisualTransformation | ||
|
|
@@ -33,21 +36,20 @@ import com.cornellappdev.score.theme.Style.bodyNormal | |
|
|
||
| @Composable | ||
| fun HighlightsSearchBar( | ||
| onSearchClick: () -> Unit | ||
| onSearchClick: () -> Unit, | ||
| focusRequester: FocusRequester, | ||
| modifier: Modifier = Modifier | ||
| ) { | ||
| val interactionSource = remember { MutableInteractionSource() } | ||
| var searchQuery by remember { mutableStateOf("") } | ||
| var searchQuery by remember { mutableStateOf("") } //todo: to be handled by viewmodel | ||
amjiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Row( | ||
amjiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| modifier = Modifier | ||
| modifier = modifier | ||
| .fillMaxWidth() | ||
| .background(Color.White, RoundedCornerShape(100.dp)) | ||
| .border(1.dp, GrayLight, RoundedCornerShape(100.dp)) | ||
| .clip(RoundedCornerShape(100.dp)) | ||
| .clickable( | ||
| interactionSource = interactionSource, | ||
| indication = null | ||
| ) { onSearchClick() } | ||
| .clickable { onSearchClick() } | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .padding(horizontal = 16.dp, vertical = 8.dp), | ||
| verticalAlignment = Alignment.CenterVertically) { | ||
|
|
||
|
|
@@ -75,15 +77,62 @@ fun HighlightsSearchBar( | |
| visualTransformation = VisualTransformation.None, | ||
| interactionSource = interactionSource, | ||
| modifier = Modifier | ||
| .then( | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| focusRequester.let { Modifier.focusRequester(it) } | ||
| ) | ||
| .fillMaxWidth() | ||
| .background(Color.Transparent) | ||
| ) | ||
| } | ||
| if (searchQuery.isNotEmpty()) { | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Icon( | ||
| painter = painterResource(R.drawable.ic_close), | ||
| contentDescription = "clear field", | ||
| modifier = Modifier.clickable( | ||
| onClick = { searchQuery = "" } | ||
|
||
| ) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun HighlightsSearchBarUI( | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| onClick: () -> Unit, | ||
| ) { | ||
| Row( | ||
amjiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .background(Color.White, RoundedCornerShape(100.dp)) | ||
| .border(1.dp, GrayLight, RoundedCornerShape(100.dp)) | ||
| .clip(RoundedCornerShape(100.dp)) | ||
| .clickable( | ||
| ) { onClick() } | ||
| .padding(horizontal = 16.dp, vertical = 8.dp), | ||
| verticalAlignment = Alignment.CenterVertically) { | ||
|
|
||
| Icon( | ||
amjiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| painter = painterResource(R.drawable.search), | ||
| contentDescription = "search icon", | ||
| tint = Color.Unspecified | ||
| ) | ||
|
|
||
| Spacer(Modifier.width(8.dp)) | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Text( | ||
| text = "Search keywords", | ||
| style = bodyNormal.copy(color = Color.Gray) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun HighlightsSearchBarUIPreview() { | ||
| HighlightsSearchBarUI({}) | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun HighlightsSearchBarPreview() { | ||
| HighlightsSearchBar({}) | ||
| HighlightsSearchBar({}, FocusRequester() ) | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.cornellappdev.score.components.highlights | ||
|
|
||
| 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.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.material3.Icon | ||
| 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.res.painterResource | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import com.cornellappdev.score.R | ||
| import com.cornellappdev.score.components.ScorePreview | ||
| import com.cornellappdev.score.theme.Style.bodyMedium | ||
| import com.cornellappdev.score.theme.Style.metricSmallNormal | ||
|
|
||
|
|
||
| @Composable | ||
| fun RecentSearchItem( | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| query: String | ||
| ) { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.SpaceBetween, | ||
| modifier = Modifier.fillMaxWidth() | ||
| ) { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| horizontalArrangement = Arrangement.spacedBy(12.dp), | ||
| modifier = Modifier.clickable(onClick = {/*search the query*/ }) | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| Icon( | ||
| painter = painterResource(R.drawable.search), | ||
| contentDescription = "search icon", | ||
| tint = Color.Unspecified | ||
| ) | ||
| Text(query, style = metricSmallNormal) | ||
| } | ||
|
|
||
| //this icon doesn't preview correctly since its too small, works when actually running though | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Icon( | ||
| painter = painterResource(R.drawable.ic_close), | ||
| contentDescription = "close icon", | ||
| tint = Color.Unspecified, | ||
| modifier = Modifier.clickable(onClick = {/*delete this search from the recent searches list*/ }) | ||
| ) | ||
|
|
||
| } | ||
| } | ||
|
|
||
| @Composable | ||
| fun RecentSearches( | ||
| recentQueriesList: List<String> | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| ) { | ||
| Text("Recent searches", style = bodyMedium) | ||
| recentQueriesList.map { query -> | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Spacer(Modifier.height(16.dp)) | ||
amjiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| RecentSearchItem(query) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| private fun RecentSearchItemPreview() { | ||
| ScorePreview { | ||
| RecentSearches(listOf("Columbia", "Men's ice hockey", "Late goal lifts No.6 men’s hockey")) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.