Compare commits
3 commits
3ddbe78fe8
...
3a8ae37c09
Author | SHA1 | Date | |
---|---|---|---|
3a8ae37c09 | |||
439b8aa4f0 | |||
ed1a870e1b |
3 changed files with 35 additions and 8 deletions
|
@ -52,7 +52,8 @@ class DashboardActivity : ComponentActivity() {
|
|||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
dashboardViewModel.refreshError.collect {
|
||||
Toast.makeText(baseContext, it, Toast.LENGTH_SHORT).show()
|
||||
if (it != null)
|
||||
Toast.makeText(baseContext, it, Toast.LENGTH_SHORT).show()
|
||||
} // TODO any better way?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,4 +113,36 @@ class DashboardViewModel(
|
|||
)
|
||||
}
|
||||
|
||||
fun toggleInstance(instance: RentedInstance) {
|
||||
val deferred =
|
||||
if (instance.status == "running") {
|
||||
vastApi.startInstance(instance.rentalId)
|
||||
} else {
|
||||
vastApi.stopInstance(instance.rentalId)
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
deferred.await()
|
||||
refresh()
|
||||
} catch (e: Exception) {
|
||||
_refreshError.value = e.message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteInstance(instance: RentedInstance) {
|
||||
val deferred = vastApi.deleteInstance(instance.rentalId)
|
||||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
deferred.await()
|
||||
refresh()
|
||||
} catch (e: Exception) {
|
||||
_refreshError.value = e.message
|
||||
}
|
||||
}
|
||||
} // TODO once again these methods share some code and more probably will so why not move the shared stuff
|
||||
// OR not refresh but refresh only instances or even better don't refresh instances but delete or edit that one
|
||||
|
||||
}
|
|
@ -108,13 +108,7 @@ class LoginActivity : ComponentActivity() {
|
|||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
val loading by loginViewModel.fullscreenLoading.collectAsState()
|
||||
|
||||
if (loading) {
|
||||
CircularProgressIndicator()
|
||||
} else {
|
||||
LoginApp(loginViewModel)
|
||||
}
|
||||
LoginApp(loginViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue