mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +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 { | ||||
| 
 | ||||
|     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; | ||||
|         double mRelative; | ||||
| 
 | ||||
| @ -149,17 +159,30 @@ public class GetRemoteUserQuotaOperation extends RemoteOperation { | ||||
|         // parse data from remote folder | ||||
|         WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], client.getWebdavUri().getPath()); | ||||
| 
 | ||||
|         BigDecimal totalQuota = we.quotaAvailableBytes().add(we.quotaUsedBytes()); | ||||
|         // If there's a special case, available bytes will contain a negative code | ||||
|         if (we.quotaAvailableBytes().compareTo(new BigDecimal(0)) == -1) { | ||||
| 
 | ||||
|         BigDecimal relativeQuota = we.quotaUsedBytes().multiply(new BigDecimal(100)).divide(totalQuota); | ||||
|             return new Quota( | ||||
|                     we.quotaAvailableBytes().longValue(), | ||||
|                     we.quotaUsedBytes().longValue(), | ||||
|                     0, | ||||
|                     0 | ||||
|             ); | ||||
| 
 | ||||
|         Quota quota = new Quota( | ||||
|                 we.quotaAvailableBytes().longValue(), | ||||
|                 we.quotaUsedBytes().longValue(), | ||||
|                 totalQuota.longValue(), | ||||
|                 relativeQuota.doubleValue() | ||||
|         ); | ||||
|         } else { | ||||
| 
 | ||||
|         return quota; | ||||
|             BigDecimal totalQuota = we.quotaAvailableBytes().add(we.quotaUsedBytes()); | ||||
| 
 | ||||
|             BigDecimal relativeQuota = we.quotaUsedBytes() | ||||
|                     .multiply(new BigDecimal(100)) | ||||
|                     .divide(totalQuota); | ||||
| 
 | ||||
|             return new Quota( | ||||
|                     we.quotaAvailableBytes().longValue(), | ||||
|                     we.quotaUsedBytes().longValue(), | ||||
|                     totalQuota.longValue(), | ||||
|                     relativeQuota.doubleValue() | ||||
|             ); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user