Skip to content

Instantly share code, notes, and snippets.

@Arunshaik2001
Last active December 25, 2022 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arunshaik2001/b715ab713604594c9aa3e54fb0ef06e2 to your computer and use it in GitHub Desktop.
Save Arunshaik2001/b715ab713604594c9aa3e54fb0ef06e2 to your computer and use it in GitHub Desktop.
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