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
.lib
.operations
.common
.ShareRemoteFile
;
21 import com
.owncloud
.android
.lib
.operations
.common
.ShareType
;
22 import com
.owncloud
.android
.utils
.Log_OC
;
24 import android
.os
.Parcel
;
25 import android
.os
.Parcelable
;
27 public class OCShare
implements Parcelable
{
29 private static final String TAG
= OCShare
.class.getSimpleName();
32 private long mFileSource
;
33 private long mItemSource
;
34 private ShareType mShareType
;
35 private String mShareWith
;
37 private int mPermissions
;
38 private long mSharedDate
;
39 private long mExpirationDate
;
40 private String mToken
;
41 private String mSharedWithDisplayName
;
42 private boolean mIsDirectory
;
44 private long mIdRemoteShared
;
48 * Create new {@link OCShare} with given path.
50 * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
52 * @param path The remote path of the file.
54 public OCShare(String path
) {
56 if (path
== null
|| path
.length() <= 0 || !path
.startsWith(OCFile
.PATH_SEPARATOR
)) {
57 Log_OC
.e(TAG
, "Trying to create a OCShare with a non valid path");
58 throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path
);
63 public OCShare(ShareRemoteFile remoteFile
) {
66 String path
= remoteFile
.getPath();
67 if (path
== null
|| path
.length() <= 0 || !path
.startsWith(OCFile
.PATH_SEPARATOR
)) {
68 Log_OC
.e(TAG
, "Trying to create a OCShare with a non valid path");
69 throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path
);
73 mFileSource
= remoteFile
.getFileSource();
74 mItemSource
= remoteFile
.getItemSource();
75 mShareType
= remoteFile
.getShareType();
76 mShareWith
= remoteFile
.getShareWith();
77 mPermissions
= remoteFile
.getPermissions();
78 mSharedDate
= remoteFile
.getSharedDate();
79 mExpirationDate
= remoteFile
.getExpirationDate();
80 mToken
= remoteFile
.getToken();
81 mSharedWithDisplayName
= remoteFile
.getSharedWithDisplayName();
82 mIsDirectory
= remoteFile
.isDirectory();
83 mUserId
= remoteFile
.getUserId();
84 mIdRemoteShared
= remoteFile
.getIdRemoteShared();
88 * Used internally. Reset all file properties
90 private void resetData() {
94 mShareType
= ShareType
.NO_SHARED
;
101 mSharedWithDisplayName
= null
;
102 mIsDirectory
= false
;
104 mIdRemoteShared
= -1;
108 /// Getters and Setters
109 public long getFileSource() {
113 public void setFileSource(long fileSource
) {
114 this.mFileSource
= fileSource
;
117 public long getItemSource() {
121 public void setItemSource(long itemSource
) {
122 this.mItemSource
= itemSource
;
125 public ShareType
getShareType() {
129 public void setShareType(ShareType shareType
) {
130 this.mShareType
= shareType
;
133 public String
getShareWith() {
137 public void setShareWith(String shareWith
) {
138 this.mShareWith
= shareWith
;
141 public String
getPath() {
145 public void setPath(String path
) {
149 public int getPermissions() {
153 public void setPermissions(int permissions
) {
154 this.mPermissions
= permissions
;
157 public long getSharedDate() {
161 public void setSharedDate(long sharedDate
) {
162 this.mSharedDate
= sharedDate
;
165 public long getExpirationDate() {
166 return mExpirationDate
;
169 public void setExpirationDate(long expirationDate
) {
170 this.mExpirationDate
= expirationDate
;
173 public String
getToken() {
177 public void setToken(String token
) {
181 public String
getSharedWithDisplayName() {
182 return mSharedWithDisplayName
;
185 public void setSharedWithDisplayName(String sharedWithDisplayName
) {
186 this.mSharedWithDisplayName
= sharedWithDisplayName
;
189 public boolean isDirectory() {
193 public void setIsDirectory(boolean isDirectory
) {
194 this.mIsDirectory
= isDirectory
;
197 public long getUserId() {
201 public void setUserId(long userId
) {
202 this.mUserId
= userId
;
205 public long getIdRemoteShared() {
206 return mIdRemoteShared
;
209 public void setIdRemoteShared(long idRemoteShared
) {
210 this.mIdRemoteShared
= idRemoteShared
;
213 public long getId() {
217 public void setId(long id
){
224 public static final Parcelable
.Creator
<OCShare
> CREATOR
= new Parcelable
.Creator
<OCShare
>() {
226 public OCShare
createFromParcel(Parcel source
) {
227 return new OCShare(source
);
231 public OCShare
[] newArray(int size
) {
232 return new OCShare
[size
];
237 * Reconstruct from parcel
239 * @param source The source parcel
241 private OCShare(Parcel source
) {
242 mId
= source
.readLong();
243 mFileSource
= source
.readLong();
244 mItemSource
= source
.readLong();
246 mShareType
= ShareType
.valueOf(source
.readString());
247 } catch (IllegalArgumentException x
) {
248 mShareType
= ShareType
.NO_SHARED
;
250 mShareWith
= source
.readString();
251 mPath
= source
.readString();
252 mPermissions
= source
.readInt();
253 mSharedDate
= source
.readLong();
254 mExpirationDate
= source
.readLong();
255 mToken
= source
.readString();
256 mSharedWithDisplayName
= source
.readString();
257 mIsDirectory
= source
.readInt() == 0;
258 mUserId
= source
.readLong();
259 mIdRemoteShared
= source
.readLong();
263 public int describeContents() {
264 return this.hashCode();
268 public void writeToParcel(Parcel dest
, int flags
) {
270 dest
.writeLong(mFileSource
);
271 dest
.writeLong(mItemSource
);
272 dest
.writeString((mShareType
== null
) ?
"" : mShareType
.name());
273 dest
.writeString(mShareWith
);
274 dest
.writeString(mPath
);
275 dest
.writeInt(mPermissions
);
276 dest
.writeLong(mSharedDate
);
277 dest
.writeLong(mExpirationDate
);
278 dest
.writeString(mToken
);
279 dest
.writeString(mSharedWithDisplayName
);
280 dest
.writeInt(mIsDirectory ?
1 : 0);
281 dest
.writeLong(mUserId
);
282 dest
.writeLong(mIdRemoteShared
);