@@ -118,9 +118,12 @@ fun ClimateTraceScreen() {
118118 }
119119
120120 Spacer (modifier = Modifier .width(1 .dp).fillMaxWidth())
121- selectedCountry?.let { country ->
122- CountryInfoDetailedView (country, countryEmissionInfo, countryAssetEmissions, isLoadingCountryDetails.value)
123- }
121+ CountryInfoDetailedView (
122+ country = selectedCountry,
123+ countryEmissionInfo = countryEmissionInfo,
124+ countryAssetEmissionsList = countryAssetEmissions,
125+ isLoading = isLoadingCountryDetails.value
126+ )
124127 }
125128 } else {
126129 Box (Modifier .width(250 .dp).fillMaxHeight().background(color = Color .LightGray )) {
@@ -131,20 +134,17 @@ fun ClimateTraceScreen() {
131134
132135 Spacer (modifier = Modifier .width(1 .dp).fillMaxHeight())
133136 Box (Modifier .fillMaxHeight()) {
134- selectedCountry?.let { country ->
135- CountryInfoDetailedView (
136- country,
137- countryEmissionInfo,
138- countryAssetEmissions,
139- isLoadingCountryDetails.value
140- )
141- }
137+ CountryInfoDetailedView (
138+ country = selectedCountry,
139+ countryEmissionInfo = countryEmissionInfo,
140+ countryAssetEmissionsList = countryAssetEmissions,
141+ isLoading = isLoadingCountryDetails.value
142+ )
142143 }
143144 }
144145 }
145146}
146147
147-
148148@Composable
149149fun CountryListView (
150150 countryList : List <Country >,
@@ -216,7 +216,6 @@ fun SearchableList(
216216 ) {
217217 IconButton (onClick = {
218218 onSearchQueryChange(" " )
219- keyboardController?.hide()
220219 }) {
221220 Icon (
222221 imageVector = Icons .Default .Close ,
@@ -232,7 +231,11 @@ fun SearchableList(
232231 } else {
233232 LazyColumn {
234233 items(filteredCountryList) { country ->
235- CountryRow (country, selectedCountry, countrySelected)
234+ CountryRow (
235+ country = country,
236+ selectedCountry = selectedCountry,
237+ countrySelected = countrySelected
238+ )
236239 }
237240 }
238241 }
@@ -282,51 +285,67 @@ fun CountryRow(
282285
283286@Composable
284287fun CountryInfoDetailedView (
285- country : Country ,
288+ country : Country ? ,
286289 countryEmissionInfo : CountryEmissionsInfo ? ,
287290 countryAssetEmissionsList : List <CountryAssetEmissionsInfo >? ,
288291 isLoading : Boolean
289292) {
290293
291- if (isLoading ) {
294+ if (country == null ) {
292295 Column (
293296 modifier = Modifier
294297 .fillMaxSize()
295298 .fillMaxHeight()
296299 .wrapContentSize(Alignment .Center )
297300 ) {
298- CircularProgressIndicator ()
301+ Column (
302+ modifier = Modifier
303+ .fillMaxSize()
304+ .fillMaxHeight()
305+ .wrapContentSize(Alignment .Center ),
306+ horizontalAlignment = Alignment .CenterHorizontally
307+ ) {
308+ Text (" No Country Selected!" , style = MaterialTheme .typography.titleLarge)
309+ }
299310 }
300311 } else {
301- Column (
302- modifier = Modifier
303- .verticalScroll(rememberScrollState())
304- .fillMaxSize()
305- .padding(16 .dp),
306- horizontalAlignment = Alignment .CenterHorizontally
307- ) {
308- Text (
309- text = country.name,
310- style = MaterialTheme .typography.titleLarge,
311- textAlign = TextAlign .Center
312- )
312+ if (isLoading) {
313+ Column (
314+ modifier = Modifier
315+ .fillMaxSize()
316+ .fillMaxHeight()
317+ .wrapContentSize(Alignment .Center )
318+ ) {
319+ CircularProgressIndicator ()
320+ }
321+ } else {
322+ Column (
323+ modifier = Modifier
324+ .verticalScroll(rememberScrollState())
325+ .fillMaxSize()
326+ .padding(16 .dp),
327+ horizontalAlignment = Alignment .CenterHorizontally
328+ ) {
329+ Text (
330+ text = country.name,
331+ style = MaterialTheme .typography.titleLarge,
332+ textAlign = TextAlign .Center
333+ )
313334
314- Spacer (modifier = Modifier .size(16 .dp))
335+ Spacer (modifier = Modifier .size(16 .dp))
315336
316- countryEmissionInfo?.let {
317- val co2 = (countryEmissionInfo.emissions.co2 / 1_000_000 ).toInt()
318- val percentage =
319- (countryEmissionInfo.emissions.co2 / countryEmissionInfo.worldEmissions.co2).toPercent(
320- 2
321- )
322- Text (" co2 = $co2 Million Tonnes (2022)" )
323- Text (" rank = ${countryEmissionInfo.rank} ($percentage )" )
324- }
337+ countryEmissionInfo?.let {
338+ val co2 = (countryEmissionInfo.emissions.co2 / 1_000_000 ).toInt()
339+ val percentage = (countryEmissionInfo.emissions.co2 / countryEmissionInfo.worldEmissions.co2).toPercent(2 )
340+ Text (" co2 = $co2 Million Tonnes (2022)" )
341+ Text (" rank = ${countryEmissionInfo.rank} ($percentage )" )
342+ }
325343
326- Spacer (modifier = Modifier .size(16 .dp))
344+ Spacer (modifier = Modifier .size(16 .dp))
327345
328- countryAssetEmissionsList?.let {
329- SectorEmissionsPieChart (countryAssetEmissionsList)
346+ countryAssetEmissionsList?.let {
347+ SectorEmissionsPieChart (countryAssetEmissionsList)
348+ }
330349 }
331350 }
332351 }
0 commit comments