-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainActivity.kt
More file actions
91 lines (82 loc) · 2.85 KB
/
Copy pathMainActivity.kt
File metadata and controls
91 lines (82 loc) · 2.85 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
package cz.eman.android.interview
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Button
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.core.view.WindowCompat
import cz.eman.android.interview.repository.Repository
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)
setContent {
MaterialTheme {
Scaffold(
modifier = Modifier
.fillMaxSize()
.windowInsetsPadding(
insets = WindowInsets.navigationBars,
),
content = { paddingValues ->
Surface(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues)
) {
content(MainViewModel(Repository())) // DI will be done in next MR
}
}
)
}
}
}
}
@Composable
private fun content(
viewModel: MainViewModel,
) {
Column {
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
color = Color.Blue,
text = "Hello eMan candidate",
)
val data = viewModel.state.collectAsState()
Button(
onClick = {
viewModel.onClick()
}
) {
Text(text = "Generate names with length ${data.value.number+1}")
}
Column {
data.value.names.forEachIndexed { index, name ->
Text(
text = name
)
if (index < data.value.names.lastIndex) {
HorizontalDivider()
}
}
}
}
}