From: masensio Date: Mon, 3 Feb 2014 13:24:36 +0000 (+0100) Subject: OC-2734: Update Database for UnshareLink operation X-Git-Tag: oc-android-1.5.5~35^2~33 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/8d493de0ea590d669dadad7f2fe6d22fd72f9cb5?ds=inline;hp=--cc OC-2734: Update Database for UnshareLink operation --- 8d493de0ea590d669dadad7f2fe6d22fd72f9cb5 diff --git a/res/values/strings.xml b/res/values/strings.xml index 854a53b6..2c4dd7ce 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -245,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/UnshareLinkOperation.java b/src/com/owncloud/android/operations/UnshareLinkOperation.java index b1ec9ccc..c588ec1a 100644 --- a/src/com/owncloud/android/operations/UnshareLinkOperation.java +++ b/src/com/owncloud/android/operations/UnshareLinkOperation.java @@ -17,14 +17,12 @@ package com.owncloud.android.operations; -import java.util.ArrayList; - 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.GetRemoteSharesOperation; +import com.owncloud.android.lib.operations.remote.UnshareLinkRemoteOperation; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.utils.Log_OC; @@ -52,13 +50,16 @@ public class UnshareLinkOperation extends SyncOperation { OCShare share = getStorageManager().getShareByPath(mFile.getRemotePath()); if (share != null) { - GetRemoteSharesOperation operation = new GetRemoteSharesOperation(); + UnshareLinkRemoteOperation operation = new UnshareLinkRemoteOperation((int) share.getIdRemoteShared()); result = operation.execute(client); if (result.isSuccess()) { Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted"); - // TODO Update DB + mFile.setShareByLink(false); + mFile.setPublicLink(""); + getStorageManager().saveFile(mFile); + getStorageManager().removeShare(share); } } else { diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index 5cae78d0..e4236a5c 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,24 @@ 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(); + + } + /** * Updates the view associated to the activity after the finish of an operation trying to remove a * file. @@ -1574,4 +1589,20 @@ 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); + + } 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/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index 5cd4a152..7691d77c 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -285,6 +285,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("."); @@ -439,6 +443,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);