@@ -5,14 +5,17 @@ import androidx.compose.foundation.background
55import androidx.compose.foundation.clickable
66import androidx.compose.foundation.layout.Arrangement
77import androidx.compose.foundation.layout.Box
8+ import androidx.compose.foundation.layout.Column
89import androidx.compose.foundation.layout.PaddingValues
10+ import androidx.compose.foundation.layout.fillMaxHeight
911import androidx.compose.foundation.layout.fillMaxSize
1012import androidx.compose.foundation.layout.fillMaxWidth
1113import androidx.compose.foundation.layout.height
1214import androidx.compose.foundation.layout.padding
1315import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
1416import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
1517import androidx.compose.foundation.lazy.staggeredgrid.items
18+ import androidx.compose.foundation.lazy.staggeredgrid.itemsIndexed
1619import androidx.compose.foundation.shape.RoundedCornerShape
1720import androidx.compose.material.icons.Icons
1821import androidx.compose.material.icons.filled.Add
@@ -31,14 +34,17 @@ import androidx.compose.ui.Modifier
3134import androidx.compose.ui.draw.clip
3235import androidx.compose.ui.graphics.Color
3336import androidx.compose.ui.platform.LocalContext
37+ import androidx.compose.ui.text.capitalize
3438import androidx.compose.ui.text.font.FontWeight
39+ import androidx.compose.ui.tooling.preview.Preview
3540import androidx.compose.ui.unit.dp
3641import androidx.compose.ui.unit.sp
3742import androidx.hilt.navigation.compose.hiltViewModel
3843import androidx.navigation.NavDestination
3944import androidx.navigation.NavHostController
4045import com.techuntried.notes.model.NoteEntity
4146import com.techuntried.notes.navigation.Screens
47+ import java.util.Locale
4248
4349@OptIn(ExperimentalMaterial3Api ::class )
4450@Composable
@@ -51,14 +57,26 @@ fun HomeScreen(onAddClick: () -> Unit, onNoteClick: (id: Long) -> Unit) {
5157 .fillMaxSize()
5258 .padding(it)
5359 ) {
60+ val pastelLightColors = listOf (
61+ Color (0xFFF5BB00 ), // Pastel Yellow
62+ Color (0xFFEC9A29 ), // Pastel Orange
63+ Color (0xFF8FD6BD ), // Pastel Green
64+ Color (0xFF6FA0A5 ), // Pastel Cyan
65+ Color (0xFFC8A2C8 ), // Pastel Purple
66+ Color (0xFFE0BBE4 ), // Pastel Lavender
67+ Color (0xFFF4CEE3 ), // Pastel Pink
68+ Color (0xFFA3D5D1 ), // Pastel Blue
69+ Color (0xFFE9D0C3 ) // Pastel Peach
70+ )
5471 LazyVerticalStaggeredGrid (
5572 columns = StaggeredGridCells .Fixed (2 ),
5673 contentPadding = PaddingValues (8 .dp),
5774 horizontalArrangement = Arrangement .spacedBy(8 .dp),
5875 verticalItemSpacing = 8 .dp
5976 ) {
60- items(notes.value) {
61- NoteItem (noteEntity = it, onNoteClick)
77+ itemsIndexed(notes.value) { index, item ->
78+ val color = pastelLightColors[index % pastelLightColors.size]
79+ NoteItem (noteEntity = item, color, onNoteClick)
6280 }
6381 }
6482 FloatingActionButton (
@@ -78,22 +96,43 @@ fun HomeScreen(onAddClick: () -> Unit, onNoteClick: (id: Long) -> Unit) {
7896@Composable
7997fun Toolbar () {
8098 TopAppBar (
81- title = { Text (text = " Home" ) },
82-
83- )
99+ title = {
100+ Text (text = " Home" )
101+ },
102+ )
84103}
85104
86105@Composable
87- fun NoteItem (noteEntity : NoteEntity , onNoteClick : (id: Long ) -> Unit ) {
88- Box (
106+ fun NoteItem (noteEntity : NoteEntity , color : Color , onNoteClick : (id: Long ) -> Unit ) {
107+ Column (
89108 modifier = Modifier
90- .fillMaxWidth()
91- .height(100 .dp)
92109 .clip(RoundedCornerShape (12 .dp))
93- .background(Color .Black )
94- .clickable { onNoteClick(noteEntity.id) },
95- contentAlignment = Alignment .Center
110+ .background(color)
111+ .clickable { onNoteClick(noteEntity.id) }
112+ .padding(16 .dp),
113+ horizontalAlignment = Alignment .Start
96114 ) {
97- Text (text = noteEntity.title, fontSize = 18 .sp, fontWeight = FontWeight .Bold )
115+ if (noteEntity.title.isNotBlank()) {
116+ Text (
117+ modifier = Modifier .padding(bottom = 8 .dp),
118+ text = noteEntity.title.take(50 )
119+ .replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale .getDefault()) else it.toString() },
120+ fontSize = 18 .sp,
121+ fontWeight = FontWeight .Bold ,
122+ color = Color .White ,
123+ )
124+ }
125+
126+ if (noteEntity.description.isNotBlank()) {
127+ Text (
128+ text = noteEntity.description.take(100 ),
129+ fontSize = 16 .sp,
130+ fontWeight = FontWeight .Normal ,
131+ color = Color .White
132+ )
133+ }
134+
98135 }
99136}
137+
138+
0 commit comments