@@ -36,6 +36,7 @@ import androidx.compose.material3.TextField
36
36
import androidx.compose.material3.TopAppBarDefaults
37
37
import androidx.compose.runtime.Composable
38
38
import androidx.compose.runtime.getValue
39
+ import androidx.compose.runtime.livedata.observeAsState
39
40
import androidx.compose.runtime.mutableStateOf
40
41
import androidx.compose.runtime.remember
41
42
import androidx.compose.runtime.setValue
@@ -44,6 +45,7 @@ import androidx.compose.ui.Modifier
44
45
import androidx.compose.ui.res.stringResource
45
46
import androidx.compose.ui.tooling.preview.Preview
46
47
import androidx.compose.ui.unit.dp
48
+ import androidx.core.view.WindowCompat
47
49
48
50
@OptIn(ExperimentalMaterial3Api ::class )
49
51
class MainActivity : AppCompatActivity () {
@@ -53,6 +55,10 @@ class MainActivity : AppCompatActivity() {
53
55
override fun onCreate (savedInstanceState : Bundle ? ) {
54
56
super .onCreate(savedInstanceState)
55
57
58
+ // Turn off the decor fitting system windows, which allows
59
+ // us to handle insets, including IME animations.
60
+ WindowCompat .setDecorFitsSystemWindows(window, false )
61
+
56
62
setContent {
57
63
MaterialTheme {
58
64
Surface (
@@ -111,9 +117,24 @@ class MainActivity : AppCompatActivity() {
111
117
textFieldLabel : String = stringResource(id = R .string.txt_encrypt_label_hint)
112
118
) {
113
119
TextFieldComponent (textFieldLabel)
120
+ // //////////////////
121
+ val name = viewModel.encryptedString.observeAsState().value
122
+ // if (name.isNotEmpty()) {
123
+ Text (
124
+ text = " Hello, $name !" ,
125
+ modifier = Modifier .padding(bottom = 8 .dp),
126
+ style = MaterialTheme .typography.bodyMedium
127
+ )
128
+ // }
129
+ // //////////////////
114
130
Spacer (modifier = Modifier .height(height = 5 .dp))
115
131
Row {
116
- ButtonComponent (buttonText)
132
+ Button (
133
+ onClick = { viewModel.encryptString(" Fernando Cejas" ) },
134
+ ) {
135
+ Text (text = buttonText)
136
+ }
137
+ // ButtonComponent(buttonText)
117
138
}
118
139
}
119
140
@@ -133,7 +154,7 @@ class MainActivity : AppCompatActivity() {
133
154
@Composable
134
155
fun ButtonComponent (buttonText : String ) {
135
156
Button (
136
- onClick = { },
157
+ onClick = { viewModel.encryptString( " Fernando " ) },
137
158
) {
138
159
Text (text = buttonText)
139
160
}
0 commit comments