-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathHomeSlidingToolbar.kt
More file actions
142 lines (135 loc) · 4.64 KB
/
HomeSlidingToolbar.kt
File metadata and controls
142 lines (135 loc) · 4.64 KB
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
// fragments/HomeSlidingToolbar.kt
package com.pennapps.labs.pennmobile.fragments
import android.content.Context
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.preference.PreferenceManager
import com.pennapps.labs.pennmobile.R
import com.pennapps.labs.pennmobile.data_classes.HomeSlidingToolbarElement
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.style.TextAlign
val homeSlidingToolbarItems = listOf(
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_dining_square,
title = "Dining",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_gsr_square,
title = "GSR",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_laundry_square,
title = "Laundry",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_news2,
title = "News",
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_contacts2,
title = "Contacts", // TODO Confirm rename from Penn Contacts
),
HomeSlidingToolbarElement(
iconRes = R.drawable.ic_fitness2,
title = "Fitness",
),
)
@Composable
fun HomeSlidingToolbar(context: Context = LocalContext.current, onFeatureClick: (Int) -> Unit) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
val firstName = sharedPreferences.getString(context.getString(R.string.first_name), null) ?: "Guest"
val textColor = if (isSystemInDarkTheme()) {
colorResource(id = R.color.color_primary_light)
} else {
colorResource(id = R.color.color_primary_dark)
}
Column(
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(Modifier.padding(10.dp))
Text(
text = "Welcome, $firstName!",
fontSize = 24.sp,
color = textColor,
fontWeight = FontWeight.Bold,
)
Spacer(Modifier.padding(10.dp))
LazyRow {
item{
Spacer(modifier = Modifier.width(8.dp))
}
items(homeSlidingToolbarItems.size) { index ->
HomeSlidingToolbarItem(index, onFeatureClick)
}
item{
Spacer(modifier = Modifier.width(8.dp))
}
}
}
}
@Composable
fun HomeSlidingToolbarItem(
index: Int,
onFeatureClick: (Int) -> Unit
) {
val feature = homeSlidingToolbarItems[index]
val lastPaddingEnd = if (index == homeSlidingToolbarItems.size - 1) 12.dp else 0.dp
// Set the textColor and backgroundColor
val textColor = colorResource(R.color.gray)
val backgroundColor = if (isSystemInDarkTheme()) {
colorResource(id = R.color.color_background_dark)
} else {
colorResource(id = R.color.color_background)
}
Box(
modifier = Modifier
.padding(6.dp)
.shadow(8.dp, RoundedCornerShape(20.dp)),
contentAlignment = Alignment.TopCenter
) {
Column(
modifier = Modifier
.clip(RoundedCornerShape(20.dp))
.background(backgroundColor)
.clickable { onFeatureClick(index) }
.size(90.dp, 130.dp)
.padding(8.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
// Icon Container
Image(
painter = painterResource(id = feature.iconRes),
contentDescription = feature.title,
modifier = Modifier
.padding(top = 8.dp)
.size(70.dp)
.align(Alignment.CenterHorizontally)
)
Spacer(modifier = Modifier.height(15.dp))
Text(
text = feature.title,
color = textColor,
fontWeight = FontWeight.Bold,
fontSize = 13.sp,
textAlign = TextAlign.Center
)
}
}
}