From: masensio Date: Tue, 21 Jan 2014 08:20:32 +0000 (+0100) Subject: OC-2489: New ShareRemoteFile, to get data from the server. ShareType in library X-Git-Tag: oc-android-1.5.5~35^2~59 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/747a39cf7d17bb3afc9248d9a32a662fabfa3b5e OC-2489: New ShareRemoteFile, to get data from the server. ShareType in library --- diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java index 922b270a..de16b137 100644 --- a/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/RemoteFile.java @@ -152,7 +152,11 @@ public class RemoteFile implements Parcelable, Serializable { * * @param source The source parcel */ - private RemoteFile(Parcel source) { + protected RemoteFile(Parcel source) { + readFromParcel(source); + } + + public void readFromParcel (Parcel source) { mRemotePath = source.readString(); mMimeType = source.readString(); mLength = source.readLong(); diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareRemoteFile.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareRemoteFile.java new file mode 100644 index 00000000..f599028c --- /dev/null +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareRemoteFile.java @@ -0,0 +1,262 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2014 ownCloud (http://www.owncloud.org/) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.oc_framework.operations; + +import android.os.Parcel; +import android.os.Parcelable; +import android.util.Log; + +import com.owncloud.android.oc_framework.network.webdav.WebdavEntry; +import com.owncloud.android.oc_framework.utils.FileUtils; + +public class ShareRemoteFile extends RemoteFile { + + /** + * Generated - should be refreshed every time the class changes!! + */ + private static final long serialVersionUID = -5916376011588784325L; + + private static final String TAG = ShareRemoteFile.class.getSimpleName(); + + private long mFileSource; + private long mItemSource; + private ShareType mShareType; + private String mShareWith; + private String mPath; + private int mPermissions; + private long mSharedDate; + private long mExpirationDate; + private String mToken; + private String mSharedWithDisplayName; + private boolean mIsDirectory; + private long mUserId; + private long mIdRemoteShared; + + + public ShareRemoteFile(String path) { + super(path); + resetData(); + if (path == null || path.length() <= 0 || !path.startsWith(FileUtils.PATH_SEPARATOR)) { + Log.e(TAG, "Trying to create a OCShare with a non valid path"); + throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path); + } + mPath = path; + } + + public ShareRemoteFile(WebdavEntry we) { + super(we); + // TODO Auto-generated constructor stub + } + + /** + * Used internally. Reset all file properties + */ + private void resetData() { + mFileSource = 0; + mItemSource = 0; + mShareType = ShareType.NO_SHARED; + mShareWith = null; + mPath = null; + mPermissions = -1; + mSharedDate = 0; + mExpirationDate = 0; + mToken = null; + mSharedWithDisplayName = null; + mIsDirectory = false; + mUserId = -1; + mIdRemoteShared = -1; + } + + /// Getters and Setters + public long getFileSource() { + return mFileSource; + } + + public void setFileSource(long fileSource) { + this.mFileSource = fileSource; + } + + public long getItemSource() { + return mItemSource; + } + + public void setItemSource(long itemSource) { + this.mItemSource = itemSource; + } + + public ShareType getShareType() { + return mShareType; + } + + public void setShareType(ShareType shareType) { + this.mShareType = shareType; + } + + public String getShareWith() { + return mShareWith; + } + + public void setShareWith(String shareWith) { + this.mShareWith = shareWith; + } + + public String getPath() { + return mPath; + } + + public void setPath(String path) { + this.mPath = path; + } + + public int getPermissions() { + return mPermissions; + } + + public void setPermissions(int permissions) { + this.mPermissions = permissions; + } + + public long getSharedDate() { + return mSharedDate; + } + + public void setSharedDate(long sharedDate) { + this.mSharedDate = sharedDate; + } + + public long getExpirationDate() { + return mExpirationDate; + } + + public void setExpirationDate(long expirationDate) { + this.mExpirationDate = expirationDate; + } + + public String getToken() { + return mToken; + } + + public void setToken(String token) { + this.mToken = token; + } + + public String getSharedWithDisplayName() { + return mSharedWithDisplayName; + } + + public void setSharedWithDisplayName(String sharedWithDisplayName) { + this.mSharedWithDisplayName = sharedWithDisplayName; + } + + public boolean isDirectory() { + return mIsDirectory; + } + + public void setIsDirectory(boolean isDirectory) { + this.mIsDirectory = isDirectory; + } + + public long getUserId() { + return mUserId; + } + + public void setUserId(long userId) { + this.mUserId = userId; + } + + public long getIdRemoteShared() { + return mIdRemoteShared; + } + + public void setIdRemoteShared(long idRemoteShared) { + this.mIdRemoteShared = idRemoteShared; + } + + /** + * Parcelable Methods + */ + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public ShareRemoteFile createFromParcel(Parcel source) { + return new ShareRemoteFile(source); + } + + @Override + public ShareRemoteFile[] newArray(int size) { + return new ShareRemoteFile[size]; + } + }; + + /** + * Reconstruct from parcel + * + * @param source The source parcel + */ + protected ShareRemoteFile(Parcel source) { + super(source); + } + + public void readFromParcel(Parcel source) { + super.readFromParcel(source); + + mFileSource = source.readLong(); + mItemSource = source.readLong(); + try { + mShareType = ShareType.valueOf(source.readString()); + } catch (IllegalArgumentException x) { + mShareType = ShareType.NO_SHARED; + } + mShareWith = source.readString(); + mPath = source.readString(); + mPermissions = source.readInt(); + mSharedDate = source.readLong(); + mExpirationDate = source.readLong(); + mToken = source.readString(); + mSharedWithDisplayName = source.readString(); + mIsDirectory = source.readInt() == 0; + mUserId = source.readLong(); + mIdRemoteShared = source.readLong(); + } + + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + + dest.writeLong(mFileSource); + dest.writeLong(mItemSource); + dest.writeString((mShareType == null) ? "" : mShareType.name()); + dest.writeString(mShareWith); + dest.writeString(mPath); + dest.writeInt(mPermissions); + dest.writeLong(mSharedDate); + dest.writeLong(mExpirationDate); + dest.writeString(mToken); + dest.writeString(mSharedWithDisplayName); + dest.writeInt(mIsDirectory ? 1 : 0); + dest.writeLong(mUserId); + dest.writeLong(mIdRemoteShared); + } +} diff --git a/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareType.java b/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareType.java new file mode 100644 index 00000000..c6849f69 --- /dev/null +++ b/oc_framework/src/com/owncloud/android/oc_framework/operations/ShareType.java @@ -0,0 +1,78 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2014 ownCloud (http://www.owncloud.org/) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +package com.owncloud.android.oc_framework.operations; + +/** + * Enum for Share Type, with values: + * -1 - No shared + * 0 - Shared by user + * 1 - Shared by group + * 3 - Shared by public link + * 4 - Shared by e-mail + * 5 - Shared by contact + * + * @author masensio + * + */ + +public enum ShareType { + NO_SHARED (-1), + USER (0), + GROUP (1), + PUBLIC_LINK (3), + EMAIL (4), + CONTACT (5); + + private int value; + + private ShareType(int value) + { + this.value = value; + } + + public int getValue() { + return value; + } + + public static ShareType fromValue(int value) + { + switch (value) + { + case -1: + return NO_SHARED; + case 0: + return USER; + case 1: + return GROUP; + case 3: + return PUBLIC_LINK; + case 4: + return EMAIL; + case 5: + return CONTACT; + } + return null; + } +}; \ No newline at end of file diff --git a/src/com/owncloud/android/datamodel/OCShare.java b/src/com/owncloud/android/datamodel/OCShare.java index 52b55433..e1ddd078 100644 --- a/src/com/owncloud/android/datamodel/OCShare.java +++ b/src/com/owncloud/android/datamodel/OCShare.java @@ -17,6 +17,7 @@ package com.owncloud.android.datamodel; +import com.owncloud.android.oc_framework.operations.ShareType; import com.owncloud.android.utils.Log_OC; import android.os.Parcel; @@ -26,47 +27,6 @@ public class OCShare implements Parcelable{ private static final String TAG = OCShare.class.getSimpleName(); - // Enum for ShareType - public enum ShareType { - NO_SHARED (-1), - USER (0), - GROUP (1), - PUBLIC_LINK (3), - EMAIL (4), - CONTACT (5); - - private int value; - - private ShareType(int value) - { - this.value = value; - } - - public int getValue() { - return value; - } - - public static ShareType fromValue(int value) - { - switch (value) - { - case -1: - return NO_SHARED; - case 0: - return USER; - case 1: - return GROUP; - case 3: - return PUBLIC_LINK; - case 4: - return EMAIL; - case 5: - return CONTACT; - } - return null; - } - }; - private long mId; private long mFileSource; private long mItemSource; @@ -229,7 +189,9 @@ public class OCShare implements Parcelable{ return mId; } - /// Parcelable methods + /** + * Parcelable Methods + */ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @Override public OCShare createFromParcel(Parcel source) {