mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 00:16:09 +00:00
Handle pending, unknown and unlimited quota
This commit is contained in:
parent
ec08bfbd7a
commit
a21614fd5a
@ -49,6 +49,16 @@ import java.util.ArrayList;
|
|||||||
public class GetRemoteUserQuotaOperation extends RemoteOperation {
|
public class GetRemoteUserQuotaOperation extends RemoteOperation {
|
||||||
|
|
||||||
static public class Quota {
|
static public class Quota {
|
||||||
|
|
||||||
|
// Not computed yet, e.g. external storage mounted but folder sizes need scanning
|
||||||
|
public static final int PENDING_FREE_QUOTA = -1;
|
||||||
|
|
||||||
|
// Storage not accessible, e.g. external storage with no API to ask for the free space
|
||||||
|
public static final int UNKNOWN_FREE_QUOTA = -2;
|
||||||
|
|
||||||
|
// Quota using all the storage
|
||||||
|
public static final int UNLIMITED_FREE_QUOTA = -3;
|
||||||
|
|
||||||
long mFree, mUsed, mTotal;
|
long mFree, mUsed, mTotal;
|
||||||
double mRelative;
|
double mRelative;
|
||||||
|
|
||||||
@ -149,17 +159,30 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation {
|
|||||||
// parse data from remote folder
|
// parse data from remote folder
|
||||||
WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath());
|
WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath());
|
||||||
|
|
||||||
|
// If there's a special case, available bytes will contain a negative code
|
||||||
|
if (we.quotaAvailableBytes().compareTo(new BigDecimal(0)) == -1) {
|
||||||
|
|
||||||
|
return new Quota(
|
||||||
|
we.quotaAvailableBytes().longValue(),
|
||||||
|
we.quotaUsedBytes().longValue(),
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
BigDecimal totalQuota = we.quotaAvailableBytes().add(we.quotaUsedBytes());
|
BigDecimal totalQuota = we.quotaAvailableBytes().add(we.quotaUsedBytes());
|
||||||
|
|
||||||
BigDecimal relativeQuota = we.quotaUsedBytes().multiply(new BigDecimal(100)).divide(totalQuota);
|
BigDecimal relativeQuota = we.quotaUsedBytes()
|
||||||
|
.multiply(new BigDecimal(100))
|
||||||
|
.divide(totalQuota);
|
||||||
|
|
||||||
Quota quota = new Quota(
|
return new Quota(
|
||||||
we.quotaAvailableBytes().longValue(),
|
we.quotaAvailableBytes().longValue(),
|
||||||
we.quotaUsedBytes().longValue(),
|
we.quotaUsedBytes().longValue(),
|
||||||
totalQuota.longValue(),
|
totalQuota.longValue(),
|
||||||
relativeQuota.doubleValue()
|
relativeQuota.doubleValue()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return quota;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user