Compare commits

...

3 commits

Author SHA1 Message Date
3a8ae37c09
null is not an error
it works now 🎉
2024-08-08 11:44:46 +02:00
439b8aa4f0
add missing methods 2024-08-08 11:44:21 +02:00
ed1a870e1b
this is no longer needed 2024-08-07 13:51:23 +02:00
3 changed files with 35 additions and 8 deletions

View file

@ -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?
}
}

View file

@ -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
}

View file

@ -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)
}
}
}