mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 10:27:45 +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()); | ||||||
| 
 | 
 | ||||||
|         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( |         } else { | ||||||
|                 we.quotaAvailableBytes().longValue(), |  | ||||||
|                 we.quotaUsedBytes().longValue(), |  | ||||||
|                 totalQuota.longValue(), |  | ||||||
|                 relativeQuota.doubleValue() |  | ||||||
|         ); |  | ||||||
| 
 | 
 | ||||||
|         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