diff --git a/app/src/main/java/eu/m724/vastapp/activity/dashboard/DashboardViewModel.kt b/app/src/main/java/eu/m724/vastapp/activity/dashboard/DashboardViewModel.kt index cade343..612a2e4 100644 --- a/app/src/main/java/eu/m724/vastapp/activity/dashboard/DashboardViewModel.kt +++ b/app/src/main/java/eu/m724/vastapp/activity/dashboard/DashboardViewModel.kt @@ -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 + } \ No newline at end of file