mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Clean up remote objects (code review)
This commit is contained in:
		
							parent
							
								
									c50e199b76
								
							
						
					
					
						commit
						f104d6842e
					
				| @ -24,11 +24,7 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.resources.shares | ||||
| 
 | ||||
| import android.os.Parcel | ||||
| import android.os.Parcelable | ||||
| import com.owncloud.android.lib.common.utils.Log_OC | ||||
| import com.owncloud.android.lib.resources.files.FileUtils | ||||
| import java.io.Serializable | ||||
| 
 | ||||
| /** | ||||
|  * Contains the data of a Share from the Share API | ||||
| @ -37,124 +33,27 @@ import java.io.Serializable | ||||
|  * @author David A. Velasco | ||||
|  * @author David González Verdugo | ||||
|  */ | ||||
| class RemoteShare : Parcelable, Serializable { | ||||
|     var id: Long = 0 | ||||
|     var shareWith: String = "" | ||||
|     var path: String = "" | ||||
|     var token: String = "" | ||||
|     var sharedWithDisplayName: String = "" | ||||
|     var sharedWithAdditionalInfo: String = "" | ||||
|     var name: String = "" | ||||
|     var shareLink: String = "" | ||||
|     var fileSource: Long = 0 | ||||
|     var itemSource: Long = 0 | ||||
|     var shareType: ShareType? = null | ||||
|     var permissions: Int = DEFAULT_PERMISSION | ||||
|     var sharedDate: Long = INIT_SHARED_DATE | ||||
|     var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS | ||||
|     var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR) | ||||
|     var userId: Long = 0 | ||||
| 
 | ||||
| data class RemoteShare( | ||||
|     var id: Long = 0, | ||||
|     var shareWith: String = "", | ||||
|     var path: String = "", | ||||
|     var token: String = "", | ||||
|     var sharedWithDisplayName: String = "", | ||||
|     var sharedWithAdditionalInfo: String = "", | ||||
|     var name: String = "", | ||||
|     var shareLink: String = "", | ||||
|     var fileSource: Long = 0, | ||||
|     var itemSource: Long = 0, | ||||
|     var shareType: ShareType? = ShareType.UNKNOWN, | ||||
|     var permissions: Int = DEFAULT_PERMISSION, | ||||
|     var sharedDate: Long = INIT_SHARED_DATE, | ||||
|     var expirationDate: Long = INIT_EXPIRATION_DATE_IN_MILLIS, | ||||
|     var isFolder: Boolean = path.endsWith(FileUtils.PATH_SEPARATOR), | ||||
|     var userId: Long = 0, | ||||
|     val isValid: Boolean = id > -1 | ||||
| 
 | ||||
|     constructor() : super() { | ||||
|         resetData() | ||||
|     } | ||||
| 
 | ||||
|     constructor(path: String?) { | ||||
|         resetData() | ||||
|         if (path.isNullOrEmpty() || !path.startsWith(FileUtils.PATH_SEPARATOR)) { | ||||
|             Log_OC.e(TAG, "Trying to create a RemoteShare with a non valid path") | ||||
|             throw IllegalArgumentException("Trying to create a RemoteShare with a non valid path: " + path!!) | ||||
|         } | ||||
|         this.path = path | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Used internally. Reset all file properties | ||||
|      */ | ||||
|     private fun resetData() { | ||||
|         id = -1 | ||||
|         shareWith = "" | ||||
|         path = "" | ||||
|         token = "" | ||||
|         sharedWithDisplayName = "" | ||||
|         sharedWithAdditionalInfo = "" | ||||
|         name = "" | ||||
|         shareLink = "" | ||||
|         fileSource = 0 | ||||
|         itemSource = 0 | ||||
|         shareType = ShareType.NO_SHARED | ||||
|         permissions = DEFAULT_PERMISSION | ||||
|         sharedDate = INIT_SHARED_DATE | ||||
|         expirationDate = INIT_EXPIRATION_DATE_IN_MILLIS | ||||
|         sharedWithAdditionalInfo = "" | ||||
|         isFolder = false | ||||
|         userId = -1 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Reconstruct from parcel | ||||
|      * | ||||
|      * @param source The source parcel | ||||
|      */ | ||||
|     protected constructor(source: Parcel) { | ||||
|         readFromParcel(source) | ||||
|     } | ||||
| 
 | ||||
|     fun readFromParcel(source: Parcel) { | ||||
|         id = source.readLong() | ||||
|         shareWith = source.readString().toString() | ||||
|         path = source.readString().toString() | ||||
|         token = source.readString().toString() | ||||
|         sharedWithDisplayName = source.readString().toString() | ||||
|         sharedWithAdditionalInfo = source.readString().toString() | ||||
|         name = source.readString().toString() | ||||
|         shareLink = source.readString().toString() | ||||
|         fileSource = source.readLong() | ||||
|         itemSource = source.readLong() | ||||
|         shareType = ShareType.NO_SHARED | ||||
|         try { | ||||
|             shareType = source.readString()?.let { ShareType.valueOf(it) } | ||||
|         } catch (x: IllegalArgumentException) { | ||||
|         } | ||||
|         permissions = source.readInt() | ||||
|         sharedDate = source.readLong() | ||||
|         expirationDate = source.readLong() | ||||
|         isFolder = source.readInt() == 0 | ||||
|         userId = source.readLong() | ||||
|     } | ||||
| 
 | ||||
|     override fun describeContents(): Int = this.hashCode() | ||||
| 
 | ||||
|     override fun writeToParcel(dest: Parcel, flags: Int) { | ||||
|         dest.writeLong(id) | ||||
|         dest.writeString(shareWith) | ||||
|         dest.writeString(path) | ||||
|         dest.writeString(token) | ||||
|         dest.writeString(sharedWithDisplayName) | ||||
|         dest.writeString(sharedWithAdditionalInfo) | ||||
|         dest.writeString(name) | ||||
|         dest.writeString(shareLink) | ||||
|         dest.writeLong(fileSource) | ||||
|         dest.writeLong(itemSource) | ||||
|         dest.writeString(shareType?.name ?: "") | ||||
|         dest.writeInt(permissions) | ||||
|         dest.writeLong(sharedDate) | ||||
|         dest.writeLong(expirationDate) | ||||
|         dest.writeInt(if (isFolder) 1 else 0) | ||||
|         dest.writeLong(userId) | ||||
|     } | ||||
| ) { | ||||
| 
 | ||||
|     companion object { | ||||
| 
 | ||||
|         /** | ||||
|          * Generated - should be refreshed every time the class changes!! | ||||
|          */ | ||||
|         private const val serialVersionUID = 4124975224281327921L | ||||
| 
 | ||||
|         private val TAG = RemoteShare::class.java.simpleName | ||||
| 
 | ||||
|         const val DEFAULT_PERMISSION = -1 | ||||
|         const val READ_PERMISSION_FLAG = 1 | ||||
|         const val UPDATE_PERMISSION_FLAG = 2 | ||||
| @ -180,30 +79,14 @@ class RemoteShare : Parcelable, Serializable { | ||||
| 
 | ||||
|         const val INIT_EXPIRATION_DATE_IN_MILLIS: Long = 0 | ||||
|         const val INIT_SHARED_DATE: Long = 0 | ||||
| 
 | ||||
|         /** | ||||
|          * Parcelable Methods | ||||
|          */ | ||||
|         @JvmField | ||||
|         val CREATOR: Parcelable.Creator<RemoteShare> = object : Parcelable.Creator<RemoteShare> { | ||||
|             override fun createFromParcel(source: Parcel): RemoteShare { | ||||
|                 return RemoteShare(source) | ||||
|     } | ||||
| 
 | ||||
|             override fun newArray(size: Int): Array<RemoteShare?> { | ||||
|                 return arrayOfNulls(size) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * // TODO This type is already included in the domain but we still need it here since the parsing takes place in this library for the moment | ||||
|  * | ||||
|  * Enum for Share Type, with values: | ||||
|  * -1 - No shared | ||||
|  * -1 - Unknown | ||||
|  * 0 - Shared by user | ||||
|  * 1 - Shared by group | ||||
|  * 3 - Shared by public link | ||||
| @ -213,8 +96,9 @@ class RemoteShare : Parcelable, Serializable { | ||||
|  * | ||||
|  * @author masensio | ||||
|  */ | ||||
| 
 | ||||
| enum class ShareType constructor(val value: Int) { | ||||
|     NO_SHARED(-1), | ||||
|     UNKNOWN(-1), | ||||
|     USER(0), | ||||
|     GROUP(1), | ||||
|     PUBLIC_LINK(3), | ||||
| @ -225,7 +109,7 @@ enum class ShareType constructor(val value: Int) { | ||||
|     companion object { | ||||
|         fun fromValue(value: Int): ShareType? { | ||||
|             return when (value) { | ||||
|                 -1 -> NO_SHARED | ||||
|                 -1 -> UNKNOWN | ||||
|                 0 -> USER | ||||
|                 1 -> GROUP | ||||
|                 3 -> PUBLIC_LINK | ||||
|  | ||||
| @ -29,81 +29,45 @@ package com.owncloud.android.lib.resources.status | ||||
| /** | ||||
|  * Contains data of the Capabilities for an account, from the Capabilities API | ||||
|  */ | ||||
| class RemoteCapability { | ||||
|     var accountName: String | ||||
| data class RemoteCapability( | ||||
|     var accountName: String = "", | ||||
| 
 | ||||
|     // Server version | ||||
|     var versionMayor: Int | ||||
|     var versionMinor: Int | ||||
|     var versionMicro: Int | ||||
|     var versionString: String | ||||
|     var versionEdition: String | ||||
|     var versionMayor: Int = 0, | ||||
|     var versionMinor: Int = 0, | ||||
|     var versionMicro: Int = 0, | ||||
|     var versionString: String = "", | ||||
|     var versionEdition: String = "", | ||||
| 
 | ||||
|     // Core PollInterval | ||||
|     var corePollinterval: Int | ||||
|     var corePollinterval: Int = 0, | ||||
| 
 | ||||
|     // Files Sharing | ||||
|     var filesSharingApiEnabled: CapabilityBooleanType | ||||
|     var filesSharingSearchMinLength: CapabilityBooleanType | ||||
|     var filesSharingMinLength: Int | ||||
|     var filesSharingPublicEnabled: CapabilityBooleanType | ||||
|     var filesSharingPublicPasswordEnforced: CapabilityBooleanType | ||||
|     var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType | ||||
|     var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType | ||||
|     var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType | ||||
|     var filesSharingPublicExpireDateEnabled: CapabilityBooleanType | ||||
|     var filesSharingPublicExpireDateDays: Int | ||||
|     var filesSharingPublicExpireDateEnforced: CapabilityBooleanType | ||||
|     var filesSharingPublicSendMail: CapabilityBooleanType | ||||
|     var filesSharingPublicUpload: CapabilityBooleanType | ||||
|     var filesSharingPublicMultiple: CapabilityBooleanType | ||||
|     var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType | ||||
|     var filesSharingUserSendMail: CapabilityBooleanType | ||||
|     var filesSharingResharing: CapabilityBooleanType | ||||
|     var filesSharingFederationOutgoing: CapabilityBooleanType | ||||
|     var filesSharingFederationIncoming: CapabilityBooleanType | ||||
|     var filesSharingApiEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingSearchMinLength: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingMinLength: Int = 0, | ||||
|     var filesSharingPublicEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicPasswordEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicPasswordEnforcedReadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicPasswordEnforcedReadWrite: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicPasswordEnforcedUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicExpireDateEnabled: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicExpireDateDays: Int = 0, | ||||
|     var filesSharingPublicExpireDateEnforced: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicUpload: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicMultiple: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingPublicSupportsUploadOnly: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingUserSendMail: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingResharing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingFederationOutgoing: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesSharingFederationIncoming: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
| 
 | ||||
|     // Files | ||||
|     var filesBigFileChunking: CapabilityBooleanType | ||||
|     var filesUndelete: CapabilityBooleanType | ||||
|     var filesVersioning: CapabilityBooleanType | ||||
| 
 | ||||
|     init { | ||||
|         accountName = "" | ||||
| 
 | ||||
|         versionMayor = 0 | ||||
|         versionMinor = 0 | ||||
|         versionMicro = 0 | ||||
|         versionString = "" | ||||
|         versionEdition = "" | ||||
| 
 | ||||
|         corePollinterval = 0 | ||||
| 
 | ||||
|         filesSharingApiEnabled = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingSearchMinLength = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingMinLength = 4 | ||||
|         filesSharingPublicEnabled = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicPasswordEnforced = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicPasswordEnforcedReadOnly = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicPasswordEnforcedReadWrite = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicPasswordEnforcedUploadOnly = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicExpireDateEnabled = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicExpireDateDays = 0 | ||||
|         filesSharingPublicExpireDateEnforced = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicSendMail = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicUpload = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicMultiple = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingPublicSupportsUploadOnly = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingUserSendMail = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingResharing = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingFederationOutgoing = CapabilityBooleanType.UNKNOWN | ||||
|         filesSharingFederationIncoming = CapabilityBooleanType.UNKNOWN | ||||
| 
 | ||||
|         filesBigFileChunking = CapabilityBooleanType.UNKNOWN | ||||
|         filesUndelete = CapabilityBooleanType.UNKNOWN | ||||
|         filesVersioning = CapabilityBooleanType.UNKNOWN | ||||
|     } | ||||
| } | ||||
|     var filesBigFileChunking: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesUndelete: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN, | ||||
|     var filesVersioning: CapabilityBooleanType = CapabilityBooleanType.UNKNOWN | ||||
| ) | ||||
| 
 | ||||
| /** | ||||
|  * Enum for Boolean Type in capabilities, with values: | ||||
| @ -116,15 +80,6 @@ enum class CapabilityBooleanType constructor(val value: Int) { | ||||
|     FALSE(0), | ||||
|     TRUE(1); | ||||
| 
 | ||||
|     val isUnknown: Boolean | ||||
|         get() = value == -1 | ||||
| 
 | ||||
|     val isFalse: Boolean | ||||
|         get() = value == 0 | ||||
| 
 | ||||
|     val isTrue: Boolean | ||||
|         get() = value == 1 | ||||
| 
 | ||||
|     companion object { | ||||
|         fun fromValue(value: Int): CapabilityBooleanType? { | ||||
|             return when (value) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user