From: David A. Velasco Date: Mon, 3 Feb 2014 08:20:49 +0000 (+0100) Subject: Fixed update of shares database - grant that shares are removed after removing all... X-Git-Tag: oc-android-1.5.5~35^2~37 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/cea1a76f48ceb400136e64b4fb921a3f92aee6e4?ds=inline;hp=-c Fixed update of shares database - grant that shares are removed after removing all of them in the server --- cea1a76f48ceb400136e64b4fb921a3f92aee6e4 diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 0b35beaa..76e3e5c8 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -972,9 +972,8 @@ public class FileDataStorageManager { } public void saveShares(Collection shares) { + cleanShares(); if (shares != null) { - cleanShares(); - ArrayList operations = new ArrayList(shares.size()); // prepare operations to insert or update files to save in the given folder @@ -1011,32 +1010,33 @@ public class FileDataStorageManager { } // 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); + if (operations.size() > 0) { + @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()); } - - } 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 sharedFiles) { + cleanSharedFiles(); + if (sharedFiles != null) { - cleanSharedFiles(); - ArrayList operations = new ArrayList(sharedFiles.size()); // prepare operations to insert or update files to save in the given folder @@ -1077,24 +1077,25 @@ public class FileDataStorageManager { } // 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); + if (operations.size() > 0) { + @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()); } - - } 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()); } - } } diff --git a/src/com/owncloud/android/operations/GetSharesOperation.java b/src/com/owncloud/android/operations/GetSharesOperation.java index 64942c09..4cbee02a 100644 --- a/src/com/owncloud/android/operations/GetSharesOperation.java +++ b/src/com/owncloud/android/operations/GetSharesOperation.java @@ -62,34 +62,29 @@ public class GetSharesOperation extends SyncOperation { } private void saveSharesDB(ArrayList shares) { - - if (shares.size() > 0) { - // Save share file - getStorageManager().saveShares(shares); - - ArrayList sharedFiles = new ArrayList(); - - 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 = getStorageManager().getFileByPath(path); - if (file != null) { - if (share.getShareType().equals(ShareType.PUBLIC_LINK)) { - file.setShareByLink(true); - sharedFiles.add(file); - } - } - } - - if (sharedFiles.size() > 0) { - getStorageManager().updateSharedFiles(sharedFiles); - } + // Save share file + getStorageManager().saveShares(shares); + + ArrayList sharedFiles = new ArrayList(); + + 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 = getStorageManager().getFileByPath(path); + if (file != null) { + if (share.getShareType().equals(ShareType.PUBLIC_LINK)) { + file.setShareByLink(true); + sharedFiles.add(file); + } + } } + + getStorageManager().updateSharedFiles(sharedFiles); } }