From: David A. Velasco Date: Wed, 21 Oct 2015 09:32:07 +0000 (+0200) Subject: Added operation to create shares with a sharee, separated from operation to create... X-Git-Tag: oc-android-1.9^2~30^2~30 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/5e0f46cc2e9c2a7202430a4aef8ed43e3851802e Added operation to create shares with a sharee, separated from operation to create shares via link --- diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 4d07b56e..7715ded7 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -31,7 +31,6 @@ import java.util.Set; import java.util.Vector; import android.accounts.Account; -import android.content.ContentProvider; import android.content.ContentProviderClient; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; @@ -193,7 +192,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0); cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0); - cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, file.isSharedViaUsers() ? 1 : 0); + cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); @@ -299,7 +298,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0); cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0); - cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, file.isSharedViaUsers() ? 1 : 0); + cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); @@ -377,7 +376,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, folder.isFavorite() ? 1 : 0); cv.put(ProviderTableMeta.FILE_ETAG, folder.getEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, folder.isSharedViaLink() ? 1 : 0); - cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, folder.isSharedViaUsers() ? 1 : 0); + cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, folder.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId()); @@ -900,8 +899,8 @@ public class FileDataStorageManager { file.setEtag(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_ETAG))); file.setShareViaLink(c.getInt( c.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_LINK)) == 1 ? true : false); - file.setShareViaUsers(c.getInt( - c.getColumnIndex(ProviderTableMeta.FILE_SHARED_VIA_USERS)) == 1 ? true : false); + file.setShareWithSharee(c.getInt( + c.getColumnIndex(ProviderTableMeta.FILE_SHARED_WITH_SHAREE)) == 1 ? true : false); file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK))); file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS))); file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID))); @@ -1086,7 +1085,7 @@ public class FileDataStorageManager { private void resetShareFlagsInAllFiles() { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false); - cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, false); + cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, ""); String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; String[] whereArgs = new String[]{mAccount.name}; @@ -1107,7 +1106,7 @@ public class FileDataStorageManager { private void resetShareFlagsInFolder(OCFile folder) { ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false); - cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, false); + cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, ""); String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PARENT + "=?"; @@ -1129,7 +1128,7 @@ public class FileDataStorageManager { private void resetShareFlagInAFile(String filePath){ ContentValues cv = new ContentValues(); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false); - cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, false); + cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, ""); String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH+ "=?"; @@ -1268,7 +1267,7 @@ public class FileDataStorageManager { cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.isFavorite() ? 1 : 0); cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag()); cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, file.isSharedViaLink() ? 1 : 0); - cv.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, file.isSharedViaUsers() ? 1 : 0); + cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, file.isSharedWithSharee() ? 1 : 0); cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink()); cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions()); cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId()); diff --git a/src/com/owncloud/android/datamodel/OCFile.java b/src/com/owncloud/android/datamodel/OCFile.java index e9facf15..a6da654d 100644 --- a/src/com/owncloud/android/datamodel/OCFile.java +++ b/src/com/owncloud/android/datamodel/OCFile.java @@ -78,7 +78,7 @@ public class OCFile implements Parcelable, Comparable { private String mEtagInConflict; // Save file etag in the server, when there is a conflict. No conflict = null - private boolean mShareWithUser; + private boolean mShareWithSharee; /** @@ -124,7 +124,7 @@ public class OCFile implements Parcelable, Comparable { mNeedsUpdateThumbnail = source.readInt() == 1; mIsDownloading = source.readInt() == 1; mEtagInConflict = source.readString(); - mShareWithUser = source.readInt() == 1; + mShareWithSharee = source.readInt() == 1; } @@ -151,7 +151,7 @@ public class OCFile implements Parcelable, Comparable { dest.writeInt(mNeedsUpdateThumbnail ? 1 : 0); dest.writeInt(mIsDownloading ? 1 : 0); dest.writeString(mEtagInConflict); - dest.writeInt(mShareWithUser ? 1 : 0); + dest.writeInt(mShareWithSharee ? 1 : 0); } /** @@ -350,7 +350,7 @@ public class OCFile implements Parcelable, Comparable { mNeedsUpdateThumbnail = false; mIsDownloading = false; mEtagInConflict = null; - mShareWithUser = false; + mShareWithSharee = false; } /** @@ -600,12 +600,12 @@ public class OCFile implements Parcelable, Comparable { mEtagInConflict = etagInConflict; } - public boolean isSharedViaUsers() { - return mShareWithUser; + public boolean isSharedWithSharee() { + return mShareWithSharee; } - public void setShareViaUsers(boolean shareWithUser) { - this.mShareWithUser = shareWithUser; + public void setShareWithSharee(boolean shareWithSharee) { + this.mShareWithSharee = shareWithSharee; } public boolean isSharedWithMe() { diff --git a/src/com/owncloud/android/db/ProviderMeta.java b/src/com/owncloud/android/db/ProviderMeta.java index 893e247a..82ad94e9 100644 --- a/src/com/owncloud/android/db/ProviderMeta.java +++ b/src/com/owncloud/android/db/ProviderMeta.java @@ -67,7 +67,7 @@ public class ProviderMeta { public static final String FILE_KEEP_IN_SYNC = "keep_in_sync"; public static final String FILE_ETAG = "etag"; public static final String FILE_SHARED_VIA_LINK = "share_by_link"; - public static final String FILE_SHARED_VIA_USERS = "shared_via_users"; + public static final String FILE_SHARED_WITH_SHAREE = "shared_via_users"; public static final String FILE_PUBLIC_LINK = "public_link"; public static final String FILE_PERMISSIONS = "permissions"; public static final String FILE_REMOTE_ID = "remote_id"; diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index d249c020..e27f84e4 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -172,7 +172,7 @@ public class FileOperationsHelper { getString(R.string.wait_a_moment)); Intent service = new Intent(mFileActivity, OperationsService.class); - service.setAction(OperationsService.ACTION_CREATE_SHARE); + service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK); service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); service.putExtra(OperationsService.EXTRA_PASSWORD_SHARE, password); diff --git a/src/com/owncloud/android/operations/CreateShareOperation.java b/src/com/owncloud/android/operations/CreateShareOperation.java deleted file mode 100644 index e65f2c36..00000000 --- a/src/com/owncloud/android/operations/CreateShareOperation.java +++ /dev/null @@ -1,191 +0,0 @@ -/** - * ownCloud Android client application - * - * @author masensio - * Copyright (C) 2015 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; - -/** - * Creates a new share from a given file - */ - - -import android.content.Context; -import android.content.Intent; - -import com.owncloud.android.R; -import com.owncloud.android.datamodel.FileDataStorageManager; -import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.lib.common.OwnCloudClient; -import com.owncloud.android.lib.common.operations.RemoteOperation; -import com.owncloud.android.lib.common.operations.RemoteOperationResult; -import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.files.FileUtils; -import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; -import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation; -import com.owncloud.android.lib.resources.shares.OCShare; -import com.owncloud.android.lib.resources.shares.ShareType; -import com.owncloud.android.operations.common.SyncOperation; - -public class CreateShareOperation extends SyncOperation { - - private static final String TAG = CreateShareOperation.class.getSimpleName(); - - protected FileDataStorageManager mStorageManager; - - private String mPath; - private ShareType mShareType; - private String mShareWith; - private boolean mPublicUpload; - private String mPassword; - private int mPermissions; - private Intent mSendIntent; - private String mFileName; - - /** - * Constructor - * @param path Full path of the file/folder being shared. Mandatory argument - * @param shareType 0 = user, 1 = group, 3 = Public link. Mandatory argument - * @param shareWith User/group ID with who the file should be shared. - * This is mandatory for shareType of 0 or 1 - * @param publicUpload If false (default) public cannot upload to a public shared folder. - * If true public can upload to a shared folder. - * Only available for public link shares - * @param password Password to protect a public link share. - * Only available for public link shares - * @param permissions 1 - Read only - Default for public shares - * 2 - Update - * 4 - Create - * 8 - Delete - * 16- Re-share - * 31- All above - Default for private shares - * For user or group shares. - * To obtain combinations, add the desired values together. - * For instance, for Re-Share, delete, read, update, add 16+8+2+1 = 27. - * @param sendIntent Optional Intent with the information of an app where the link to the new share (if public) - * should be posted later. - */ - public CreateShareOperation(String path, ShareType shareType, String shareWith, - boolean publicUpload, String password, int permissions, Intent sendIntent) { - - mPath = path; - mShareType = shareType; - mShareWith = shareWith != null ? shareWith : ""; - mPublicUpload = publicUpload; - mPassword = password; - mPermissions = permissions; - mSendIntent = sendIntent; - mFileName = null; - } - - @Override - protected RemoteOperationResult run(OwnCloudClient client) { - // Check if the share link already exists - RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false); - RemoteOperationResult result = operation.execute(client); - - if (!result.isSuccess() || result.getData().size() <= 0) { - operation = new CreateRemoteShareOperation( - mPath, mShareType, mShareWith, - mPublicUpload, mPassword, mPermissions - ); - result = operation.execute(client); - } - - if (result.isSuccess()) { - if (result.getData().size() > 0) { - OCShare share = (OCShare) result.getData().get(0); - updateData(share); - } - } - - return result; - } - - public String getPath() { - return mPath; - } - - public ShareType getShareType() { - return mShareType; - } - - public String getShareWith() { - return mShareWith; - } - - public boolean getPublicUpload() { - return mPublicUpload; - } - - public String getPassword() { - return mPassword; - } - - public int getPermissions() { - return mPermissions; - } - - public Intent getSendIntent() { - return mSendIntent; - } - - public Intent getSendIntentWithSubject(Context context) { - if (context != null && mSendIntent != null && mSendIntent.getStringExtra(Intent.EXTRA_SUBJECT) != null) { - if (getClient() == null || getClient().getCredentials().getUsername() == null) { - mSendIntent.putExtra( - Intent.EXTRA_SUBJECT, - context.getString(R.string.subject_shared_with_you, mFileName) - ); - } else { - mSendIntent.putExtra( - Intent.EXTRA_SUBJECT, - context.getString( - R.string.subject_user_shared_with_you, - getClient().getCredentials().getUsername(), - mFileName - ) - ); - } - } - return mSendIntent; - } - - private void updateData(OCShare share) { - // Update DB with the response - share.setPath(mPath); - if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) { - share.setIsFolder(true); - } else { - share.setIsFolder(false); - } - share.setPermissions(mPermissions); - - getStorageManager().saveShare(share); - - // Update OCFile with data from share: ShareByLink and publicLink - OCFile file = getStorageManager().getFileByPath(mPath); - if (file!=null) { - mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink()); - file.setPublicLink(share.getShareLink()); - file.setShareViaLink(true); - getStorageManager().saveFile(file); - } - } - -} diff --git a/src/com/owncloud/android/operations/CreateShareViaLinkOperation.java b/src/com/owncloud/android/operations/CreateShareViaLinkOperation.java new file mode 100644 index 00000000..14490944 --- /dev/null +++ b/src/com/owncloud/android/operations/CreateShareViaLinkOperation.java @@ -0,0 +1,160 @@ +/** + * ownCloud Android client application + * + * @author masensio + * @author David A. Velasco + * Copyright (C) 2015 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; + +/** + * Creates a new public share for a given file + */ + + +import android.content.Context; +import android.content.Intent; + +import com.owncloud.android.R; +import com.owncloud.android.datamodel.FileDataStorageManager; +import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; +import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.operations.common.SyncOperation; + +public class CreateShareViaLinkOperation extends SyncOperation { + + private static final int READ_ONLY = 1; + + protected FileDataStorageManager mStorageManager; + + private String mPath; + private String mPassword; + private Intent mSendIntent; + private String mFileName; + + /** + * Constructor + * @param path Full path of the file/folder being shared. Mandatory argument + * @param password Password to protect a public link share. + * Only available for public link shares + * @param sendIntent Optional Intent with the information of an app where the link to the new share (if public) + * should be posted later. + */ + public CreateShareViaLinkOperation( + String path, + String password, + Intent sendIntent + ) { + + mPath = path; + mPassword = password; + mSendIntent = sendIntent; + mFileName = null; + } + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + // Check if the share link already exists + RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false); + RemoteOperationResult result = operation.execute(client); + // TODO - fix this check; if the user already shared the file with users or group, a share via link will not be created + + if (!result.isSuccess() || result.getData().size() <= 0) { + operation = new CreateRemoteShareOperation( + mPath, + ShareType.PUBLIC_LINK, + "", + false, + mPassword, + READ_ONLY + ); + result = operation.execute(client); + } + + if (result.isSuccess()) { + if (result.getData().size() > 0) { + OCShare share = (OCShare) result.getData().get(0); + updateData(share); + } + } + + return result; + } + + public String getPath() { + return mPath; + } + + public String getPassword() { + return mPassword; + } + + public Intent getSendIntent() { + return mSendIntent; + } + + public Intent getSendIntentWithSubject(Context context) { + if (context != null && mSendIntent != null && mSendIntent.getStringExtra(Intent.EXTRA_SUBJECT) != null) { + if (getClient() == null || getClient().getCredentials().getUsername() == null) { + mSendIntent.putExtra( + Intent.EXTRA_SUBJECT, + context.getString(R.string.subject_shared_with_you, mFileName) + ); + } else { + mSendIntent.putExtra( + Intent.EXTRA_SUBJECT, + context.getString( + R.string.subject_user_shared_with_you, + getClient().getCredentials().getUsername(), + mFileName + ) + ); + } + } + return mSendIntent; + } + + private void updateData(OCShare share) { + // Update DB with the response + share.setPath(mPath); + if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) { + share.setIsFolder(true); + } else { + share.setIsFolder(false); + } + share.setPermissions(READ_ONLY); + + getStorageManager().saveShare(share); + + // Update OCFile with data from share: ShareByLink and publicLink + OCFile file = getStorageManager().getFileByPath(mPath); + if (file!=null) { + mSendIntent.putExtra(Intent.EXTRA_TEXT, share.getShareLink()); + file.setPublicLink(share.getShareLink()); + file.setShareViaLink(true); + getStorageManager().saveFile(file); + } + } + +} diff --git a/src/com/owncloud/android/operations/CreateShareWithShareeOperation.java b/src/com/owncloud/android/operations/CreateShareWithShareeOperation.java new file mode 100644 index 00000000..d7beea0a --- /dev/null +++ b/src/com/owncloud/android/operations/CreateShareWithShareeOperation.java @@ -0,0 +1,120 @@ +/** + * ownCloud Android client application + * + * @author masensio + * @author David A. Velasco + * Copyright (C) 2015 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; + +/** + * Creates a new private share for a given file + */ + + +import com.owncloud.android.datamodel.FileDataStorageManager; +import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.operations.common.SyncOperation; + +public class CreateShareWithShareeOperation extends SyncOperation { + + private static final int READ_ONLY = 1; + + protected FileDataStorageManager mStorageManager; + + private String mPath; + private String mTargetName; + private boolean mWithGroup; + + /** + * Constructor + * @param path Full path of the file/folder being shared. Mandatory argument + */ + public CreateShareWithShareeOperation( + String path, + String targetName, + boolean withGroup + ) { + + mPath = path; + mTargetName = targetName; + mWithGroup = withGroup; + } + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + // Check if the share link already exists + // TODO or not + /* + RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false); + RemoteOperationResult result = operation.execute(client); + if (!result.isSuccess() || result.getData().size() <= 0) { + */ + + RemoteOperation operation = new CreateRemoteShareOperation( + mPath, + (mWithGroup ? ShareType.GROUP : ShareType.USER), + mTargetName, + false, + "", + READ_ONLY + ); + RemoteOperationResult result = operation.execute(client); + + + if (result.isSuccess()) { + if (result.getData().size() > 0) { + OCShare share = (OCShare) result.getData().get(0); + updateData(share); + } + } + + return result; + } + + public String getPath() { + return mPath; + } + + private void updateData(OCShare share) { + // Update DB with the response + share.setPath(mPath); + if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) { + share.setIsFolder(true); + } else { + share.setIsFolder(false); + } + share.setPermissions(READ_ONLY); + + getStorageManager().saveShare(share); + + // Update OCFile with data from share: ShareByLink and publicLink + OCFile file = getStorageManager().getFileByPath(mPath); + if (file!=null) { + file.setShareWithSharee(true); // TODO - this should be done by the FileContentProvider, as part of getStorageManager().saveShare(share) + getStorageManager().saveFile(file); + } + } + +} diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index 54dd7535..adb4ac4c 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -392,7 +392,7 @@ public class RefreshFolderOperation extends RemoteOperation { } updatedFile.setPublicLink(localFile.getPublicLink()); updatedFile.setShareViaLink(localFile.isSharedViaLink()); - updatedFile.setShareViaUsers(localFile.isSharedViaUsers()); + updatedFile.setShareWithSharee(localFile.isSharedWithSharee()); updatedFile.setEtagInConflict(localFile.getEtagInConflict()); } else { // remote eTag will not be updated unless file CONTENTS are synchronized diff --git a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java index 136bb8bc..675295a3 100644 --- a/src/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/src/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -340,7 +340,7 @@ public class SynchronizeFolderOperation extends SyncOperation { } updatedFile.setPublicLink(localFile.getPublicLink()); updatedFile.setShareViaLink(localFile.isSharedViaLink()); - updatedFile.setShareViaUsers(localFile.isSharedViaUsers()); + updatedFile.setShareWithSharee(localFile.isSharedWithSharee()); updatedFile.setEtagInConflict(localFile.getEtagInConflict()); } else { // remote eTag will not be updated unless file CONTENTS are synchronized diff --git a/src/com/owncloud/android/operations/UnshareOperation.java b/src/com/owncloud/android/operations/UnshareOperation.java index 42d25a36..dcc4bdc6 100644 --- a/src/com/owncloud/android/operations/UnshareOperation.java +++ b/src/com/owncloud/android/operations/UnshareOperation.java @@ -84,7 +84,7 @@ public class UnshareOperation extends SyncOperation { getSharesWithForAFile(mRemotePath, getStorageManager().getAccount().name); if (sharesWith.size() == 1) { - file.setShareViaUsers(false); + file.setShareWithSharee(false); } } diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index bd7b6dcc..d94d5b5a 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -96,8 +96,8 @@ public class FileContentProvider extends ContentProvider { ProviderTableMeta.FILE_ETAG); mFileProjectionMap.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, ProviderTableMeta.FILE_SHARED_VIA_LINK); - mFileProjectionMap.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, - ProviderTableMeta.FILE_SHARED_VIA_USERS); + mFileProjectionMap.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, + ProviderTableMeta.FILE_SHARED_WITH_SHAREE); mFileProjectionMap.put(ProviderTableMeta.FILE_PUBLIC_LINK, ProviderTableMeta.FILE_PUBLIC_LINK); mFileProjectionMap.put(ProviderTableMeta.FILE_PERMISSIONS, @@ -353,7 +353,7 @@ public class FileContentProvider extends ContentProvider { if (newShareType == ShareType.PUBLIC_LINK.getValue()) { fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, 1); } else if (newShareType == ShareType.USER.getValue() || newShareType == ShareType.GROUP.getValue()) { - fileValues.put(ProviderTableMeta.FILE_SHARED_VIA_USERS, 1); + fileValues.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, 1); } String where = ProviderTableMeta.FILE_PATH + "=? AND " + @@ -561,7 +561,7 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER," //boolean + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT," - + ProviderTableMeta.FILE_SHARED_VIA_USERS + " INTEGER);" + + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);" ); // Create table ocshares @@ -785,7 +785,7 @@ public class FileContentProvider extends ContentProvider { db.beginTransaction(); try { db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME + - " ADD COLUMN " + ProviderTableMeta.FILE_SHARED_VIA_USERS + " INTEGER " + + " ADD COLUMN " + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER " + " DEFAULT 0"); upgraded = true; db.setTransactionSuccessful(); diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index b6326446..d14b6e2f 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -54,7 +54,8 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; -import com.owncloud.android.operations.CreateShareOperation; +import com.owncloud.android.operations.CreateShareViaLinkOperation; +import com.owncloud.android.operations.CreateShareWithShareeOperation; import com.owncloud.android.operations.GetServerInfoOperation; import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.OAuth2GetAccessToken; @@ -93,7 +94,8 @@ public class OperationsService extends Service { public static final String EXTRA_COOKIE = "COOKIE"; - public static final String ACTION_CREATE_SHARE = "CREATE_SHARE"; + public static final String ACTION_CREATE_SHARE_VIA_LINK = "CREATE_SHARE_VIA_LINK"; + private static final String ACTION_CREATE_SHARE_WITH_SHAREE = "CREATE_SHARE_WITH_SHAREE"; public static final String ACTION_UNSHARE = "UNSHARE"; public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO"; public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN"; @@ -112,7 +114,6 @@ public class OperationsService extends Service { ".OPERATION_FINISHED"; - private ConcurrentMap> mUndispatchedFinishedOperations = new ConcurrentHashMap>(); @@ -550,21 +551,30 @@ public class OperationsService extends Service { ); String action = operationIntent.getAction(); - if (action.equals(ACTION_CREATE_SHARE)) { // Create Share + if (action.equals(ACTION_CREATE_SHARE_VIA_LINK)) { // Create public share via link String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); String password = operationIntent.getStringExtra(EXTRA_PASSWORD_SHARE); Intent sendIntent = operationIntent.getParcelableExtra(EXTRA_SEND_INTENT); if (remotePath.length() > 0) { - operation = new CreateShareOperation( + operation = new CreateShareViaLinkOperation( remotePath, - ShareType.PUBLIC_LINK, - null, - false, password, - 1, - sendIntent); + sendIntent + ); } + } else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) { // Create private share with user or group + String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); + String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH); + ShareType shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE); + if (remotePath.length() > 0) { + operation = new CreateShareWithShareeOperation( + remotePath, + shareeName, + ShareType.GROUP.equals(shareType) + ); + } + } else if (action.equals(ACTION_UNSHARE)) { // Unshare file String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); ShareType shareType = (ShareType) operationIntent. @@ -575,7 +585,8 @@ public class OperationsService extends Service { remotePath, shareType, shareWith, - OperationsService.this); + OperationsService.this + ); } } else if (action.equals(ACTION_GET_SERVER_INFO)) { diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 0878682f..d0f5c1fb 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -67,7 +67,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.operations.CreateShareOperation; +import com.owncloud.android.operations.CreateShareViaLinkOperation; +import com.owncloud.android.operations.CreateShareWithShareeOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UnshareOperation; @@ -728,14 +729,17 @@ public class FileActivity extends AppCompatActivity } mTryShareAgain = false; - } else if (operation instanceof CreateShareOperation) { - onCreateShareOperationFinish((CreateShareOperation) operation, result); + } else if (operation instanceof CreateShareViaLinkOperation) { + onCreateShareViaLinkOperationFinish((CreateShareViaLinkOperation) operation, result); + + } else if (operation instanceof CreateShareWithShareeOperation) { + onCreateShareWithShareeOperationFinish((CreateShareWithShareeOperation) operation, result); } else if (operation instanceof UnshareOperation) { - onUnshareLinkOperationFinish((UnshareOperation)operation, result); + onUnshareLinkOperationFinish((UnshareOperation) operation, result); } else if (operation instanceof SynchronizeFolderOperation) { - onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result); + onSynchronizeFolderOperationFinish((SynchronizeFolderOperation) operation, result); }else if (operation instanceof SynchronizeFileOperation) { onSynchronizeFileOperationFinish((SynchronizeFileOperation)operation, result); @@ -755,8 +759,8 @@ public class FileActivity extends AppCompatActivity - private void onCreateShareOperationFinish(CreateShareOperation operation, - RemoteOperationResult result) { + private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation, + RemoteOperationResult result) { dismissLoadingDialog(); if (result.isSuccess()) { mTryShareAgain = false; @@ -788,6 +792,19 @@ public class FileActivity extends AppCompatActivity } } + private void onCreateShareWithShareeOperationFinish(CreateShareWithShareeOperation operation, + RemoteOperationResult result) { + dismissLoadingDialog(); + if (result.isSuccess()) { + updateFileFromDB(); + + } else { + Toast t = Toast.makeText(this, + ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), + Toast.LENGTH_LONG); + t.show(); + } + } private void onUnshareLinkOperationFinish(UnshareOperation operation, RemoteOperationResult result) { diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 28119279..2d494351 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -79,7 +79,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; -import com.owncloud.android.operations.CreateShareOperation; +import com.owncloud.android.operations.CreateShareViaLinkOperation; +import com.owncloud.android.operations.CreateShareWithShareeOperation; import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.RemoveFileOperation; @@ -1358,8 +1359,11 @@ public class FileDisplayActivity extends HookActivity } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation) operation, result); - } else if (operation instanceof CreateShareOperation) { - onCreateShareOperationFinish((CreateShareOperation) operation, result); + } else if (operation instanceof CreateShareViaLinkOperation || + operation instanceof CreateShareWithShareeOperation ) { + + refreshShowDetails(); + refreshListOfFilesFragment(); } else if (operation instanceof UnshareOperation) { onUnshareLinkOperationFinish((UnshareOperation) operation, result); @@ -1372,13 +1376,6 @@ public class FileDisplayActivity extends HookActivity } } - private void onCreateShareOperationFinish(CreateShareOperation operation, - RemoteOperationResult result) { - if (result.isSuccess()) { - refreshShowDetails(); - refreshListOfFilesFragment(); - } - } private void onUnshareLinkOperationFinish(UnshareOperation operation, RemoteOperationResult result) { diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 1f07d4a8..07a3eed5 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -238,7 +238,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { sharedIconV.setImageResource(R.drawable.shared_via_link); sharedIconV.setVisibility(View.VISIBLE); sharedIconV.bringToFront(); - } else if (file.isSharedViaUsers() || file.isSharedWithMe() ) { + } else if (file.isSharedWithSharee() || file.isSharedWithMe() ) { sharedIconV.setImageResource(R.drawable.shared_via_users); sharedIconV.setVisibility(View.VISIBLE); sharedIconV.bringToFront(); @@ -357,7 +357,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter { // Folder fileIcon.setImageResource( MimetypeIconUtil.getFolderTypeIconId( - file.isSharedWithMe() || file.isSharedViaUsers(), + file.isSharedWithMe() || file.isSharedWithSharee(), file.isSharedViaLink() ) ); diff --git a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java index 8bcffe44..b3b949a9 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageActivity.java @@ -53,7 +53,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.operations.CreateShareOperation; +import com.owncloud.android.operations.CreateShareViaLinkOperation; +import com.owncloud.android.operations.CreateShareWithShareeOperation; import com.owncloud.android.operations.RemoveFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.UnshareOperation; @@ -229,9 +230,10 @@ public class PreviewImageActivity extends FileActivity implements public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { super.onRemoteOperationFinish(operation, result); - if (operation instanceof CreateShareOperation) { - onCreateShareOperationFinish((CreateShareOperation) operation, result); - + if (operation instanceof CreateShareViaLinkOperation || + operation instanceof CreateShareWithShareeOperation) { + onCreateShareOperationFinish(result); + } else if (operation instanceof UnshareOperation) { onUnshareLinkOperationFinish((UnshareOperation) operation, result); @@ -258,8 +260,7 @@ public class PreviewImageActivity extends FileActivity implements } - private void onCreateShareOperationFinish(CreateShareOperation operation, - RemoteOperationResult result) { + private void onCreateShareOperationFinish(RemoteOperationResult result) { if (result.isSuccess()) { OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath()); if (file != null) { diff --git a/src/com/owncloud/android/utils/ErrorMessageAdapter.java b/src/com/owncloud/android/utils/ErrorMessageAdapter.java index 91ee87fc..fe6f6506 100644 --- a/src/com/owncloud/android/utils/ErrorMessageAdapter.java +++ b/src/com/owncloud/android/utils/ErrorMessageAdapter.java @@ -29,7 +29,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; -import com.owncloud.android.operations.CreateShareOperation; +import com.owncloud.android.operations.CreateShareViaLinkOperation; +import com.owncloud.android.operations.CreateShareWithShareeOperation; import com.owncloud.android.operations.DownloadFileOperation; import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.RemoveFileOperation; @@ -170,7 +171,8 @@ public class ErrorMessageAdapter { } else { message = res.getString(R.string.create_dir_fail_msg); } - } else if (operation instanceof CreateShareOperation) { + } else if (operation instanceof CreateShareViaLinkOperation || + operation instanceof CreateShareWithShareeOperation) { if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND message = res.getString(R.string.share_link_file_no_exist);