Selaa lähdekoodia

OC-2697: Save data from the Share API response in oc database

masensio 11 vuotta sitten
vanhempi
commit
9243d216fc

+ 5 - 2
oc_framework/src/com/owncloud/android/oc_framework/utils/ShareXMLParser.java

@@ -61,7 +61,7 @@ public class ShareXMLParser {
 
 	private static final String NODE_DATA = "data";
 	private static final String NODE_ELEMENT = "element";
-	//private static final String NODE_ID = "id";
+	private static final String NODE_ID = "id";
 	private static final String NODE_ITEM_TYPE = "item_type";
 	private static final String NODE_ITEM_SOURCE = "item_source";
 	private static final String NODE_PARENT = "parent";
@@ -235,7 +235,10 @@ public class ShareXMLParser {
 			
 			String name = parser.getName();
 
-			if (name.equalsIgnoreCase(NODE_ITEM_TYPE)) {
+			if (name.equalsIgnoreCase(NODE_ID)) {
+				sharedFile.setIdRemoteShared(Integer.parseInt(readNode(parser, NODE_ID)));
+
+			} else if (name.equalsIgnoreCase(NODE_ITEM_TYPE)) {
 				sharedFile.setIsDirectory(readNode(parser, NODE_ITEM_TYPE).equalsIgnoreCase(TYPE_FOLDER));
 
 			} else if (name.equalsIgnoreCase(NODE_ITEM_SOURCE)) {

+ 186 - 0
src/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -27,6 +27,7 @@ import java.util.Vector;
 
 import com.owncloud.android.MainApp;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
+import com.owncloud.android.oc_framework.operations.ShareType;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.Log_OC;
 
@@ -670,6 +671,32 @@ public class FileDataStorageManager {
         }
         return c;
     }
+    
+    private Cursor getShareCursorForValue(String key, String value) {
+        Cursor c = null;
+        if (getContentResolver() != null) {
+            c = getContentResolver()
+                    .query(ProviderTableMeta.CONTENT_URI_SHARE,
+                            null,
+                            key + "=? AND "
+                                    + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
+                                    + "=?",
+                                    new String[] { value, mAccount.name }, null);
+        } else {
+            try {
+                c = getContentProviderClient().query(
+                        ProviderTableMeta.CONTENT_URI_SHARE,
+                        null,
+                        key + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
+                        + "=?", new String[] { value, mAccount.name },
+                        null);
+            } catch (RemoteException e) {
+                Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
+                c = null;
+            }
+        }
+        return c;
+    }
 
     private OCFile createFileInstance(Cursor c) {
         OCFile file = null;
@@ -745,5 +772,164 @@ public class FileDataStorageManager {
         c.close();
         return file.getPublicLink();
     }
+    
+    
+    // Methods for Share Files
+    public boolean saveShareFile(OCShare shareFile) {
+        boolean overriden = false;
+        ContentValues cv = new ContentValues();
+        cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, shareFile.getFileSource());
+        cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, shareFile.getItemSource());
+        cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, shareFile.getShareType().getValue());
+        cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, shareFile.getShareWith());
+        cv.put(ProviderTableMeta.OCSHARES_PATH, shareFile.getPath());
+        cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, shareFile.getPermissions());
+        cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, shareFile.getSharedDate());
+        cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, shareFile.getExpirationDate());
+        cv.put(ProviderTableMeta.OCSHARES_TOKEN, shareFile.getToken());
+        cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, shareFile.getSharedWithDisplayName());
+        cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, shareFile.isDirectory() ? 1 : 0);
+        cv.put(ProviderTableMeta.OCSHARES_USER_ID, shareFile.getUserId());
+        cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, shareFile.getIdRemoteShared());
+        cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
+        
+        boolean samePath = fileShareExists(shareFile.getPath());
+        if (samePath ||
+                fileShareExists(shareFile.getId())        ) {           // for renamed files; no more delete and create
+
+            OCShare oldFile = null;
+            if (samePath) {
+                oldFile = getShareFileByPath(shareFile.getPath());
+                shareFile.setId(oldFile.getId());
+            } else {
+                oldFile = getShareFileById(shareFile.getId());
+            }
 
+            overriden = true;
+            if (getContentResolver() != null) {
+                getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv,
+                        ProviderTableMeta._ID + "=?",
+                        new String[] { String.valueOf(shareFile.getId()) });
+            } else {
+                try {
+                    getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE,
+                            cv, ProviderTableMeta._ID + "=?",
+                            new String[] { String.valueOf(shareFile.getId()) });
+                } catch (RemoteException e) {
+                    Log_OC.e(TAG,
+                            "Fail to insert insert file to database "
+                                    + e.getMessage());
+                }
+            }
+        } else {
+            Uri result_uri = null;
+            if (getContentResolver() != null) {
+                result_uri = getContentResolver().insert(
+                        ProviderTableMeta.CONTENT_URI_SHARE, cv);
+            } else {
+                try {
+                    result_uri = getContentProviderClient().insert(
+                            ProviderTableMeta.CONTENT_URI_SHARE, cv);
+                } catch (RemoteException e) {
+                    Log_OC.e(TAG,
+                            "Fail to insert insert file to database "
+                                    + e.getMessage());
+                }
+            }
+            if (result_uri != null) {
+                long new_id = Long.parseLong(result_uri.getPathSegments()
+                        .get(1));
+                shareFile.setId(new_id);
+            }            
+        }
+
+        return overriden;
+    }
+
+    private OCShare getShareFileById(long id) {
+        Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
+        OCShare share = null;
+        if (c.moveToFirst()) {
+            share = createShareInstance(c);
+        }
+        c.close();
+        return share;
+    }
+
+    public OCShare getShareFileByPath(String path) {
+        Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_PATH, path);
+        OCShare share = null;
+        if (c.moveToFirst()) {
+            share = createShareInstance(c);
+        }
+        c.close();
+        return share;
+    }
+    
+    private OCShare createShareInstance(Cursor c) {
+        OCShare share = null;
+        if (c != null) {
+            share = new OCShare(c.getString(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_PATH)));
+            share.setId(c.getLong(c.getColumnIndex(ProviderTableMeta._ID)));
+            share.setFileSource(c.getLong(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_ITEM_SOURCE)));
+            share.setShareType(ShareType.fromValue(c.getInt(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_TYPE))));
+            share.setPermissions(c.getInt(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_PERMISSIONS)));
+            share.setSharedDate(c.getLong(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_SHARED_DATE)));
+            share.setExpirationDate(c.getLong(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_EXPIRATION_DATE)));
+            share.setToken(c.getString(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_TOKEN)));
+            share.setSharedWithDisplayName(c.getString(c
+                    .getColumnIndex(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME)));
+            share.setIsDirectory(c.getInt(
+                    c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_DIRECTORY)) == 1 ? true : false);
+            share.setUserId(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_USER_ID)));
+            share.setIdRemoteShared(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED)));
+                    
+        }
+        return share;
+    }
+
+    private boolean fileShareExists(String cmp_key, String value) {
+        Cursor c;
+        if (getContentResolver() != null) {
+            c = getContentResolver()
+                    .query(ProviderTableMeta.CONTENT_URI_SHARE,
+                            null,
+                            cmp_key + "=? AND "
+                                    + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
+                                    + "=?",
+                                    new String[] { value, mAccount.name }, null);
+        } else {
+            try {
+                c = getContentProviderClient().query(
+                        ProviderTableMeta.CONTENT_URI_SHARE,
+                        null,
+                        cmp_key + "=? AND "
+                                + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
+                                new String[] { value, mAccount.name }, null);
+            } catch (RemoteException e) {
+                Log_OC.e(TAG,
+                        "Couldn't determine file existance, assuming non existance: "
+                                + e.getMessage());
+                return false;
+            }
+        }
+        boolean retval = c.moveToFirst();
+        c.close();
+        return retval;
+    }
+    
+    public boolean fileShareExists(long id) {
+        return fileShareExists(ProviderTableMeta._ID, String.valueOf(id));
+    }
+
+    public boolean fileShareExists(String path) {
+        return fileShareExists(ProviderTableMeta.OCSHARES_PATH, path);
+    }
 }

