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
.oc_framework
.operations
.ShareType
;
21 import com
.owncloud
.android
.utils
.Log_OC
;
23 import android
.os
.Parcel
;
24 import android
.os
.Parcelable
;
26 public class OCShare
implements Parcelable
{
28 private static final String TAG
= OCShare
.class.getSimpleName();
31 private long mFileSource
;
32 private long mItemSource
;
33 private ShareType mShareType
;
34 private String mShareWith
;
36 private int mPermissions
;
37 private long mSharedDate
;
38 private long mExpirationDate
;
39 private String mToken
;
40 private String mSharedWithDisplayName
;
41 private boolean mIsDirectory
;
43 private long mIdRemoteShared
;
47 * Create new {@link OCShare} with given path.
49 * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
51 * @param path The remote path of the file.
53 public OCShare(String path
) {
55 if (path
== null
|| path
.length() <= 0 || !path
.startsWith(OCFile
.PATH_SEPARATOR
)) {
56 Log_OC
.e(TAG
, "Trying to create a OCShare with a non valid path");
57 throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path
);
63 * Used internally. Reset all file properties
65 private void resetData() {
69 mShareType
= ShareType
.NO_SHARED
;
76 mSharedWithDisplayName
= null
;
83 /// Getters and Setters
84 public long getFileSource() {
88 public void setFileSource(long fileSource
) {
89 this.mFileSource
= fileSource
;
92 public long getItemSource() {
96 public void setItemSource(long itemSource
) {
97 this.mItemSource
= itemSource
;
100 public ShareType
getShareType() {
104 public void setShareType(ShareType shareType
) {
105 this.mShareType
= shareType
;
108 public String
getShareWith() {
112 public void setShareWith(String shareWith
) {
113 this.mShareWith
= shareWith
;
116 public String
getPath() {
120 public void setPath(String path
) {
124 public int getPermissions() {
128 public void setPermissions(int permissions
) {
129 this.mPermissions
= permissions
;
132 public long getSharedDate() {
136 public void setSharedDate(long sharedDate
) {
137 this.mSharedDate
= sharedDate
;
140 public long getExpirationDate() {
141 return mExpirationDate
;
144 public void setExpirationDate(long expirationDate
) {
145 this.mExpirationDate
= expirationDate
;
148 public String
getToken() {
152 public void setToken(String token
) {
156 public String
getSharedWithDisplayName() {
157 return mSharedWithDisplayName
;
160 public void setSharedWithDisplayName(String sharedWithDisplayName
) {
161 this.mSharedWithDisplayName
= sharedWithDisplayName
;
164 public boolean isDirectory() {
168 public void setIsDirectory(boolean isDirectory
) {
169 this.mIsDirectory
= isDirectory
;
172 public long getUserId() {
176 public void setUserId(long userId
) {
177 this.mUserId
= userId
;
180 public long getIdRemoteShared() {
181 return mIdRemoteShared
;
184 public void setIdRemoteShared(long idRemoteShared
) {
185 this.mIdRemoteShared
= idRemoteShared
;
188 public long getId() {
195 public static final Parcelable
.Creator
<OCShare
> CREATOR
= new Parcelable
.Creator
<OCShare
>() {
197 public OCShare
createFromParcel(Parcel source
) {
198 return new OCShare(source
);
202 public OCShare
[] newArray(int size
) {
203 return new OCShare
[size
];
208 * Reconstruct from parcel
210 * @param source The source parcel
212 private OCShare(Parcel source
) {
213 mId
= source
.readLong();
214 mFileSource
= source
.readLong();
215 mItemSource
= source
.readLong();
217 mShareType
= ShareType
.valueOf(source
.readString());
218 } catch (IllegalArgumentException x
) {
219 mShareType
= ShareType
.NO_SHARED
;
221 mShareWith
= source
.readString();
222 mPath
= source
.readString();
223 mPermissions
= source
.readInt();
224 mSharedDate
= source
.readLong();
225 mExpirationDate
= source
.readLong();
226 mToken
= source
.readString();
227 mSharedWithDisplayName
= source
.readString();
228 mIsDirectory
= source
.readInt() == 0;
229 mUserId
= source
.readLong();
230 mIdRemoteShared
= source
.readLong();
234 public int describeContents() {
235 return this.hashCode();
239 public void writeToParcel(Parcel dest
, int flags
) {
241 dest
.writeLong(mFileSource
);
242 dest
.writeLong(mItemSource
);
243 dest
.writeString((mShareType
== null
) ?
"" : mShareType
.name());
244 dest
.writeString(mShareWith
);
245 dest
.writeString(mPath
);
246 dest
.writeInt(mPermissions
);
247 dest
.writeLong(mSharedDate
);
248 dest
.writeLong(mExpirationDate
);
249 dest
.writeString(mToken
);
250 dest
.writeString(mSharedWithDisplayName
);
251 dest
.writeInt(mIsDirectory ?
1 : 0);
252 dest
.writeLong(mUserId
);
253 dest
.writeLong(mIdRemoteShared
);