FileDetailsSharingProcessFragment: clean up last detekt issues

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey 2022-05-31 12:54:52 +02:00 committed by Álvaro Brey (Rebase PR Action)
parent 29bf03a4e4
commit 43215a0833

View file

@ -181,8 +181,22 @@ class FileDetailsSharingProcessFragment : Fragment(), ExpirationDatePickerDialog
binding.shareProcessEditShareLink.visibility = View.VISIBLE
binding.shareProcessGroupTwo.visibility = View.GONE
// set up UI for modifying share
if (share != null) {
setupModificationUI()
} else {
setupUpdateUI()
}
// show or hide expiry date
if (isExpDateShown) {
binding.shareProcessSetExpDateSwitch.visibility = View.VISIBLE
} else {
binding.shareProcessSetExpDateSwitch.visibility = View.GONE
}
shareProcessStep = SCREEN_TYPE_PERMISSION
}
private fun setupModificationUI() {
if (share?.isFolder == true) {
updateViewForFolder()
} else {
@ -213,8 +227,7 @@ class FileDetailsSharingProcessFragment : Fragment(), ExpirationDatePickerDialog
showExpirationDateInput(binding.shareProcessSetExpDateSwitch.isChecked)
}
// update UI for creating new share
else {
private fun setupUpdateUI() {
binding.shareProcessBtnNext.text = requireContext().resources.getString(R.string.common_next)
file.let {
if (file?.isFolder == true) {
@ -228,15 +241,6 @@ class FileDetailsSharingProcessFragment : Fragment(), ExpirationDatePickerDialog
showExpirationDateInput(binding.shareProcessSetExpDateSwitch.isChecked)
}
// show or hide expiry date
if (isExpDateShown) {
binding.shareProcessSetExpDateSwitch.visibility = View.VISIBLE
} else {
binding.shareProcessSetExpDateSwitch.visibility = View.GONE
}
shareProcessStep = SCREEN_TYPE_PERMISSION
}
/**
* method to update views on the basis of Share type
*/
@ -434,54 +438,28 @@ class FileDetailsSharingProcessFragment : Fragment(), ExpirationDatePickerDialog
*/
@Suppress("ReturnCount")
private fun validateShareProcessFirst() {
// get the permissions on the basis of selection
when {
binding.shareProcessPermissionReadOnly.isChecked -> {
permission = OCShare.READ_PERMISSION_FLAG
}
binding.shareProcessPermissionUploadEditing.isChecked -> {
permission = if (file?.isFolder == true || share?.isFolder == true) {
OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
} else {
OCShare.MAXIMUM_PERMISSIONS_FOR_FILE
}
}
binding.shareProcessPermissionFileDrop.isChecked -> {
permission = OCShare.CREATE_PERMISSION_FLAG
}
}
if (binding.shareProcessAllowResharingCheckbox.isChecked) {
permission = getResharePermission()
}
permission = getSelectedPermission()
if (permission == OCShare.NO_PERMISSION) {
DisplayUtils.showSnackMessage(binding.root, R.string.no_share_permission_selected)
return
}
if (binding.shareProcessSetPasswordSwitch.isChecked && TextUtils.isEmpty(
binding.shareProcessEnterPassword
.text.toString().trim()
)
if (binding.shareProcessSetPasswordSwitch.isChecked &&
binding.shareProcessEnterPassword.text?.trim().isNullOrEmpty()
) {
DisplayUtils.showSnackMessage(binding.root, R.string.share_link_empty_password)
return
}
if (binding.shareProcessSetExpDateSwitch.isChecked && TextUtils.isEmpty(
binding.shareProcessSelectExpDate
.text.toString().trim()
)
if (binding.shareProcessSetExpDateSwitch.isChecked &&
binding.shareProcessSelectExpDate.text?.trim().isNullOrEmpty()
) {
showExpirationDateDialog()
return
}
if (binding.shareProcessChangeNameSwitch.isChecked && TextUtils.isEmpty(
binding.shareProcessChangeNameEt
.text.toString().trim()
)
if (binding.shareProcessChangeNameSwitch.isChecked &&
binding.shareProcessChangeNameEt.text?.trim().isNullOrEmpty()
) {
DisplayUtils.showSnackMessage(binding.root, R.string.label_empty)
return
@ -489,6 +467,29 @@ class FileDetailsSharingProcessFragment : Fragment(), ExpirationDatePickerDialog
// if modifying existing share information then execute the process
if (share != null) {
updateShare()
removeCurrentFragment()
} else {
// else show step 2 (note screen)
showShareProcessSecond()
}
}
/**
* get the permissions on the basis of selection
*/
private fun getSelectedPermission() = when {
binding.shareProcessAllowResharingCheckbox.isChecked -> getResharePermission()
binding.shareProcessPermissionReadOnly.isChecked -> OCShare.READ_PERMISSION_FLAG
binding.shareProcessPermissionUploadEditing.isChecked -> when {
file?.isFolder == true || share?.isFolder == true -> OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
else -> OCShare.MAXIMUM_PERMISSIONS_FOR_FILE
}
binding.shareProcessPermissionFileDrop.isChecked -> OCShare.CREATE_PERMISSION_FLAG
else -> permission
}
private fun updateShare() {
fileOperationsHelper?.updateShareInformation(
share, permission,
binding.shareProcessHideDownloadCheckbox.isChecked,
@ -499,11 +500,6 @@ class FileDetailsSharingProcessFragment : Fragment(), ExpirationDatePickerDialog
if (!TextUtils.isEmpty(share?.shareLink)) {
ClipboardUtil.copyToClipboard(activity, share?.shareLink)
}
removeCurrentFragment()
} else {
// else show step 2 (note screen)
showShareProcessSecond()
}
}
/**