-Subproject commit 8c87d88cff376038248216ea2eb00c0c5ed110e0
+Subproject commit ccb079935f53dcd97c5b21ca121f31dd611a094e
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<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_unshare_file" android:title="@string/action_unshare_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_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="action_unshare_file">Unshare link</string>
<string name="common_yes">Yes</string>
<string name="common_no">No</string>
<string name="common_ok">OK</string>
<string name="failed_upload_retry_do_nothing_text">do nothing you are not online for instant upload</string>
<string name="failed_upload_failure_text">Failure Message: </string>
<string name="failed_upload_quota_exceeded_text">Please check your server configuration,maybe your quota is exceeded.</string>
+
+ <string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your administrator.</string>
+ <string name="share_link_file_no_exist">Unable to share this file or folder. Please, make sure it exists</string>
</resources>
}
}
+
+ public void removeShare(OCShare share){
+ Uri share_uri = ProviderTableMeta.CONTENT_URI_SHARE;
+ String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
+ String [] whereArgs = new String[]{mAccount.name, share.getPath()};
+ if (getContentProviderClient() != null) {
+ try {
+ getContentProviderClient().delete(share_uri, where, whereArgs);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ } else {
+ getContentResolver().delete(share_uri, where, whereArgs);
+ }
+ }
}
/* ownCloud Android client application
- * Copyright (C) 2012-2013 ownCloud Inc.
+ * 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,
--- /dev/null
+/* ownCloud Android client application
+ * Copyright (C) 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.operations;
+
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.lib.network.OwnCloudClient;
+import com.owncloud.android.lib.operations.common.OCShare;
+import com.owncloud.android.lib.operations.common.RemoteOperationResult;
+import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;
+import com.owncloud.android.lib.operations.remote.RemoveRemoteShareOperation;
+import com.owncloud.android.operations.common.SyncOperation;
+import com.owncloud.android.utils.Log_OC;
+
+/**
+ * Unshare file/folder
+ * Save the data in Database
+ *
+ * @author masensio
+ */
+public class UnshareLinkOperation extends SyncOperation {
+
+ private static final String TAG = UnshareLinkOperation.class.getSimpleName();
+
+ private OCFile mFile;
+
+ public UnshareLinkOperation(OCFile file) {
+ mFile = file;
+ }
+
+ @Override
+ protected RemoteOperationResult run(OwnCloudClient client) {
+ RemoteOperationResult result = null;
+
+ // Get Share for a file
+ String path = mFile.getRemotePath();
+ if (mFile.isFolder()) {
+ path = path.substring(0, path.length()-1); // Remove last /
+ }
+ OCShare share = getStorageManager().getShareByPath(path);
+
+ if (share != null) {
+ RemoveRemoteShareOperation operation = new RemoveRemoteShareOperation((int) share.getIdRemoteShared());
+ result = operation.execute(client);
+
+ 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);
+ getStorageManager().removeShare(share);
+
+ if (result.getCode() == ResultCode.SHARE_NOT_FOUND) {
+ result = new RemoteOperationResult(ResultCode.OK);
+ }
+ }
+
+ } else {
+ result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
+ }
+
+ return result;
+ }
+
+}
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.services.OperationsService;
import com.owncloud.android.syncadapter.FileSyncAdapter;
import com.owncloud.android.ui.dialog.EditNameDialog;
} else if (operation instanceof CreateFolderOperation) {
onCreateFolderOperationFinish((CreateFolderOperation)operation, result);
+
+ } else if (operation instanceof UnshareLinkOperation) {
+ onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result);
}
}
+ private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) {
+ if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
+ // Show a Message
+ Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG);
+ t.show();
+ }
+
+ refeshListOfFilesFragment();
+
+ dismissLoadingDialog();
+ }
+
/**
* Updates the view associated to the activity after the finish of an operation trying to remove a
* file.
mRefreshSharesInProgress = true;
}
+
+ public void unshareFileWithLink(OCFile file) {
+
+ if (isSharedSupported()) {
+ // Unshare the file
+ UnshareLinkOperation unshare = new UnshareLinkOperation(file);
+ unshare.execute(getStorageManager(), this, this, mHandler, this);
+
+ showLoadingDialog();
+
+ } else {
+ // Show a Message
+ Toast t = Toast.makeText(this, getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG);
+ t.show();
+
+ }
+ }
+
}
toHide.add(R.id.action_remove_file);
}
-
+
+ // Options shareLink
+ if (!file.isShareByLink()) {
+ toHide.add(R.id.action_unshare_file);
+ }
+
MenuItem item = null;
for (int i : toHide) {
item = menu.findItem(i);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mTargetFile = (OCFile) mAdapter.getItem(info.position);
switch (item.getItemId()) {
+ case R.id.action_unshare_file: {
+ mContainerActivity.unshareFileWithLink(mTargetFile);
+ return true;
+ }
case R.id.action_rename_file: {
String fileName = mTargetFile.getFileName();
int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf(".");
return super.onContextItemSelected(item);
}
}
-
+
/**
* Use this to query the {@link OCFile} that is currently
*/
public void onBrowsedDownTo(OCFile folder);
+ public void unshareFileWithLink(OCFile mTargetFile);
+
public void startDownloadForPreview(OCFile file);
public void startMediaPreview(OCFile file, int i, boolean b);
toHide.add(R.id.action_cancel_upload);
toHide.add(R.id.action_download_file);
toHide.add(R.id.action_rename_file); // by now
+
+ // Options shareLink
+ if (!getFile().isShareByLink()) {
+ toHide.add(R.id.action_unshare_file);
+ }
for (int i : toHide) {
item = menu.findItem(i);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ }
+
+
private void seeDetails() {
((FileFragment.ContainerActivity)getActivity()).showDetails(getFile());
}
toHide.add(R.id.action_download_file);
toHide.add(R.id.action_sync_file);
toHide.add(R.id.action_rename_file); // by now
-
+
+ // Options shareLink
+ if (!getFile().isShareByLink()) {
+ toHide.add(R.id.action_unshare_file);
+ }
+
for (int i : toHide) {
item = menu.findItem(i);
if (item != null) {
return false;
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+ }
private void seeDetails() {