f5dd3fce03dd700e366a43860b77049662847e1b
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
;
51 * Create new {@link OCFile} with given path
54 * The remote path of the file
56 public OCFile(String path
) {
58 mNeedsUpdating
= false
;
63 * Reconstruct from parcel
64 * @param source The source parcel
66 private OCFile(Parcel source
){
67 mId
= source
.readLong();
68 mParentId
= source
.readLong();
69 mLength
= source
.readLong();
70 mCreationTimestamp
= source
.readLong();
71 mModifiedTimestamp
= source
.readLong();
72 mRemotePath
= source
.readString();
73 mLocalPath
= source
.readString();
74 mMimeType
= source
.readString();
75 mNeedsUpdating
= source
.readInt() == 0;
79 * Gets the ID of the file
83 public long getFileId() {
88 * Returns the path of the file
92 public String
getPath() {
97 * Can be used to check, whether or not this file exists in the database
100 * @return true, if the file exists in the database
102 public boolean fileExists() {
107 * Use this to find out if this file is a Directory
109 * @return true if it is a directory
111 public boolean isDirectory() {
112 return mMimeType
!= null
&& mMimeType
.equals("DIR");
116 * Use this to check if this file is available locally
118 * @return true if it is
120 public boolean isDownloaded() {
121 return mLocalPath
!= null
|| mLocalPath
.equals("");
125 * The path, where the file is stored locally
127 * @return The local path to the file
129 public String
getStoragePath() {
134 * Can be used to set the path where the file is stored
136 * @param storage_path
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
158 public void setCreationTimestamp(long creation_timestamp
) {
159 mCreationTimestamp
= creation_timestamp
;
163 * Get a UNIX timestamp of the file modification time
165 * @return A UNIX timestamp of the modification time
167 public long getModificationTimestamp() {
168 return mModifiedTimestamp
;
172 * Set a UNIX timestamp of the time the time the file was modified.
174 * @param modification_timestamp
177 public void setModificationTimestamp(long modification_timestamp
) {
178 mModifiedTimestamp
= modification_timestamp
;
182 * Returns the filename and "/" for the root directory
184 * @return The name of the file
186 public String
getFileName() {
187 if (mRemotePath
!= null
) {
188 File f
= new File(mRemotePath
);
189 return f
.getName().equals("") ?
"/" : f
.getName();
195 * Can be used to get the Mimetype
197 * @return the Mimetype as a String
199 public String
getMimetype() {
204 * Adds a file to this directory. If this file is not a directory, an
205 * exception gets thrown.
209 * @throws IllegalStateException
210 * if you try to add a something and this is not a directory
212 public void addFile(OCFile file
) throws IllegalStateException
{
214 file
.mParentId
= mId
;
215 mNeedsUpdating
= true
;
218 throw new IllegalStateException(
219 "This is not a directory where you can add stuff to!");
223 * Used internally. Reset all file properties
225 private void resetData() {
232 mCreationTimestamp
= 0;
233 mModifiedTimestamp
= 0;
237 * Sets the ID of the file
242 public void setFileId(long file_id
) {
247 * Sets the Mime-Type of the
252 public void setMimetype(String mimetype
) {
253 mMimeType
= mimetype
;
257 * Sets the ID of the parent folder
262 public void setParentId(long parent_id
) {
263 mParentId
= parent_id
;
267 * Sets the file size in bytes
272 public void setFileLength(long file_len
) {
277 * Returns the size of the file in bytes
279 * @return The filesize in bytes
281 public long getFileLength() {
286 * Returns the ID of the parent Folder
290 public long getParentId() {
295 * Check, if this file needs updating
299 public boolean needsUpdatingWhileSaving() {
300 return mNeedsUpdating
;
304 public int describeContents() {
305 return this.hashCode();
309 public void writeToParcel(Parcel dest
, int flags
) {
311 dest
.writeLong(mParentId
);
312 dest
.writeLong(mLength
);
313 dest
.writeLong(mCreationTimestamp
);
314 dest
.writeLong(mModifiedTimestamp
);
315 dest
.writeString(mRemotePath
);
316 dest
.writeString(mLocalPath
);
317 dest
.writeString(mMimeType
);
318 dest
.writeInt(mNeedsUpdating ?
0 : 1 ); // No writeBoolean method exists - yay :D