From d6ea5800eb119c0e683cb867e014745ccd74d2a6 Mon Sep 17 00:00:00 2001 From: agarcia Date: Fri, 5 Jun 2020 15:01:39 +0200 Subject: [PATCH] Take care when quota available and used are 0 --- .../lib/resources/users/GetRemoteUserQuotaOperation.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.kt index e2e00230..4e6bd84a 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/users/GetRemoteUserQuotaOperation.kt @@ -92,7 +92,7 @@ class GetRemoteUserQuotaOperation : RemoteOperation() { quotaUsed = property.quotaUsedBytes } } - + Timber.d("Quota used: $quotaUsed, QuotaAvailable: $quotaAvailable") // If there's a special case, quota available will contain a negative code // -1, PENDING: Not computed yet, e.g. external storage mounted but folder sizes need scanning // -2, UNKNOWN: Storage not accessible, e.g. external storage with no API to ask for the free space @@ -106,8 +106,11 @@ class GetRemoteUserQuotaOperation : RemoteOperation() { ) } else { val totalQuota = quotaAvailable + quotaUsed - val relativeQuota = (quotaUsed * 100).toDouble() / totalQuota - val roundedRelativeQuota = (relativeQuota * 100).roundToLong() / 100.0 + val roundedRelativeQuota = if (totalQuota > 0) { + val relativeQuota = (quotaUsed * 100).toDouble() / totalQuota + (relativeQuota * 100).roundToLong() / 100.0 + } else 0.0 + RemoteQuota(quotaAvailable, quotaUsed, totalQuota, roundedRelativeQuota) } }