-Subproject commit 7b5d6cdef791cd27a573fcaa9c8214970753843c
+Subproject commit 7126c73e6324ca8d3615fc4757191848e03d5644
-->
<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" />
<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>
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;
* @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()) {
* @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()) {
}
- // 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 "
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()) {
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()) {
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()
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, "");
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());
+ }
+
+ }
+
}
}
+++ /dev/null
-/* 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);
- }
-}
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);
}
+++ /dev/null
-/* 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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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<ShareRemoteFile> shareRemoteFiles = operation.getSharedFiles();
- Log_OC.d(TAG, "Share list size = " + shareRemoteFiles.size());
- for (ShareRemoteFile remoteFile: shareRemoteFiles) {
- OCShare shareFile = new OCShare(remoteFile);
- saveShareFileInDB(shareFile);
- }
- }
-
- return result;
- }
-
- private void saveShareFileInDB(OCShare shareFile) {
- // Save share file
- mStorageManager.saveShareFile(shareFile);
-
- // Get the path
- String path = shareFile.getPath();
- if (shareFile.isDirectory()) {
- path = path + FileUtils.PATH_SEPARATOR;
- }
-
- // Update OCFile with data from share: ShareByLink ¿and publicLink?
- OCFile file = mStorageManager.getFileByPath(path);
- if (file != null) {
- if (shareFile.getShareType().equals(ShareType.PUBLIC_LINK)) {
- file.setShareByLink(true);
- mStorageManager.saveFile(file);
- }
- }
- }
-
-}
--- /dev/null
+/* 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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<OCShare> shares = new ArrayList<OCShare>();
+ for(Object obj: result.getData()) {
+ shares.add((OCShare) obj);
+ }
+
+ saveSharesDB(shares);
+ }
+
+ return result;
+ }
+
+ 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);
+ }
+ }
+ }
+
+ if (sharedFiles.size() > 0) {
+ mStorageManager.updateSharedFiles(sharedFiles);
+ }
+ }
+ }
+
+}
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);
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());
}
}
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;
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());
}
}
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()));
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
}
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)
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);
import java.io.File;
import android.accounts.Account;
-import android.accounts.AccountManager;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
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;
/// get the shared files
if (isSharedSupported()) {
- startGetSharedFiles();
+ startGetShares();
}
String synchFolderRemotePath = intent.getStringExtra(FileSyncService.SYNC_FOLDER_REMOTE_PATH);
} 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);
}
}
* @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();
}
- 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);