Fixed crash in first installation
[pub/Android/ownCloud.git] / src / com / owncloud / android / datamodel / OCShare.java
index 52b5543..07069f9 100644 (file)
@@ -17,6 +17,8 @@
 
 package com.owncloud.android.datamodel;
 
+import com.owncloud.android.oc_framework.operations.ShareRemoteFile;
+import com.owncloud.android.oc_framework.operations.ShareType;
 import com.owncloud.android.utils.Log_OC;
 
 import android.os.Parcel;
@@ -26,47 +28,6 @@ public class OCShare implements Parcelable{
 
     private static final String TAG = OCShare.class.getSimpleName();
     
-    // Enum for ShareType
-    public enum ShareType {
-        NO_SHARED (-1),
-        USER (0),
-        GROUP (1),
-        PUBLIC_LINK (3),
-        EMAIL (4),
-        CONTACT (5);
-        
-        private int value;
-        
-        private ShareType(int value)
-        {
-            this.value = value;
-        }
-        
-        public int getValue() {
-            return value;
-        }
-        
-        public static ShareType fromValue(int value)
-        {
-            switch (value)
-            {
-            case -1:
-                return NO_SHARED;
-            case 0:
-                return USER;
-            case 1:
-                return GROUP;
-            case 3:
-                return PUBLIC_LINK;
-            case 4:
-                return EMAIL;
-            case 5:
-                return CONTACT;
-            }
-            return null;
-        }
-    };
-    
     private long mId;
     private long mFileSource;
     private long mItemSource;
@@ -99,6 +60,30 @@ public class OCShare implements Parcelable{
         mPath = path;
     }
 
+    public OCShare(ShareRemoteFile remoteFile) {
+        mId = -1;
+
+        String path = remoteFile.getPath();
+        if (path == null || path.length() <= 0 || !path.startsWith(OCFile.PATH_SEPARATOR)) {
+            Log_OC.e(TAG, "Trying to create a OCShare with a non valid path");
+            throw new IllegalArgumentException("Trying to create a OCShare with a non valid path: " + path);
+        }
+        mPath = path;
+        
+        mFileSource = remoteFile.getFileSource();
+        mItemSource = remoteFile.getItemSource();
+        mShareType = remoteFile.getShareType();
+        mShareWith = remoteFile.getShareWith();
+        mPermissions = remoteFile.getPermissions();
+        mSharedDate = remoteFile.getSharedDate();
+        mExpirationDate = remoteFile.getExpirationDate();
+        mToken = remoteFile.getToken();
+        mSharedWithDisplayName = remoteFile.getSharedWithDisplayName();
+        mIsDirectory = remoteFile.isDirectory();
+        mUserId = remoteFile.getUserId();
+        mIdRemoteShared = remoteFile.getIdRemoteShared();
+    }
+    
     /**
      * Used internally. Reset all file properties
      */
@@ -228,8 +213,14 @@ public class OCShare implements Parcelable{
     public long getId() {
         return mId;
     }
+    
+    public void setId(long id){
+        mId = id;
+    }
 
-    /// Parcelable methods
+    /** 
+     * Parcelable Methods
+     */
     public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
         @Override
         public OCShare createFromParcel(Parcel source) {
@@ -290,5 +281,4 @@ public class OCShare implements Parcelable{
         dest.writeLong(mUserId);
         dest.writeLong(mIdRemoteShared);
     }
-
 }