Skip to content

Commit 87fa3d9

Browse files
committed
UI updates
1 parent 49c7568 commit 87fa3d9

File tree

5 files changed

+382
-109
lines changed

5 files changed

+382
-109
lines changed

common/BikeShareNotebook.ipynb

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"source": [
6-
"import dev.johnoreilly.common.di.createHttpClient\n",
7-
"import dev.johnoreilly.common.remote.CityBikesApi\n",
8-
"import io.ktor.client.engine.java.Java\n",
9-
"import kotlinx.coroutines.GlobalScope\n",
10-
"import kotlinx.coroutines.MainScope\n",
11-
"import kotlinx.coroutines.launch\n",
12-
"import kotlinx.coroutines.runBlocking\n",
13-
"import kotlinx.serialization.json.Json\n",
14-
"%useLatestDescriptors\n",
15-
"%use dataframe, kandy\n",
16-
"%use kandy-geo\n",
17-
"\n",
18-
"val json = Json { isLenient = true; ignoreUnknownKeys = true; useAlternativeNames = false }\n",
19-
"val engine = Java.create()\n",
20-
"val httpClient = createHttpClient(engine, json)\n",
21-
"val api = CityBikesApi(httpClient)\n",
22-
"\n",
23-
"val networkList = runBlocking { api.fetchNetworkList().networks }\n",
24-
"val coordinates = networkList.map { it.location }.toDataFrame()\n",
25-
"\n",
26-
"val points = coordinates.map {\n",
27-
" GeometryFactory().createPoint(Coordinate(it.get(\"longitude\").toString().toDouble(), it.get(\"latitude\").toString().toDouble()))\n",
28-
"}.filter { it.y > 35 && it.y < 75 && it.x > -10 && it.x < 65}\n",
29-
"\n",
30-
"GeoDataFrame.readGeoJson(\"europe.geojson\").plot {\n",
31-
" geoMap()\n",
32-
" geoPoints(points) {\n",
33-
" size = 2.0\n",
34-
" color = Color.RED\n",
35-
" }\n",
36-
" layout {\n",
37-
" size = 4000 to 4000\n",
38-
" }\n",
39-
"}\n"
40-
],
5+
"source": "",
416
"metadata": {
427
"collapsed": false,
438
"ExecuteTime": {

common/src/commonMain/kotlin/dev/johnoreilly/common/countrylist/CountryListUI.kt

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,25 @@
33
package dev.johnoreilly.common.countrylist
44

55
import androidx.compose.foundation.Image
6+
import androidx.compose.foundation.background
67
import androidx.compose.foundation.clickable
78
import androidx.compose.foundation.layout.*
89
import androidx.compose.foundation.lazy.LazyColumn
910
import androidx.compose.foundation.lazy.items
11+
import androidx.compose.foundation.shape.RoundedCornerShape
12+
import androidx.compose.material3.Card
13+
import androidx.compose.material3.CardDefaults
1014
import androidx.compose.material3.ExperimentalMaterial3Api
1115
import androidx.compose.material3.MaterialTheme
1216
import androidx.compose.material3.Scaffold
1317
import androidx.compose.material3.Text
1418
import androidx.compose.material3.TopAppBar
19+
import androidx.compose.material3.TopAppBarDefaults
1520
import androidx.compose.runtime.*
1621
import androidx.compose.ui.Alignment
1722
import androidx.compose.ui.Modifier
23+
import androidx.compose.ui.draw.clip
24+
import androidx.compose.ui.text.font.FontWeight
1825
import androidx.compose.ui.unit.dp
1926
import bikeshare.common.generated.resources.Res
2027
import bikeshare.common.generated.resources.allDrawableResources
@@ -29,8 +36,24 @@ import software.amazon.lastmile.kotlin.inject.anvil.AppScope
2936
@CircuitInject(CountryListScreen::class, AppScope::class)
3037
@Composable
3138
fun CountryListUi(state: CountryListScreen.State, modifier: Modifier = Modifier) {
32-
Scaffold(modifier = modifier, topBar = { TopAppBar(title = { Text("Countries") }) }) { innerPadding ->
33-
LazyColumn(modifier = Modifier.padding(innerPadding)) {
39+
Scaffold(
40+
modifier = modifier,
41+
topBar = {
42+
TopAppBar(
43+
title = { Text("Choose a Country", style = MaterialTheme.typography.titleLarge) },
44+
colors = TopAppBarDefaults.topAppBarColors(
45+
containerColor = MaterialTheme.colorScheme.primary,
46+
titleContentColor = MaterialTheme.colorScheme.onPrimary
47+
)
48+
)
49+
}
50+
) { innerPadding ->
51+
LazyColumn(
52+
modifier = Modifier
53+
.padding(innerPadding)
54+
.padding(horizontal = 12.dp, vertical = 8.dp),
55+
verticalArrangement = Arrangement.spacedBy(8.dp)
56+
) {
3457
items(state.countryList) { country ->
3558
CountryView(country) {
3659
state.eventSink(CountryListScreen.Event.CountryClicked(country.code))
@@ -44,23 +67,45 @@ fun CountryListUi(state: CountryListScreen.State, modifier: Modifier = Modifier)
4467
@OptIn(ExperimentalResourceApi::class)
4568
@Composable
4669
fun CountryView(country: Country, countrySelected: (country: Country) -> Unit) {
47-
Row(
70+
Card(
4871
modifier = Modifier
4972
.fillMaxWidth()
50-
.clickable(onClick = { countrySelected(country) })
51-
.padding(start = 16.dp, top = 8.dp, end = 16.dp, bottom = 8.dp),
52-
verticalAlignment = Alignment.CenterVertically
73+
.clickable(onClick = { countrySelected(country) }),
74+
shape = RoundedCornerShape(8.dp),
75+
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
76+
colors = CardDefaults.cardColors(
77+
containerColor = MaterialTheme.colorScheme.surface
78+
)
5379
) {
54-
val flagDrawable = Res.allDrawableResources["flag_${country.code.lowercase()}"]
55-
if (flagDrawable != null) {
56-
Image(
57-
painterResource(flagDrawable),
58-
modifier = Modifier.size(32.dp),
59-
contentDescription = country.displayName
80+
Row(
81+
modifier = Modifier
82+
.fillMaxWidth()
83+
.padding(16.dp),
84+
verticalAlignment = Alignment.CenterVertically
85+
) {
86+
val flagDrawable = Res.allDrawableResources["flag_${country.code.lowercase()}"]
87+
if (flagDrawable != null) {
88+
Box(
89+
modifier = Modifier
90+
.size(48.dp)
91+
.clip(RoundedCornerShape(4.dp))
92+
.background(MaterialTheme.colorScheme.surfaceVariant)
93+
.padding(4.dp)
94+
) {
95+
Image(
96+
painterResource(flagDrawable),
97+
modifier = Modifier.size(40.dp),
98+
contentDescription = country.displayName
99+
)
100+
}
101+
}
102+
103+
Spacer(modifier = Modifier.width(16.dp))
104+
Text(
105+
text = country.displayName,
106+
style = MaterialTheme.typography.bodyLarge,
107+
fontWeight = FontWeight.Medium
60108
)
61109
}
62-
63-
Spacer(modifier = Modifier.size(16.dp))
64-
Text(text = country.displayName, style = MaterialTheme.typography.bodyLarge)
65110
}
66111
}

0 commit comments

Comments
 (0)