+ 29 - 1
src/com/owncloud/android/datamodel/OCShare.java

@@ -17,6 +17,7 @@
 
 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;
 
@@ -59,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
      */
@@ -188,6 +213,10 @@ public class OCShare implements Parcelable{
     public long getId() {
         return mId;
     }
+    
+    public void setId(long id){
+        mId = id;
+    }
 
     /** 
      * Parcelable Methods
@@ -252,5 +281,4 @@ public class OCShare implements Parcelable{
         dest.writeLong(mUserId);
         dest.writeLong(mIdRemoteShared);
     }
-
 }

+ 1 - 0
src/com/owncloud/android/db/ProviderMeta.java

@@ -86,6 +86,7 @@ public class ProviderMeta {
         public static final String OCSHARES_IS_DIRECTORY = "is_directory";
         public static final String OCSHARES_USER_ID = "user_id";
         public static final String OCSHARES_ID_REMOTE_SHARED = "id_remote_shared";
+        public static final String OCSHARES_ACCOUNT_OWNER = "owner_share";
         
         public static final String OCSHARES_DEFAULT_SORT_ORDER = OCSHARES_FILE_SOURCE 
                 + " collate nocase asc";

+ 42 - 4
src/com/owncloud/android/operations/GetSharedFilesOperation.java

@@ -17,10 +17,19 @@
 
 package com.owncloud.android.operations;
 
+import java.util.ArrayList;
+
+import com.owncloud.android.datamodel.FileDataStorageManager;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.OCShare;
 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
 import com.owncloud.android.oc_framework.operations.RemoteOperation;
 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
+import com.owncloud.android.oc_framework.operations.ShareRemoteFile;
+import com.owncloud.android.oc_framework.operations.ShareType;
 import com.owncloud.android.oc_framework.operations.remote.GetRemoteSharedFilesOperation;
+import com.owncloud.android.oc_framework.utils.FileUtils;
+import com.owncloud.android.utils.Log_OC;
 
 /**
  * Access to remote operation to get the share files/folders
@@ -30,11 +39,16 @@ import com.owncloud.android.oc_framework.operations.remote.GetRemoteSharedFilesO
  */
 
 public class GetSharedFilesOperation extends RemoteOperation {
+    
+    private static final String TAG = GetSharedFilesOperation.class.getSimpleName();
 
     private String mUrlServer;
+    protected FileDataStorageManager mStorageManager;
+    
 
-    public GetSharedFilesOperation(String urlServer) {
+    public GetSharedFilesOperation(String urlServer, FileDataStorageManager storageManager) {
         mUrlServer = urlServer;
+        mStorageManager = storageManager;
     }
 
     @Override
@@ -45,12 +59,36 @@ public class GetSharedFilesOperation extends RemoteOperation {
         if (result.isSuccess()) {
             
             // Update DB with the response
-            
-        } else {
-            
+            ArrayList<ShareRemoteFile> shareRemoteFiles = operation.getSharedFiles();
+            Log_OC.d(TAG, "Share list size = " + shareRemoteFiles.size());
+            for (ShareRemoteFile remoteFile: shareRemoteFiles) {
+                OCShare shareFile = new OCShare(remoteFile);
+                saveShareFileInDB(shareFile);
+            }
         }
         
         return result;
     }
 
+    private void saveShareFileInDB(OCShare shareFile) {
+        // Save share file
+        mStorageManager.saveShareFile(shareFile);
+        
+        // Get the path
+        String path = shareFile.getPath();
+        if (shareFile.isDirectory()) {
+            path = path + FileUtils.PATH_SEPARATOR;
+        }           
+            
+        // Update OCFile with data from share: ShareByLink  ¿and publicLink?
+        OCFile file = mStorageManager.getFileByPath(path);
+        if (file != null) {
+            if (shareFile.getShareType().equals(ShareType.PUBLIC_LINK)) {
+                file.setShareByLink(true);
+                mStorageManager.saveFile(file);
+            }
+        } 
+    }
+
+    
 }

+ 97 - 31
src/com/owncloud/android/providers/FileContentProvider.java

@@ -131,6 +131,8 @@ public class FileContentProvider extends ContentProvider {
                 ProviderTableMeta.OCSHARES_USER_ID);
         mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED,
                 ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED);
+        mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER,
+                ProviderTableMeta.OCSHARES_ACCOUNT_OWNER);
     }
     
     private UriMatcher mUriMatcher;
