X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/a4ba6170ea7696e085b07adfef73eeb8b77cb8e2..8361540852ec87b51c85937e0f326a83e19cd8ad:/src/com/owncloud/android/datamodel/OCFile.java diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index f50a86fc..ec4e749b 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -19,15 +19,10 @@ package com.owncloud.android.datamodel; import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import com.owncloud.android.files.services.FileDownloader; - - -import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; +import android.util.Log; public class OCFile implements Parcelable, Comparable { @@ -44,6 +39,8 @@ public class OCFile implements Parcelable, Comparable { }; public static final String PATH_SEPARATOR = "/"; + + private static final String TAG = OCFile.class.getSimpleName(); private long mId; private long mParentId; @@ -54,9 +51,12 @@ public class OCFile implements Parcelable, Comparable { private String mLocalPath; private String mMimeType; private boolean mNeedsUpdating; - private long mLastSyncDate; + private long mLastSyncDateForProperties; + private long mLastSyncDateForData; private boolean mKeepInSync; + private String mEtag; + /** * Create new {@link OCFile} with given path. * @@ -89,7 +89,8 @@ public class OCFile implements Parcelable, Comparable { mMimeType = source.readString(); mNeedsUpdating = source.readInt() == 0; mKeepInSync = source.readInt() == 1; - mLastSyncDate = source.readLong(); + mLastSyncDateForProperties = source.readLong(); + mLastSyncDateForData = source.readLong(); } @Override @@ -104,7 +105,8 @@ public class OCFile implements Parcelable, Comparable { dest.writeString(mMimeType); dest.writeInt(mNeedsUpdating ? 1 : 0); dest.writeInt(mKeepInSync ? 1 : 0); - dest.writeLong(mLastSyncDate); + dest.writeLong(mLastSyncDateForProperties); + dest.writeLong(mLastSyncDateForData); } /** @@ -218,7 +220,25 @@ public class OCFile implements Parcelable, Comparable { */ public String getFileName() { File f = new File(getRemotePath()); - return f.getName().length() == 0 ? "/" : f.getName(); + return f.getName().length() == 0 ? PATH_SEPARATOR : f.getName(); + } + + /** + * Sets the name of the file + * + * Does nothing if the new name is null, empty or includes "/" ; or if the file is the root directory + */ + public void setFileName(String name) { + Log.d(TAG, "OCFile name changin from " + mRemotePath); + if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(PATH_SEPARATOR)) { + String parent = (new File(getRemotePath())).getParent(); + parent = (parent.endsWith(PATH_SEPARATOR)) ? parent : parent + PATH_SEPARATOR; + mRemotePath = parent + name; + if (isDirectory()) { + mRemotePath += PATH_SEPARATOR; + } + Log.d(TAG, "OCFile name changed to " + mRemotePath); + } } /** @@ -260,7 +280,8 @@ public class OCFile implements Parcelable, Comparable { mLength = 0; mCreationTimestamp = 0; mModifiedTimestamp = 0; - mLastSyncDate = 0; + mLastSyncDateForProperties = 0; + mLastSyncDateForData = 0; mKeepInSync = false; mNeedsUpdating = false; } @@ -328,12 +349,20 @@ public class OCFile implements Parcelable, Comparable { return mNeedsUpdating; } - public long getLastSyncDate() { - return mLastSyncDate; + public long getLastSyncDateForProperties() { + return mLastSyncDateForProperties; } - public void setLastSyncDate(long lastSyncDate) { - mLastSyncDate = lastSyncDate; + public void setLastSyncDateForProperties(long lastSyncDate) { + mLastSyncDateForProperties = lastSyncDate; + } + + public long getLastSyncDateForData() { + return mLastSyncDateForData; + } + + public void setLastSyncDateForData(long lastSyncDate) { + mLastSyncDateForData = lastSyncDate; } public void setKeepInSync(boolean keepInSync) { @@ -361,6 +390,7 @@ public class OCFile implements Parcelable, Comparable { return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase()); } + @Override public boolean equals(Object o) { if(o instanceof OCFile){ OCFile that = (OCFile) o; @@ -375,8 +405,20 @@ public class OCFile implements Parcelable, Comparable { @Override public String toString() { String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, parentId=%s, keepInSinc=%s]"; - asString = String.format(asString, new Long(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath, new Long(mParentId), new Boolean(mKeepInSync)); + asString = String.format(asString, Long.valueOf(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath, Long.valueOf(mParentId), Boolean.valueOf(mKeepInSync)); return asString; } + public String getEtag() { + return mEtag; + } + + public long getLocalModificationTimestamp() { + if (mLocalPath != null && mLocalPath.length() > 0) { + File f = new File(mLocalPath); + return f.lastModified(); + } + return 0; + } + }