forked from microsoft/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathV2PersonaChipActivity.kt
374 lines (362 loc) · 16.6 KB
/
V2PersonaChipActivity.kt
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
package com.microsoft.fluentuidemo.demos
import android.os.Bundle
import android.widget.Toast
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.microsoft.fluentui.theme.FluentTheme
import com.microsoft.fluentui.theme.token.FluentAliasTokens
import com.microsoft.fluentui.theme.token.FluentStyle
import com.microsoft.fluentui.theme.token.controlTokens.AvatarStatus.Available
import com.microsoft.fluentui.theme.token.controlTokens.PersonaChipSize
import com.microsoft.fluentui.theme.token.controlTokens.PersonaChipStyle.*
import com.microsoft.fluentui.tokenized.controls.ToggleSwitch
import com.microsoft.fluentui.tokenized.persona.Person
import com.microsoft.fluentui.tokenized.persona.PersonaChip
import com.microsoft.fluentui.tokenized.persona.SearchBarPersonaChip
import com.microsoft.fluentuidemo.R.drawable
import com.microsoft.fluentuidemo.V2DemoActivity
// Tags used for testing
const val PERSONA_CHIP_SMALL_CHIP = "persona chip small"
const val PERSONA_CHIP_MEDIUM_CHIP = "persona chip medium"
const val PERSONA_CHIP_ANONYMOUS = "persona chip ann"
const val PERSONA_CHIP_DISABLED = "persona chip disabled"
const val PERSONA_CHIP_SWITCH = "persona chip switch"
class V2PersonaChipActivity : V2DemoActivity() {
init {
setupActivity(this)
}
override val paramsUrl = "https://github.com/microsoft/fluentui-android/wiki/Controls#params-24"
override val controlTokensUrl =
"https://github.com/microsoft/fluentui-android/wiki/Controls#control-tokens-23"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setActivityContent {
createPersonaChipActivityUI()
}
}
private fun createPersonWithName(): Person {
return Person(
"Allan",
"Munger",
image = drawable.avatar_allan_munger,
email = "[email protected]",
isActive = true,
status = Available,
isOOO = false
)
}
private fun createPersonWithEmail(): Person {
return Person(
"",
"",
image = drawable.avatar_allan_munger,
email = "[email protected]",
isActive = true,
status = Available,
isOOO = false
)
}
private fun createPersonWithNothing(): Person {
return Person(
"",
"",
image = drawable.avatar_allan_munger,
email = "",
isActive = true,
status = Available,
isOOO = false
)
}
@Composable
private fun createPersonaChipActivityUI() {
val textColor =
FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground1].value(
themeMode = FluentTheme.themeMode
)
val brandTextColor =
FluentTheme.aliasTokens.brandForegroundColor[FluentAliasTokens.BrandForegroundColorTokens.BrandForeground1].value(
themeMode = FluentTheme.themeMode
)
var showCloseButton by remember { mutableStateOf(false) }
var selectedList = rememberSaveable(
saver = listSaver(
save = { stateList ->
if (stateList.isNotEmpty()) {
val first = stateList.first()
if (!canBeSaved(first)) {
throw IllegalStateException("${first::class} cannot be saved. By default only types which can be stored in the Bundle class can be saved.")
}
}
stateList.toList()
},
restore = { it.toMutableStateList() }
)) {
mutableStateListOf(
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
)
}
//TODO: Clean Activity using for loops
Box(Modifier.padding(16.dp)) {
LazyColumn(verticalArrangement = Arrangement.spacedBy(16.dp)) {
item {
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
BasicText(
text = "Enable/Disable close button on selected state",
style = TextStyle(
color = brandTextColor,
fontSize = 10.sp
)
)
ToggleSwitch(
modifier = Modifier.testTag(PERSONA_CHIP_SWITCH),
onValueChange = { showCloseButton = !showCloseButton },
checkedState = showCloseButton
)
}
}
item {
BasicText(
text = "Basic Persona chip",
style = TextStyle(color = brandTextColor, fontSize = 20.sp)
)
}
item {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
BasicText(
text = "Person Chip Neutral",
style = TextStyle(color = textColor)
)
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
PersonaChip(
person = createPersonWithName(),
size = PersonaChipSize.Small,
style = Neutral,
selected = selectedList[0],
onClick = { selectedList[0] = !selectedList[0] })
PersonaChip(
person = createPersonWithName(),
style = Neutral,
selected = selectedList[1],
onClick = { selectedList[1] = !selectedList[1] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
BasicText(text = "Person Chip Brand", style = TextStyle(color = textColor))
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
PersonaChip(
modifier = Modifier.testTag(PERSONA_CHIP_SMALL_CHIP),
person = createPersonWithName(),
size = PersonaChipSize.Small,
style = Brand,
selected = selectedList[2],
onClick = { selectedList[2] = !selectedList[2] })
PersonaChip(
modifier = Modifier.testTag(PERSONA_CHIP_MEDIUM_CHIP),
person = createPersonWithName(),
style = Brand,
selected = selectedList[3],
onClick = { selectedList[3] = !selectedList[3] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
BasicText(text = "Person Chip Danger", style = TextStyle(color = textColor))
LazyRow(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
item {
PersonaChip(
person = createPersonWithEmail(),
size = PersonaChipSize.Small,
style = Danger,
selected = selectedList[4],
onClick = { selectedList[4] = !selectedList[4] })
}
item {
PersonaChip(
person = createPersonWithEmail(),
style = Danger,
selected = selectedList[5],
onClick = { selectedList[5] = !selectedList[5] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
}
BasicText(
text = "Person Chip Severe Warning",
style = TextStyle(color = textColor)
)
LazyRow(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
item {
PersonaChip(
person = createPersonWithEmail(),
size = PersonaChipSize.Small,
style = SevereWarning,
selected = selectedList[6],
onClick = { selectedList[6] = !selectedList[6] })
}
item {
PersonaChip(
person = createPersonWithEmail(),
style = SevereWarning,
selected = selectedList[7],
onClick = { selectedList[7] = !selectedList[7] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
}
BasicText(
text = "Person Chip Warning",
style = TextStyle(color = textColor)
)
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
PersonaChip(
modifier = Modifier.testTag(PERSONA_CHIP_ANONYMOUS),
person = createPersonWithNothing(),
size = PersonaChipSize.Small,
style = Warning,
selected = selectedList[8],
onClick = { selectedList[8] = !selectedList[8] })
PersonaChip(
person = createPersonWithNothing(),
style = Warning,
selected = selectedList[9],
onClick = { selectedList[9] = !selectedList[9] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
BasicText(
text = "Person Chip Success",
style = TextStyle(color = textColor)
)
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
PersonaChip(
person = createPersonWithName(),
size = PersonaChipSize.Small,
style = Success,
selected = selectedList[10],
onClick = { selectedList[10] = !selectedList[10] })
PersonaChip(
person = createPersonWithName(),
style = Success,
selected = selectedList[11],
onClick = { selectedList[11] = !selectedList[11] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
BasicText(
text = "Person Chip Disabled",
style = TextStyle(color = textColor)
)
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
PersonaChip(
person = createPersonWithName(),
size = PersonaChipSize.Small,
style = Neutral,
enabled = false,
selected = selectedList[12],
onClick = { selectedList[12] = !selectedList[12] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
PersonaChip(
modifier = Modifier.testTag(PERSONA_CHIP_DISABLED),
person = createPersonWithName(),
style = Neutral,
enabled = false,
selected = selectedList[13],
onClick = { selectedList[13] = !selectedList[13] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
}
}
item {
BasicText(
text = "SearchBox Basic Persona chip",
style = TextStyle(
color = brandTextColor,
fontSize = 20.sp
)
)
}
item {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
BasicText(
text = "Persona chip Neutral",
style = TextStyle(color = textColor)
)
SearchBarPersonaChip(
person = createPersonWithName(),
size = PersonaChipSize.Small,
selected = selectedList[14],
onClick = { selectedList[14] = !selectedList[14] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
BasicText(text = "Persona chip Brand", style = TextStyle(color = textColor))
SearchBarPersonaChip(
person = createPersonWithName(),
style = FluentStyle.Brand,
selected = selectedList[15],
onClick = { selectedList[15] = !selectedList[15] },
onCloseClick = if (showCloseButton) {
{ onClickToast() }
} else null
)
}
}
}
}
}
private fun onClickToast() {
Toast.makeText(
this,
"Clicked on close icon",
Toast.LENGTH_SHORT
).show()
}
}