import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.accounts.OwnCloudAccount;
import com.owncloud.android.lib.network.webdav.WebdavUtils;
-import com.owncloud.android.lib.operations.common.ShareType;
-import com.owncloud.android.operations.CreateShareOperation;
-import com.owncloud.android.operations.UnshareLinkOperation;
+import com.owncloud.android.services.OperationsService;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.dialog.ActivityChooserDialog;
import com.owncloud.android.utils.Log_OC;
if (file != null) {
callerActivity.showLoadingDialog();
- CreateShareOperation createShare = new CreateShareOperation(file.getRemotePath(), ShareType.PUBLIC_LINK, "", false, "", 1, sendIntent);
- createShare.execute(callerActivity.getStorageManager(),
- callerActivity,
- callerActivity.getRemoteOperationListener(),
- callerActivity.getHandler(),
- callerActivity);
+
+ Intent service = new Intent(callerActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_CREATE_SHARE);
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, callerActivity.getAccount());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ service.putExtra(OperationsService.EXTRA_SEND_INTENT, sendIntent);
+ callerActivity.startService(service);
} else {
Log_OC.wtf(TAG, "Trying to open a NULL OCFile");
if (isSharedSupported(callerActivity)) {
// Unshare the file
- UnshareLinkOperation unshare = new UnshareLinkOperation(file, callerActivity);
- unshare.execute(callerActivity.getStorageManager(),
- callerActivity,
- callerActivity.getRemoteOperationListener(),
- callerActivity.getHandler(),
- callerActivity);
-
+ Intent service = new Intent(callerActivity, OperationsService.class);
+ service.setAction(OperationsService.ACTION_UNSHARE);
+ service.putExtra(OperationsService.EXTRA_ACCOUNT, callerActivity.getAccount());
+ service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
+ callerActivity.startService(service);
+
callerActivity.showLoadingDialog();
} else {
import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.operations.remote.ExistenceCheckRemoteOperation;
import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
+import com.owncloud.android.lib.utils.FileUtils;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.utils.Log_OC;
private static final String TAG = UnshareLinkOperation.class.getSimpleName();
- private OCFile mFile;
+ private String mRemotePath;
private Context mContext;
- public UnshareLinkOperation(OCFile file, Context context) {
- mFile = file;
+ public UnshareLinkOperation(String remotePath, Context context) {
+ mRemotePath = remotePath;
mContext = context;
}
RemoteOperationResult result = null;
// Get Share for a file
- String path = mFile.getRemotePath();
- if (mFile.isFolder()) {
- path = path.substring(0, path.length()-1); // Remove last /
+ String path = mRemotePath;
+ if (path.endsWith(FileUtils.PATH_SEPARATOR)) {
+ path = path.substring(0, path.length()-1); // Remove last /
}
OCShare share = getStorageManager().getShareByPath(path);
if (result.isSuccess() || result.getCode() == ResultCode.SHARE_NOT_FOUND) {
Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted");
- mFile.setShareByLink(false);
- mFile.setPublicLink("");
- getStorageManager().saveFile(mFile);
+ OCFile file = getStorageManager().getFileByPath(mRemotePath);
+ file.setShareByLink(false);
+ file.setPublicLink("");
+ getStorageManager().saveFile(file);
getStorageManager().removeShare(share);
if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
- if (existsFile(client, mFile.getRemotePath())) {
+ if (existsFile(client, file.getRemotePath())) {
result = new RemoteOperationResult(ResultCode.OK);
} else {
- getStorageManager().removeFile(mFile, true, true);
+ getStorageManager().removeFile(file, true, true);
}
}
}
import com.owncloud.android.lib.network.OwnCloudClientFactory;
import com.owncloud.android.lib.network.OwnCloudClient;
+import com.owncloud.android.operations.CreateShareOperation;
import com.owncloud.android.operations.GetSharesOperation;
+import com.owncloud.android.operations.UnshareLinkOperation;
import com.owncloud.android.operations.common.SyncOperation;
import com.owncloud.android.lib.operations.common.RemoteOperation;
import com.owncloud.android.lib.operations.common.RemoteOperationResult;
+import com.owncloud.android.lib.operations.common.ShareType;
import com.owncloud.android.utils.Log_OC;
import android.accounts.Account;
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_SERVER_URL = "SERVER_URL";
- public static final String EXTRA_RESULT = "RESULT";
+ public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
+ public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
+ public static final String EXTRA_RESULT = "RESULT";
+
+ public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
+ public static final String ACTION_UNSHARE = "UNSHARE";
public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
try {
Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
String serverUrl = intent.getStringExtra(EXTRA_SERVER_URL);
+
Target target = new Target(account, (serverUrl == null) ? null : Uri.parse(serverUrl));
- GetSharesOperation operation = new GetSharesOperation();
+ RemoteOperation operation = null;
+
+ String action = intent.getAction();
+ if (action == ACTION_CREATE_SHARE) { // Create Share
+ String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
+ Intent sendIntent = intent.getParcelableExtra(EXTRA_SEND_INTENT);
+ if (remotePath.length() > 0) {
+ operation = new CreateShareOperation(remotePath, ShareType.PUBLIC_LINK,
+ "", false, "", 1, sendIntent);
+ }
+ } else if (action == ACTION_UNSHARE) { // Unshare file
+ String remotePath = intent.getStringExtra(EXTRA_REMOTE_PATH);
+ if (remotePath.length() > 0) {
+ operation = new UnshareLinkOperation(remotePath, this.getApplicationContext());
+ }
+ } else {
+ operation = new GetSharesOperation();
+ }
+
mPendingOperations.add(new Pair<Target , RemoteOperation>(target, operation));
sendBroadcastNewOperation(target, operation);