@@ -151,7 +153,6 @@ public class FileContentProvider extends ContentProvider {
         return count;
     }
     
-    // TODO: switch(uri)
     private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
         int count = 0;
         switch (mUriMatcher.match(uri)) {
@@ -222,6 +223,14 @@ public class FileContentProvider extends ContentProvider {
             //Log_OC.d(TAG, "Removing ROOT!");
             count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
             break;
+        case SHARES:
+            count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME,
+                    ProviderTableMeta._ID
+                            + "="
+                            + uri.getPathSegments().get(1)
+                            + (!TextUtils.isEmpty(where) ? " AND (" + where
+                                    + ")" : ""), whereArgs);
+            break;
         default:
             //Log_OC.e(TAG, "Unknown uri " + uri);
             throw new IllegalArgumentException("Unknown uri: " + uri.toString());
@@ -260,36 +269,63 @@ public class FileContentProvider extends ContentProvider {
         return newUri;
     }
     
-    // TODO: switch(uri)
     private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
-        if (mUriMatcher.match(uri) != SINGLE_FILE &&
-                mUriMatcher.match(uri) != ROOT_DIRECTORY) {
-            //Log_OC.e(TAG, "Inserting invalid URI: " + uri);
-            throw new IllegalArgumentException("Unknown uri id: " + uri);
-        }
+        switch (mUriMatcher.match(uri)){
+        case ROOT_DIRECTORY:
+        case SINGLE_FILE:
+            String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
+            String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
+            String[] projection = new String[] {ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER };
+            String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
+            String[] whereArgs = new String[] {remotePath, accountName};
+            Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
+            if (doubleCheck == null || !doubleCheck.moveToFirst()) {    // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider 
+                long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
+                if (rowId > 0) {
+                    Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
+                    //Log_OC.d(TAG, "Inserted " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
+                    return insertedFileUri;
+                } else {
+                    //Log_OC.d(TAG, "Error while inserting " + values.getAsString(ProviderTableMeta.FILE_PATH)  + " at provider " + this);
+                    throw new SQLException("ERROR " + uri);
+                }
+            } else {
+                // file is already inserted; race condition, let's avoid a duplicated entry
+                Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID)));
+                doubleCheck.close();
 
-        String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
-        String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
-        String[] projection = new String[] {ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER };
-        String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
-        String[] whereArgs = new String[] {remotePath, accountName};
-        Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
-        if (doubleCheck == null || !doubleCheck.moveToFirst()) {    // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider 
-            long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
-            if (rowId > 0) {
-                Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
-                //Log_OC.d(TAG, "Inserted " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
                 return insertedFileUri;
+            }
+            
+        case SHARES:
+            String path = values.getAsString(ProviderTableMeta.OCSHARES_PATH);
+            String accountNameShare= values.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER);
+            String[] projectionShare = new String[] {ProviderTableMeta._ID, ProviderTableMeta.OCSHARES_PATH, ProviderTableMeta.OCSHARES_ACCOUNT_OWNER };
+            String whereShare = ProviderTableMeta.OCSHARES_PATH + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
+            String[] whereArgsShare = new String[] {path, accountNameShare};
+            Cursor doubleCheckShare = query(db, uri, projectionShare, whereShare, whereArgsShare, null);
+            if (doubleCheckShare == null || !doubleCheckShare.moveToFirst()) {    // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider 
+                long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
+                if (rowId >0) {
+                    Uri insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
+                    return insertedShareUri;
+                } else {
+                    throw new SQLException("ERROR " + uri);
+
+                }
             } else {
-                //Log_OC.d(TAG, "Error while inserting " + values.getAsString(ProviderTableMeta.FILE_PATH)  + " at provider " + this);
-                throw new SQLException("ERROR " + uri);
+                // file is already inserted; race condition, let's avoid a duplicated entry
+                Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, doubleCheckShare.getLong(doubleCheckShare.getColumnIndex(ProviderTableMeta._ID)));
+                doubleCheckShare.close();
+
+                return insertedFileUri;
             }
-        } else {
-            // file is already inserted; race condition, let's avoid a duplicated entry
-            Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID)));
-            doubleCheck.close();
-            return insertedFileUri;
+            
+
+        default:
+            throw new IllegalArgumentException("Unknown uri id: " + uri);
         }
+        
     }
 
     
@@ -345,7 +381,13 @@ public class FileContentProvider extends ContentProvider {
                         + uri.getPathSegments().get(1));
             }
             break;
-        case SHARES: //TODO
+        case SHARES: 
+            sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME);
+            sqlQuery.setProjectionMap(mOCSharesProjectionMap);
+            if (uri.getPathSegments().size() > 1) {
+                sqlQuery.appendWhere(ProviderTableMeta._ID + "="
+                        + uri.getPathSegments().get(1));
+            }
             break;
         default:
             throw new IllegalArgumentException("Unknown uri id: " + uri);
@@ -353,7 +395,12 @@ public class FileContentProvider extends ContentProvider {
 
         String order;
         if (TextUtils.isEmpty(sortOrder)) {
-            order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
+            if (mUriMatcher.match(uri) == SHARES) {
+                order = ProviderTableMeta.OCSHARES_DEFAULT_SORT_ORDER;
+            } else {
+
+                order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
+            }
         } else {
             order = sortOrder;
         }
@@ -365,7 +412,6 @@ public class FileContentProvider extends ContentProvider {
         return c;
     }
 
-    // TODO: switch(uri)
     @Override
     public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
         
@@ -384,11 +430,13 @@ public class FileContentProvider extends ContentProvider {
     }
     
     
-    // TODO: switch(uri)
+
     private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
         switch (mUriMatcher.match(uri)) {
             case DIRECTORY:
                 return updateFolderSize(db, selectionArgs[0]);
+            case SHARES:
+                return db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs);
             default:
                 return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
         }
@@ -499,6 +547,24 @@ public class FileContentProvider extends ContentProvider {
                     + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, "
                     + ProviderTableMeta.FILE_PUBLIC_LINK  + " TEXT );"
                     );
+            
+            // Create table ocshares
+            db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
+                    + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
+                    + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_PATH + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, "
+                    + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, "  // boolean
+                    + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
+                    + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," 
+                    + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" );
         }
 
         @Override
@@ -596,8 +662,8 @@ public class FileContentProvider extends ContentProvider {
                             + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, "
                             + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, "  // boolean
                             + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
-                            + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER );"
-                            );
+                            + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," 
+                            + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" );
                     
                     upgraded = true;
                     db.setTransactionSuccessful();

+ 1 - 1
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -1519,7 +1519,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         AccountManager accountMngr = AccountManager.get(this); 
         String urlServer = accountMngr.getUserData(getAccount(), OwnCloudAccount.Constants.KEY_OC_BASE_URL);
         
-        RemoteOperation getSharedFiles = new GetSharedFilesOperation(urlServer);
+        RemoteOperation getSharedFiles = new GetSharedFilesOperation(urlServer, mStorageManager);
         getSharedFiles.execute(getAccount(), this, null, null, this);
         
     }