From: David A. Velasco Date: Mon, 16 Nov 2015 14:13:45 +0000 (+0100) Subject: Hide UI elements about public share when this is disabled in the server X-Git-Tag: oc-android-1.9^2~10^2~5 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/f5369ac4b2437f27af0240f64762cd77f0a61f41 Hide UI elements about public share when this is disabled in the server --- diff --git a/res/layout/share_file_layout.xml b/res/layout/share_file_layout.xml index 23581e77..27a6133d 100644 --- a/res/layout/share_file_layout.xml +++ b/res/layout/share_file_layout.xml @@ -228,7 +228,7 @@ mPrivateShares; + /** Capabilities of the server */ + private OCCapability mCapabilities; + /** Adapter to show private shares */ private ShareUserListAdapter mUserGroupsAdapter = null; @@ -117,6 +118,7 @@ public class ShareFileFragment extends Fragment */ private OnExpirationDateInteractionListener mOnExpirationDateInteractionListener = null; + /** * Public factory method to create new ShareFileFragment instances. * @@ -230,7 +232,6 @@ public class ShareFileFragment extends Fragment return view; } - /** * Binds listener for user actions that start any update on a expiration date * for the public link to the views receiving the user events. @@ -388,6 +389,9 @@ public class ShareFileFragment extends Fragment public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + // Load known capabilities of the server from DB + refreshCapabilitiesFromDB(); + // Load data into the list of private shares refreshUsersOrGroupsListFromDB(); @@ -412,6 +416,21 @@ public class ShareFileFragment extends Fragment mListener = null; } + + /** + * 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(). + getCapability(mAccount.name); + } + } + + /** * Get users and groups from the DB to fill in the "share with" list. * @@ -472,11 +491,16 @@ 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. */ public void refreshPublicShareFromDB() { - if (((FileActivity) mListener).getStorageManager() != null) { + if (isPublicShareDisabled()) { + hidePublicShare(); + + } else if (((FileActivity) mListener).getStorageManager() != null) { // Get public share mPublicShare = ((FileActivity) mListener).getStorageManager().getFirstShareByPathAndType( mFile.getRemotePath(), @@ -490,6 +514,15 @@ public class ShareFileFragment extends Fragment } /** + * @return 'True' when public share is disabled in the server + */ + private boolean isPublicShareDisabled() { + return (mCapabilities != null && + mCapabilities.getFilesSharingPublicEnabled().isFalse() + ); + } + + /** * Updates in the UI the section about public share with the information in the current * public share bound to mFile, if any */ @@ -521,7 +554,6 @@ public class ShareFileFragment extends Fragment }); /// update state of expiration date switch and message depending on expiration date - /// update state of expiration date switch and message depending on expiration date Switch expirationDateSwitch = getExpirationDateSwitch(); // set null listener before setChecked() to prevent infinite loop of calls expirationDateSwitch.setOnCheckedChangeListener(null); @@ -615,7 +647,17 @@ public class ShareFileFragment extends Fragment } private AppCompatButton getGetLinkButton() { - return (AppCompatButton) getView().findViewById(R.id.shareViewLinkGetLinkButton); + return (AppCompatButton) getView().findViewById(R.id.shareViaLinkGetLinkButton); + } + + /** + * Hides all the UI elements related to public share + */ + private void hidePublicShare() { + getShareViaLinkSwitch().setVisibility(View.GONE); + getExpirationDateSection().setVisibility(View.GONE); + getPasswordSection().setVisibility(View.GONE); + getGetLinkButton().setVisibility(View.GONE); } public static void setListViewHeightBasedOnChildren(ListView listView) { @@ -639,7 +681,7 @@ public class ShareFileFragment extends Fragment listView.setLayoutParams(params); listView.requestLayout(); } - + /** * This interface must be implemented by activities that contain this * fragment to allow an interaction in this fragment to be communicated