Merge branch 'develop' into setup_buttons
[pub/Android/ownCloud.git] / src / com / owncloud / android / datamodel / OCFile.java
index 76fb6b2..67de500 100644 (file)
@@ -42,6 +42,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     };
 
     public static final String PATH_SEPARATOR = "/";
+    public static final String ROOT_PATH = PATH_SEPARATOR;
 
     private static final String TAG = OCFile.class.getSimpleName();
     
@@ -61,6 +62,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     private String mEtag;
 
+
     /**
      * Create new {@link OCFile} with given path.
      * 
@@ -96,6 +98,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mKeepInSync = source.readInt() == 1;
         mLastSyncDateForProperties = source.readLong();
         mLastSyncDateForData = source.readLong();
+        mEtag = source.readString();
     }
 
     @Override
@@ -113,6 +116,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         dest.writeInt(mKeepInSync ? 1 : 0);
         dest.writeLong(mLastSyncDateForProperties);
         dest.writeLong(mLastSyncDateForData);
+        dest.writeString(mEtag);
     }
     
     /**
@@ -144,11 +148,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
     }
 
     /**
-     * Use this to find out if this file is a Directory
+     * Use this to find out if this file is a folder.
      * 
-     * @return true if it is a directory
+     * @return true if it is a folder
      */
-    public boolean isDirectory() {
+    public boolean isFolder() {
         return mMimeType != null && mMimeType.equals("DIR");
     }
 
@@ -255,7 +259,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
      */
     public String getFileName() {
         File f = new File(getRemotePath());
-        return f.getName().length() == 0 ? PATH_SEPARATOR : f.getName();
+        return f.getName().length() == 0 ? ROOT_PATH : f.getName();
     }
     
     /**
@@ -265,11 +269,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
      */
     public void setFileName(String name) {
         Log_OC.d(TAG, "OCFile name changin from " + mRemotePath);
-        if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(PATH_SEPARATOR)) {
+        if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) && !mRemotePath.equals(ROOT_PATH)) {
             String parent = (new File(getRemotePath())).getParent();
             parent = (parent.endsWith(PATH_SEPARATOR)) ? parent : parent + PATH_SEPARATOR;
             mRemotePath =  parent + name;
-            if (isDirectory()) {
+            if (isFolder()) {
                 mRemotePath += PATH_SEPARATOR;
             }
             Log_OC.d(TAG, "OCFile name changed to " + mRemotePath);
@@ -294,7 +298,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
      *             not a directory
      */
     public void addFile(OCFile file) throws IllegalStateException {
-        if (isDirectory()) {
+        if (isFolder()) {
             file.mParentId = mId;
             mNeedsUpdating = true;
             return;
@@ -320,6 +324,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         mLastSyncDateForData = 0;
         mKeepInSync = false;
         mNeedsUpdating = false;
+        mEtag = null;
     }
 
     /**
@@ -416,11 +421,11 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     @Override
     public int compareTo(OCFile another) {
-        if (isDirectory() && another.isDirectory()) {
+        if (isFolder() && another.isFolder()) {
             return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());
-        } else if (isDirectory()) {
+        } else if (isFolder()) {
             return -1;
-        } else if (another.isDirectory()) {
+        } else if (another.isFolder()) {
             return 1;
         }
         return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase());
@@ -440,8 +445,8 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
 
     @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, Long.valueOf(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath, Long.valueOf(mParentId), Boolean.valueOf(mKeepInSync));
+        String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, parentId=%s, keepInSinc=%s etag=%s]";
+        asString = String.format(asString, Long.valueOf(mId), getFileName(), mMimeType, isDown(), mLocalPath, mRemotePath, Long.valueOf(mParentId), Boolean.valueOf(mKeepInSync), mEtag);
         return asString;
     }
 
@@ -449,6 +454,10 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
         return mEtag;
     }
 
+    public void setEtag(String etag) {
+        this.mEtag = etag;
+    }
+    
     public long getLocalModificationTimestamp() {
         if (mLocalPath != null && mLocalPath.length() > 0) {
             File f = new File(mLocalPath);