-
-
Save Arunshaik2001/b715ab713604594c9aa3e54fb0ef06e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
val mainViewModel: MainViewModel by viewModels() | |
super.onCreate(savedInstanceState) | |
setContent { | |
GRPC_APP_DEMOTheme { | |
// A surface container using the 'background' color from the theme | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = MaterialTheme.colors.background | |
) { | |
Scaffold( | |
topBar = { | |
TopAppBar( | |
title = { | |
Text("GRPC Demo") | |
} | |
) | |
} | |
) { | |
Column( | |
modifier = Modifier | |
.padding(24.dp) | |
){ | |
Row( | |
modifier = Modifier.fillMaxWidth() | |
){ | |
OutlinedTextField( | |
enabled = mainViewModel.hostEnabled.value, | |
value = mainViewModel.ip.value, | |
onValueChange = { | |
mainViewModel.onIpChange(it) | |
}, | |
modifier = Modifier | |
.fillMaxWidth() | |
.weight(1f), | |
placeholder = { | |
Text("IP address") | |
}, | |
label = { | |
Text("Server") | |
} | |
) | |
Spacer(modifier = Modifier.size(16.dp)) | |
OutlinedTextField( | |
enabled = mainViewModel.portEnabled.value, | |
value = mainViewModel.port.value, | |
onValueChange = { | |
mainViewModel.onPortChange(it) | |
}, | |
modifier = Modifier | |
.fillMaxWidth() | |
.weight(1f), | |
placeholder = { | |
Text("Port") | |
}, | |
label = { | |
Text("Port") | |
} | |
) | |
} | |
Row( | |
modifier = Modifier.fillMaxWidth() | |
){ | |
Button( | |
enabled = mainViewModel.startEnabled.value, | |
onClick = { | |
mainViewModel.start() | |
}, | |
modifier = Modifier | |
.fillMaxWidth() | |
.weight(1f) | |
) { | |
Text("Start") | |
} | |
Spacer(modifier = Modifier.size(16.dp)) | |
Button( | |
enabled = mainViewModel.endEnabled.value, | |
onClick = { | |
mainViewModel.exit() | |
}, | |
modifier = Modifier | |
.fillMaxWidth() | |
.weight(1f) | |
) { | |
Text("End") | |
} | |
} | |
Button( | |
enabled = mainViewModel.buttonsEnabled.value, | |
onClick = { | |
mainViewModel.sayHello("Arun") | |
}, | |
modifier = Modifier.fillMaxWidth() | |
) { | |
Text("Simple RPC: Say Hello") | |
} | |
Text("Result: ${mainViewModel.result.value}") | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment