Browse Source

Merge pull request #364 from owncloud/share_link__code_improvements

Code improvements in code for getting all the remote shares
David A. Velasco 11 years ago
parent
commit
ab3044dc82

+ 1 - 1
owncloud-android-library

@@ -1 +1 @@
-Subproject commit 7b5d6cdef791cd27a573fcaa9c8214970753843c
+Subproject commit 7126c73e6324ca8d3615fc4757191848e03d5644

+ 2 - 1
res/menu/file_actions_menu.xml

@@ -19,7 +19,8 @@
 -->
 <menu 	xmlns:android="http://schemas.android.com/apk/res/android">
     
-	<item 	android:id="@+id/action_open_file_with"			android:title="@string/actionbar_open_with"			android:icon="@android:drawable/ic_menu_edit"					android:orderInCategory="1" />
+	<item 	android:id="@+id/action_share_file"				android:title="@string/action_share_file"			android:icon="@android:drawable/ic_menu_share"					android:orderInCategory="1" />
+    <item 	android:id="@+id/action_open_file_with"			android:title="@string/actionbar_open_with"			android:icon="@android:drawable/ic_menu_edit"					android:orderInCategory="1" />
 	<item 	android:id="@+id/action_download_file" 			android:title="@string/filedetails_download"		android:icon="@drawable/ic_action_download"						android:orderInCategory="1" />
     <item 	android:id="@+id/action_sync_file"				android:title="@string/filedetails_sync_file"		android:icon="@drawable/ic_action_refresh"						android:orderInCategory="1" />
 	<item 	android:id="@+id/action_cancel_download"		android:title="@string/common_cancel_download"	 	android:icon="@android:drawable/ic_menu_close_clear_cancel"		android:orderInCategory="1" />

+ 1 - 0
res/values-es-rCL/strings.xml

@@ -12,4 +12,5 @@
   <string name="setup_btn_connect">Conectar</string>
   <string name="uploader_btn_upload_text">Subir</string>
   <string name="uploader_wrn_no_account_title">No se encuentra la cuenta</string>
+  <string name="uploader_info_uploading">Subiendo</string>
 </resources>

+ 5 - 0
res/values-eu-rES/strings.xml

@@ -0,0 +1,5 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<resources>
+  <string name="filedetails_download">Deskargatu</string>
+  <string name="common_cancel">Ezeztatu</string>
+</resources>

+ 1 - 0
res/values/strings.xml

@@ -59,6 +59,7 @@
     <string name="filedetails_download">Download</string>
     <string name="filedetails_sync_file">Refresh file</string>
     <string name="filedetails_renamed_in_upload_msg">File was renamed to %1$s during upload</string>
+    <string name="action_share_file">Share link</string>
     <string name="common_yes">Yes</string>
     <string name="common_no">No</string>
     <string name="common_ok">OK</string>

+ 180 - 34
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.lib.operations.common.OCShare;
 import com.owncloud.android.lib.operations.common.ShareType;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.Log_OC;
@@ -748,7 +749,7 @@ public class FileDataStorageManager {
      * @param path  Path of the file/folder
      * @return
      */
-    public boolean isFileShareByLink(String path) {
+    public boolean isShareByLink(String path) {
         Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
         OCFile file = null;
         if (c.moveToFirst()) {
@@ -763,7 +764,7 @@ public class FileDataStorageManager {
      * @param path  Path of the file/folder
      * @return
      */
-    public String getFilePublicLink(String path) {
+    public String getPublicLink(String path) {
         Cursor c = getCursorForValue(ProviderTableMeta.FILE_STORAGE_PATH, path);
         OCFile file = null;
         if (c.moveToFirst()) {
@@ -774,47 +775,47 @@ public class FileDataStorageManager {
     }
     
     
-    // Methods for Share Files
-    public boolean saveShareFile(OCShare shareFile) {
+    // Methods for Shares
+    public boolean saveShare(OCShare share) {
         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_FILE_SOURCE, share.getFileSource());
+        cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
+        cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
+        cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
+        cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
+        cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
+        cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
+        cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
+        cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
+        cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
+        cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isDirectory() ? 1 : 0);
+        cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
+        cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
         cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
         
-        boolean samePath = fileShareExists(shareFile.getPath());
+        boolean samePath = shareExists(share.getPath());
         if (samePath ||
-                fileShareExists(shareFile.getId())        ) {           // for renamed files; no more delete and create
+                shareExists(share.getId())) {           // for renamed files; no more delete and create
 
             OCShare oldFile = null;
             if (samePath) {
-                oldFile = getShareFileByPath(shareFile.getPath());
-                shareFile.setId(oldFile.getId());
+                oldFile = getShareByPath(share.getPath());
+                share.setId(oldFile.getId());
             } else {
-                oldFile = getShareFileById(shareFile.getId());
+                oldFile = getShareById(share.getId());
             }
 
             overriden = true;
             if (getContentResolver() != null) {
                 getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv,
                         ProviderTableMeta._ID + "=?",
-                        new String[] { String.valueOf(shareFile.getId()) });
+                        new String[] { String.valueOf(share.getId()) });
             } else {
                 try {
                     getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE,
                             cv, ProviderTableMeta._ID + "=?",
-                            new String[] { String.valueOf(shareFile.getId()) });
+                            new String[] { String.valueOf(share.getId()) });
                 } catch (RemoteException e) {
                     Log_OC.e(TAG,
                             "Fail to insert insert file to database "
@@ -839,14 +840,14 @@ public class FileDataStorageManager {
             if (result_uri != null) {
                 long new_id = Long.parseLong(result_uri.getPathSegments()
                         .get(1));
-                shareFile.setId(new_id);
+                share.setId(new_id);
             }            
         }
 
         return overriden;
     }
 
-    private OCShare getShareFileById(long id) {
+    private OCShare getShareById(long id) {
         Cursor c = getShareCursorForValue(ProviderTableMeta._ID, String.valueOf(id));
         OCShare share = null;
         if (c.moveToFirst()) {
@@ -856,7 +857,7 @@ public class FileDataStorageManager {
         return share;
     }
 
-    public OCShare getShareFileByPath(String path) {
+    public OCShare getShareByPath(String path) {
         Cursor c = getShareCursorForValue(ProviderTableMeta.OCSHARES_PATH, path);
         OCShare share = null;
         if (c.moveToFirst()) {
@@ -895,7 +896,7 @@ public class FileDataStorageManager {
         return share;
     }
 
-    private boolean fileShareExists(String cmp_key, String value) {
+    private boolean shareExists(String cmp_key, String value) {
         Cursor c;
         if (getContentResolver() != null) {
             c = getContentResolver()
@@ -925,15 +926,15 @@ public class FileDataStorageManager {
         return retval;
     }
     
-    public boolean fileShareExists(long id) {
-        return fileShareExists(ProviderTableMeta._ID, String.valueOf(id));
+    public boolean shareExists(long id) {
+        return shareExists(ProviderTableMeta._ID, String.valueOf(id));
     }
 
-    public boolean fileShareExists(String path) {
-        return fileShareExists(ProviderTableMeta.OCSHARES_PATH, path);
+    public boolean shareExists(String path) {
+        return shareExists(ProviderTableMeta.OCSHARES_PATH, path);
     }
     
-    public void cleanShareFile() {
+    private void cleanSharedFiles() {
         ContentValues cv = new ContentValues();
         cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, false);
         cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
@@ -948,8 +949,153 @@ public class FileDataStorageManager {
                 getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
                 
             } catch (RemoteException e) {
-                Log_OC.e(TAG, "Exception in cleanShareFile" + e.getMessage());
+                Log_OC.e(TAG, "Exception in cleanSharedFiles" + e.getMessage());
             }
         }
+    }
+
+    private void cleanShares() {
+        String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
+        String [] whereArgs = new String[]{mAccount.name};
+        
+        if (getContentResolver() != null) {
+            getContentResolver().delete(ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs);
+
+        } else {
+            try {
+                getContentProviderClient().delete(ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs);
+                
+            } catch (RemoteException e) {
+                Log_OC.e(TAG, "Exception in cleanShares" + e.getMessage());
+            }
+        }
+    }
+    
+    public void saveShares(Collection<OCShare> shares) {
+        if (shares != null) {
+            cleanShares();
+            
+            ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(shares.size());
+
+            // prepare operations to insert or update files to save in the given folder
+            for (OCShare share : shares) {
+                ContentValues cv = new ContentValues();
+                cv.put(ProviderTableMeta.OCSHARES_FILE_SOURCE, share.getFileSource());
+                cv.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE, share.getItemSource());
+                cv.put(ProviderTableMeta.OCSHARES_SHARE_TYPE, share.getShareType().getValue());
+                cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH, share.getShareWith());
+                cv.put(ProviderTableMeta.OCSHARES_PATH, share.getPath());
+                cv.put(ProviderTableMeta.OCSHARES_PERMISSIONS, share.getPermissions());
+                cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
+                cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
+                cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
+                cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
+                cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isDirectory() ? 1 : 0);
+                cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
+                cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
+                cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
+
+                boolean existsByPath = shareExists(share.getPath());
+                if (existsByPath || shareExists(share.getId())) {
+                    // updating an existing file
+                    operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
+                            withValues(cv).
+                            withSelection(  ProviderTableMeta._ID + "=?", 
+                                    new String[] { String.valueOf(share.getId()) })
+                                    .build());
+
+                } else {
+                    // adding a new file
+                    operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).build());
+                }
+            }
+            
+            // apply operations in batch
+            @SuppressWarnings("unused")
+            ContentProviderResult[] results = null;
+            Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
+            try {
+                if (getContentResolver() != null) {
+                    results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
+
+                } else {
+                    results = getContentProviderClient().applyBatch(operations);
+                }
+
+            } catch (OperationApplicationException e) {
+                Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
+
+            } catch (RemoteException e) {
+                Log_OC.e(TAG, "Exception in batch of operations  " + e.getMessage());
+            }
+            
+        }
+        
+    }
+    
+    public void updateSharedFiles(Collection<OCFile> sharedFiles) {
+        if (sharedFiles != null) {
+            cleanSharedFiles();
+            
+            ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(sharedFiles.size());
+
+            // prepare operations to insert or update files to save in the given folder
+            for (OCFile file : sharedFiles) {
+                ContentValues cv = new ContentValues();
+                cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
+                cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
+                cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
+                cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
+                cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
+                cv.put(ProviderTableMeta.FILE_NAME, file.getFileName());
+                cv.put(ProviderTableMeta.FILE_PARENT, file.getParentId());
+                cv.put(ProviderTableMeta.FILE_PATH, file.getRemotePath());
+                if (!file.isFolder()) {
+                    cv.put(ProviderTableMeta.FILE_STORAGE_PATH, file.getStoragePath());
+                }
+                cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
+                cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
+                cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
+                cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
+                cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
+                cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
+                cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
+
+                boolean existsByPath = fileExists(file.getRemotePath());
+                if (existsByPath || fileExists(file.getFileId())) {
+                    // updating an existing file
+                    operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
+                            withValues(cv).
+                            withSelection(  ProviderTableMeta._ID + "=?", 
+                                    new String[] { String.valueOf(file.getFileId()) })
+                                    .build());
+
+                } else {
+                    // adding a new file
+                    operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build());
+                }
+            }
+            
+            // apply operations in batch
+            @SuppressWarnings("unused")
+            ContentProviderResult[] results = null;
+            Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
+            try {
+                if (getContentResolver() != null) {
+                    results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
+
+                } else {
+                    results = getContentProviderClient().applyBatch(operations);
+                }
+
+            } catch (OperationApplicationException e) {
+                Log_OC.e(TAG, "Exception in batch of operations " + e.getMessage());
+
+            } catch (RemoteException e) {
+                Log_OC.e(TAG, "Exception in batch of operations  " + e.getMessage());
+            }
+            
+        }
+        
     } 
 }

+ 0 - 284
src/com/owncloud/android/datamodel/OCShare.java

@@ -1,284 +0,0 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012-2014 ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.datamodel;
-
-import com.owncloud.android.lib.operations.common.ShareRemoteFile;
-import com.owncloud.android.lib.operations.common.ShareType;
-import com.owncloud.android.utils.Log_OC;
-
-import android.os.Parcel;
-import android.os.Parcelable;
-
-public class OCShare implements Parcelable{
-
-    private static final String TAG = OCShare.class.getSimpleName();
-    
-    private long mId;
-    private long mFileSource;
-    private long mItemSource;
-    private ShareType mShareType;
-    private String mShareWith;
-    private String mPath;
-    private int mPermissions;
-    private long mSharedDate;
-    private long mExpirationDate;
-    private String mToken;
-    private String mSharedWithDisplayName;
-    private boolean mIsDirectory;
-    private long mUserId;
-    private long mIdRemoteShared;
-    
-    
-    /**
-     * Create new {@link OCShare} with given path.
-     * 
-     * The path received must be URL-decoded. Path separator must be OCFile.PATH_SEPARATOR, and it must be the first character in 'path'.
-     * 
-     * @param path The remote path of the file.
-     */
-    public OCShare(String path) {
-        resetData();
-        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;
-    }
-
-    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
-     */
-    private void resetData() {
-        mId = -1;
-        mFileSource = 0;
-        mItemSource = 0;
-        mShareType = ShareType.NO_SHARED; 
-        mShareWith = null;
-        mPath = null;
-        mPermissions = -1;
-        mSharedDate = 0;
-        mExpirationDate = 0;
-        mToken = null;
-        mSharedWithDisplayName = null;
-        mIsDirectory = false;
-        mUserId = -1;
-        mIdRemoteShared = -1;
-        
-    }
-    
-    /// Getters and Setters
-    public long getFileSource() {
-        return mFileSource;
-    }
-
-    public void setFileSource(long fileSource) {
-        this.mFileSource = fileSource;
-    }
-
-    public long getItemSource() {
-        return mItemSource;
-    }
-
-    public void setItemSource(long itemSource) {
-        this.mItemSource = itemSource;
-    }
-
-    public ShareType getShareType() {
-        return mShareType;
-    }
-
-    public void setShareType(ShareType shareType) {
-        this.mShareType = shareType;
-    }
-
-    public String getShareWith() {
-        return mShareWith;
-    }
-
-    public void setShareWith(String shareWith) {
-        this.mShareWith = shareWith;
-    }
-
-    public String getPath() {
-        return mPath;
-    }
-
-    public void setPath(String path) {
-        this.mPath = path;
-    }
-
-    public int getPermissions() {
-        return mPermissions;
-    }
-
-    public void setPermissions(int permissions) {
-        this.mPermissions = permissions;
-    }
-
-    public long getSharedDate() {
-        return mSharedDate;
-    }
-
-    public void setSharedDate(long sharedDate) {
-        this.mSharedDate = sharedDate;
-    }
-
-    public long getExpirationDate() {
-        return mExpirationDate;
-    }
-
-    public void setExpirationDate(long expirationDate) {
-        this.mExpirationDate = expirationDate;
-    }
-
-    public String getToken() {
-        return mToken;
-    }
-
-    public void setToken(String token) {
-        this.mToken = token;
-    }
-
-    public String getSharedWithDisplayName() {
-        return mSharedWithDisplayName;
-    }
-
-    public void setSharedWithDisplayName(String sharedWithDisplayName) {
-        this.mSharedWithDisplayName = sharedWithDisplayName;
-    }
-
-    public boolean isDirectory() {
-        return mIsDirectory;
-    }
-
-    public void setIsDirectory(boolean isDirectory) {
-        this.mIsDirectory = isDirectory;
-    }
-
-    public long getUserId() {
-        return mUserId;
-    }
-
-    public void setUserId(long userId) {
-        this.mUserId = userId;
-    }
-
-    public long getIdRemoteShared() {
-        return mIdRemoteShared;
-    }
-
-    public void setIdRemoteShared(long idRemoteShared) {
-        this.mIdRemoteShared = idRemoteShared;
-    }
-
-    public long getId() {
-        return mId;
-    }
-    
-    public void setId(long id){
-        mId = id;
-    }
-
-    /** 
-     * Parcelable Methods
-     */
-    public static final Parcelable.Creator<OCShare> CREATOR = new Parcelable.Creator<OCShare>() {
-        @Override
-        public OCShare createFromParcel(Parcel source) {
-            return new OCShare(source);
-        }
-
-        @Override
-        public OCShare[] newArray(int size) {
-            return new OCShare[size];
-        }
-    };
-    
-    /**
-     * Reconstruct from parcel
-     * 
-     * @param source The source parcel
-     */
-    private OCShare(Parcel source) {
-        mId = source.readLong();
-        mFileSource = source.readLong();
-        mItemSource = source.readLong();
-        try {
-            mShareType = ShareType.valueOf(source.readString());
-        } catch (IllegalArgumentException x) {
-            mShareType = ShareType.NO_SHARED;
-        }
-        mShareWith = source.readString();
-        mPath = source.readString();
-        mPermissions = source.readInt();
-        mSharedDate = source.readLong();
-        mExpirationDate = source.readLong();
-        mToken = source.readString();
-        mSharedWithDisplayName = source.readString();
-        mIsDirectory = source.readInt() == 0;
-        mUserId = source.readLong();
-        mIdRemoteShared = source.readLong();
-    }
-    
-    @Override
-    public int describeContents() {
-        return this.hashCode();
-    }
-
-    @Override
-    public void writeToParcel(Parcel dest, int flags) {
-        dest.writeLong(mId);
-        dest.writeLong(mFileSource);
-        dest.writeLong(mItemSource);
-        dest.writeString((mShareType == null) ? "" : mShareType.name());
-        dest.writeString(mShareWith);
-        dest.writeString(mPath);
-        dest.writeInt(mPermissions);
-        dest.writeLong(mSharedDate);
-        dest.writeLong(mExpirationDate);
-        dest.writeString(mToken);
-        dest.writeString(mSharedWithDisplayName);
-        dest.writeInt(mIsDirectory ? 1 : 0);
-        dest.writeLong(mUserId);
-        dest.writeLong(mIdRemoteShared);
-    }
-}

+ 1 - 1
src/com/owncloud/android/files/services/FileUploader.java

@@ -605,7 +605,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
         ReadRemoteFileOperation operation = new ReadRemoteFileOperation(mCurrentUpload.getRemotePath());
         RemoteOperationResult result = operation.execute(mUploadClient);
         if (result.isSuccess()) {
-            updateOCFile(file, result.getData().get(0));
+            updateOCFile(file, (RemoteFile) result.getData().get(0));
             file.setLastSyncDateForProperties(syncDate);
         }
         

+ 44 - 37
src/com/owncloud/android/operations/GetSharedFilesOperation.java → src/com/owncloud/android/operations/GetSharesOperation.java

@@ -21,13 +21,12 @@ 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.lib.network.OwnCloudClient;
 import com.owncloud.android.lib.operations.common.RemoteOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
-import com.owncloud.android.lib.operations.common.ShareRemoteFile;
+import com.owncloud.android.lib.operations.common.OCShare;
 import com.owncloud.android.lib.operations.common.ShareType;
-import com.owncloud.android.lib.operations.remote.GetRemoteSharedFilesOperation;
+import com.owncloud.android.lib.operations.remote.GetRemoteSharesOperation;
 import com.owncloud.android.lib.utils.FileUtils;
 import com.owncloud.android.utils.Log_OC;
 
@@ -38,58 +37,66 @@ import com.owncloud.android.utils.Log_OC;
  * @author masensio
  */
 
-public class GetSharedFilesOperation extends RemoteOperation {
-    
-    private static final String TAG = GetSharedFilesOperation.class.getSimpleName();
+public class GetSharesOperation extends RemoteOperation {
+
+    private static final String TAG = GetSharesOperation.class.getSimpleName();
 
-    private String mUrlServer;
     protected FileDataStorageManager mStorageManager;
-    
 
-    public GetSharedFilesOperation(String urlServer, FileDataStorageManager storageManager) {
-        mUrlServer = urlServer;
+
+    public GetSharesOperation(FileDataStorageManager storageManager) {
         mStorageManager = storageManager;
     }
 
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
-        GetRemoteSharedFilesOperation operation = new GetRemoteSharedFilesOperation(mUrlServer);
+        GetRemoteSharesOperation operation = new GetRemoteSharesOperation();
         RemoteOperationResult result = operation.execute(client);
-        
+
         if (result.isSuccess()) {
-            
-            // Clean Share data in filelist table
-            mStorageManager.cleanShareFile();
+
             // Update DB with the response
-            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);
+            Log_OC.d(TAG, "Share list size = " + result.getData().size());
+            ArrayList<OCShare> shares = new ArrayList<OCShare>();
+            for(Object obj: result.getData()) {
+                shares.add((OCShare) obj);
             }
+
+            saveSharesDB(shares);
         }
-        
+
         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;
-        }           
+    private void saveSharesDB(ArrayList<OCShare> shares) {
+
+        if (shares.size() > 0) {
+            // Save share file
+            mStorageManager.saveShares(shares);
+
+            ArrayList<OCFile> sharedFiles = new ArrayList<OCFile>();
+
+            for (OCShare share : shares) {
+                // Get the path
+                String path = share.getPath();
+                if (share.isDirectory()) {
+                    path = path + FileUtils.PATH_SEPARATOR;
+                }           
+
+                // Update OCFile with data from share: ShareByLink  ¿and publicLink?
+                OCFile file = mStorageManager.getFileByPath(path);
+                if (file != null) {
+                    if (share.getShareType().equals(ShareType.PUBLIC_LINK)) {
+                        file.setShareByLink(true);
+                        sharedFiles.add(file);
+                    }
+                } 
+            }
             
-        // 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);
+            if (sharedFiles.size() > 0) {
+                mStorageManager.updateSharedFiles(sharedFiles);
             }
-        } 
+        }
     }
 
 }

+ 5 - 5
src/com/owncloud/android/operations/OAuth2GetAccessToken.java

@@ -70,7 +70,7 @@ public class OAuth2GetAccessToken extends RemoteOperation {
                 nameValuePairs[3] = new NameValuePair(OAuth2Constants.KEY_CLIENT_ID, mClientId);
                 //nameValuePairs[4] = new NameValuePair(OAuth2Constants.KEY_SCOPE, mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_SCOPE));         
                 
-                postMethod = new PostMethod(client.getBaseUri().toString());
+                postMethod = new PostMethod(client.getWebdavUri().toString());
                 postMethod.setRequestBody(nameValuePairs);
                 int status = client.executeMethod(postMethod);
                 
@@ -99,16 +99,16 @@ public class OAuth2GetAccessToken extends RemoteOperation {
                 postMethod.releaseConnection();    // let the connection available for other methods
             
             if (result.isSuccess()) {
-                Log_OC.i(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getBaseUri() + ": " + result.getLogMessage());
+                Log_OC.i(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
             
             } else if (result.getException() != null) {
-                Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getBaseUri() + ": " + result.getLogMessage(), result.getException());
+                Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + result.getLogMessage(), result.getException());
                 
             } else if (result.getCode() == ResultCode.OAUTH2_ERROR) {
-                Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getBaseUri() + ": " + ((mResultTokenMap != null) ? mResultTokenMap.get(OAuth2Constants.KEY_ERROR) : "NULL"));
+                Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + ((mResultTokenMap != null) ? mResultTokenMap.get(OAuth2Constants.KEY_ERROR) : "NULL"));
                     
             } else {
-                Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getBaseUri() + ": " + result.getLogMessage());
+                Log_OC.e(TAG, "OAuth2 TOKEN REQUEST with auth code " + mOAuth2ParsedAuthorizationResponse.get("code") + " to " + client.getWebdavUri() + ": " + result.getLogMessage());
             }
         }
         

+ 2 - 1
src/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -23,6 +23,7 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileDownloader;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.network.OwnCloudClient;
+import com.owncloud.android.lib.operations.common.RemoteFile;
 import com.owncloud.android.lib.operations.common.RemoteOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
@@ -89,7 +90,7 @@ public class SynchronizeFileOperation extends RemoteOperation {
                 ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath);
                 result = operation.execute(client);
                 if (result.isSuccess()){
-                    mServerFile = FileStorageUtils.fillOCFile(result.getData().get(0));
+                    mServerFile = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
                     mServerFile.setLastSyncDateForProperties(System.currentTimeMillis());
                 }
             }

+ 6 - 2
src/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -192,7 +192,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
             ReadRemoteFileOperation operation = new ReadRemoteFileOperation(remotePath);
             result = operation.execute(client);
             if (result.isSuccess()){
-                OCFile remoteFolder = FileStorageUtils.fillOCFile(result.getData().get(0));
+                OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) result.getData().get(0));
                 
              // check if remote and local folder are different
               mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
@@ -223,7 +223,11 @@ public class SynchronizeFolderOperation extends RemoteOperation {
         Log_OC.d(TAG, "Synchronizing " + mAccount.name + remotePath);
         
         if (result.isSuccess()) {
-            synchronizeData(result.getData(), client);
+            ArrayList<RemoteFile> remotes = new ArrayList<RemoteFile>();
+            for(Object obj: result.getData()) {
+                remotes.add((RemoteFile) obj);
+            }
+            synchronizeData(remotes, client);
             if (mConflictsFound > 0  || mFailsInFavouritesFound > 0) { 
                 result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);   // should be different result, but will do the job
             }

+ 3 - 3
src/com/owncloud/android/operations/UpdateOCVersionOperation.java

@@ -90,15 +90,15 @@ public class UpdateOCVersionOperation extends RemoteOperation {
                     result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
                 }
             }
-            Log_OC.i(TAG, "Check for update of ownCloud server version at " + client.getBaseUri() + ": " + result.getLogMessage());
+            Log_OC.i(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage());
             
         } catch (JSONException e) {
             result = new RemoteOperationResult(RemoteOperationResult.ResultCode.INSTANCE_NOT_CONFIGURED);
-            Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getBaseUri() + ": " + result.getLogMessage(), e);
+            Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
                 
         } catch (Exception e) {
             result = new RemoteOperationResult(e);
-            Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getBaseUri() + ": " + result.getLogMessage(), e);
+            Log_OC.e(TAG, "Check for update of ownCloud server version at " + client.getWebdavUri() + ": " + result.getLogMessage(), e);
             
         } finally {
             if (get != null) 

+ 1 - 6
src/com/owncloud/android/providers/FileContentProvider.java

@@ -224,12 +224,7 @@ public class FileContentProvider extends ContentProvider {
             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);
+            count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs);
             break;
         default:
             //Log_OC.e(TAG, "Unknown uri " + uri);

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

@@ -21,7 +21,6 @@ package com.owncloud.android.ui.activity;
 import java.io.File;
 
 import android.accounts.Account;
-import android.accounts.AccountManager;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.ProgressDialog;
@@ -70,9 +69,8 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.operations.CreateFolderOperation;
 
-import com.owncloud.android.operations.GetSharedFilesOperation;
+import com.owncloud.android.operations.GetSharesOperation;
 
-import com.owncloud.android.lib.accounts.OwnCloudAccount;
 import com.owncloud.android.lib.operations.common.OnRemoteOperationListener;
 import com.owncloud.android.lib.operations.common.RemoteOperation;
 import com.owncloud.android.lib.operations.common.RemoteOperationResult;
@@ -930,7 +928,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
 
                 /// get the shared files
                 if (isSharedSupported()) {
-                    startGetSharedFiles();
+                    startGetShares();
                 }
                 
                 String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH); 
@@ -1300,8 +1298,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
         } else if (operation instanceof CreateFolderOperation) {
             onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
             
-        } else if (operation instanceof GetSharedFilesOperation) {
-            onGetSharedFilesOperationFinish((GetSharedFilesOperation) operation, result);
+        } else if (operation instanceof GetSharesOperation) {
+            onGetSharesOperationFinish((GetSharesOperation) operation, result);
         }
     }
 
@@ -1311,7 +1309,7 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
      * @param operation     Get Shared Files
      * @param result        Result of the operation
      */
-    private void onGetSharedFilesOperationFinish(GetSharedFilesOperation operation, RemoteOperationResult result) {
+    private void onGetSharesOperationFinish(GetSharesOperation operation, RemoteOperationResult result) {
         // Refresh the filelist with the information
         refeshListOfFilesFragment();  
         
@@ -1531,13 +1529,10 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa
     }
 
     
-    private void startGetSharedFiles() {
+    private void startGetShares() {
         // Get shared files/folders
-        AccountManager accountMngr = AccountManager.get(this); 
-        String urlServer = accountMngr.getUserData(getAccount(), OwnCloudAccount.Constants.KEY_OC_BASE_URL);
-        
-        RemoteOperation getSharedFiles = new GetSharedFilesOperation(urlServer, mStorageManager);
-        getSharedFiles.execute(getAccount(), this, this, mHandler, this);
+        RemoteOperation getShares = new GetSharesOperation(mStorageManager);
+        getShares.execute(getAccount(), this, this, mHandler, this);
         
         mRefreshSharesInProgress = true;
         setSupportProgressBarIndeterminateVisibility(true);