From: masensio Date: Thu, 6 Feb 2014 10:23:30 +0000 (+0100) Subject: Merge branch 'share_link__new_share' into share_link__unshare_file X-Git-Tag: oc-android-1.5.5~35^2~22 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/1bdf1e60f1c18762d0a77543f74a2c28fb859557?hp=45b73934faa70408007ca4461d8a514282806c3a Merge branch 'share_link__new_share' into share_link__unshare_file --- diff --git a/owncloud-android-library b/owncloud-android-library index d96e31b5..e9a1ee81 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit d96e31b5e595518dc6365e5b290dba124140dc26 +Subproject commit e9a1ee81ca37182963467f85476de0fbc216d2e7 diff --git a/res/menu/file_actions_menu.xml b/res/menu/file_actions_menu.xml index dcd451c4..1e78a367 100644 --- a/res/menu/file_actions_menu.xml +++ b/res/menu/file_actions_menu.xml @@ -20,7 +20,8 @@ - + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 1725ae38..b86d6085 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -60,6 +60,7 @@ Refresh file File was renamed to %1$s during upload Share link + Unshare link Yes No OK @@ -249,4 +250,5 @@ Sorry, sharing is not enabled on your server. Please contact your administrator. Unable to share this file or folder. Please, make sure it exists An error occurred while trying to share this file or folder + An error occurred while trying to unshare this file or folder diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 279229af..181a7d49 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1100,8 +1100,22 @@ public class FileDataStorageManager { } } - - + + 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); + } + } + public void saveSharesDB(ArrayList shares) { saveShares(shares); diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index ab8395cd..1c0db87b 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -32,6 +32,7 @@ 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.ui.activity.FileActivity; import com.owncloud.android.ui.dialog.ActivityChooserDialog; import com.owncloud.android.utils.Log_OC; @@ -140,4 +141,25 @@ public class FileOperationsHelper { return false; } + + public void unshareFileWithLink(OCFile file, FileActivity callerActivity) { + + if (isSharedSupported(callerActivity)) { + // Unshare the file + UnshareLinkOperation unshare = new UnshareLinkOperation(file); + unshare.execute(callerActivity.getStorageManager(), + callerActivity, + callerActivity.getRemoteOperationListener(), + callerActivity.getHandler(), + callerActivity); + + callerActivity.showLoadingDialog(); + + } else { + // Show a Message + Toast t = Toast.makeText(callerActivity, callerActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG); + t.show(); + + } + } } diff --git a/src/com/owncloud/android/operations/GetSharesOperation.java b/src/com/owncloud/android/operations/GetSharesOperation.java index 8f7a2ae8..eb221598 100644 --- a/src/com/owncloud/android/operations/GetSharesOperation.java +++ b/src/com/owncloud/android/operations/GetSharesOperation.java @@ -1,5 +1,5 @@ /* 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, diff --git a/src/com/owncloud/android/operations/UnshareLinkOperation.java b/src/com/owncloud/android/operations/UnshareLinkOperation.java new file mode 100644 index 00000000..ad23427f --- /dev/null +++ b/src/com/owncloud/android/operations/UnshareLinkOperation.java @@ -0,0 +1,80 @@ +/* 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 . + * + */ + +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; + } + +} diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 3c8a2011..fac275ca 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -43,6 +43,7 @@ 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; import com.owncloud.android.operations.CreateShareOperation; +import com.owncloud.android.operations.UnshareLinkOperation; import com.owncloud.android.ui.dialog.LoadingDialog; import com.owncloud.android.utils.Log_OC; @@ -353,7 +354,11 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp Log_OC.d(TAG, "Received result of operation in FileActivity - common behaviour for all the FileActivities "); if (operation instanceof CreateShareOperation) { onCreateShareOperationFinish((CreateShareOperation) operation, result); - } + + } else if (operation instanceof UnshareLinkOperation) { + onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result); + + } } private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { @@ -362,7 +367,7 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp Intent sendIntent = operation.getSendIntent(); startActivity(sendIntent); - } else if (result.getCode() == ResultCode.FILE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND + } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { // Error --> SHARE_NOT_FOUND Toast t = Toast.makeText(this, getString(R.string.share_link_file_no_exist), Toast.LENGTH_LONG); t.show(); } else { // Generic error @@ -373,6 +378,17 @@ public class FileActivity extends SherlockFragmentActivity implements OnRemoteOp } + private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) { + dismissLoadingDialog(); + + if (!result.isSuccess()){ // Generic error + // Show a Message, operation finished without success + Toast t = Toast.makeText(this, getString(R.string.unshare_link_file_error), Toast.LENGTH_LONG); + t.show(); + } + + } + /** * Show loading dialog */ diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index a56fe3d9..55b89bd6 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -75,6 +75,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.services.OperationsService; import com.owncloud.android.syncadapter.FileSyncAdapter; import com.owncloud.android.ui.dialog.EditNameDialog; @@ -1303,14 +1304,18 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } else if (operation instanceof CreateFolderOperation) { onCreateFolderOperationFinish((CreateFolderOperation)operation, result); - + } else if (operation instanceof CreateShareOperation) { onCreateShareOperationFinish((CreateShareOperation) operation, result); - } + + } else if (operation instanceof UnshareLinkOperation) { + onUnshareLinkOperationFinish((UnshareLinkOperation)operation, result); + + } } - + private void onCreateShareOperationFinish(CreateShareOperation operation, RemoteOperationResult result) { if (result.isSuccess()) { refeshListOfFilesFragment(); @@ -1318,6 +1323,13 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } + private void onUnshareLinkOperationFinish(UnshareLinkOperation operation, RemoteOperationResult result) { + if (result.isSuccess()) { + refeshListOfFilesFragment(); + } + } + + /** * Updates the view associated to the activity after the finish of an operation trying to remove a * file. @@ -1535,5 +1547,8 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa mRefreshSharesInProgress = true; } + + + } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 216cceec..310da9cf 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -310,7 +310,12 @@ public class FileDetailFragment extends FileFragment implements 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); @@ -340,6 +345,11 @@ public class FileDetailFragment extends FileFragment implements activity.getFileOperationsHelper().shareFileWithLink(getFile(), activity); return true; } + case R.id.action_unshare_file: { + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity); + return true; + } case R.id.action_open_file_with: { FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); activity.getFileOperationsHelper().openFile(getFile(), activity); diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 96aa2dc2..810602a8 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -282,12 +282,17 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName public boolean onContextItemSelected (MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); mTargetFile = (OCFile) mAdapter.getItem(info.position); - switch (item.getItemId()) { + switch (item.getItemId()) { case R.id.action_share_file: { FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); activity.getFileOperationsHelper().shareFileWithLink(mTargetFile, activity); return true; } + case R.id.action_unshare_file: { + FileDisplayActivity activity = (FileDisplayActivity) getSherlockActivity(); + activity.getFileOperationsHelper().unshareFileWithLink(mTargetFile, activity); + return true; + } case R.id.action_rename_file: { String fileName = mTargetFile.getFileName(); int extensionStart = mTargetFile.isFolder() ? -1 : fileName.lastIndexOf("."); @@ -353,7 +358,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName return super.onContextItemSelected(item); } } - + /** * Use this to query the {@link OCFile} that is currently @@ -422,7 +427,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName * @param file */ public void onBrowsedDownTo(OCFile folder); - + public void startDownloadForPreview(OCFile file); public void startMediaPreview(OCFile file, int i, boolean b); diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index a2d05370..d8622f24 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -230,6 +230,11 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper 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); @@ -241,6 +246,22 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper } + /** + * {@inheritDoc} + */ + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + // Options shareLink + if (!getFile().isShareByLink()) { + MenuItem item = menu.findItem(R.id.action_unshare_file); + item.setVisible(false); + item.setEnabled(false); + } + } + + /** * {@inheritDoc} @@ -253,6 +274,11 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper act.getFileOperationsHelper().shareFileWithLink(getFile(), act); return true; } + case R.id.action_unshare_file: { + FileActivity act = (FileActivity)getSherlockActivity(); + act.getFileOperationsHelper().unshareFileWithLink(getFile(), act); + return true; + } case R.id.action_open_file_with: { openFile(); return true; @@ -272,6 +298,7 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper } + private void seeDetails() { ((FileFragment.ContainerActivity)getActivity()).showDetails(getFile()); } diff --git a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index ee4a7b00..f83e1ab0 100644 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -289,7 +289,12 @@ public class PreviewMediaFragment extends FileFragment implements 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) { @@ -300,6 +305,22 @@ public class PreviewMediaFragment extends FileFragment implements } + + /** + * {@inheritDoc} + */ + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + // Options shareLink + if (!getFile().isShareByLink()) { + MenuItem item = menu.findItem(R.id.action_unshare_file); + item.setVisible(false); + item.setEnabled(false); + } + } + /** * {@inheritDoc} @@ -311,6 +332,10 @@ public class PreviewMediaFragment extends FileFragment implements shareFileWithLink(); return true; } + case R.id.action_unshare_file: { + unshareFileWithLink(); + return true; + } case R.id.action_open_file_with: { openFile(); return true; @@ -328,7 +353,14 @@ public class PreviewMediaFragment extends FileFragment implements return false; } } + + + private void unshareFileWithLink() { + stopPreview(false); + FileActivity activity = (FileActivity)((FileFragment.ContainerActivity)getActivity()); + activity.getFileOperationsHelper().unshareFileWithLink(getFile(), activity); + } private void shareFileWithLink() { stopPreview(false);