-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
details screen navigation and UI refinement
- Loading branch information
Showing
4 changed files
with
101 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 95 additions & 57 deletions
152
...ain/java/com/example/kocelainterview/presentation/ship_details_screen/ShipDetailScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,139 @@ | ||
package com.example.kocelainterview.presentation.ship_details_screen | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material3.Card | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import coil.compose.rememberAsyncImagePainter | ||
import com.example.kocelainterview.domain.model.ShipDetail | ||
|
||
|
||
@Composable | ||
fun ShipDetailScreen( | ||
viewModel: ShipDetailViewModel = hiltViewModel() | ||
) { | ||
|
||
val state = viewModel.state.value | ||
|
||
Box (modifier = Modifier.fillMaxSize()){ | ||
state.ship?.let { shipDetail -> | ||
LazyColumn( | ||
modifier = Modifier.fillMaxSize(), | ||
contentPadding = PaddingValues(20.dp) | ||
) { | ||
item{ | ||
Row ( | ||
modifier = Modifier.fillMaxWidth(), | ||
horizontalArrangement = Arrangement.SpaceBetween | ||
){ | ||
Text( | ||
text = "$shipDetail.ship_name. $shipDetail.weight_kg ($shipDetail.year_built)", | ||
style = MaterialTheme.typography.bodyMedium, | ||
modifier = Modifier.weight(8f) | ||
) | ||
Text( | ||
text = if (shipDetail.active) "active" else "inactive", | ||
color = if (shipDetail.active) Color.Green else Color.Red, | ||
fontStyle = FontStyle.Italic, | ||
textAlign = TextAlign.End, | ||
style = MaterialTheme.typography.bodyMedium, | ||
modifier = Modifier | ||
.align(Alignment.CenterVertically) | ||
.weight(2f) | ||
) | ||
Spacer(modifier = Modifier.height(15.dp)) | ||
Text( | ||
text = "More Details", | ||
style = MaterialTheme.typography.bodyMedium | ||
) | ||
Spacer(modifier = Modifier.height(15.dp)) | ||
Text( | ||
text = "$shipDetail.ship_type " , | ||
fontStyle = FontStyle.Italic, | ||
style = MaterialTheme.typography.bodyMedium, | ||
) | ||
Spacer(modifier = Modifier.height(4.dp)) | ||
Text( | ||
text = "$shipDetail.home_port", | ||
fontStyle = FontStyle.Italic, | ||
style = MaterialTheme.typography.bodyMedium | ||
) | ||
} | ||
|
||
} | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(16.dp) | ||
) { | ||
|
||
Text(text = "Ships Details", style = MaterialTheme.typography.bodyMedium) | ||
|
||
Spacer(modifier = Modifier.height(24.dp)) | ||
|
||
LazyColumn { | ||
if (state.isLoading) { | ||
item { | ||
CircularProgressIndicator( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.wrapContentSize(align = Alignment.Center) | ||
) | ||
} | ||
} | ||
state.ship?.let { shipDetail -> | ||
item { | ||
ShipDetailImageCard(shipDetail = shipDetail) | ||
} | ||
} | ||
} | ||
|
||
if (state.error.isNotBlank()){ | ||
if (state.error.isNotBlank()) { | ||
Text( | ||
text =state.error, | ||
text = state.error, | ||
color = Color.Red, | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 20.dp) | ||
.align(Alignment.Center) | ||
.align(Alignment.CenterHorizontally) | ||
) | ||
} | ||
|
||
if (state.isLoading){ | ||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center)) | ||
} | ||
|
||
} | ||
|
||
|
||
@Composable | ||
fun ShipDetailImageCard(shipDetail: ShipDetail) { | ||
val imagePainter = rememberAsyncImagePainter(model = shipDetail.image) | ||
Card( | ||
shape = MaterialTheme.shapes.medium, | ||
modifier = Modifier.padding(16.dp) | ||
|
||
) { | ||
Box { | ||
|
||
Image( | ||
painter = imagePainter, | ||
contentDescription = null, | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.height(200.dp), | ||
contentScale = ContentScale.FillBounds | ||
) | ||
|
||
Surface( | ||
color = MaterialTheme.colorScheme.onSurface.copy(alpha = .3f), | ||
modifier = Modifier | ||
.align( | ||
Alignment.BottomCenter | ||
), | ||
contentColor = MaterialTheme.colorScheme.surface | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(4.dp) | ||
) { | ||
|
||
//Text(text = "Ship: ${shipDetail.ship_name}") | ||
|
||
Text(text = "Home Port: ${shipDetail.home_port}") | ||
|
||
Text( | ||
text = if (shipDetail.active) "Active" else "Inactive", | ||
color = if (shipDetail.active) Color.Green else Color.Red, | ||
style = MaterialTheme.typography.bodyLarge | ||
) | ||
|
||
|
||
//Text(text = "Ship Type: ${shipDetail.ship_type}") | ||
|
||
|
||
Text(text = "Year Built: ${shipDetail.year_built}") | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
} | ||
|
||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters