Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup UI #27

Merged
merged 4 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package com.theophiluskibet.calorees.calorees.screens

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Row
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.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
Expand All @@ -29,10 +29,13 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.capitalize
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.theophilus.kibet.caloree.data.model.Caloree
import com.theophiluskibet.caloree.designsystem.components.EmptyScreenComponent
import com.theophiluskibet.caloree.designsystem.components.LoadingComponent
Expand All @@ -58,7 +61,6 @@ fun CaloreesScreen(
.background(MaterialTheme.colors.surface)
.padding(vertical = 8.dp, horizontal = 16.dp),
) {
Text("Calories")
OutlinedTextField(
value = searchString,
onValueChange = {
Expand All @@ -80,11 +82,11 @@ fun CaloreesScreen(
colors =
TextFieldDefaults.textFieldColors(
textColor = MaterialTheme.colors.onBackground,
disabledLabelColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent,
cursorColor = MaterialTheme.colors.background,
disabledLabelColor = MaterialTheme.colors.surface,
focusedIndicatorColor = MaterialTheme.colors.surface,
unfocusedIndicatorColor = MaterialTheme.colors.surface,
disabledIndicatorColor = MaterialTheme.colors.surface,
cursorColor = MaterialTheme.colors.primary,
),
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
keyboardActions =
Expand Down Expand Up @@ -131,10 +133,6 @@ fun CaloreeListSection(
}
}
}

else -> {
EmptyScreenComponent(text = "No data, Please search")
}
}
}

Expand All @@ -146,16 +144,66 @@ fun CaloreeCard(
) {
Card(
elevation = 10.dp,
modifier = Modifier.padding(10.dp),
modifier = Modifier.padding(10.dp).fillMaxWidth(),
onClick = {
onNavigateToDetails(caloryItem.name)
},
border = BorderStroke(1.dp, Color.Black),
border = BorderStroke(1.dp, Color.Cyan),
) {
Column(modifier = Modifier.padding(10.dp)) {
Text(text = "Name: ${caloryItem.name}")
Spacer(modifier = Modifier.height(5.dp))
Text(text = "Calories: ${caloryItem.calories}")
Row(
modifier = Modifier.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = caloryItem.name.capitalize(),
fontSize = 24.sp,
color = Color.Black,
modifier = Modifier.weight(1f),
)
Column(modifier = Modifier.padding(horizontal = 16.dp).weight(2f).fillMaxWidth()) {
Row(
modifier = Modifier.padding(vertical = 8.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = "Calories:",
fontSize = 16.sp,
)
Text(
text = "${caloryItem.calories} grams",
fontSize = 12.sp,
)
}
Row(
modifier = Modifier.padding(vertical = 8.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = "Proteins:",
fontSize = 16.sp,
)
Text(
text = "${caloryItem.proteinGrams} grams",
fontSize = 12.sp,
)
}
Row(
modifier = Modifier.padding(vertical = 8.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = "Fats:",
fontSize = 16.sp,
)
Text(
text = "${caloryItem.fatTotalGrams} grams",
fontSize = 12.sp,
)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.theophiluskibet.calorees.details.screens

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
Expand All @@ -15,9 +20,9 @@ import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.theophiluskibet.caloree.designsystem.components.EmptyScreenComponent
import com.theophiluskibet.caloree.designsystem.components.LoadingComponent
import com.theophiluskibet.calorees.details.utils.DetailsUiState
Expand Down Expand Up @@ -64,14 +69,35 @@ fun DetailScreen(
}

is DetailsUiState.Success -> {
Column(
modifier =
Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text("${caloreeUiState.data.calories}")
Column {
Row {
DetailItem(
modifier = Modifier.weight(1f),
borderStroke = BorderStroke(width = 0.5.dp, color = Color.Black),
title = "Calories",
value = "${caloreeUiState.data.calories}kcal",
)
DetailItem(
modifier = Modifier.weight(1f),
borderStroke = BorderStroke(width = 0.5.dp, color = Color.Black),
title = "Proteins",
value = "${caloreeUiState.data.proteinGrams}grams",
)
}
Row {
DetailItem(
modifier = Modifier.weight(1f),
borderStroke = BorderStroke(width = 0.5.dp, color = Color.Black),
title = "Carbohydrates",
value = "${caloreeUiState.data.carbohydratesTotalGrams}grams",
)
DetailItem(
modifier = Modifier.weight(1f),
borderStroke = BorderStroke(width = 0.5.dp, color = Color.Black),
title = "Fats",
value = "${caloreeUiState.data.fatTotalGrams}grams",
)
}
}
}

Expand All @@ -82,3 +108,29 @@ fun DetailScreen(
}
}
}

@Composable
fun DetailItem(
modifier: Modifier,
borderStroke: BorderStroke,
title: String,
value: String,
) {
Card(
modifier =
modifier
.padding(8.dp),
border = borderStroke,
) {
Column(
modifier =
Modifier
.fillMaxWidth()
.background(MaterialTheme.colors.surface)
.padding(16.dp),
) {
Text(text = title)
Text(text = value)
}
}
}