diff --git a/owncloudApp/src/androidTest/java/com/owncloud/android/shares/domain/publicShares/EditPublicShareTest.kt b/owncloudApp/src/androidTest/java/com/owncloud/android/shares/domain/publicShares/EditPublicShareTest.kt index cce86558add..b17523abca8 100644 --- a/owncloudApp/src/androidTest/java/com/owncloud/android/shares/domain/publicShares/EditPublicShareTest.kt +++ b/owncloudApp/src/androidTest/java/com/owncloud/android/shares/domain/publicShares/EditPublicShareTest.kt @@ -325,7 +325,7 @@ class EditPublicShareTest { calendar.add(Calendar.DAY_OF_YEAR, 1) val formatter: DateFormat = SimpleDateFormat("MMM dd, yyyy"); val expirationDate = formatter.format(calendar.time); - val publicLinkExpirationDateInMillis = SimpleDateFormat.getDateInstance().parse(expirationDate).time + val publicLinkExpirationDateInMillis = formatter.parse(expirationDate).time // 1. Open dialog to edit an existing public share onView(withId(R.id.editPublicLinkButton)).perform(click()) diff --git a/owncloudApp/src/androidTest/java/com/owncloud/android/shares/presentation/ui/ShareFileFragmentTest.kt b/owncloudApp/src/androidTest/java/com/owncloud/android/shares/presentation/ui/ShareFileFragmentTest.kt index cc99d46b6b7..651a681524c 100644 --- a/owncloudApp/src/androidTest/java/com/owncloud/android/shares/presentation/ui/ShareFileFragmentTest.kt +++ b/owncloudApp/src/androidTest/java/com/owncloud/android/shares/presentation/ui/ShareFileFragmentTest.kt @@ -256,6 +256,18 @@ class ShareFileFragmentTest { *********************************************** COMMON *********************************************** ******************************************************************************************************/ + @Test + fun hideSharesSharingApiDisabled() { + loadShareFileFragment( + capabilities = TestUtil.createCapability(sharingApiEnabled = CapabilityBooleanType.FALSE.value) + ) + onView(withId(R.id.shareWithUsersSection)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))) + + onView(withId(R.id.shareViaLinkSection)) + .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))) + } + private fun getOCFileForTesting(name: String = "default") = OCFile("/Photos").apply { availableOfflineStatus = OCFile.AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE fileName = name diff --git a/owncloudApp/src/main/java/com/owncloud/android/files/FileMenuFilter.java b/owncloudApp/src/main/java/com/owncloud/android/files/FileMenuFilter.java index 43644718510..6e3616bdba2 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/files/FileMenuFilter.java +++ b/owncloudApp/src/main/java/com/owncloud/android/files/FileMenuFilter.java @@ -43,7 +43,7 @@ /** * Filters out the file actions available in a given {@link Menu} for a given {@link OCFile} - * according to the current state of the latest. + * according to the current state of the latest. */ public class FileMenuFilter { @@ -58,10 +58,10 @@ public class FileMenuFilter { /** * Constructor * - * @param targetFiles List of {@link OCFile} file targets of the action to filter in the {@link Menu}. - * @param account ownCloud {@link Account} holding targetFile. - * @param cg Accessor to app components, needed to access synchronization services - * @param context Android {@link Context}, needed to access build setup resources. + * @param targetFiles List of {@link OCFile} file targets of the action to filter in the {@link Menu}. + * @param account ownCloud {@link Account} holding targetFile. + * @param cg Accessor to app components, needed to access synchronization services + * @param context Android {@link Context}, needed to access build setup resources. */ public FileMenuFilter(List targetFiles, Account account, ComponentsGetter cg, Context context) { @@ -74,10 +74,10 @@ public FileMenuFilter(List targetFiles, Account account, ComponentsGette /** * Constructor * - * @param targetFile {@link OCFile} target of the action to filter in the {@link Menu}. - * @param account ownCloud {@link Account} holding targetFile. - * @param cg Accessor to app components, needed to access synchronization services - * @param context Android {@link Context}, needed to access build setup resources. + * @param targetFile {@link OCFile} target of the action to filter in the {@link Menu}. + * @param account ownCloud {@link Account} holding targetFile. + * @param cg Accessor to app components, needed to access synchronization services + * @param context Android {@link Context}, needed to access build setup resources. */ public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg, Context context) { @@ -88,7 +88,7 @@ public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg, * Filters out the file actions available in the passed {@link Menu} taken into account * the state of the {@link OCFile} held by the filter. * - * @param menu Options or context menu to filter. + * @param menu Options or context menu to filter. */ public void filter(Menu menu, boolean displaySelectAll, boolean displaySelectInverse, boolean onlyAvailableOffline) { @@ -131,14 +131,14 @@ private void hideAll(Menu menu) { /** * Performs the real filtering, to be applied in the {@link Menu} by the caller methods. - * + *

* Decides what actions must be shown and hidden. * - * @param toShow List to save the options that must be shown in the menu. - * @param toHide List to save the options that must be shown in the menu. + * @param toShow List to save the options that must be shown in the menu. + * @param toHide List to save the options that must be shown in the menu. */ - private void filter(List toShow, List toHide, boolean displaySelectAll, + private void filter(List toShow, List toHide, boolean displaySelectAll, boolean displaySelectInverse, boolean onlyAvailableOffline) { boolean synchronizing = anyFileSynchronizing(); @@ -226,16 +226,12 @@ private void filter(List toShow, List toHide, boolean display mContext.getResources().getBoolean(R.bool.share_with_users_feature)); RemoteCapability capability = mComponentsGetter.getStorageManager().getCapability(mAccount.name); - boolean shareApiEnabled = capability != null && - (capability.getFilesSharingApiEnabled().isTrue() || - capability.getFilesSharingApiEnabled().isUnknown() - ); boolean notAllowResharing = anyFileSharedWithMe() && capability != null && capability.getFilesSharingResharing().isFalse(); if ((!shareViaLinkAllowed && !shareWithUsersAllowed) || !isSingleSelection() || - !shareApiEnabled || notAllowResharing || onlyAvailableOffline) { + notAllowResharing || onlyAvailableOffline) { toHide.add(R.id.action_share_file); } else { toShow.add(R.id.action_share_file); diff --git a/owncloudApp/src/main/java/com/owncloud/android/shares/presentation/fragment/ShareFileFragment.kt b/owncloudApp/src/main/java/com/owncloud/android/shares/presentation/fragment/ShareFileFragment.kt index 8d461f57543..5b9dcade9ee 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/shares/presentation/fragment/ShareFileFragment.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/shares/presentation/fragment/ShareFileFragment.kt @@ -32,6 +32,7 @@ import android.view.ViewGroup import android.widget.ListView import android.widget.Toast import androidx.core.view.isGone +import androidx.core.view.isVisible import androidx.fragment.app.Fragment import com.google.android.material.snackbar.Snackbar import com.owncloud.android.R @@ -43,9 +44,9 @@ import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.shares.ShareType import com.owncloud.android.lib.resources.status.CapabilityBooleanType import com.owncloud.android.lib.resources.status.OwnCloudVersion -import com.owncloud.android.shares.presentation.ShareUserListAdapter import com.owncloud.android.shares.domain.OCShare import com.owncloud.android.shares.presentation.SharePublicLinkListAdapter +import com.owncloud.android.shares.presentation.ShareUserListAdapter import com.owncloud.android.utils.DisplayUtils import com.owncloud.android.utils.MimetypeIconUtil import kotlinx.android.synthetic.main.share_file_layout.* @@ -176,11 +177,16 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe ) } + private val isShareApiEnabled: Boolean + get() = capabilities?.filesSharingApiEnabled == CapabilityBooleanType.TRUE.value || + capabilities?.filesSharingApiEnabled == CapabilityBooleanType.UNKNOWN.value + /** * @return 'True' when public share is disabled in the server */ - private val isPublicShareDisabled: Boolean - get() = capabilities != null && capabilities?.filesSharingPublicEnabled == CapabilityBooleanType.FALSE.value + private val isPublicShareEnabled: Boolean + get() = capabilities?.filesSharingPublicEnabled == CapabilityBooleanType.TRUE.value || + capabilities?.filesSharingPublicEnabled == CapabilityBooleanType.UNKNOWN.value /** * {@inheritDoc} @@ -322,13 +328,9 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe updatePublicLinkButton() // Update view depending on updated capabilities - if (isPublicShareDisabled) { - shareViaLinkSection.visibility = View.GONE - } else { - shareViaLinkSection.visibility = View.VISIBLE - } - - shareViaLinkSection.isGone = isPublicShareDisabled + shareHeaderDivider.isVisible = isShareApiEnabled + shareWithUsersSection.isVisible = isShareApiEnabled + shareViaLinkSection.isVisible = isShareApiEnabled && isPublicShareEnabled } /************************************************************************************************************** diff --git a/owncloudApp/src/main/res/layout/edit_share_layout.xml b/owncloudApp/src/main/res/layout/edit_share_layout.xml index afd4cb8d988..5c0a3179862 100644 --- a/owncloudApp/src/main/res/layout/edit_share_layout.xml +++ b/owncloudApp/src/main/res/layout/edit_share_layout.xml @@ -45,7 +45,7 @@ diff --git a/owncloudApp/src/test-common/java/com/owncloud/android/utils/TestUtil.kt b/owncloudApp/src/test-common/java/com/owncloud/android/utils/TestUtil.kt index 375e04d6320..294a769df40 100644 --- a/owncloudApp/src/test-common/java/com/owncloud/android/utils/TestUtil.kt +++ b/owncloudApp/src/test-common/java/com/owncloud/android/utils/TestUtil.kt @@ -189,7 +189,7 @@ object TestUtil { versionString: String = "1.0.0", versionEdition: String = "1.0.0", corePollinterval: Int = 0, - sharingApiEnabled: Int = 0, + sharingApiEnabled: Int = 1, sharingPublicEnabled: Int = 1, sharingPublicPasswordEnforced: Int = 0, sharingPublicPasswordEnforcedReadOnly: Int = 0,