X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/45c1e47e5fcc4ed0a55601725813810982746109..3662fda2defcaeddfdfcdfe27ad23c40493ccbc6:/src/com/owncloud/android/datamodel/FileDataStorageManager.java diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 0b35beaa..279229af 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -29,6 +29,7 @@ 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.lib.utils.FileUtils; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.Log_OC; @@ -972,9 +973,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 +1011,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,25 +1078,52 @@ 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 saveSharesDB(ArrayList shares) { + 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 = getFileByPath(path); + if (file != null) { + if (share.getShareType().equals(ShareType.PUBLIC_LINK)) { + file.setShareByLink(true); + sharedFiles.add(file); + } + } + } + + updateSharedFiles(sharedFiles); + } }