@@ -3,35 +3,37 @@ package com.cornellappdev.scoop.ui.components.search
3
3
import androidx.compose.foundation.BorderStroke
4
4
import androidx.compose.foundation.Canvas
5
5
import androidx.compose.foundation.clickable
6
- import androidx.compose.foundation.layout.*
6
+ import androidx.compose.foundation.layout.Arrangement
7
+ import androidx.compose.foundation.layout.Column
8
+ import androidx.compose.foundation.layout.Row
9
+ import androidx.compose.foundation.layout.Spacer
10
+ import androidx.compose.foundation.layout.fillMaxWidth
11
+ import androidx.compose.foundation.layout.height
12
+ import androidx.compose.foundation.layout.padding
13
+ import androidx.compose.foundation.layout.size
14
+ import androidx.compose.foundation.layout.wrapContentHeight
7
15
import androidx.compose.foundation.shape.RoundedCornerShape
8
- import androidx.compose.material.*
16
+ import androidx.compose.material.Card
17
+ import androidx.compose.material.Icon
18
+ import androidx.compose.material.MaterialTheme
19
+ import androidx.compose.material.Text
9
20
import androidx.compose.material.icons.Icons
21
+ import androidx.compose.material.icons.filled.CalendarToday
10
22
import androidx.compose.material.icons.filled.NearMe
11
23
import androidx.compose.material.icons.filled.Place
12
- import androidx.compose.material.icons.outlined.CalendarToday
13
- import androidx.compose.material.icons.outlined.NearMe
14
- import androidx.compose.material.icons.outlined.Place
15
24
import androidx.compose.runtime.Composable
16
25
import androidx.compose.runtime.MutableState
17
- import androidx.compose.runtime.mutableStateOf
18
- import androidx.compose.runtime.remember
19
26
import androidx.compose.ui.Alignment
20
27
import androidx.compose.ui.Modifier
21
28
import androidx.compose.ui.geometry.Offset
22
29
import androidx.compose.ui.graphics.Color
23
30
import androidx.compose.ui.graphics.PathEffect
24
- import androidx.compose.ui.platform.LocalContext
25
31
import androidx.compose.ui.res.painterResource
26
32
import androidx.compose.ui.res.stringResource
27
33
import androidx.compose.ui.unit.dp
28
34
import com.cornellappdev.scoop.R
29
35
import com.cornellappdev.scoop.data.models.Ride
30
- import com.cornellappdev.scoop.ui.components.general.CityPicker
31
- import com.cornellappdev.scoop.ui.components.post.createDatePickerDialog
32
36
import com.cornellappdev.scoop.ui.viewmodel.SearchScreenViewModel
33
- import java.text.SimpleDateFormat
34
- import java.util.*
35
37
36
38
/* *
37
39
* Composable that displays information about the current state of search of the user.
@@ -43,42 +45,22 @@ import java.util.*
43
45
* on in the SearchCard, the manager of this composable is responsible for stopping it (this composable
44
46
* has no icons to switch editing mode off).
45
47
*
46
- * @param search State that represents the current state of search of the user
48
+ * @param searchScreenViewModel State that represents the current state of search of the user
47
49
* @param filter State that represents the current filter applied to the results of search
48
- * @param isEditing State that represents the current mode of the [SearchCard]
50
+ * @param onBack Function to return to editing Search
49
51
* @param onSearchCompleted Callback that returns the results of the edited search back to the caller
50
52
*/
51
53
@Composable
52
54
fun SearchCard (
53
55
searchScreenViewModel : SearchScreenViewModel ,
54
56
filter : MutableState <String ?>,
55
- isEditing : MutableState < Boolean > ,
57
+ onBack : () -> Unit ,
56
58
onSearchCompleted : (List <Ride >) -> Unit ,
57
59
) {
58
60
// CityPicker requires MutableStates for its values but the Search model does
59
61
// not have MutableStates for its fields, so we must convert them and update the
60
62
// search state in the callback of CityPicker.
61
- val departureLocationName =
62
- remember { mutableStateOf(searchScreenViewModel.search.departureLocationName.orEmpty()) }
63
- val arrivalLocationName =
64
- remember { mutableStateOf(searchScreenViewModel.search.arrivalLocationName.orEmpty()) }
65
- val departureDate =
66
- remember { mutableStateOf(searchScreenViewModel.search.departureDate.orEmpty()) }
67
63
68
- val dateFormatter =
69
- SimpleDateFormat (stringResource(R .string.month_name_day_year_format), Locale .US )
70
- val datePickerDialog = createDatePickerDialog(
71
- LocalContext .current,
72
- { newDate ->
73
- if (departureDate.value != newDate) {
74
- searchScreenViewModel.search.departureDate = newDate
75
- departureDate.value = newDate
76
-
77
- // Query backend to get results with given date, filter if there's a filter
78
- onSearchCompleted(listOf ())
79
- }
80
- }, dateFormatter
81
- )
82
64
Column (modifier = Modifier .fillMaxWidth()) {
83
65
Card (
84
66
shape = RoundedCornerShape (10 .dp),
@@ -94,137 +76,71 @@ fun SearchCard(
94
76
) {
95
77
Row {
96
78
Icon (
97
- Icons .Outlined .NearMe ,
79
+ Icons .Filled .NearMe ,
98
80
modifier = Modifier
99
81
.padding(end = 12 .dp)
100
82
.size(32 .dp)
101
83
.align(Alignment .CenterVertically ),
102
84
contentDescription = stringResource(R .string.details_icon_description)
103
85
)
104
- CityPicker (
105
- cityState = departureLocationName,
106
- modifier = Modifier .apply {
107
- if (isEditing.value) {
108
- align(Alignment .Bottom )
109
- } else {
110
- align(Alignment .CenterVertically )
111
- }
112
- },
113
- icon = Icons .Filled .NearMe ,
114
- placeholder = " " , // CityPicker should never be empty.
115
- enabled = isEditing.value,
116
- disabledTextStyle = MaterialTheme .typography.subtitle1,
117
- disableDivider = ! isEditing.value
118
- ) { name, id ->
119
- if (searchScreenViewModel.search.departureLocationPlaceId != id) {
120
- searchScreenViewModel.setDepartureName(name)
121
- searchScreenViewModel.setDeparturePlaceId(id)
122
-
123
- // TODO: Networking for searching for rides should be inserted here and passed into callback.
124
- onSearchCompleted(listOf ())
125
- }
126
- }
86
+ Text (
87
+ text = searchScreenViewModel.search.departureLocationName ? : " null" ,
88
+ style = MaterialTheme .typography.subtitle1
89
+ )
127
90
}
128
91
129
92
Icon (
130
93
painterResource(R .drawable.ic_details_icon),
131
94
modifier = Modifier
132
- .size(32 .dp)
133
- .clickable { isEditing.value = ! isEditing.value }
95
+ .size(26 .dp)
96
+ .clickable { onBack() }
134
97
.align(Alignment .CenterVertically ),
135
98
contentDescription = stringResource(R .string.details_icon_description)
136
99
)
137
100
}
138
-
139
- if (! isEditing.value) {
140
- Canvas (
141
- Modifier
142
- .padding(start = 16 .dp)
143
- .height(17 .dp)
144
- ) {
145
- drawLine(
146
- color = Color .Black ,
147
- start = Offset (0f , 0f ),
148
- end = Offset (0f , size.height),
149
- pathEffect = PathEffect .dashPathEffect(floatArrayOf(8f , 8f ), 0f ),
150
- strokeWidth = 3f
151
- )
152
- }
101
+ Canvas (
102
+ Modifier
103
+ .padding(start = 16 .dp)
104
+ .height(10 .dp)
105
+ ) {
106
+ drawLine(
107
+ color = Color .Black ,
108
+ start = Offset (0f , 0f ),
109
+ end = Offset (0f , size.height),
110
+ pathEffect = PathEffect .dashPathEffect(floatArrayOf(8f , 8f ), 0f ),
111
+ strokeWidth = 3f
112
+ )
153
113
}
154
-
155
- Row (modifier = Modifier .padding(top = if (isEditing.value) 17 .dp else 0 .dp)) {
114
+ Row {
156
115
Icon (
157
- Icons .Outlined .Place ,
116
+ Icons .Filled .Place ,
158
117
modifier = Modifier
159
118
.padding(end = 12 .dp)
160
119
.size(32 .dp)
161
120
.align(Alignment .CenterVertically ),
162
121
contentDescription = stringResource(R .string.details_icon_description)
163
122
)
164
- CityPicker (
165
- cityState = arrivalLocationName,
166
- modifier = Modifier .apply {
167
- if (isEditing.value) {
168
- align(Alignment .Bottom )
169
- } else {
170
- align(Alignment .CenterVertically )
171
- }
172
- },
173
- icon = Icons .Filled .Place ,
174
- placeholder = " " ,
175
- enabled = isEditing.value,
176
- disabledTextStyle = MaterialTheme .typography.subtitle1,
177
- disableDivider = ! isEditing.value
178
- ) { name, id ->
179
- if (searchScreenViewModel.search.arrivalLocationPlaceId != id) {
180
- searchScreenViewModel.setArrivalName(name)
181
- searchScreenViewModel.setArrivalPlaceId(id)
182
-
183
- /* * TODO: Networking for searching for rides should be inserted here and passed into callback. */
184
- onSearchCompleted(listOf ())
185
- }
186
- }
123
+ Text (
124
+ text = searchScreenViewModel.search.arrivalLocationName ? : " null" ,
125
+ style = MaterialTheme .typography.subtitle1
126
+ )
187
127
}
188
-
189
- Row (modifier = Modifier .padding(top = if (isEditing.value) 17 .dp else 0 .dp)) {
128
+ Spacer (
129
+ modifier = Modifier .height(10 .dp)
130
+ )
131
+ Row {
190
132
Icon (
191
- Icons .Outlined .CalendarToday ,
133
+ Icons .Filled .CalendarToday ,
192
134
modifier = Modifier
193
135
.padding(end = 12 .dp)
194
136
.size(32 .dp)
195
137
.align(Alignment .CenterVertically ),
196
138
contentDescription = stringResource(R .string.calendar_icon_description)
197
139
)
198
- TextButton (
199
- enabled = isEditing.value,
200
- modifier = Modifier .apply {
201
- if (isEditing.value) {
202
- align(Alignment .Bottom )
203
- } else {
204
- align(Alignment .CenterVertically )
205
- }
206
- },
207
- contentPadding = PaddingValues (
208
- all = 0 .dp
209
- ),
210
- onClick = {
211
- /* * TODO: Change with custom calendar view if made eventually. */
212
- datePickerDialog.show()
213
- }) {
214
- Column {
215
- Text (
216
- departureDate.value,
217
- style = if (isEditing.value) MaterialTheme .typography.h5 else MaterialTheme .typography.subtitle1
218
- )
219
- if (isEditing.value) {
220
- Divider (
221
- modifier = Modifier .padding(top = 4 .dp),
222
- color = Color .Black ,
223
- thickness = 2 .dp
224
- )
225
- }
226
- }
227
- }
140
+ Text (
141
+ text = searchScreenViewModel.search.departureDate ? : " null" ,
142
+ style = MaterialTheme .typography.subtitle1
143
+ )
228
144
}
229
145
}
230
146
}
0 commit comments