-
Notifications
You must be signed in to change notification settings - Fork 3
/
Screens.kt
138 lines (129 loc) · 3.2 KB
/
Screens.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
package com.jshvarts.conditionalbottomnav
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.jshvarts.conditionalbottomnav.model.SnackbarManager
import kotlin.random.Random
@Composable
fun HomeScreen(
onItemClick: (Int) -> Unit,
modifier: Modifier = Modifier
) {
val homeItems = remember { HomeItemRepo.getItems() }
LazyColumn(
verticalArrangement = Arrangement.spacedBy(12.dp),
contentPadding = PaddingValues(24.dp),
modifier = modifier
) {
items(homeItems) { item ->
HomeItemCard(item) {
onItemClick(it.id)
}
}
}
}
@Composable
fun CalendarScreen() {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
Text(
text = stringResource(id = R.string.calendar),
style = MaterialTheme.typography.h6
)
}
}
@Composable
fun ChatScreen() {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
Text(
text = stringResource(id = R.string.chat),
style = MaterialTheme.typography.h6
)
}
}
@Composable
fun HomeItemDetailScreen(
itemId: Int,
upPress: () -> Unit
) {
val item = remember(itemId) { HomeItemRepo.getItem(itemId) }
Scaffold(
topBar = {
TopAppBar(
backgroundColor = Color.White,
navigationIcon = {
IconButton(onClick = upPress) {
Icon(
imageVector = Icons.Filled.Close,
contentDescription = stringResource(id = R.string.close)
)
}
},
title = {
Text(
text = item.text,
modifier = Modifier.fillMaxWidth(),
style = MaterialTheme.typography.h6
)
}
)
}
) { innerPaddingModifier ->
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.padding(innerPaddingModifier)
.fillMaxSize()
) {
if (ifRandomlyFailed()) {
SnackbarManager.showMessage(R.string.item_lookup_failed_error)
} else {
Text(
text = "Home Item $itemId",
style = MaterialTheme.typography.h6
)
}
}
}
}
@Composable
fun HomeItemCard(
item: HomeItem,
onClick: (HomeItem) -> Unit
) {
Row(
modifier = Modifier
.fillMaxWidth()
.background(
color = Color.LightGray,
shape = RoundedCornerShape(4.dp)
)
.clickable { onClick(item) }
) {
Text(
text = item.text,
style = MaterialTheme.typography.h5,
modifier = Modifier
.padding(16.dp)
)
}
}
private fun ifRandomlyFailed() = Random.nextBoolean()