1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.datamodel
;
23 import android
.os
.Parcel
;
24 import android
.os
.Parcelable
;
26 public class OCFile
implements Parcelable
{
28 public static final Parcelable
.Creator
<OCFile
> CREATOR
= new Parcelable
.Creator
<OCFile
>() {
30 public OCFile
createFromParcel(Parcel source
) {
31 return new OCFile(source
);
35 public OCFile
[] newArray(int size
) {
36 return new OCFile
[size
];
41 private long mParentId
;
43 private long mCreationTimestamp
;
44 private long mModifiedTimestamp
;
45 private String mRemotePath
;
46 private String mLocalPath
;
47 private String mMimeType
;
48 private boolean mNeedsUpdating
;
49 private long mLastSyncDate
;
52 * Create new {@link OCFile} with given path
54 * @param path The remote path of the file
56 public OCFile(String path
) {
58 mNeedsUpdating
= false
;
63 * Reconstruct from parcel
65 * @param source The source parcel
67 private OCFile(Parcel source
) {
68 mId
= source
.readLong();
69 mParentId
= source
.readLong();
70 mLength
= source
.readLong();
71 mCreationTimestamp
= source
.readLong();
72 mModifiedTimestamp
= source
.readLong();
73 mRemotePath
= source
.readString();
74 mLocalPath
= source
.readString();
75 mMimeType
= source
.readString();
76 mNeedsUpdating
= source
.readInt() == 0;
80 * Gets the ID of the file
84 public long getFileId() {
89 * Returns the path of the file
93 public String
getPath() {
98 * Can be used to check, whether or not this file exists in the database
101 * @return true, if the file exists in the database
103 public boolean fileExists() {
108 * Use this to find out if this file is a Directory
110 * @return true if it is a directory
112 public boolean isDirectory() {
113 return mMimeType
!= null
&& mMimeType
.equals("DIR");
117 * Use this to check if this file is available locally
119 * @return true if it is
121 public boolean isDownloaded() {
122 return mLocalPath
!= null
|| mLocalPath
.equals("");
126 * The path, where the file is stored locally
128 * @return The local path to the file
130 public String
getStoragePath() {
135 * Can be used to set the path where the file is stored
137 * @param storage_path to set
139 public void setStoragePath(String storage_path
) {
140 mLocalPath
= storage_path
;
144 * Get a UNIX timestamp of the file creation time
146 * @return A UNIX timestamp of the time that file was created
148 public long getCreationTimestamp() {
149 return mCreationTimestamp
;
153 * Set a UNIX timestamp of the time the file was created
155 * @param creation_timestamp to set
157 public void setCreationTimestamp(long creation_timestamp
) {
158 mCreationTimestamp
= creation_timestamp
;
162 * Get a UNIX timestamp of the file modification time
164 * @return A UNIX timestamp of the modification time
166 public long getModificationTimestamp() {
167 return mModifiedTimestamp
;
171 * Set a UNIX timestamp of the time the time the file was modified.
173 * @param modification_timestamp to set
175 public void setModificationTimestamp(long modification_timestamp
) {
176 mModifiedTimestamp
= modification_timestamp
;
180 * Returns the filename and "/" for the root directory
182 * @return The name of the file
184 public String
getFileName() {
185 if (mRemotePath
!= null
) {
186 File f
= new File(mRemotePath
);
187 return f
.getName().equals("") ?
"/" : f
.getName();
193 * Can be used to get the Mimetype
195 * @return the Mimetype as a String
197 public String
getMimetype() {
202 * Adds a file to this directory. If this file is not a directory, an
203 * exception gets thrown.
206 * @throws IllegalStateException if you try to add a something and this is
209 public void addFile(OCFile file
) throws IllegalStateException
{
211 file
.mParentId
= mId
;
212 mNeedsUpdating
= true
;
215 throw new IllegalStateException(
216 "This is not a directory where you can add stuff to!");
220 * Used internally. Reset all file properties
222 private void resetData() {
229 mCreationTimestamp
= 0;
230 mModifiedTimestamp
= 0;
235 * Sets the ID of the file
237 * @param file_id to set
239 public void setFileId(long file_id
) {
244 * Sets the Mime-Type of the
246 * @param mimetype to set
248 public void setMimetype(String mimetype
) {
249 mMimeType
= mimetype
;
253 * Sets the ID of the parent folder
255 * @param parent_id to set
257 public void setParentId(long parent_id
) {
258 mParentId
= parent_id
;
262 * Sets the file size in bytes
264 * @param file_len to set
266 public void setFileLength(long file_len
) {
271 * Returns the size of the file in bytes
273 * @return The filesize in bytes
275 public long getFileLength() {
280 * Returns the ID of the parent Folder
284 public long getParentId() {
289 * Check, if this file needs updating
293 public boolean needsUpdatingWhileSaving() {
294 return mNeedsUpdating
;
297 public long getLastSyncDate() {
298 return mLastSyncDate
;
301 public void setLastSyncDate(long lastSyncDate
) {
302 mLastSyncDate
= lastSyncDate
;
306 public int describeContents() {
307 return this.hashCode();
311 public void writeToParcel(Parcel dest
, int flags
) {
313 dest
.writeLong(mParentId
);
314 dest
.writeLong(mLength
);
315 dest
.writeLong(mCreationTimestamp
);
316 dest
.writeLong(mModifiedTimestamp
);
317 dest
.writeString(mRemotePath
);
318 dest
.writeString(mLocalPath
);
319 dest
.writeString(mMimeType
);
320 dest
.writeInt(mNeedsUpdating ?
1 : 0);
321 dest
.writeLong(mLastSyncDate
);