From: masensio Date: Wed, 29 Jan 2014 10:14:19 +0000 (+0100) Subject: Merge branch 'share_link_show_shared_files' into share_link__code_improvements X-Git-Tag: oc-android-1.5.5~35^2~43^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7c0accf714ec85a08c70747cf8d84dbada817a67?hp=063ec9eff5b80ef9f8fd9ff3c400fae24c70996c Merge branch 'share_link_show_shared_files' into share_link__code_improvements --- diff --git a/owncloud-android-library b/owncloud-android-library index 7b5d6cde..7126c73e 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 7b5d6cdef791cd27a573fcaa9c8214970753843c +Subproject commit 7126c73e6324ca8d3615fc4757191848e03d5644 diff --git a/res/menu/file_actions_menu.xml b/res/menu/file_actions_menu.xml index 1aa2823e..dcd451c4 100644 --- a/res/menu/file_actions_menu.xml +++ b/res/menu/file_actions_menu.xml @@ -19,7 +19,8 @@ --> - + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 2c06bb82..7ae67dc1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -59,6 +59,7 @@ Download Refresh file File was renamed to %1$s during upload + Share link Yes No OK diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 5709dc19..0b35beaa 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/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 shares) { + if (shares != null) { + cleanShares(); + + ArrayList operations = new ArrayList(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 sharedFiles) { + if (sharedFiles != null) { + cleanSharedFiles(); + + ArrayList operations = new ArrayList(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()); + } + + } + } } diff --git a/src/com/owncloud/android/datamodel/OCShare.java b/src/com/owncloud/android/datamodel/OCShare.java deleted file mode 100644 index 9946ba7e..00000000 --- a/src/com/owncloud/android/datamodel/OCShare.java +++ /dev/null @@ -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 . - * - */ - -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 CREATOR = new Parcelable.Creator() { - @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); - } -} diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index f05f0846..06400c06 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/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); } diff --git a/src/com/owncloud/android/operations/GetSharedFilesOperation.java b/src/com/owncloud/android/operations/GetSharedFilesOperation.java deleted file mode 100644 index 174ebbc0..00000000 --- a/src/com/owncloud/android/operations/GetSharedFilesOperation.java +++ /dev/null @@ -1,95 +0,0 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2013 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 . - * - */ - -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.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.ShareType; -import com.owncloud.android.lib.operations.remote.GetRemoteSharedFilesOperation; -import com.owncloud.android.lib.utils.FileUtils; -import com.owncloud.android.utils.Log_OC; - -/** - * Access to remote operation to get the share files/folders - * Save the data in Database - * - * @author masensio - */ - -public class GetSharedFilesOperation extends RemoteOperation { - - private static final String TAG = GetSharedFilesOperation.class.getSimpleName(); - - private String mUrlServer; - protected FileDataStorageManager mStorageManager; - - - public GetSharedFilesOperation(String urlServer, FileDataStorageManager storageManager) { - mUrlServer = urlServer; - mStorageManager = storageManager; - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - GetRemoteSharedFilesOperation operation = new GetRemoteSharedFilesOperation(mUrlServer); - RemoteOperationResult result = operation.execute(client); - - if (result.isSuccess()) { - - // Clean Share data in filelist table - mStorageManager.cleanShareFile(); - // Update DB with the response - ArrayList 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); - } - } - } - -} diff --git a/src/com/owncloud/android/operations/GetSharesOperation.java b/src/com/owncloud/android/operations/GetSharesOperation.java new file mode 100644 index 00000000..3b879c06 --- /dev/null +++ b/src/com/owncloud/android/operations/GetSharesOperation.java @@ -0,0 +1,102 @@ +/* ownCloud Android client application + * Copyright (C) 2012-2013 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 . + * + */ + +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.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.OCShare; +import com.owncloud.android.lib.operations.common.ShareType; +import com.owncloud.android.lib.operations.remote.GetRemoteSharesOperation; +import com.owncloud.android.lib.utils.FileUtils; +import com.owncloud.android.utils.Log_OC; + +/** + * Access to remote operation to get the share files/folders + * Save the data in Database + * + * @author masensio + */ + +public class GetSharesOperation extends RemoteOperation { + + private static final String TAG = GetSharesOperation.class.getSimpleName(); + + protected FileDataStorageManager mStorageManager; + + + public GetSharesOperation(FileDataStorageManager storageManager) { + mStorageManager = storageManager; + } + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + GetRemoteSharesOperation operation = new GetRemoteSharesOperation(); + RemoteOperationResult result = operation.execute(client); + + if (result.isSuccess()) { + + // Update DB with the response + Log_OC.d(TAG, "Share list size = " + result.getData().size()); + ArrayList shares = new ArrayList(); + for(Object obj: result.getData()) { + shares.add((OCShare) obj); + } + + saveSharesDB(shares); + } + + return result; + } + + private void saveSharesDB(ArrayList shares) { + + if (shares.size() > 0) { + // Save share file + mStorageManager.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 = mStorageManager.getFileByPath(path); + if (file != null) { + if (share.getShareType().equals(ShareType.PUBLIC_LINK)) { + file.setShareByLink(true); + sharedFiles.add(file); + } + } + } + + if (sharedFiles.size() > 0) { + mStorageManager.updateSharedFiles(sharedFiles); + } + } + } + +} diff --git a/src/com/owncloud/android/operations/OAuth2GetAccessToken.java b/src/com/owncloud/android/operations/OAuth2GetAccessToken.java index 57295ad6..45238ba2 100644 --- a/src/com/owncloud/android/operations/OAuth2GetAccessToken.java +++ b/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()); } } diff --git a/src/com/owncloud/android/operations/SynchronizeFileOperation.java b/src/com/owncloud/android/operations/SynchronizeFileOperation.java index ec51392d..2b948857 100644 --- a/src/com/owncloud/android/operations/SynchronizeFileOperation.java +++ b/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()); } } diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 497058a0..0aae4a9c 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/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 remotes = new ArrayList(); + 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 } diff --git a/src/com/owncloud/android/operations/UpdateOCVersionOperation.java b/src/com/owncloud/android/operations/UpdateOCVersionOperation.java index ca4387ce..a047f110 100644 --- a/src/com/owncloud/android/operations/UpdateOCVersionOperation.java +++ b/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) diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index 7463d20f..8bf258f4 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/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); diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 1168c75e..0eb1966c 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/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);