1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package com
.owncloud
.android
.datamodel
;
20 import com
.owncloud
.android
.utils
.Log_OC
;
22 import android
.os
.Parcel
;
23 import android
.os
.Parcelable
;
25 public class OCShare
implements Parcelable
{
27 private static final String TAG
= OCShare
.class.getSimpleName();
30 public enum ShareType
{
40 private ShareType(int value
)
45 public int getValue() {
49 public static ShareType
fromValue(int value
)
71 private long mFileSource
;
72 private long mItemSource
;
73 private ShareType mShareType
;
74 private String mShareWith
;
76 private int mPermissions
;
77 private long mSharedDate
;
78 private long mExpirationDate
;
79 private String mToken
;
80 private String mSharedWithDisplayName
;
81 private boolean mIsDirectory
;
83 private long mIdRemoteShared
;
87 * Create new {@link OCShare} with given path.
89 * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
91 * @param path The remote path of the file.
93 public OCShare(String path
) {
95 if (path
== null
|| path
.length() <= 0 || !path
.startsWith(OCFile
.PATH_SEPARATOR
)) {
96 Log_OC
.e(TAG
, "Trying to create a OCShare with a non valid path");
97 throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path
);
103 * Used internally. Reset all file properties
105 private void resetData() {
109 mShareType
= ShareType
.NO_SHARED
;
116 mSharedWithDisplayName
= null
;
117 mIsDirectory
= false
;
119 mIdRemoteShared
= -1;
123 /// Getters and Setters
124 public long getFileSource() {
128 public void setFileSource(long fileSource
) {
129 this.mFileSource
= fileSource
;
132 public long getItemSource() {
136 public void setItemSource(long itemSource
) {
137 this.mItemSource
= itemSource
;
140 public ShareType
getShareType() {
144 public void setShareType(ShareType shareType
) {
145 this.mShareType
= shareType
;
148 public String
getShareWith() {
152 public void setShareWith(String shareWith
) {
153 this.mShareWith
= shareWith
;
156 public String
getPath() {
160 public void setPath(String path
) {
164 public int getPermissions() {
168 public void setPermissions(int permissions
) {
169 this.mPermissions
= permissions
;
172 public long getSharedDate() {
176 public void setSharedDate(long sharedDate
) {
177 this.mSharedDate
= sharedDate
;
180 public long getExpirationDate() {
181 return mExpirationDate
;
184 public void setExpirationDate(long expirationDate
) {
185 this.mExpirationDate
= expirationDate
;
188 public String
getToken() {
192 public void setToken(String token
) {
196 public String
getSharedWithDisplayName() {
197 return mSharedWithDisplayName
;
200 public void setSharedWithDisplayName(String sharedWithDisplayName
) {
201 this.mSharedWithDisplayName
= sharedWithDisplayName
;
204 public boolean isDirectory() {
208 public void setIsDirectory(boolean isDirectory
) {
209 this.mIsDirectory
= isDirectory
;
212 public long getUserId() {
216 public void setUserId(long userId
) {
217 this.mUserId
= userId
;
220 public long getIdRemoteShared() {
221 return mIdRemoteShared
;
224 public void setIdRemoteShared(long idRemoteShared
) {
225 this.mIdRemoteShared
= idRemoteShared
;
228 public long getId() {
232 /// Parcelable methods
233 public static final Parcelable
.Creator
<OCShare
> CREATOR
= new Parcelable
.Creator
<OCShare
>() {
235 public OCShare
createFromParcel(Parcel source
) {
236 return new OCShare(source
);
240 public OCShare
[] newArray(int size
) {
241 return new OCShare
[size
];
246 * Reconstruct from parcel
248 * @param source The source parcel
250 private OCShare(Parcel source
) {
251 mId
= source
.readLong();
252 mFileSource
= source
.readLong();
253 mItemSource
= source
.readLong();
255 mShareType
= ShareType
.valueOf(source
.readString());
256 } catch (IllegalArgumentException x
) {
257 mShareType
= ShareType
.NO_SHARED
;
259 mShareWith
= source
.readString();
260 mPath
= source
.readString();
261 mPermissions
= source
.readInt();
262 mSharedDate
= source
.readLong();
263 mExpirationDate
= source
.readLong();
264 mToken
= source
.readString();
265 mSharedWithDisplayName
= source
.readString();
266 mIsDirectory
= source
.readInt() == 0;
267 mUserId
= source
.readLong();
268 mIdRemoteShared
= source
.readLong();
272 public int describeContents() {
273 return this.hashCode();
277 public void writeToParcel(Parcel dest
, int flags
) {
279 dest
.writeLong(mFileSource
);
280 dest
.writeLong(mItemSource
);
281 dest
.writeString((mShareType
== null
) ?
"" : mShareType
.name());
282 dest
.writeString(mShareWith
);
283 dest
.writeString(mPath
);
284 dest
.writeInt(mPermissions
);
285 dest
.writeLong(mSharedDate
);
286 dest
.writeLong(mExpirationDate
);
287 dest
.writeString(mToken
);
288 dest
.writeString(mSharedWithDisplayName
);
289 dest
.writeInt(mIsDirectory ?
1 : 0);
290 dest
.writeLong(mUserId
);
291 dest
.writeLong(mIdRemoteShared
);