Fixed: Rotating screen after viewing a file would return you to the
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / datamodel / OCFile.java
index 7e8f428..6861933 100644 (file)
@@ -23,7 +23,7 @@ import java.io.File;
 import android.os.Parcel;
 import android.os.Parcelable;
 
-public class OCFile implements Parcelable {
+public class OCFile implements Parcelable, Comparable<OCFile> {
 
     public static final Parcelable.Creator<OCFile> CREATOR = new Parcelable.Creator<OCFile>() {
         @Override
@@ -86,11 +86,11 @@ public class OCFile implements Parcelable {
     }
 
     /**
-     * Returns the path of the file
+     * Returns the remote path of the file on ownCloud
      * 
-     * @return The path
+     * @return The remote path to the file
      */
-    public String getPath() {
+    public String getRemotePath() {
         return mRemotePath;
     }
 
@@ -119,7 +119,7 @@ public class OCFile implements Parcelable {
      * @return true if it is
      */
     public boolean isDownloaded() {
-        return mLocalPath != null || mLocalPath.equals("");
+        return mLocalPath != null && !mLocalPath.equals("");
     }
 
     /**
@@ -321,4 +321,34 @@ public class OCFile implements Parcelable {
         dest.writeLong(mLastSyncDate);
     }
 
+    @Override
+    public int compareTo(OCFile another) {
+        if (isDirectory() && another.isDirectory()) {
+            return getFileName().toLowerCase().compareTo(another.getFileName().toLowerCase());
+        } else if (isDirectory()) {
+            return -1;
+        } else if (another.isDirectory()) {
+            return 1;
+        }
+        return getFileName().toLowerCase().compareTo(another.getFileName().toLowerCase());
+    }
+
+    public boolean equals(Object o) {
+        if(o instanceof OCFile){
+            OCFile that = (OCFile) o;
+            if(that != null){
+                return this.mId == that.mId;
+            }
+        }
+        
+        return false;
+    }
+
+    @Override
+    public String toString() {
+        String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s]";
+        asString = String.format(asString, new Long(mId), getFileName(), mMimeType, isDownloaded(), mLocalPath, mRemotePath);
+        return asString;
+    }
+
 }