mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
Adapt UnshareLinkOperation to support also ShareType: USER or GROUP. UnshareLinkOperation --> UnshareOperation
This commit is contained in:
parent
043d2128ad
commit
a00b272903
8 changed files with 63 additions and 33 deletions
|
@ -974,26 +974,29 @@ public class FileDataStorageManager {
|
|||
}
|
||||
|
||||
|
||||
public OCShare getFirstShareByPathAndType(String path, ShareType type) {
|
||||
public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
|
||||
Cursor c = null;
|
||||
|
||||
String selection = ProviderTableMeta.OCSHARES_PATH + "=? AND "
|
||||
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
|
||||
+ ProviderTableMeta.OCSHARES_SHARE_WITH + "=? AND "
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" ;
|
||||
|
||||
String [] selectionArgs = new String[]{path, Integer.toString(type.getValue()),
|
||||
shareWith, mAccount.name};
|
||||
|
||||
if (getContentResolver() != null) {
|
||||
c = getContentResolver().query(
|
||||
ProviderTableMeta.CONTENT_URI_SHARE,
|
||||
null,
|
||||
ProviderTableMeta.OCSHARES_PATH + "=? AND "
|
||||
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
|
||||
new String[]{path, Integer.toString(type.getValue()), mAccount.name},
|
||||
selection, selectionArgs,
|
||||
null);
|
||||
} else {
|
||||
try {
|
||||
c = getContentProviderClient().query(
|
||||
ProviderTableMeta.CONTENT_URI_SHARE,
|
||||
null,
|
||||
ProviderTableMeta.OCSHARES_PATH + "=? AND "
|
||||
+ ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND "
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?",
|
||||
new String[]{path, Integer.toString(type.getValue()), mAccount.name},
|
||||
selection, selectionArgs,
|
||||
null);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
|
|
|
@ -39,6 +39,7 @@ import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
|||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||
import com.owncloud.android.services.OperationsService;
|
||||
import com.owncloud.android.services.observer.FileObserverService;
|
||||
|
@ -212,6 +213,8 @@ public class FileOperationsHelper {
|
|||
service.setAction(OperationsService.ACTION_UNSHARE);
|
||||
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
|
||||
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
|
||||
service.putExtra(OperationsService.EXTRA_SHARE_TYPE, ShareType.PUBLIC_LINK);
|
||||
service.putExtra(OperationsService.EXTRA_SHARE_WITH, "");
|
||||
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
|
||||
|
||||
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
|
||||
|
|
|
@ -35,20 +35,26 @@ import com.owncloud.android.lib.resources.shares.ShareType;
|
|||
|
||||
import com.owncloud.android.operations.common.SyncOperation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Unshare file/folder
|
||||
* Save the data in Database
|
||||
*/
|
||||
public class UnshareLinkOperation extends SyncOperation {
|
||||
public class UnshareOperation extends SyncOperation {
|
||||
|
||||
private static final String TAG = UnshareLinkOperation.class.getSimpleName();
|
||||
private static final String TAG = UnshareOperation.class.getSimpleName();
|
||||
|
||||
private String mRemotePath;
|
||||
private ShareType mShareType;
|
||||
private String mShareWith;
|
||||
private Context mContext;
|
||||
|
||||
|
||||
public UnshareLinkOperation(String remotePath, Context context) {
|
||||
public UnshareOperation(String remotePath, ShareType shareType, String shareWith,
|
||||
Context context) {
|
||||
mRemotePath = remotePath;
|
||||
mShareType = shareType;
|
||||
mShareWith = shareWith;
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
|
@ -58,7 +64,7 @@ public class UnshareLinkOperation extends SyncOperation {
|
|||
|
||||
// Get Share for a file
|
||||
OCShare share = getStorageManager().getFirstShareByPathAndType(mRemotePath,
|
||||
ShareType.PUBLIC_LINK);
|
||||
mShareType, mShareWith);
|
||||
|
||||
if (share != null) {
|
||||
RemoveRemoteShareOperation operation =
|
||||
|
@ -69,8 +75,19 @@ public class UnshareLinkOperation extends SyncOperation {
|
|||
Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
|
||||
|
||||
OCFile file = getStorageManager().getFileByPath(mRemotePath);
|
||||
file.setShareViaLink(false);
|
||||
file.setPublicLink("");
|
||||
if (mShareType == ShareType.PUBLIC_LINK) {
|
||||
file.setShareViaLink(false);
|
||||
file.setPublicLink("");
|
||||
} else if (mShareType == ShareType.USER || mShareType == ShareType.GROUP){
|
||||
// Check if it is the last share
|
||||
ArrayList <OCShare> sharesWith = getStorageManager().
|
||||
getSharesWithForAFile(mRemotePath,
|
||||
getStorageManager().getAccount().name);
|
||||
if (sharesWith.size() == 1) {
|
||||
file.setShareViaUsers(false);
|
||||
}
|
||||
}
|
||||
|
||||
getStorageManager().saveFile(file);
|
||||
getStorageManager().removeShare(share);
|
||||
|
|
@ -62,7 +62,7 @@ import com.owncloud.android.operations.RemoveFileOperation;
|
|||
import com.owncloud.android.operations.RenameFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFolderOperation;
|
||||
import com.owncloud.android.operations.UnshareLinkOperation;
|
||||
import com.owncloud.android.operations.UnshareOperation;
|
||||
import com.owncloud.android.operations.common.SyncOperation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -88,6 +88,8 @@ public class OperationsService extends Service {
|
|||
public static final String EXTRA_NEW_PARENT_PATH = "NEW_PARENT_PATH";
|
||||
public static final String EXTRA_FILE = "FILE";
|
||||
public static final String EXTRA_PASSWORD_SHARE = "PASSWORD_SHARE";
|
||||
public static final String EXTRA_SHARE_TYPE = "SHARE_TYPE";
|
||||
public static final String EXTRA_SHARE_WITH = "SHARE_WITH";
|
||||
|
||||
public static final String EXTRA_COOKIE = "COOKIE";
|
||||
|
||||
|
@ -560,9 +562,14 @@ public class OperationsService extends Service {
|
|||
|
||||
} else if (action.equals(ACTION_UNSHARE)) { // Unshare file
|
||||
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
|
||||
ShareType shareType = (ShareType) operationIntent.
|
||||
getSerializableExtra(EXTRA_SHARE_TYPE);
|
||||
String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
|
||||
if (remotePath.length() > 0) {
|
||||
operation = new UnshareLinkOperation(
|
||||
remotePath,
|
||||
operation = new UnshareOperation(
|
||||
remotePath,
|
||||
shareType,
|
||||
shareWith,
|
||||
OperationsService.this);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||
import com.owncloud.android.operations.CreateShareOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFolderOperation;
|
||||
import com.owncloud.android.operations.UnshareLinkOperation;
|
||||
import com.owncloud.android.operations.UnshareOperation;
|
||||
import com.owncloud.android.services.OperationsService;
|
||||
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
|
||||
import com.owncloud.android.ui.NavigationDrawerItem;
|
||||
|
@ -732,8 +732,8 @@ public class FileActivity extends AppCompatActivity
|
|||
} else if (operation instanceof CreateShareOperation) {
|
||||
onCreateShareOperationFinish((CreateShareOperation) operation, result);
|
||||
|
||||
} else if (operation instanceof UnshareLinkOperation) {
|
||||
onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
|
||||
} else if (operation instanceof UnshareOperation) {
|
||||
onUnshareLinkOperationFinish((UnshareOperation)operation, result);
|
||||
|
||||
} else if (operation instanceof SynchronizeFolderOperation) {
|
||||
onSynchronizeFolderOperationFinish((SynchronizeFolderOperation)operation, result);
|
||||
|
@ -790,7 +790,7 @@ public class FileActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
|
||||
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
|
||||
private void onUnshareLinkOperationFinish(UnshareOperation operation,
|
||||
RemoteOperationResult result) {
|
||||
dismissLoadingDialog();
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ import com.owncloud.android.operations.RefreshFolderOperation;
|
|||
import com.owncloud.android.operations.RemoveFileOperation;
|
||||
import com.owncloud.android.operations.RenameFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFileOperation;
|
||||
import com.owncloud.android.operations.UnshareLinkOperation;
|
||||
import com.owncloud.android.operations.UnshareOperation;
|
||||
import com.owncloud.android.services.observer.FileObserverService;
|
||||
import com.owncloud.android.syncadapter.FileSyncAdapter;
|
||||
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
|
||||
|
@ -1361,8 +1361,8 @@ public class FileDisplayActivity extends HookActivity
|
|||
} else if (operation instanceof CreateShareOperation) {
|
||||
onCreateShareOperationFinish((CreateShareOperation) operation, result);
|
||||
|
||||
} else if (operation instanceof UnshareLinkOperation) {
|
||||
onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result);
|
||||
} else if (operation instanceof UnshareOperation) {
|
||||
onUnshareLinkOperationFinish((UnshareOperation) operation, result);
|
||||
|
||||
} else if (operation instanceof MoveFileOperation) {
|
||||
onMoveFileOperationFinish((MoveFileOperation) operation, result);
|
||||
|
@ -1380,7 +1380,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
}
|
||||
}
|
||||
|
||||
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
|
||||
private void onUnshareLinkOperationFinish(UnshareOperation operation,
|
||||
RemoteOperationResult result) {
|
||||
if (result.isSuccess()) {
|
||||
refreshShowDetails();
|
||||
|
|
|
@ -56,7 +56,7 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||
import com.owncloud.android.operations.CreateShareOperation;
|
||||
import com.owncloud.android.operations.RemoveFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFileOperation;
|
||||
import com.owncloud.android.operations.UnshareLinkOperation;
|
||||
import com.owncloud.android.operations.UnshareOperation;
|
||||
import com.owncloud.android.ui.activity.FileActivity;
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity;
|
||||
import com.owncloud.android.ui.activity.ShareActivity;
|
||||
|
@ -232,8 +232,8 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
if (operation instanceof CreateShareOperation) {
|
||||
onCreateShareOperationFinish((CreateShareOperation) operation, result);
|
||||
|
||||
} else if (operation instanceof UnshareLinkOperation) {
|
||||
onUnshareLinkOperationFinish((UnshareLinkOperation) operation, result);
|
||||
} else if (operation instanceof UnshareOperation) {
|
||||
onUnshareLinkOperationFinish((UnshareOperation) operation, result);
|
||||
|
||||
} else if (operation instanceof RemoveFileOperation) {
|
||||
finish();
|
||||
|
@ -244,7 +244,7 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
}
|
||||
|
||||
|
||||
private void onUnshareLinkOperationFinish(UnshareLinkOperation operation,
|
||||
private void onUnshareLinkOperationFinish(UnshareOperation operation,
|
||||
RemoteOperationResult result) {
|
||||
if (result.isSuccess()) {
|
||||
OCFile file = getStorageManager().getFileByPath(getFile().getRemotePath());
|
||||
|
|
|
@ -36,7 +36,7 @@ import com.owncloud.android.operations.RemoveFileOperation;
|
|||
import com.owncloud.android.operations.RenameFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFileOperation;
|
||||
import com.owncloud.android.operations.SynchronizeFolderOperation;
|
||||
import com.owncloud.android.operations.UnshareLinkOperation;
|
||||
import com.owncloud.android.operations.UnshareOperation;
|
||||
import com.owncloud.android.operations.UploadFileOperation;
|
||||
|
||||
import org.apache.commons.httpclient.ConnectTimeoutException;
|
||||
|
@ -187,7 +187,7 @@ public class ErrorMessageAdapter {
|
|||
message = res.getString(R.string.share_link_file_error);
|
||||
}
|
||||
|
||||
} else if (operation instanceof UnshareLinkOperation) {
|
||||
} else if (operation instanceof UnshareOperation) {
|
||||
|
||||
if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND
|
||||
message = res.getString(R.string.unshare_link_file_no_exist);
|
||||
|
|
Loading…
Reference in a new issue