diff --git a/res/values/strings.xml b/res/values/strings.xml index f82dc45182..fe7854ea5d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -288,6 +288,8 @@ An error occurred while trying to share this file or folder Unable to unshare. Please check whether the file exists An error occurred while trying to unshare this file or folder + Unable to update. Please check whether the file exists + An error occurred while trying to update the shared link Enter a password You must enter a password @@ -309,6 +311,7 @@ to delete this file to share this file to unshare this file + to update this shared link to create the file to upload in this folder The file is no longer available on the server diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index 237c84698d..0588ad9d52 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -47,7 +47,6 @@ import android.provider.MediaStore; import com.owncloud.android.MainApp; import com.owncloud.android.db.ProviderMeta.ProviderTableMeta; import com.owncloud.android.lib.common.utils.Log_OC; -import com.owncloud.android.lib.resources.files.FileUtils; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.status.CapabilityBooleanType; @@ -935,20 +934,20 @@ public class FileDataStorageManager { ); cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0); cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId()); - cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared()); + cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId()); cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name); - if (shareExists(share.getIdRemoteShared())) {// for renamed files; no more delete and create + if (shareExists(share.getRemoteId())) {// for renamed files; no more delete and create overriden = true; if (getContentResolver() != null) { getContentResolver().update(ProviderTableMeta.CONTENT_URI_SHARE, cv, ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", - new String[]{String.valueOf(share.getIdRemoteShared())}); + new String[]{String.valueOf(share.getRemoteId())}); } else { try { getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_SHARE, cv, ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", - new String[]{String.valueOf(share.getIdRemoteShared())}); + new String[]{String.valueOf(share.getRemoteId())}); } catch (RemoteException e) { Log_OC.e(TAG, "Fail to insert insert file to database " @@ -981,16 +980,42 @@ public class FileDataStorageManager { } + /** + * Get first share bound to a file with a known path and given {@link ShareType}. + * + * @param path Path of the file. + * @param type Type of the share to get + * @param shareWith Target of the share. Ignored in type is {@link ShareType#PUBLIC_LINK} + * @return First {@OCShare} instance found in DB bound to the file in 'path' + */ public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) { Cursor c = null; + if (shareWith == null) { + shareWith = ""; + } String selection = ProviderTableMeta.OCSHARES_PATH + "=? AND " + ProviderTableMeta.OCSHARES_SHARE_TYPE + "=? AND " - + ProviderTableMeta.OCSHARES_SHARE_WITH + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" ; + if (!ShareType.PUBLIC_LINK.equals(type)) { + selection += ProviderTableMeta.OCSHARES_SHARE_WITH + "=? AND "; + } - String [] selectionArgs = new String[]{path, Integer.toString(type.getValue()), - shareWith, mAccount.name}; + String [] selectionArgs; + if (ShareType.PUBLIC_LINK.equals(type)) { + selectionArgs = new String[]{ + path, + Integer.toString(type.getValue()), + mAccount.name + }; + } else { + selectionArgs = new String[]{ + path, + Integer.toString(type.getValue()), + mAccount.name, + shareWith + }; + } if (getContentResolver() != null) { c = getContentResolver().query( @@ -1190,16 +1215,16 @@ public class FileDataStorageManager { ); cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0); cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId()); - cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared()); + cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId()); cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name); - if (shareExists(share.getIdRemoteShared())) { + if (shareExists(share.getRemoteId())) { // updating an existing file operations.add( ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE). withValues(cv). withSelection(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?", - new String[]{String.valueOf(share.getIdRemoteShared())}) + new String[]{String.valueOf(share.getRemoteId())}) .build()); } else { // adding a new file @@ -1463,7 +1488,7 @@ public class FileDataStorageManager { ); cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0); cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId()); - cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared()); + cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getRemoteId()); cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name); // adding a new share resource diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index ccbcf07df4..f0f66a7e50 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -46,6 +46,7 @@ import com.owncloud.android.services.observer.FileObserverService; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.ShareActivity; import com.owncloud.android.ui.dialog.ShareLinkToDialog; +import com.owncloud.android.ui.dialog.SharePasswordDialogFragment; import org.apache.http.protocol.HTTP; @@ -283,7 +284,7 @@ public class FileOperationsHelper { unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, ShareType.PUBLIC_LINK); unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, ""); - unshareFile(unshareService); + queueShareIntent(unshareService); } public void unshareFileWithUserOrGroup(OCFile file, ShareType shareType, String userOrGroup){ @@ -296,15 +297,15 @@ public class FileOperationsHelper { unshareService.putExtra(OperationsService.EXTRA_SHARE_TYPE, shareType); unshareService.putExtra(OperationsService.EXTRA_SHARE_WITH, userOrGroup); - unshareFile(unshareService); + queueShareIntent(unshareService); } - private void unshareFile(Intent unshareService){ + private void queueShareIntent(Intent shareIntent){ if (isSharedSupported()) { // Unshare the file mWaitingForOpId = mFileActivity.getOperationsServiceBinder(). - queueNewOperation(unshareService); + queueNewOperation(shareIntent); mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext(). getString(R.string.wait_a_moment)); @@ -333,6 +334,46 @@ public class FileOperationsHelper { } + /** + * Starts a dialog that requests a password to the user to protect a share link. + * + * @param file File which public share will be protected by the requested password + */ + public void requestPasswordForShareViaLink(OCFile file) { + SharePasswordDialogFragment dialog = + SharePasswordDialogFragment.newInstance( + file, + null + ); + dialog.show( + mFileActivity.getSupportFragmentManager(), + SharePasswordDialogFragment.PASSWORD_FRAGMENT + ); + } + + /** + * Updates a public share on a file to set its password. + * Starts a request to do it in {@link OperationsService} + * + * @param file File which public share will be protected with a password. + * @param password Password to set for the public link; null or empty string to clear + * the current password + */ + public void setPasswordToShareViaLink(OCFile file, String password) { + // Set password updating share + Intent updateShareIntent = new Intent(mFileActivity, OperationsService.class); + updateShareIntent.setAction(OperationsService.ACTION_UPDATE_SHARE); + updateShareIntent.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount()); + updateShareIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath()); + updateShareIntent.putExtra( + OperationsService.EXTRA_PASSWORD_SHARE, + (password == null) ? "" : password + ); + + queueShareIntent(updateShareIntent); + } + + /** * @return 'True' if the server supports the Search Users API */ diff --git a/src/com/owncloud/android/operations/CreateShareViaLinkOperation.java b/src/com/owncloud/android/operations/CreateShareViaLinkOperation.java index 5958c7f1d8..52baa417e8 100644 --- a/src/com/owncloud/android/operations/CreateShareViaLinkOperation.java +++ b/src/com/owncloud/android/operations/CreateShareViaLinkOperation.java @@ -30,7 +30,6 @@ import android.content.Context; import android.content.Intent; import com.owncloud.android.R; -import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.operations.RemoteOperation; @@ -44,8 +43,6 @@ import com.owncloud.android.operations.common.SyncOperation; public class CreateShareViaLinkOperation extends SyncOperation { - protected FileDataStorageManager mStorageManager; - private String mPath; private String mPassword; private Intent mSendIntent; diff --git a/src/com/owncloud/android/operations/UnshareOperation.java b/src/com/owncloud/android/operations/UnshareOperation.java index 4167831406..d819abf5e9 100644 --- a/src/com/owncloud/android/operations/UnshareOperation.java +++ b/src/com/owncloud/android/operations/UnshareOperation.java @@ -69,11 +69,11 @@ public class UnshareOperation extends SyncOperation { if (share != null) { OCFile file = getStorageManager().getFileByPath(mRemotePath); RemoveRemoteShareOperation operation = - new RemoveRemoteShareOperation((int) share.getIdRemoteShared()); + new RemoveRemoteShareOperation((int) share.getRemoteId()); result = operation.execute(client); if (result.isSuccess()) { - Log_OC.d(TAG, "Share id = " + share.getIdRemoteShared() + " deleted"); + Log_OC.d(TAG, "Share id = " + share.getRemoteId() + " deleted"); if (mShareType == ShareType.PUBLIC_LINK) { file.setShareViaLink(false); diff --git a/src/com/owncloud/android/operations/UpdateShareViaLinkOperation.java b/src/com/owncloud/android/operations/UpdateShareViaLinkOperation.java new file mode 100644 index 0000000000..64c25df36b --- /dev/null +++ b/src/com/owncloud/android/operations/UpdateShareViaLinkOperation.java @@ -0,0 +1,136 @@ +/** + * ownCloud Android client application + * + * @author David A. Velasco + * Copyright (C) 2015 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.common.OwnCloudClient; +import com.owncloud.android.lib.common.operations.RemoteOperation; +import com.owncloud.android.lib.common.operations.RemoteOperationResult; +import com.owncloud.android.lib.resources.files.FileUtils; +import com.owncloud.android.lib.resources.shares.GetRemoteShareOperation; +import com.owncloud.android.lib.resources.shares.OCShare; +import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; +import com.owncloud.android.operations.common.SyncOperation; + + +/** + * Updates an existing public share for a given file + */ + +public class UpdateShareViaLinkOperation extends SyncOperation { + + private String mPath; + private String mPassword; + + /** + * Constructor + * @param path Full path of the file/folder being shared. Mandatory argument + * @param password Password to protect a public link share. + */ + public UpdateShareViaLinkOperation( + String path, + String password + ) { + + mPath = path; + mPassword = password; + } + + @Override + protected RemoteOperationResult run(OwnCloudClient client) { + + OCShare publicShare = getStorageManager().getFirstShareByPathAndType( + mPath, + ShareType.PUBLIC_LINK, + "" + ); + + if (publicShare == null) { + // TODO try to get remote? + + } + + // Update remote share with password + RemoteOperation operation = new UpdateRemoteShareOperation( + publicShare.getRemoteId() + ); + ((UpdateRemoteShareOperation)operation).setPassword(mPassword); + RemoteOperationResult result = operation.execute(client); + + /* + if (!result.isSuccess() || result.getData().size() <= 0) { + operation = new CreateRemoteShareOperation( + mPath, + ShareType.PUBLIC_LINK, + "", + false, + mPassword, + OCShare.DEFAULT_PERMISSION + ); + result = operation.execute(client); + } + */ + + if (result.isSuccess()) { + // Retrieve updated share / save directly with password? -> no; the password is not be saved + operation = new GetRemoteShareOperation(publicShare.getRemoteId()); + result = operation.execute(client); + if (result.isSuccess()) { + OCShare share = (OCShare) result.getData().get(0); + updateData(share); + } + } + + return result; + } + + public String getPath() { + return mPath; + } + + public String getPassword() { + return mPassword; + } + + private void updateData(OCShare share) { + // Update DB with the response + share.setPath(mPath); + if (mPath.endsWith(FileUtils.PATH_SEPARATOR)) { + share.setIsFolder(true); + } else { + share.setIsFolder(false); + } + + getStorageManager().saveShare(share); // TODO info about having a password? ask to Gonzalo + + // Update OCFile with data from share: ShareByLink and publicLink + // TODO check & remove if not needed + OCFile file = getStorageManager().getFileByPath(mPath); + if (file != null) { + file.setPublicLink(share.getShareLink()); + file.setShareViaLink(true); + getStorageManager().saveFile(file); + } + } + +} + diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index eff8e0324a..6c0dde6834 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -64,6 +64,7 @@ import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UnshareOperation; +import com.owncloud.android.operations.UpdateShareViaLinkOperation; import com.owncloud.android.operations.common.SyncOperation; import java.io.IOException; @@ -97,6 +98,7 @@ public class OperationsService extends Service { public static final String ACTION_CREATE_SHARE_VIA_LINK = "CREATE_SHARE_VIA_LINK"; public static final String ACTION_CREATE_SHARE_WITH_SHAREE = "CREATE_SHARE_WITH_SHAREE"; public static final String ACTION_UNSHARE = "UNSHARE"; + public static final String ACTION_UPDATE_SHARE = "UPDATE_SHARE"; public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO"; public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN"; public static final String ACTION_GET_USER_NAME = "GET_USER_NAME"; @@ -563,6 +565,13 @@ public class OperationsService extends Service { ); } + } else if (ACTION_UPDATE_SHARE.equals(action)) { + String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); + String password = operationIntent.getStringExtra(EXTRA_PASSWORD_SHARE); + if (remotePath.length() > 0) { + operation = new UpdateShareViaLinkOperation(remotePath, password); + } + } else if (action.equals(ACTION_CREATE_SHARE_WITH_SHAREE)) { // Create private share with user or group String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH); String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH); diff --git a/src/com/owncloud/android/ui/activity/FileActivity.java b/src/com/owncloud/android/ui/activity/FileActivity.java index 6091c6f72e..58dd595809 100644 --- a/src/com/owncloud/android/ui/activity/FileActivity.java +++ b/src/com/owncloud/android/ui/activity/FileActivity.java @@ -73,6 +73,7 @@ import com.owncloud.android.operations.GetSharesForFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UnshareOperation; +import com.owncloud.android.operations.UpdateShareViaLinkOperation; import com.owncloud.android.services.OperationsService; import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.NavigationDrawerItem; @@ -735,7 +736,8 @@ public class FileActivity extends AppCompatActivity } else if (operation == null || operation instanceof CreateShareWithShareeOperation || operation instanceof UnshareOperation || - operation instanceof SynchronizeFolderOperation + operation instanceof SynchronizeFolderOperation || + operation instanceof UpdateShareViaLinkOperation ) { if (result.isSuccess()) { updateFileFromDB(); diff --git a/src/com/owncloud/android/ui/activity/ShareActivity.java b/src/com/owncloud/android/ui/activity/ShareActivity.java index 44543b93b3..46b044041f 100644 --- a/src/com/owncloud/android/ui/activity/ShareActivity.java +++ b/src/com/owncloud/android/ui/activity/ShareActivity.java @@ -154,7 +154,7 @@ public class ShareActivity extends FileActivity super.onRemoteOperationFinish(operation, result); if (result.isSuccess()) { - Log_OC.d(TAG, "Refreshing lists on successful sync"); + Log_OC.d(TAG, "Refreshing lists on successful operation"); refreshSharesFromStorageManager(); } diff --git a/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java b/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java index d069b5a0bc..9fbdbc492f 100644 --- a/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java +++ b/src/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java @@ -113,8 +113,14 @@ public class SharePasswordDialogFragment extends DialogFragment } // Share the file - ((FileActivity)getActivity()).getFileOperationsHelper() - .shareFileWithLinkToApp(mFile, password, mSendIntent); + if (mSendIntent == null) { + ((FileActivity) getActivity()).getFileOperationsHelper(). + setPasswordToShareViaLink(mFile, password); + + } else { // TODO remove old flow + ((FileActivity) getActivity()).getFileOperationsHelper() + .shareFileWithLinkToApp(mFile, password, mSendIntent); + } } else { // Disable the flag "Share again" diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index db1e98d36f..2ed5d0b2c5 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -95,6 +95,9 @@ public class ShareFileFragment extends Fragment /** Listener for changes on switch to share / unshare publicly */ private CompoundButton.OnCheckedChangeListener mOnShareViaLinkSwitchCheckedChangeListener; + /** Listener for changes on switch to set / clear password on public link */ + private CompoundButton.OnCheckedChangeListener mOnPasswordSwitchCheckedChangeListener; + /** * Public factory method to create new ShareFileFragment instances. @@ -181,15 +184,19 @@ public class ShareFileFragment extends Fragment mOnShareViaLinkSwitchCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (isResumed()) { - if (isChecked) { - ((FileActivity) getActivity()).getFileOperationsHelper().shareFileViaLink(mFile); + if (!isResumed()) { + // very important, setCheched(...) is called automatically during + // Fragment recreation on device rotations + return; + } + if (isChecked) { + ((FileActivity) getActivity()).getFileOperationsHelper(). + shareFileViaLink(mFile); - } else { - ((FileActivity) getActivity()).getFileOperationsHelper().unshareFileViaLink(mFile); - } - } // else, nothing; very important, setCheched(...) is called automatically during Fragment - // recreation on device rotations + } else { + ((FileActivity) getActivity()).getFileOperationsHelper(). + unshareFileViaLink(mFile); + } } }; Switch shareViaLinkSwitch = (Switch) view.findViewById(R.id.shareViaLinkSectionSwitch); @@ -200,6 +207,11 @@ public class ShareFileFragment extends Fragment shareViaLinkExpirationSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (!isResumed()) { + // very important, setCheched(...) is called automatically during + // Fragment recreation on device rotations + return; + } if (isChecked) { // TODO real implementation: update share with expiration date // show value of expiration date @@ -214,23 +226,25 @@ public class ShareFileFragment extends Fragment }); // Switch for password - Switch shareViaLinkPasswordSwitch = (Switch) view.findViewById(R.id.shareViaLinkPasswordSwitch); - shareViaLinkPasswordSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + mOnPasswordSwitchCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (!isResumed()) { + // very important, setCheched(...) is called automatically during + // Fragment recreation on device rotations + return; + } if (isChecked) { - // TODO real implementation: update share with password - // show - getExpirationPasswordValue().setVisibility(View.VISIBLE); - + ((FileActivity) getActivity()).getFileOperationsHelper(). + requestPasswordForShareViaLink(mFile); } else { - // TODO real implementation: update share without password - // empty value - getExpirationPasswordValue().setVisibility(View.INVISIBLE); + ((FileActivity) getActivity()).getFileOperationsHelper(). + setPasswordToShareViaLink(mFile, ""); // "" clears } } - }); - + }; + Switch shareViaLinkPasswordSwitch = (Switch) view.findViewById(R.id.shareViaLinkPasswordSwitch); + shareViaLinkPasswordSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener); return view; } @@ -342,12 +356,12 @@ public class ShareFileFragment extends Fragment */ private void updatePublicShareSection() { if (mPublicShare != null && ShareType.PUBLIC_LINK.equals(mPublicShare.getShareType())) { - // public share bound -> expand section + /// public share bound -> expand section Switch shareViaLinkSwitch = getShareViaLinkSwitch(); if (!shareViaLinkSwitch.isChecked()) { // set null listener before setChecked() to prevent infinite loop of calls shareViaLinkSwitch.setOnCheckedChangeListener(null); - getShareViaLinkSwitch().setChecked(true); + shareViaLinkSwitch.setChecked(true); shareViaLinkSwitch.setOnCheckedChangeListener( mOnShareViaLinkSwitchCheckedChangeListener ); @@ -356,8 +370,29 @@ public class ShareFileFragment extends Fragment getPasswordSection().setVisibility(View.VISIBLE); getGetLinkButton().setVisibility(View.VISIBLE); + /// update state of password switch and message depending on password protection + Switch passwordSwitch = getPasswordSwitch(); + // set null listener before setChecked() to prevent infinite loop of calls + passwordSwitch.setOnCheckedChangeListener(null); + if (mPublicShare.isPasswordProtected()) { + if (!passwordSwitch.isChecked()) { + passwordSwitch.toggle(); + } + getPasswordValue().setVisibility(View.VISIBLE); + } else { + if (passwordSwitch.isChecked()) { + passwordSwitch.toggle(); + } + getPasswordValue().setVisibility(View.INVISIBLE); + } + // recover listener + passwordSwitch.setOnCheckedChangeListener( + mOnPasswordSwitchCheckedChangeListener + ); + + } else { - // no public share -> collapse section + /// no public share -> collapse section Switch shareViaLinkSwitch = getShareViaLinkSwitch(); if (shareViaLinkSwitch.isChecked()) { shareViaLinkSwitch.setOnCheckedChangeListener(null); @@ -372,6 +407,8 @@ public class ShareFileFragment extends Fragment } } + /// BEWARE: next methods will failed with NullPointerException if called before onCreateView() finishes + private Switch getShareViaLinkSwitch() { return (Switch) getView().findViewById(R.id.shareViaLinkSectionSwitch); } @@ -388,7 +425,11 @@ public class ShareFileFragment extends Fragment return getView().findViewById(R.id.shareViaLinkPasswordSection); } - private TextView getExpirationPasswordValue() { + private Switch getPasswordSwitch() { + return (Switch) getView().findViewById(R.id.shareViaLinkPasswordSwitch); + } + + private TextView getPasswordValue() { return (TextView) getView().findViewById(R.id.shareViaLinkPasswordValue); } diff --git a/src/com/owncloud/android/utils/ErrorMessageAdapter.java b/src/com/owncloud/android/utils/ErrorMessageAdapter.java index 37b2fbacca..be7438668e 100644 --- a/src/com/owncloud/android/utils/ErrorMessageAdapter.java +++ b/src/com/owncloud/android/utils/ErrorMessageAdapter.java @@ -27,6 +27,7 @@ import com.owncloud.android.R; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; +import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.operations.CreateShareViaLinkOperation; @@ -38,6 +39,7 @@ import com.owncloud.android.operations.RenameFileOperation; import com.owncloud.android.operations.SynchronizeFileOperation; import com.owncloud.android.operations.SynchronizeFolderOperation; import com.owncloud.android.operations.UnshareOperation; +import com.owncloud.android.operations.UpdateShareViaLinkOperation; import com.owncloud.android.operations.UploadFileOperation; import org.apache.commons.httpclient.ConnectTimeoutException; @@ -189,7 +191,7 @@ public class ErrorMessageAdapter { if (result.getData() != null && result.getData().size() > 0) { message = (String) result.getData().get(0); // share API sends its own error messages - } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { + } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { message = res.getString(R.string.unshare_link_file_no_exist); } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { @@ -201,6 +203,25 @@ public class ErrorMessageAdapter { // Show a Message, operation finished without success message = res.getString(R.string.unshare_link_file_error); } + + } else if (operation instanceof UpdateShareViaLinkOperation) { + + if (result.getData() != null && result.getData().size() > 0) { + message = (String) result.getData().get(0); // share API sends its own error messages + + } else if (result.getCode() == ResultCode.SHARE_NOT_FOUND) { + message = res.getString(R.string.update_link_file_no_exist); + + } else if (result.getCode() == ResultCode.SHARE_FORBIDDEN) { + // Error --> No permissions + message = String.format(res.getString(R.string.forbidden_permissions), + res.getString(R.string.update_link_forbidden_permissions)); + + } else { // Generic error + // Show a Message, operation finished without success + message = res.getString(R.string.update_link_file_error); + } + } else if (operation instanceof MoveFileOperation) { if (result.getCode() == ResultCode.FILE_NOT_FOUND) {