@@ -5,30 +5,24 @@ import androidx.annotation.RequiresApi
55import androidx.compose.animation.animateContentSize
66import androidx.compose.animation.core.Spring
77import androidx.compose.animation.core.spring
8- import androidx.compose.foundation.background
9- import androidx.compose.foundation.border
108import androidx.compose.foundation.layout.*
119import androidx.compose.foundation.lazy.LazyRow
12- import androidx.compose.foundation.shape.RoundedCornerShape
1310import androidx.compose.material.*
1411import androidx.compose.material.icons.Icons
1512import androidx.compose.material.icons.filled.*
1613import androidx.compose.runtime.*
1714import androidx.compose.runtime.livedata.observeAsState
1815import androidx.compose.ui.Alignment
1916import androidx.compose.ui.Modifier
20- import androidx.compose.ui.graphics.Color
2117import androidx.compose.ui.res.dimensionResource
22- import androidx.compose.ui.text.font.FontWeight
23- import androidx.compose.ui.unit.dp
18+ import androidx.compose.ui.res.stringResource
2419import androidx.compose.ui.unit.sp
2520import androidx.hilt.navigation.compose.hiltViewModel
2621import com.adyen.android.assignment.R
2722import com.adyen.android.assignment.model.response.Category
2823import com.adyen.android.assignment.model.response.Result
2924import com.adyen.android.assignment.screens.home.viewmodel.HomeViewModel
30- import com.adyen.android.assignment.screens.permission.screen.LocationPermissionScreen
31- import com.adyen.android.assignment.screens.permission.viewmodel.PermissionViewModel
25+ import com.adyen.android.assignment.ui.components.CategoryChip
3226import com.adyen.android.assignment.utils.Constant.GOOGLE_MAPS_CAMERA_ZOOM
3327import com.google.android.gms.maps.model.CameraPosition
3428import com.google.android.gms.maps.model.LatLng
@@ -41,27 +35,20 @@ import com.google.maps.android.compose.rememberCameraPositionState
4135fun HomeScreen (
4236 locationRequestOnClick : () -> Unit ,
4337 homeViewModel : HomeViewModel = hiltViewModel(),
44- permissionViewModel : PermissionViewModel = hiltViewModel()
4538) {
46- val venuesListState = homeViewModel.venuesListState
47-
4839 val showProgress = remember { mutableStateOf(false ) }
4940 val showInfo = remember { mutableStateOf(false ) }
41+ val cameraPositionState = rememberCameraPositionState {}
42+ val venuesListState = homeViewModel.venuesListState
5043 val selectedPlaceState = homeViewModel.selectedPlace.observeAsState()
51- val permissionsState = permissionViewModel.locationPermission.observeAsState()
5244 val currentLocation = homeViewModel.currentLocation.observeAsState()
53- val cameraPositionState = rememberCameraPositionState {}
5445
55- if (permissionsState.value == true ) {
56- LaunchedEffect (Unit ) {
57- homeViewModel.getPlaces(homeViewModel.getDummyLocationRequest())
58- cameraPositionState.position = CameraPosition .fromLatLngZoom(
59- homeViewModel.getDummyAmsterdamLocation(),
60- GOOGLE_MAPS_CAMERA_ZOOM
61- )
62- }
63- } else {
64- LocationPermissionScreen ()
46+ LaunchedEffect (Unit ) {
47+ homeViewModel.getPlaces(homeViewModel.getDummyLocationRequest())
48+ cameraPositionState.position = CameraPosition .fromLatLngZoom(
49+ homeViewModel.getDummyAmsterdamLocation(),
50+ GOOGLE_MAPS_CAMERA_ZOOM
51+ )
6552 }
6653
6754 if (venuesListState.venueList?.isNotEmpty() == true ) {
@@ -89,7 +76,7 @@ fun HomeScreen(
8976 Box (
9077 modifier = Modifier
9178 .fillMaxWidth()
92- .padding(all = 16 .dp ),
79+ .padding(all = dimensionResource(id = R .dimen.home_screen_show_my_current_location_box_padding) ),
9380 contentAlignment = Alignment .BottomStart
9481 ) {
9582 Button (modifier = Modifier
@@ -100,9 +87,9 @@ fun HomeScreen(
10087 }) {
10188 Icon (
10289 Icons .Default .Place ,
103- contentDescription = " Show My Location "
90+ contentDescription = stringResource(id = R .string.home_screen_show_my_current_location_button_content_description)
10491 )
105- Text (text = " My Location " )
92+ Text (text = stringResource(id = R .string.home_screen_show_my_current_location_button_text) )
10693 }
10794 }
10895 }
@@ -146,7 +133,6 @@ fun HomeScreen(
146133 SelectedPlaceInfo (showInfo, place)
147134 }
148135 }
149-
150136}
151137
152138@Composable
@@ -191,13 +177,13 @@ fun SelectedPlaceInfo(showInfo: MutableState<Boolean>, place: Result) {
191177 IconButton (onClick = { expanded = ! expanded }) {
192178 Icon (
193179 imageVector = if (expanded) Icons .Filled .ExpandLess else Icons .Filled .ExpandMore ,
194- contentDescription = " "
180+ contentDescription = stringResource(id = R .string.home_screen_place_detail_expand_content_description)
195181 )
196182 }
197183 IconButton (onClick = { showInfo.value = false }) {
198184 Icon (
199185 imageVector = Icons .Filled .Close ,
200- contentDescription = " "
186+ contentDescription = stringResource(id = R .string.home_screen_place_detail_close_content_description)
201187 )
202188 }
203189 }
@@ -218,10 +204,10 @@ fun SelectedPlaceNameField(name: String?) {
218204 Spacer (modifier = Modifier .height(dimensionResource(id = R .dimen.place_info_spacer)))
219205 Icon (
220206 Icons .Default .Business ,
221- contentDescription = " "
207+ contentDescription = stringResource(id = R .string.home_screen_place_detail_name_content_description)
222208 )
223209 Spacer (modifier = Modifier .width(dimensionResource(id = R .dimen.place_info_spacer)))
224- Text (text = " Name : $name " )
210+ Text (text = stringResource(id = R .string.home_screen_place_detail_name) + " $name " )
225211}
226212
227213@Composable
@@ -230,10 +216,10 @@ fun SelectedPlaceAddressField(formatted_address: String?) {
230216 Row (modifier = Modifier .fillMaxWidth()) {
231217 Icon (
232218 Icons .Default .Place ,
233- contentDescription = " "
219+ contentDescription = stringResource(id = R .string.home_screen_place_detail_address_content_description)
234220 )
235221 Spacer (modifier = Modifier .width(dimensionResource(id = R .dimen.place_info_spacer)))
236- Text (text = " Address : $formatted_address " )
222+ Text (text = stringResource(id = R .string.home_screen_place_detail_address) + " $formatted_address " )
237223 }
238224 }
239225}
@@ -245,12 +231,12 @@ fun SelectedPlaceCategoriesField(categoryList: List<Category>?) {
245231 Row (modifier = Modifier .fillMaxWidth()) {
246232 Icon (
247233 Icons .Filled .Storefront ,
248- contentDescription = " "
234+ contentDescription = stringResource(id = R .string.home_screen_place_detail_categories_content_description)
249235 )
250236 Spacer (modifier = Modifier .width(dimensionResource(id = R .dimen.place_info_spacer)))
251237 Text (
252- text = " Categories " ,
253- fontSize = 16 .sp
238+ text = stringResource(id = R .string.home_screen_place_detail_categories) ,
239+ fontSize = dimensionResource(id = R .dimen.place_info_categories_text_size).value .sp
254240 )
255241 }
256242 Spacer (modifier = Modifier .height(dimensionResource(id = R .dimen.place_info_spacer)))
@@ -266,36 +252,6 @@ fun SelectedPlaceCategoriesField(categoryList: List<Category>?) {
266252 }
267253}
268254
269- @Composable
270- fun CategoryChip (
271- categoryName : String
272- ) {
273- Row (
274- horizontalArrangement = Arrangement .Center ,
275- verticalAlignment = Alignment .CenterVertically ,
276- modifier = Modifier
277- .padding(
278- vertical = 2 .dp,
279- horizontal = 4 .dp
280- )
281- .border(
282- width = 1 .dp,
283- color = Color .White ,
284- shape = RoundedCornerShape (16 .dp)
285- )
286- .background(
287- color = Color .Transparent ,
288- )
289- .padding(4 .dp)
290- ) {
291- Text (
292- text = categoryName,
293- fontWeight = FontWeight .Bold ,
294- fontSize = 14 .sp,
295- modifier = Modifier .padding(4 .dp)
296- )
297- }
298- }
299255
300256
301257
0 commit comments