-
Notifications
You must be signed in to change notification settings - Fork 15
/
updatedMediationHomeScreen
306 lines (282 loc) · 9.97 KB
/
updatedMediationHomeScreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
package journey.started.meditation_composecamp.ui.theme
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.GridCells
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.LazyVerticalGrid
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import journey.started.meditation_composecamp.BottomBarItemProperties
import journey.started.meditation_composecamp.GridProperties
import journey.started.meditation_composecamp.R
import java.util.*
@Composable
fun HomeScreen () {
Box(modifier = Modifier
.fillMaxSize()
.background(DeepBlue)) {
Column {
GreetingSection(name = GreetingUpdate())
ChipSection(chips = mutableListOf<String>("Sound Sleep", "Insomnia", "Depression", "Aashiqui") )
ThirdSection()
FourthSection()
FifthSection(properties = listOf(
GridProperties(
title = "Sleep Meditation",
icon = R.drawable.ic_music,
squareColor = BlueViolet2
), GridProperties(
title = "Tips for Sleeping",
icon = R.drawable.ic_videocam,
squareColor = LightGreen2
), GridProperties(
title = "Night Island",
icon = R.drawable.ic_moon,
squareColor = OrangeYellow3
), GridProperties(
title = "Calming Sounds",
icon = R.drawable.ic_headphone,
squareColor = Beige2
), GridProperties(
title = "Morning Prayer",
icon = R.drawable.ic_music,
squareColor = skyblue
), GridProperties(
title = "Focus Zone",
icon = R.drawable.ic_headphone,
squareColor = skyred
)
))
}
BottomBar(list = listOf(
BottomBarItemProperties("Home", R.drawable.ic_home ),
BottomBarItemProperties("Meditation", R.drawable.ic_bubble),
BottomBarItemProperties("Sleep", R.drawable.ic_moon),
BottomBarItemProperties("Music", R.drawable.ic_music),
BottomBarItemProperties("Profile", R.drawable.ic_profile)
), modi = Modifier.align(Alignment.BottomCenter))
}
}
@Composable
fun GreetingSection(name: String) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(15.dp)
){
Column(verticalArrangement = Arrangement.Center) {
Text(text = "Good $name, Vaibhav", color = TextWhite,
style = MaterialTheme.typography.h5)
Text(text = "We wish you a good day!", color = TextWhite,
style = MaterialTheme.typography.body1)
}
Icon(painter = painterResource(id = R.drawable.ic_search), contentDescription ="search",
tint = Color.White,
modifier = Modifier.size(24.dp))
}
}
@Composable
fun ChipSection(chips: List<String>) {
var selectedChipIndex by remember {
mutableStateOf(0)
}
LazyRow{
items(chips.size) {
Box(
modifier = Modifier
.padding(start = 16.dp, top = 16.dp, bottom = 16.dp, end = 4.dp)
.clickable {
selectedChipIndex = it
}
.clip(RoundedCornerShape(10.dp))
.background(
if (selectedChipIndex == it) ButtonBlue
else DarkerButtonBlue
)
.padding(15.dp)
) {
Text(text = chips[it])
}
}
}
}
@Composable
fun ThirdSection() {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.clip(RoundedCornerShape(15.dp))
.background(LightRed)
.padding(15.dp)
){
Column(verticalArrangement = Arrangement.Center) {
Text(text = "Daily Thought", color = TextWhite,
style = MaterialTheme.typography.h5)
Text(text = "Meditation 3 - 10 min", color = TextWhite,
style = MaterialTheme.typography.body1)
}
Box(modifier = Modifier
.clip(CircleShape)
.background(ButtonBlue)
.size(40.dp).clickable { }
,
contentAlignment = Alignment.Center
// we use content alignment for box
){
Icon(painter = painterResource(id = R.drawable.ic_play), contentDescription ="search",
tint = Color.White,
modifier = Modifier.size(16.dp))
}
}
}
@Composable
fun FourthSection(){
Box(contentAlignment = Alignment.CenterStart,
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(10.dp))
.padding(16.dp)
){
Text(text = "Featured", color = TextWhite,
style = MaterialTheme.typography.h5 )
}
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun FifthSection(properties: List<GridProperties>){
LazyVerticalGrid(cells = GridCells.Fixed(2),
contentPadding = PaddingValues(start = 8.dp, end = 8.dp, bottom = 100.dp),
modifier = Modifier.fillMaxHeight()) {
items(properties.size) {
SquareContents( values = properties[it])
}
}
}
@Composable
fun SquareContents(values: GridProperties) {
BoxWithConstraints(modifier = Modifier
.padding(8.dp)
.aspectRatio(1f)
.clip(RoundedCornerShape(10.dp))
.background(values.squareColor)
) {
Box(modifier = Modifier
.fillMaxSize()
.padding(16.dp)) {
Text(text = values.title, style = MaterialTheme.typography.h6,
color = TextWhite,
lineHeight = 26.sp, modifier = Modifier.align(Alignment.TopStart)
)
Icon(painter = painterResource(id = values.icon),
contentDescription = "Music",
modifier = Modifier.align(Alignment.BottomStart),
tint = TextWhite
)
Text(text = "Start",
fontSize = 14.sp,
color = TextWhite,
fontWeight = FontWeight.Bold,
modifier = Modifier
.clickable {
}
.align(Alignment.BottomEnd)
.clip(RoundedCornerShape(10.dp))
.background(ButtonBlue)
.padding(horizontal = 15.dp, vertical = 6.dp)
)
}
}
}
@Composable
fun BottomBar(list: List<BottomBarItemProperties>,
modi: Modifier = Modifier,
//initialSelectIndex: Int = 0
){
var selectedMenuIndex by remember {
mutableStateOf(0)
}
Row(
horizontalArrangement = Arrangement.SpaceAround,
verticalAlignment = Alignment.CenterVertically,
modifier = modi
.fillMaxWidth().background(DeepBlue)
.padding(top = 16.dp, bottom = 16.dp)
) {
list.forEachIndexed {
index, item ->
BottomBarMenuItems(values = item,
isSelected = selectedMenuIndex == index
) {
selectedMenuIndex = index
}
}
}
}
@Composable
fun BottomBarMenuItems(values: BottomBarItemProperties,
isSelected: Boolean = false,
selectColor: Color = ButtonBlue,
selectTextColor: Color = Color.White,
unselectTextColor: Color = AquaBlue,
onClick: () -> Unit
) {
Column(horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.clickable { onClick() }
) {
Box(contentAlignment = Alignment.Center,
modifier = Modifier
.clip(RoundedCornerShape(10.dp))
.background(if (isSelected) ButtonBlue else Color.Transparent)
.padding(10.dp)
){
Icon(painter = painterResource(id = values.iconNav) , contentDescription = values.iconName,
tint = if (isSelected) selectTextColor else unselectTextColor,
modifier = Modifier.size(20.dp))
}
Text(
text = values.iconName,
color = if (isSelected) selectTextColor else unselectTextColor)
}
}
fun GreetingUpdate():String{
val time = Calendar.getInstance()
val timeOfDay = time.get(Calendar.HOUR_OF_DAY)
return when (timeOfDay) {
in 0..11 -> "Morning"
in 12..15 -> "Afternoon"
in 16..20 -> "Evening"
else -> "Night"
}
}
@Preview(showBackground = true)
@Composable
fun HomeScreenPreview() {
MeditationComposeCampTheme {
HomeScreen()
}
}