@@ -5,14 +5,17 @@ import androidx.compose.foundation.background
5
5
import androidx.compose.foundation.clickable
6
6
import androidx.compose.foundation.layout.Arrangement
7
7
import androidx.compose.foundation.layout.Box
8
+ import androidx.compose.foundation.layout.Column
8
9
import androidx.compose.foundation.layout.PaddingValues
10
+ import androidx.compose.foundation.layout.fillMaxHeight
9
11
import androidx.compose.foundation.layout.fillMaxSize
10
12
import androidx.compose.foundation.layout.fillMaxWidth
11
13
import androidx.compose.foundation.layout.height
12
14
import androidx.compose.foundation.layout.padding
13
15
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
14
16
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
15
17
import androidx.compose.foundation.lazy.staggeredgrid.items
18
+ import androidx.compose.foundation.lazy.staggeredgrid.itemsIndexed
16
19
import androidx.compose.foundation.shape.RoundedCornerShape
17
20
import androidx.compose.material.icons.Icons
18
21
import androidx.compose.material.icons.filled.Add
@@ -31,14 +34,17 @@ import androidx.compose.ui.Modifier
31
34
import androidx.compose.ui.draw.clip
32
35
import androidx.compose.ui.graphics.Color
33
36
import androidx.compose.ui.platform.LocalContext
37
+ import androidx.compose.ui.text.capitalize
34
38
import androidx.compose.ui.text.font.FontWeight
39
+ import androidx.compose.ui.tooling.preview.Preview
35
40
import androidx.compose.ui.unit.dp
36
41
import androidx.compose.ui.unit.sp
37
42
import androidx.hilt.navigation.compose.hiltViewModel
38
43
import androidx.navigation.NavDestination
39
44
import androidx.navigation.NavHostController
40
45
import com.techuntried.notes.model.NoteEntity
41
46
import com.techuntried.notes.navigation.Screens
47
+ import java.util.Locale
42
48
43
49
@OptIn(ExperimentalMaterial3Api ::class )
44
50
@Composable
@@ -51,14 +57,26 @@ fun HomeScreen(onAddClick: () -> Unit, onNoteClick: (id: Long) -> Unit) {
51
57
.fillMaxSize()
52
58
.padding(it)
53
59
) {
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
+ )
54
71
LazyVerticalStaggeredGrid (
55
72
columns = StaggeredGridCells .Fixed (2 ),
56
73
contentPadding = PaddingValues (8 .dp),
57
74
horizontalArrangement = Arrangement .spacedBy(8 .dp),
58
75
verticalItemSpacing = 8 .dp
59
76
) {
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)
62
80
}
63
81
}
64
82
FloatingActionButton (
@@ -78,22 +96,43 @@ fun HomeScreen(onAddClick: () -> Unit, onNoteClick: (id: Long) -> Unit) {
78
96
@Composable
79
97
fun Toolbar () {
80
98
TopAppBar (
81
- title = { Text (text = " Home" ) },
82
-
83
- )
99
+ title = {
100
+ Text (text = " Home" )
101
+ },
102
+ )
84
103
}
85
104
86
105
@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 (
89
108
modifier = Modifier
90
- .fillMaxWidth()
91
- .height(100 .dp)
92
109
.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
96
114
) {
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
+
98
135
}
99
136
}
137
+
138
+
0 commit comments