From: masensio Date: Tue, 4 Feb 2014 12:31:30 +0000 (+0100) Subject: Merge branch 'share_link_show_shared_files' into share_link__unshare_file X-Git-Tag: oc-android-1.5.5~35^2~29 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/09bb7bce234cf9fc22d23a598ab4f9aec46909ec?hp=5b5a9782c94777d33cbf958fc08b4be1981df615 Merge branch 'share_link_show_shared_files' into share_link__unshare_file --- diff --git a/owncloud-android-library b/owncloud-android-library index 8c87d88c..ccb07993 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 8c87d88cff376038248216ea2eb00c0c5ed110e0 +Subproject commit ccb079935f53dcd97c5b21ca121f31dd611a094e 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 7ae67dc1..2c4dd7ce 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 @@ -244,4 +245,7 @@ do nothing you are not online for instant upload Failure Message: Please check your server configuration,maybe your quota is exceeded. + + Sorry, sharing is not enabled on your server. Please contact your administrator. + Unable to share this file or folder. Please, make sure it exists diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 76e3e5c8..7b5380f7 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -1099,4 +1099,19 @@ 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); + } + } } diff --git a/src/com/owncloud/android/operations/GetSharesOperation.java b/src/com/owncloud/android/operations/GetSharesOperation.java index 4cbee02a..7129a213 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/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 5cae78d0..02da64ef 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -79,6 +79,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; @@ -1352,10 +1353,25 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa } 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. @@ -1574,4 +1590,22 @@ OCFileListFragment.ContainerActivity, FileDetailFragment.ContainerActivity, OnNa 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(); + + } + } + } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index 49895260..09d31c43 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); diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 91abe7d1..a1ff5d4e 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -284,6 +284,10 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName 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("."); @@ -349,7 +353,7 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName return super.onContextItemSelected(item); } } - + /** * Use this to query the {@link OCFile} that is currently @@ -419,6 +423,8 @@ public class OCFileListFragment extends ExtendedListFragment implements EditName */ public void onBrowsedDownTo(OCFile folder); + public void unshareFileWithLink(OCFile mTargetFile); + 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 8555fa77..c6d9825d 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -229,6 +229,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); @@ -266,6 +271,15 @@ public class PreviewImageFragment extends FileFragment implements OnRemoteOper } + /** + * {@inheritDoc} + */ + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + } + + 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 464ea6db..d68332e1 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) { @@ -324,6 +329,14 @@ public class PreviewMediaFragment extends FileFragment implements return false; } } + + /** + * {@inheritDoc} + */ + @Override + public void onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + } private void seeDetails() {