@@ -7,6 +7,7 @@ import androidx.compose.animation.core.animateDpAsState
77import androidx.compose.animation.fadeIn
88import androidx.compose.animation.fadeOut
99import androidx.compose.foundation.background
10+ import androidx.compose.foundation.border
1011import androidx.compose.foundation.clickable
1112import androidx.compose.foundation.layout.Arrangement
1213import androidx.compose.foundation.layout.Box
@@ -32,6 +33,7 @@ import androidx.compose.material3.IconButton
3233import androidx.compose.material3.MaterialTheme
3334import androidx.compose.material3.SearchBar
3435import androidx.compose.material3.Text
36+ import androidx.compose.material3.VerticalDivider
3537import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
3638import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
3739import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
@@ -47,6 +49,9 @@ import androidx.compose.ui.Modifier
4749import androidx.compose.ui.graphics.Color
4850import androidx.compose.ui.platform.LocalSoftwareKeyboardController
4951import androidx.compose.ui.unit.dp
52+ import cafe.adriel.voyager.core.screen.Screen
53+ import cafe.adriel.voyager.navigator.LocalNavigator
54+ import cafe.adriel.voyager.navigator.currentOrThrow
5055import dev.johnoreilly.climatetrace.remote.ClimateTraceApi
5156import dev.johnoreilly.climatetrace.remote.Country
5257import dev.johnoreilly.climatetrace.ui.utils.PanelState
@@ -57,82 +62,84 @@ import org.koin.core.component.inject
5762
5863
5964@OptIn(ExperimentalMaterial3WindowSizeClassApi ::class )
60- @Composable
61- fun ClimateTraceScreen () {
62- val windowSizeClass = calculateWindowSizeClass()
63- val viewModel = koinInject<ClimateTraceViewModel >()
65+ class ClimateTraceScreen : Screen {
66+ @Composable
67+ override fun Content () {
68+ val navigator = LocalNavigator .currentOrThrow
69+ val windowSizeClass = calculateWindowSizeClass()
70+ val viewModel = koinInject<ClimateTraceViewModel >()
6471
65- val countryList by viewModel.countryList.collectAsState()
66- val selectedCountry by viewModel.selectedCountry.collectAsState()
67- val countryEmissionInfo by viewModel.countryEmissionInfo.collectAsState()
68- val countryAssetEmissions by viewModel.countryAssetEmissions.collectAsState()
72+ val countryList by viewModel.countryList.collectAsState()
73+ val selectedCountry by viewModel.selectedCountry.collectAsState()
74+ val countryEmissionInfo by viewModel.countryEmissionInfo.collectAsState()
75+ val countryAssetEmissions by viewModel.countryAssetEmissions.collectAsState()
6976
70- val isLoadingCountries by viewModel.isLoadingCountries.collectAsState()
71- val isLoadingCountryDetails by viewModel.isLoadingCountryDetails.collectAsState()
77+ val isLoadingCountries by viewModel.isLoadingCountries.collectAsState()
78+ val isLoadingCountryDetails by viewModel.isLoadingCountryDetails.collectAsState()
7279
7380
74- val panelState = remember { PanelState () }
81+ val panelState = remember { PanelState () }
7582
76- val animatedSize = if (panelState.splitter.isResizing) {
77- if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize
78- } else {
79- animateDpAsState(
80- if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize,
81- SpringSpec (stiffness = Spring .StiffnessLow )
82- ).value
83- }
83+ val animatedSize = if (panelState.splitter.isResizing) {
84+ if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize
85+ } else {
86+ animateDpAsState(
87+ if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize,
88+ SpringSpec (stiffness = Spring .StiffnessLow )
89+ ).value
90+ }
8491
8592
86- Row (Modifier .fillMaxSize()) {
93+ Row (Modifier .fillMaxSize()) {
8794
88- if (windowSizeClass.widthSizeClass == WindowWidthSizeClass .Compact ) {
89- Column (Modifier .fillMaxWidth()) {
95+ if (windowSizeClass.widthSizeClass == WindowWidthSizeClass .Compact ) {
96+ Column (Modifier .fillMaxWidth()) {
9097
91- Box (Modifier .height(250 .dp).fillMaxWidth().background(color = Color .LightGray )) {
92- CountryListView (
93- countryList = countryList,
94- selectedCountry = selectedCountry,
95- isLoading = isLoadingCountries
96- ) { country ->
97- viewModel.fetchCountryDetails(country)
98+ Box (
99+ Modifier .height(250 .dp).fillMaxWidth().background(color = Color .LightGray )
100+ ) {
101+ CountryListView (
102+ countryList = countryList,
103+ selectedCountry = selectedCountry,
104+ isLoading = isLoadingCountries
105+ ) { country ->
106+ viewModel.fetchCountryDetails(country)
107+ }
98108 }
99- }
100-
101- Spacer (modifier = Modifier .width(1 .dp).fillMaxWidth())
102- CountryInfoDetailedView (
103- country = selectedCountry,
104- countryEmissionInfo = countryEmissionInfo,
105- countryAssetEmissionsList = countryAssetEmissions,
106- isLoading = isLoadingCountryDetails
107- )
108- }
109- } else {
110109
111- ResizablePanel (
112- Modifier .width(animatedSize).fillMaxHeight(),
113- title = " Countries" ,
114- state = panelState
115- ) {
110+ Spacer (modifier = Modifier .width(1 .dp).fillMaxWidth())
111+ CountryInfoDetailedView (
112+ country = selectedCountry,
113+ countryEmissionInfo = countryEmissionInfo,
114+ countryAssetEmissionsList = countryAssetEmissions,
115+ isLoading = isLoadingCountryDetails
116+ )
117+ }
118+ } else {
116119
117- // Box(Modifier.width(250.dp).fillMaxHeight().background(color = Color.LightGray)) {
120+ ResizablePanel (
121+ Modifier .width(animatedSize).fillMaxHeight(),
122+ title = " Countries" ,
123+ state = panelState
124+ ) {
118125 CountryListView (
119126 countryList = countryList,
120127 selectedCountry = selectedCountry,
121128 isLoading = isLoadingCountries
122129 ) { country ->
123130 viewModel.fetchCountryDetails(country)
124131 }
125- // }
126- }
132+ }
127133
128- Spacer (modifier = Modifier .width(1 .dp).fillMaxHeight())
129- Box (Modifier .fillMaxHeight()) {
130- CountryInfoDetailedView (
131- country = viewModel.selectedCountry.value,
132- countryEmissionInfo = countryEmissionInfo,
133- countryAssetEmissionsList = countryAssetEmissions,
134- isLoading = isLoadingCountryDetails
135- )
134+ VerticalDivider (thickness = 1 .dp, color = Color .DarkGray )
135+ Box (Modifier .fillMaxHeight()) {
136+ CountryInfoDetailedView (
137+ country = viewModel.selectedCountry.value,
138+ countryEmissionInfo = countryEmissionInfo,
139+ countryAssetEmissionsList = countryAssetEmissions,
140+ isLoading = isLoadingCountryDetails
141+ )
142+ }
136143 }
137144 }
138145 }
0 commit comments