@@ -5,6 +5,7 @@ import androidx.compose.animation.fadeIn
55import androidx.compose.animation.fadeOut
66import androidx.compose.foundation.background
77import androidx.compose.foundation.clickable
8+ import androidx.compose.foundation.layout.Arrangement
89import androidx.compose.foundation.layout.Box
910import androidx.compose.foundation.layout.Column
1011import androidx.compose.foundation.layout.Row
@@ -112,7 +113,11 @@ fun ClimateTraceScreen() {
112113 Column (Modifier .fillMaxWidth()) {
113114
114115 Box (Modifier .height(250 .dp).fillMaxWidth().background(color = Color .LightGray )) {
115- CountryListView (countryList, selectedCountry, isLoadingCountries.value) { country ->
116+ CountryListView (
117+ countryList,
118+ selectedCountry,
119+ isLoadingCountries.value
120+ ) { country ->
116121 selectedCountry = country
117122 }
118123 }
@@ -227,7 +232,7 @@ fun SearchableList(
227232 },
228233 content = {
229234 if (filteredCountryList.isEmpty() && isLoading.not ()) {
230- CountryListEmptyState ( )
235+ EmptyState (message = " search differently " )
231236 } else {
232237 LazyColumn {
233238 items(filteredCountryList) { country ->
@@ -247,16 +252,19 @@ fun SearchableList(
247252}
248253
249254@Composable
250- fun CountryListEmptyState () {
255+ fun EmptyState (
256+ title : String? = null,
257+ message : String? = null
258+ ) {
251259 Column (
252- modifier = Modifier
253- .fillMaxSize()
254- .fillMaxHeight()
255- .wrapContentSize(Alignment .Center ),
256- horizontalAlignment = Alignment .CenterHorizontally
260+ modifier = Modifier .fillMaxSize(),
261+ horizontalAlignment = Alignment .CenterHorizontally ,
262+ verticalArrangement = Arrangement .Center
257263 ) {
258- Text (" No Countries Found!" , style = MaterialTheme .typography.titleMedium)
259- Text (" search differently" , style = MaterialTheme .typography.bodyLarge)
264+ Text (title ? : " No Countries Found!" , style = MaterialTheme .typography.titleMedium)
265+ message?.let {
266+ Text (message, style = MaterialTheme .typography.bodyLarge)
267+ }
260268 }
261269}
262270
@@ -290,7 +298,6 @@ fun CountryInfoDetailedView(
290298 countryAssetEmissionsList : List <CountryAssetEmissionsInfo >? ,
291299 isLoading : Boolean
292300) {
293-
294301 if (country == null ) {
295302 Column (
296303 modifier = Modifier
@@ -305,9 +312,11 @@ fun CountryInfoDetailedView(
305312 .wrapContentSize(Alignment .Center ),
306313 horizontalAlignment = Alignment .CenterHorizontally
307314 ) {
308- Text (" No Country Selected!" , style = MaterialTheme .typography.titleLarge)
315+ Text (text = " No Country Selected!" , style = MaterialTheme .typography.titleLarge)
309316 }
310317 }
318+ } else if ((countryEmissionInfo == null || countryAssetEmissionsList.isNullOrEmpty()) && isLoading.not ()) {
319+ EmptyState (title = " No data found for ${country.name} " )
311320 } else {
312321 if (isLoading) {
313322 Column (
@@ -326,25 +335,26 @@ fun CountryInfoDetailedView(
326335 .padding(16 .dp),
327336 horizontalAlignment = Alignment .CenterHorizontally
328337 ) {
329- Text (
330- text = country.name,
331- style = MaterialTheme .typography.titleLarge,
332- textAlign = TextAlign .Center
333- )
338+ countryEmissionInfo?.let {
339+ countryAssetEmissionsList?.let {
340+ Text (
341+ text = country.name,
342+ style = MaterialTheme .typography.titleLarge,
343+ textAlign = TextAlign .Center
344+ )
334345
335- Spacer (modifier = Modifier .size(16 .dp))
346+ Spacer (modifier = Modifier .size(16 .dp))
336347
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- }
348+ val co2 = (countryEmissionInfo.emissions.co2 / 1_000_000 ).toInt()
349+ val percentage = (countryEmissionInfo.emissions.co2 / countryEmissionInfo.worldEmissions.co2).toPercent(2 )
343350
344- Spacer (modifier = Modifier .size(16 .dp))
351+ Text (text = " co2 = $co2 Million Tonnes (2022)" )
352+ Text (text = " rank = ${countryEmissionInfo.rank} ($percentage )" )
345353
346- countryAssetEmissionsList?.let {
347- SectorEmissionsPieChart (countryAssetEmissionsList)
354+ Spacer (modifier = Modifier .size(16 .dp))
355+
356+ SectorEmissionsPieChart (countryAssetEmissionsList)
357+ }
348358 }
349359 }
350360 }
0 commit comments