From 55fdcee912f3524a4216829537798aeee16df9b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Gonz=C3=A1lez=20Cabrero?= Date: Mon, 14 Mar 2016 09:55:10 +0100 Subject: [PATCH 1/7] New switch in share via link to allow editing --- res/layout/share_file_layout.xml | 34 ++++++++++ res/values/strings.xml | 1 + .../ui/fragment/ShareFileFragment.java | 68 +++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/res/layout/share_file_layout.xml b/res/layout/share_file_layout.xml index 4b46315eff..ce445ff6d3 100644 --- a/res/layout/share_file_layout.xml +++ b/res/layout/share_file_layout.xml @@ -228,6 +228,40 @@ + + + + + + + + Set expiration date Password protect Secured + Allow edit Get link Search diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index 08443aad5c..ab8330f80b 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -118,6 +118,11 @@ public class ShareFileFragment extends Fragment */ private OnExpirationDateInteractionListener mOnExpirationDateInteractionListener = null; + /** + * Listener for user actions to set or unset edit permission on public link + */ + private OnEditPermissionInteractionListener mOnEditPermissionInteractionListener = null; + /** * Public factory method to create new ShareFileFragment instances. @@ -432,6 +437,39 @@ public class ShareFileFragment extends Fragment } } + /** + * Listener for user actions that start any update on the edit permissions for the public link. + */ + private class OnEditPermissionInteractionListener + implements CompoundButton.OnCheckedChangeListener { + + /** + * Called by R.id.shareViaLinkEditPermissionSwitch to set or clear the edit permission. + * + * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkEditPermissionSwitch + * @param isChecked New switch state. + */ + @Override + public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { + if (!isResumed()) { + // very important, setCheched(...) is called automatically during + // Fragment recreation on device rotations + return; + } + if (isChecked) { + // Pending to implement + } else { + // Pending to implement + } + + // undo the toggle to grant the view will be correct if the dialog is cancelled + switchView.setOnCheckedChangeListener(null); + switchView.toggle(); + switchView.setOnCheckedChangeListener(mOnEditPermissionInteractionListener); + } + + } + @Override public void onActivityCreated(Bundle savedInstanceState) { @@ -597,6 +635,9 @@ public class ShareFileFragment extends Fragment } getExpirationDateSection().setVisibility(View.VISIBLE); getPasswordSection().setVisibility(View.VISIBLE); + if(mFile.isFolder()) { + getEditPermissionSection().setVisibility(View.VISIBLE); + } // GetLink button AppCompatButton getLinkButton = getGetLinkButton(); getLinkButton.setVisibility(View.VISIBLE); @@ -655,6 +696,23 @@ public class ShareFileFragment extends Fragment mOnPasswordInteractionListener ); + /// update state of the edit permission switch + Switch editPermissionSwitch = getEditPermissionSwitch(); + // set null listener before setChecked() to prevent infinite loop of calls + editPermissionSwitch.setOnCheckedChangeListener(null); + if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) { + if (!editPermissionSwitch.isChecked()) { + editPermissionSwitch.toggle(); + } + } else { + if (editPermissionSwitch.isChecked()) { + editPermissionSwitch.toggle(); + } + } + // recover listener + editPermissionSwitch.setOnCheckedChangeListener( + mOnEditPermissionInteractionListener + ); } else { /// no public share -> collapse section @@ -668,6 +726,7 @@ public class ShareFileFragment extends Fragment } getExpirationDateSection().setVisibility(View.GONE); getPasswordSection().setVisibility(View.GONE); + getEditPermissionSection().setVisibility(View.GONE); getGetLinkButton().setVisibility(View.GONE); } } @@ -703,6 +762,14 @@ public class ShareFileFragment extends Fragment return (TextView) getView().findViewById(R.id.shareViaLinkPasswordValue); } + private View getEditPermissionSection() { + return getView().findViewById(R.id.shareViaLinkEditPermissionSection); + } + + private Switch getEditPermissionSwitch() { + return (Switch) getView().findViewById(R.id.shareViaLinkEditPermissionSwitch); + } + private AppCompatButton getGetLinkButton() { return (AppCompatButton) getView().findViewById(R.id.shareViaLinkGetLinkButton); } @@ -714,6 +781,7 @@ public class ShareFileFragment extends Fragment getShareViaLinkSwitch().setVisibility(View.GONE); getExpirationDateSection().setVisibility(View.GONE); getPasswordSection().setVisibility(View.GONE); + getEditPermissionSection().setVisibility(View.GONE); getGetLinkButton().setVisibility(View.GONE); } From ee22243bb09d3dedb18a9b56321cfede7fcc299b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Gonz=C3=A1lez=20Cabrero?= Date: Mon, 14 Mar 2016 13:26:57 +0100 Subject: [PATCH 2/7] New Intent to request the share permission update, and fragment update to manage the event correctly --- owncloud-android-library | 2 +- .../android/files/FileOperationsHelper.java | 20 +++ .../UpdateShareViaLinkOperation.java | 14 +- .../android/services/OperationsService.java | 6 +- .../ui/fragment/ShareFileFragment.java | 152 +++++++++++------- 5 files changed, 135 insertions(+), 59 deletions(-) diff --git a/owncloud-android-library b/owncloud-android-library index 996660b88c..573afa1538 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 996660b88c4e2b3cef08604963cf2c29491efa1b +Subproject commit 573afa15382b67cc84f67fc9a7b2329a72ecb352 diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index a0ea508838..58ff16c54e 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -3,6 +3,7 @@ * * @author masensio * @author David A. Velasco + * @author Juan Carlos González Cabrero * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify @@ -409,6 +410,25 @@ public class FileOperationsHelper { queueShareIntent(updateShareIntent); } + /** + * Updates a public share on a file to set its edit permissions. + * Starts a request to do it in {@link OperationsService} + * + * @param file File which public share will be constrained with an expiration date. + * @param uploadPermission New state of the permissions of edit a folder shared via link. + */ + public void setUploadPermissionsToShare(OCFile file, boolean uploadPermission) { + 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_SHARE_PUBLIC_UPLOAD, + uploadPermission + ); + queueShareIntent(updateShareIntent); + } + /** * @return 'True' if the server supports the Search Users API diff --git a/src/com/owncloud/android/operations/UpdateShareViaLinkOperation.java b/src/com/owncloud/android/operations/UpdateShareViaLinkOperation.java index f1f575423b..e267b06e19 100644 --- a/src/com/owncloud/android/operations/UpdateShareViaLinkOperation.java +++ b/src/com/owncloud/android/operations/UpdateShareViaLinkOperation.java @@ -31,8 +31,6 @@ import com.owncloud.android.lib.resources.shares.ShareType; import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation; import com.owncloud.android.operations.common.SyncOperation; -import java.util.Calendar; - /** * Updates an existing public share for a given file @@ -42,6 +40,7 @@ public class UpdateShareViaLinkOperation extends SyncOperation { private String mPath; private String mPassword; + private boolean mPublicUpload; private long mExpirationDateInMillis; /** @@ -54,6 +53,7 @@ public class UpdateShareViaLinkOperation extends SyncOperation { mPath = path; mPassword = null; mExpirationDateInMillis = 0; + mPublicUpload = false; } @@ -81,6 +81,15 @@ public class UpdateShareViaLinkOperation extends SyncOperation { mExpirationDateInMillis = expirationDateInMillis; } + /** + * Enable upload permissions to update in Share resource. + * + * @param publicUpload Upload Permission to set to the public link. + */ + public void setPublicUpload(boolean publicUpload) { + mPublicUpload = publicUpload; + } + @Override protected RemoteOperationResult run(OwnCloudClient client) { @@ -104,6 +113,7 @@ public class UpdateShareViaLinkOperation extends SyncOperation { ); updateOp.setPassword(mPassword); updateOp.setExpirationDate(mExpirationDateInMillis); + updateOp.setPublicUpload(mPublicUpload); RemoteOperationResult result = updateOp.execute(client); if (result.isSuccess()) { diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 172a72867d..e0f2d9f178 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -95,6 +95,7 @@ public class OperationsService extends Service { public static final String EXTRA_SHARE_WITH = "SHARE_WITH"; public static final String EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS = "SHARE_EXPIRATION_YEAR"; public static final String EXTRA_SHARE_PERMISSIONS = "SHARE_PERMISSIONS"; + public static final String EXTRA_SHARE_PUBLIC_UPLOAD = "SHARE_PUBLIC_UPLOAD"; public static final String EXTRA_SHARE_ID = "SHARE_ID"; public static final String EXTRA_COOKIE = "COOKIE"; @@ -576,7 +577,7 @@ public class OperationsService extends Service { operation = new UpdateShareViaLinkOperation(remotePath); String password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD); - ((UpdateShareViaLinkOperation)operation).setPassword(password); + ((UpdateShareViaLinkOperation) operation).setPassword(password); long expirationDate = operationIntent.getLongExtra( EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, @@ -586,6 +587,9 @@ public class OperationsService extends Service { expirationDate ); + boolean publicUpload = operationIntent.getBooleanExtra(EXTRA_SHARE_PUBLIC_UPLOAD, false); + ((UpdateShareViaLinkOperation) operation).setPublicUpload(publicUpload); + } else if (shareId > 0) { operation = new UpdateSharePermissionsOperation(shareId); int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, 1); diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index ab8330f80b..6f9e0d2751 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -1,22 +1,22 @@ /** - * ownCloud Android client application - * - * @author masensio - * @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 . + * ownCloud Android client application * + * @author masensio + * @author David A. Velasco + * @author Juan Carlos González Cabrero + * 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.ui.fragment; @@ -55,57 +55,74 @@ import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.MimetypeIconUtil; import java.text.SimpleDateFormat; - import java.util.ArrayList; import java.util.Date; /** * Fragment for Sharing a file with sharees (users or groups) or creating * a public link. - * + *

* A simple {@link Fragment} subclass. - * + *

* Activities that contain this fragment must implement the * {@link ShareFragmentListener} interface * to handle interaction events. - * + *

* Use the {@link ShareFileFragment#newInstance} factory method to * create an instance of this fragment. */ public class ShareFileFragment extends Fragment - implements ShareUserListAdapter.ShareUserAdapterListener{ + implements ShareUserListAdapter.ShareUserAdapterListener { private static final String TAG = ShareFileFragment.class.getSimpleName(); - /** The fragment initialization parameters */ + /** + * The fragment initialization parameters + */ private static final String ARG_FILE = "FILE"; private static final String ARG_ACCOUNT = "ACCOUNT"; // /** Tag for dialog */ // private static final String FTAG_CHOOSER_DIALOG = "CHOOSER_DIALOG"; - /** File to share, received as a parameter in construction time */ + /** + * File to share, received as a parameter in construction time + */ private OCFile mFile; - /** OC account holding the file to share, received as a parameter in construction time */ + /** + * OC account holding the file to share, received as a parameter in construction time + */ private Account mAccount; - /** Reference to parent listener */ + /** + * Reference to parent listener + */ private ShareFragmentListener mListener; - /** List of private shares bound to the file */ + /** + * List of private shares bound to the file + */ private ArrayList mPrivateShares; - /** Capabilities of the server */ + /** + * Capabilities of the server + */ private OCCapability mCapabilities; - /** Adapter to show private shares */ + /** + * Adapter to show private shares + */ private ShareUserListAdapter mUserGroupsAdapter = null; - /** Public share bound to the file */ + /** + * Public share bound to the file + */ private OCShare mPublicShare; - /** Listener for changes on switch to share / unshare publicly */ + /** + * Listener for changes on switch to share / unshare publicly + */ private CompoundButton.OnCheckedChangeListener mOnShareViaLinkSwitchCheckedChangeListener; /** @@ -220,6 +237,9 @@ public class ShareFileFragment extends Fragment // Set listener for user actions on password initPasswordListener(view); + // Set listener for user actions on edit permission + initEditPermissionListener(view); + return view; } @@ -228,7 +248,7 @@ public class ShareFileFragment extends Fragment * Binds listener for user actions to create or delete a public share * to the views receiving the user events. * - * @param shareView Root view in the fragment. + * @param shareView Root view in the fragment. */ private void initShareViaLinkListener(View shareView) { mOnShareViaLinkSwitchCheckedChangeListener = new OnShareViaLinkListener(); @@ -245,8 +265,8 @@ public class ShareFileFragment extends Fragment /** * Called by R.id.shareViaLinkSectionSwitch to create or delete a public link. * - * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkSectionSwitch - * @param isChecked New switch state. + * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkSectionSwitch + * @param isChecked New switch state. */ @Override public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { @@ -289,7 +309,7 @@ public class ShareFileFragment extends Fragment * Binds listener for user actions that start any update on a expiration date * for the public link to the views receiving the user events. * - * @param shareView Root view in the fragment. + * @param shareView Root view in the fragment. */ private void initExpirationListener(View shareView) { mOnExpirationDateInteractionListener = new OnExpirationDateInteractionListener(); @@ -313,8 +333,8 @@ public class ShareFileFragment extends Fragment /** * Called by R.id.shareViaLinkExpirationSwitch to set or clear the expiration date. * - * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkExpirationSwitch - * @param isChecked New switch state. + * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkExpirationSwitch + * @param isChecked New switch state. */ @Override public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { @@ -346,7 +366,7 @@ public class ShareFileFragment extends Fragment * Called by R.id.shareViaLinkExpirationLabel or R.id.shareViaLinkExpirationValue * to change the current expiration date. * - * @param expirationView Label or value view touched by the user. + * @param expirationView Label or value view touched by the user. */ @Override public void onClick(View expirationView) { @@ -373,7 +393,7 @@ public class ShareFileFragment extends Fragment * Binds listener for user actions that start any update on a password for the public link * to the views receiving the user events. * - * @param shareView Root view in the fragment. + * @param shareView Root view in the fragment. */ private void initPasswordListener(View shareView) { mOnPasswordInteractionListener = new OnPasswordInteractionListener(); @@ -398,8 +418,8 @@ public class ShareFileFragment extends Fragment /** * Called by R.id.shareViaLinkPasswordSwitch to set or clear the password. * - * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkPasswordSwitch - * @param isChecked New switch state. + * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkPasswordSwitch + * @param isChecked New switch state. */ @Override public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { @@ -426,7 +446,7 @@ public class ShareFileFragment extends Fragment * Called by R.id.shareViaLinkPasswordLabel or R.id.shareViaLinkPasswordValue * to change the current password. * - * @param passwordView Label or value view touched by the user. + * @param passwordView Label or value view touched by the user. */ @Override public void onClick(View passwordView) { @@ -437,6 +457,20 @@ public class ShareFileFragment extends Fragment } } + /** + * Binds listener for user actions that start any update the edit permissions + * for the public link to the views receiving the user events. + * + * @param shareView Root view in the fragment. + */ + private void initEditPermissionListener(View shareView) { + mOnEditPermissionInteractionListener = new OnEditPermissionInteractionListener(); + + ((Switch) shareView.findViewById(R.id.shareViaLinkEditPermissionSwitch)). + setOnCheckedChangeListener(mOnEditPermissionInteractionListener); + + } + /** * Listener for user actions that start any update on the edit permissions for the public link. */ @@ -446,8 +480,8 @@ public class ShareFileFragment extends Fragment /** * Called by R.id.shareViaLinkEditPermissionSwitch to set or clear the edit permission. * - * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkEditPermissionSwitch - * @param isChecked New switch state. + * @param switchView {@link Switch} toggled by the user, R.id.shareViaLinkEditPermissionSwitch + * @param isChecked New switch state. */ @Override public void onCheckedChanged(CompoundButton switchView, boolean isChecked) { @@ -456,12 +490,20 @@ public class ShareFileFragment extends Fragment // Fragment recreation on device rotations return; } + boolean permission; if (isChecked) { - // Pending to implement + permission = true; } else { - // Pending to implement + permission = false; } + ((FileActivity) getActivity()).getFileOperationsHelper(). + setUploadPermissionsToShare( + mFile, + permission + ); + ; + // undo the toggle to grant the view will be correct if the dialog is cancelled switchView.setOnCheckedChangeListener(null); switchView.toggle(); @@ -508,13 +550,13 @@ public class ShareFileFragment extends Fragment /** * Get known server capabilities from DB - * + *

* Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager} * instance ready to use. If not ready, does nothing. */ public void refreshCapabilitiesFromDB() { - if (((FileActivity)mListener).getStorageManager() != null) { - mCapabilities = ((FileActivity)mListener).getStorageManager(). + if (((FileActivity) mListener).getStorageManager() != null) { + mCapabilities = ((FileActivity) mListener).getStorageManager(). getCapability(mAccount.name); } } @@ -522,11 +564,11 @@ public class ShareFileFragment extends Fragment /** * Get users and groups from the DB to fill in the "share with" list. - * + *

* Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager} * instance ready to use. If not ready, does nothing. */ - public void refreshUsersOrGroupsListFromDB (){ + public void refreshUsersOrGroupsListFromDB() { if (((FileActivity) mListener).getStorageManager() != null) { // Get Users and Groups mPrivateShares = ((FileActivity) mListener).getStorageManager().getSharesWithForAFile( @@ -585,9 +627,9 @@ public class ShareFileFragment extends Fragment /** * Get public link from the DB to fill in the "Share link" section in the UI. - * + *

* Takes into account server capabilities before reading database. - * + *

* Depends on the parent Activity provides a {@link com.owncloud.android.datamodel.FileDataStorageManager} * instance ready to use. If not ready, does nothing. */ @@ -609,7 +651,7 @@ public class ShareFileFragment extends Fragment } /** - * @return 'True' when public share is disabled in the server + * @return 'True' when public share is disabled in the server */ private boolean isPublicShareDisabled() { return (mCapabilities != null && @@ -635,7 +677,7 @@ public class ShareFileFragment extends Fragment } getExpirationDateSection().setVisibility(View.VISIBLE); getPasswordSection().setVisibility(View.VISIBLE); - if(mFile.isFolder()) { + if (mFile.isFolder()) { getEditPermissionSection().setVisibility(View.VISIBLE); } // GetLink button From 02eade8029af17d2220987c87a799c0abf908bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Gonz=C3=A1lez=20Cabrero?= Date: Mon, 14 Mar 2016 13:56:03 +0100 Subject: [PATCH 3/7] Hide edition of public share when the related capability is disable --- .../ui/fragment/ShareFileFragment.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index 6f9e0d2751..be3bbbf991 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -677,8 +677,10 @@ public class ShareFileFragment extends Fragment } getExpirationDateSection().setVisibility(View.VISIBLE); getPasswordSection().setVisibility(View.VISIBLE); - if (mFile.isFolder()) { + if (mFile.isFolder() && mCapabilities.getFilesSharingPublicUpload().isTrue()) { getEditPermissionSection().setVisibility(View.VISIBLE); + } else { + getEditPermissionSection().setVisibility(View.GONE); } // GetLink button AppCompatButton getLinkButton = getGetLinkButton(); @@ -740,21 +742,23 @@ public class ShareFileFragment extends Fragment /// update state of the edit permission switch Switch editPermissionSwitch = getEditPermissionSwitch(); - // set null listener before setChecked() to prevent infinite loop of calls - editPermissionSwitch.setOnCheckedChangeListener(null); - if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) { - if (!editPermissionSwitch.isChecked()) { - editPermissionSwitch.toggle(); - } - } else { - if (editPermissionSwitch.isChecked()) { - editPermissionSwitch.toggle(); + if(getEditPermissionSection().getVisibility() == View.VISIBLE) { + // set null listener before setChecked() to prevent infinite loop of calls + editPermissionSwitch.setOnCheckedChangeListener(null); + if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) { + if (!editPermissionSwitch.isChecked()) { + editPermissionSwitch.toggle(); + } + } else { + if (editPermissionSwitch.isChecked()) { + editPermissionSwitch.toggle(); + } } + // recover listener + editPermissionSwitch.setOnCheckedChangeListener( + mOnEditPermissionInteractionListener + ); } - // recover listener - editPermissionSwitch.setOnCheckedChangeListener( - mOnEditPermissionInteractionListener - ); } else { /// no public share -> collapse section From ceffd197a97fd74d144c2861530a8e37d0f242cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Gonz=C3=A1lez=20Cabrero?= Date: Mon, 14 Mar 2016 14:02:45 +0100 Subject: [PATCH 4/7] Refactor calls to find views in ShareFileFragment --- .../android/ui/fragment/ShareFileFragment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index be3bbbf991..9cf5597848 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -252,7 +252,7 @@ public class ShareFileFragment extends Fragment */ private void initShareViaLinkListener(View shareView) { mOnShareViaLinkSwitchCheckedChangeListener = new OnShareViaLinkListener(); - Switch shareViaLinkSwitch = (Switch) shareView.findViewById(R.id.shareViaLinkSectionSwitch); + Switch shareViaLinkSwitch = getShareViaLinkSwitch(); shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener); } @@ -314,13 +314,13 @@ public class ShareFileFragment extends Fragment private void initExpirationListener(View shareView) { mOnExpirationDateInteractionListener = new OnExpirationDateInteractionListener(); - ((Switch) shareView.findViewById(R.id.shareViaLinkExpirationSwitch)). + getExpirationDateSwitch(). setOnCheckedChangeListener(mOnExpirationDateInteractionListener); shareView.findViewById(R.id.shareViaLinkExpirationLabel). setOnClickListener(mOnExpirationDateInteractionListener); - shareView.findViewById(R.id.shareViaLinkExpirationValue). + getExpirationDateValue(). setOnClickListener(mOnExpirationDateInteractionListener); } @@ -398,13 +398,13 @@ public class ShareFileFragment extends Fragment private void initPasswordListener(View shareView) { mOnPasswordInteractionListener = new OnPasswordInteractionListener(); - ((Switch) shareView.findViewById(R.id.shareViaLinkPasswordSwitch)). + getPasswordSwitch(). setOnCheckedChangeListener(mOnPasswordInteractionListener); shareView.findViewById(R.id.shareViaLinkPasswordLabel). setOnClickListener(mOnPasswordInteractionListener); - shareView.findViewById(R.id.shareViaLinkPasswordValue). + getPasswordValue(). setOnClickListener(mOnPasswordInteractionListener); } @@ -466,7 +466,7 @@ public class ShareFileFragment extends Fragment private void initEditPermissionListener(View shareView) { mOnEditPermissionInteractionListener = new OnEditPermissionInteractionListener(); - ((Switch) shareView.findViewById(R.id.shareViaLinkEditPermissionSwitch)). + getEditPermissionSwitch(). setOnCheckedChangeListener(mOnEditPermissionInteractionListener); } @@ -742,7 +742,7 @@ public class ShareFileFragment extends Fragment /// update state of the edit permission switch Switch editPermissionSwitch = getEditPermissionSwitch(); - if(getEditPermissionSection().getVisibility() == View.VISIBLE) { + if (getEditPermissionSection().getVisibility() == View.VISIBLE) { // set null listener before setChecked() to prevent infinite loop of calls editPermissionSwitch.setOnCheckedChangeListener(null); if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) { From 3d8195795b0cbd0f5992ba86be77d13012a8d1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Gonz=C3=A1lez=20Cabrero?= Date: Mon, 14 Mar 2016 14:08:03 +0100 Subject: [PATCH 5/7] Revert "Refactor calls to find views in ShareFileFragment" This reverts commit 6143872543d30569e46fb4c5edc559f26cdd8bd6. --- .../android/ui/fragment/ShareFileFragment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index 9cf5597848..be3bbbf991 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -252,7 +252,7 @@ public class ShareFileFragment extends Fragment */ private void initShareViaLinkListener(View shareView) { mOnShareViaLinkSwitchCheckedChangeListener = new OnShareViaLinkListener(); - Switch shareViaLinkSwitch = getShareViaLinkSwitch(); + Switch shareViaLinkSwitch = (Switch) shareView.findViewById(R.id.shareViaLinkSectionSwitch); shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener); } @@ -314,13 +314,13 @@ public class ShareFileFragment extends Fragment private void initExpirationListener(View shareView) { mOnExpirationDateInteractionListener = new OnExpirationDateInteractionListener(); - getExpirationDateSwitch(). + ((Switch) shareView.findViewById(R.id.shareViaLinkExpirationSwitch)). setOnCheckedChangeListener(mOnExpirationDateInteractionListener); shareView.findViewById(R.id.shareViaLinkExpirationLabel). setOnClickListener(mOnExpirationDateInteractionListener); - getExpirationDateValue(). + shareView.findViewById(R.id.shareViaLinkExpirationValue). setOnClickListener(mOnExpirationDateInteractionListener); } @@ -398,13 +398,13 @@ public class ShareFileFragment extends Fragment private void initPasswordListener(View shareView) { mOnPasswordInteractionListener = new OnPasswordInteractionListener(); - getPasswordSwitch(). + ((Switch) shareView.findViewById(R.id.shareViaLinkPasswordSwitch)). setOnCheckedChangeListener(mOnPasswordInteractionListener); shareView.findViewById(R.id.shareViaLinkPasswordLabel). setOnClickListener(mOnPasswordInteractionListener); - getPasswordValue(). + shareView.findViewById(R.id.shareViaLinkPasswordValue). setOnClickListener(mOnPasswordInteractionListener); } @@ -466,7 +466,7 @@ public class ShareFileFragment extends Fragment private void initEditPermissionListener(View shareView) { mOnEditPermissionInteractionListener = new OnEditPermissionInteractionListener(); - getEditPermissionSwitch(). + ((Switch) shareView.findViewById(R.id.shareViaLinkEditPermissionSwitch)). setOnCheckedChangeListener(mOnEditPermissionInteractionListener); } @@ -742,7 +742,7 @@ public class ShareFileFragment extends Fragment /// update state of the edit permission switch Switch editPermissionSwitch = getEditPermissionSwitch(); - if (getEditPermissionSection().getVisibility() == View.VISIBLE) { + if(getEditPermissionSection().getVisibility() == View.VISIBLE) { // set null listener before setChecked() to prevent infinite loop of calls editPermissionSwitch.setOnCheckedChangeListener(null); if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) { From ac6d0038ec04afa019bbfe8370014f4afc9cede9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Gonz=C3=A1lez=20Cabrero?= Date: Tue, 15 Mar 2016 10:00:41 +0100 Subject: [PATCH 6/7] Enable change the permission when the capability is unknown too --- src/com/owncloud/android/ui/fragment/ShareFileFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index be3bbbf991..66328dc8d1 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -677,7 +677,7 @@ public class ShareFileFragment extends Fragment } getExpirationDateSection().setVisibility(View.VISIBLE); getPasswordSection().setVisibility(View.VISIBLE); - if (mFile.isFolder() && mCapabilities.getFilesSharingPublicUpload().isTrue()) { + if (mFile.isFolder() && !mCapabilities.getFilesSharingPublicUpload().isFalse()) { getEditPermissionSection().setVisibility(View.VISIBLE); } else { getEditPermissionSection().setVisibility(View.GONE); From 94864bb09413f6868875b325f19a7ccff16687a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Gonz=C3=A1lez=20Cabrero?= Date: Mon, 21 Mar 2016 09:45:27 +0100 Subject: [PATCH 7/7] Update strings, comments and removed some conditions --- res/values/strings.xml | 2 +- .../android/files/FileOperationsHelper.java | 10 ++--- .../ui/fragment/ShareFileFragment.java | 37 ++++++++----------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 9c5300eb7a..b4bddb7281 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -382,7 +382,7 @@ Set expiration date Password protect Secured - Allow edit + Allow editing Get link Search diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 58ff16c54e..402706743c 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -411,17 +411,17 @@ public class FileOperationsHelper { } /** - * Updates a public share on a file to set its edit permissions. + * Updates a public share on a folder to set its editing permission. * Starts a request to do it in {@link OperationsService} * - * @param file File which public share will be constrained with an expiration date. - * @param uploadPermission New state of the permissions of edit a folder shared via link. + * @param folder Folder which editing permission of his public share will be modified. + * @param uploadPermission New state of the permission for editing the folder shared via link. */ - public void setUploadPermissionsToShare(OCFile file, boolean uploadPermission) { + public void setUploadPermissionsToShare(OCFile folder, boolean uploadPermission) { 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_REMOTE_PATH, folder.getRemotePath()); updateShareIntent.putExtra( OperationsService.EXTRA_SHARE_PUBLIC_UPLOAD, uploadPermission diff --git a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java index 66328dc8d1..a42731e9c7 100644 --- a/src/com/owncloud/android/ui/fragment/ShareFileFragment.java +++ b/src/com/owncloud/android/ui/fragment/ShareFileFragment.java @@ -490,17 +490,11 @@ public class ShareFileFragment extends Fragment // Fragment recreation on device rotations return; } - boolean permission; - if (isChecked) { - permission = true; - } else { - permission = false; - } ((FileActivity) getActivity()).getFileOperationsHelper(). setUploadPermissionsToShare( mFile, - permission + isChecked ); ; @@ -742,23 +736,22 @@ public class ShareFileFragment extends Fragment /// update state of the edit permission switch Switch editPermissionSwitch = getEditPermissionSwitch(); - if(getEditPermissionSection().getVisibility() == View.VISIBLE) { - // set null listener before setChecked() to prevent infinite loop of calls - editPermissionSwitch.setOnCheckedChangeListener(null); - if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) { - if (!editPermissionSwitch.isChecked()) { - editPermissionSwitch.toggle(); - } - } else { - if (editPermissionSwitch.isChecked()) { - editPermissionSwitch.toggle(); - } + + // set null listener before setChecked() to prevent infinite loop of calls + editPermissionSwitch.setOnCheckedChangeListener(null); + if (mPublicShare.getPermissions() > OCShare.READ_PERMISSION_FLAG) { + if (!editPermissionSwitch.isChecked()) { + editPermissionSwitch.toggle(); + } + } else { + if (editPermissionSwitch.isChecked()) { + editPermissionSwitch.toggle(); } - // recover listener - editPermissionSwitch.setOnCheckedChangeListener( - mOnEditPermissionInteractionListener - ); } + // recover listener + editPermissionSwitch.setOnCheckedChangeListener( + mOnEditPermissionInteractionListener + ); } else { /// no public share -> collapse section