From 0b4bc2e524b4eaccb97929ee404fceeb3a04596d Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 8 Aug 2024 13:53:59 +0200 Subject: [PATCH] make helper functions in rented instance data class --- .../vastapp/vastai/data/RentedInstance.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/src/main/java/eu/m724/vastapp/vastai/data/RentedInstance.kt b/app/src/main/java/eu/m724/vastapp/vastai/data/RentedInstance.kt index c3570fc..91b0140 100644 --- a/app/src/main/java/eu/m724/vastapp/vastai/data/RentedInstance.kt +++ b/app/src/main/java/eu/m724/vastapp/vastai/data/RentedInstance.kt @@ -72,4 +72,26 @@ data class RentedInstance( ) } } + + /** + * returns whether the instance is running + * this is true also if the instance is stopping + * vice versa, false if stopped or starting + * @return is the instance running + */ + fun isRunning(): Boolean { + return status == "running" + } + + fun isStopping(): Boolean { + return status == "running" && targetStatus == "stopped" + } + + fun isStarting(): Boolean { + return status == "exited" && targetStatus == "running" + } + + fun isChangingState(): Boolean { + return isStopping() || isStarting() + } } \ No newline at end of file