From 439b8aa4f0306de20e3a14d5830e6caea268c96d Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 8 Aug 2024 11:44:21 +0200 Subject: [PATCH] add missing methods --- .../activity/dashboard/DashboardViewModel.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) 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