11package com.cornellappdev.score.components
22
3+ import androidx.compose.animation.AnimatedVisibility
4+ import androidx.compose.animation.animateContentSize
35import androidx.compose.foundation.clickable
46import androidx.compose.foundation.layout.Arrangement
57import androidx.compose.foundation.layout.Column
68import androidx.compose.foundation.layout.Row
79import androidx.compose.foundation.layout.fillMaxWidth
810import androidx.compose.foundation.layout.padding
911import androidx.compose.material3.Icon
10- import androidx.compose.material3.RadioButton
1112import androidx.compose.material3.Text
1213import androidx.compose.runtime.Composable
1314import androidx.compose.runtime.getValue
@@ -18,13 +19,43 @@ import androidx.compose.ui.Alignment
1819import androidx.compose.ui.Modifier
1920import androidx.compose.ui.res.painterResource
2021import androidx.compose.ui.unit.dp
21- import androidx.compose.ui.unit.sp
2222import com.cornellappdev.score.R
23+ import com.cornellappdev.score.theme.Style.bodyNormal
24+ import com.cornellappdev.score.theme.Style.heading2
25+
26+ interface DisplayableFilter {
27+ val displayName: String
28+ }
29+
30+ enum class PriceFilter (override val displayName : String ) : DisplayableFilter {
31+ UNTICKETED (" Unticketed" ),
32+ UNDER_20 (" Under $20" ),
33+ UNDER_50 (" Under $50" ),
34+ OVER_50 (" Over $50" )
35+ }
36+
37+ enum class LocationFilter (override val displayName : String ) : DisplayableFilter {
38+ ON_CAMPUS (" On Campus" ),
39+ ONE_TO_TWO_HOURS (" 1-2 Hours" ),
40+ TWO_TO_FOUR_HOURS (" 2-4 Hours" ),
41+ OVER_FOUR_HOURS (" Over 4 Hours" )
42+ }
43+
44+ enum class DateFilter (override val displayName : String ) : DisplayableFilter {
45+ TODAY (" Today" ),
46+ WITHIN_7_DAYS (" Within 7 Days" ),
47+ WITHIN_A_MONTH (" Within a Month" ),
48+ OVER_A_MONTH (" Over a Month" )
49+ }
2350
2451@Composable
25- fun ExpandableSection (title : String , options : List <String >) {
52+ fun <T : DisplayableFilter > ExpandableSection (
53+ title : String ,
54+ options : List <T >,
55+ selectedOption : T ? ,
56+ onOptionSelected : (T ? ) -> Unit
57+ ) {
2658 var expanded by remember { mutableStateOf(false ) }
27- var selectedOption by remember { mutableStateOf(" Under $20" ) }
2859
2960 Column {
3061 Row (
@@ -34,7 +65,7 @@ fun ExpandableSection(title: String, options: List<String>) {
3465 horizontalArrangement = Arrangement .SpaceBetween ,
3566 verticalAlignment = Alignment .CenterVertically
3667 ) {
37- Text (title, fontSize = 18 .sp )
68+ Text (title, style = heading2 )
3869 Icon (
3970 painter = painterResource(
4071 id = if (expanded) R .drawable.ic_round_minus else R .drawable.ic_round_plus
@@ -43,24 +74,31 @@ fun ExpandableSection(title: String, options: List<String>) {
4374 )
4475 }
4576
46- if (expanded) {
47- Column {
48- options.forEach { option ->
49- Row (
50- verticalAlignment = Alignment .CenterVertically ,
51- modifier = Modifier
52- .fillMaxWidth()
53- .clickable { selectedOption = option }
54- .padding(vertical = 4 .dp)
55- ) {
56- RadioButton (
57- selected = (selectedOption == option),
58- onClick = { selectedOption = option }
59- )
60- Text (option)
77+ // Options
78+ Column (
79+ modifier = Modifier
80+ .fillMaxWidth()
81+ .animateContentSize()
82+ ) {
83+ AnimatedVisibility (visible = expanded) {
84+ Column {
85+ options.forEach { option ->
86+ Row (
87+ verticalAlignment = Alignment .CenterVertically ,
88+ modifier = Modifier
89+ .fillMaxWidth()
90+ .clickable { onOptionSelected(option) }
91+ .padding(start = 16 .dp, top = 4 .dp, bottom = 4 .dp)
92+ ) {
93+ CustomRadioButton (
94+ selected = (selectedOption == option),
95+ onClick = { onOptionSelected(option) }
96+ )
97+ Text (option.displayName, style = bodyNormal)
98+ }
6199 }
62100 }
63101 }
64102 }
65103 }
66- }
104+ }
0 commit comments