Skip to content

Commit 0d6331a

Browse files
Merge pull request #16899 from nextcloud/backport/16898/stable-33.1.0
[stable-33.1.0] refactor
2 parents 96b7c8a + 243d414 commit 0d6331a

2 files changed

Lines changed: 30 additions & 17 deletions

File tree

app/src/main/java/com/owncloud/android/ui/fragment/FileDetailsSharingProcessFragment.kt

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class FileDetailsSharingProcessFragment :
139139

140140
private var expirationDatePickerFragment: ExpirationDatePickerDialogFragment? = null
141141
private var downloadAttribute: String? = null
142+
private var passwordModified = false
142143

143144
override fun onAttach(context: Context) {
144145
super.onAttach(context)
@@ -362,17 +363,20 @@ class FileDetailsSharingProcessFragment :
362363
maskPasswordInput()
363364
}
364365

366+
/**
367+
* When a share already has a password, mask the field with placeholder dots.
368+
* The first time the user focuses the field, its contents are cleared and
369+
* [passwordModified] is set so we know to send the new value to the server.
370+
*/
365371
private fun maskPasswordInput() {
366-
if (share?.isPasswordProtected == false) {
367-
return
368-
}
372+
if (share?.isPasswordProtected == false) return
369373

370-
binding.shareProcessEnterPassword.run {
371-
setText("••••••")
372-
setOnFocusChangeListener { _, hasFocus ->
373-
if (hasFocus) {
374-
text?.clear()
375-
}
374+
binding.shareProcessEnterPasswordContainer.hint = "••••••"
375+
binding.shareProcessEnterPasswordContainer.placeholderText = "••••••"
376+
binding.shareProcessEnterPassword.setOnFocusChangeListener { _, hasFocus ->
377+
if (hasFocus && !passwordModified) {
378+
binding.shareProcessEnterPassword.text?.clear()
379+
passwordModified = true
376380
}
377381
}
378382
}
@@ -756,11 +760,15 @@ class FileDetailsSharingProcessFragment :
756760
return
757761
}
758762

759-
if (binding.shareProcessSetPasswordSwitch.isChecked &&
760-
binding.shareProcessEnterPassword.text?.isBlank() == true
761-
) {
762-
DisplayUtils.showSnackMessage(this, R.string.share_link_empty_password)
763-
return
763+
if (binding.shareProcessSetPasswordSwitch.isChecked) {
764+
val enteredPassword = binding.shareProcessEnterPassword.text?.toString()?.trim().orEmpty()
765+
val hasExistingPassword = (share?.isPasswordProtected == true)
766+
val needsPasswordEntry = (!hasExistingPassword || passwordModified)
767+
768+
if (needsPasswordEntry && enteredPassword.isBlank()) {
769+
DisplayUtils.showSnackMessage(this, R.string.share_link_empty_password)
770+
return
771+
}
764772
}
765773

766774
if (binding.shareProcessSetExpDateSwitch.isChecked &&
@@ -825,11 +833,17 @@ class FileDetailsSharingProcessFragment :
825833
share?.attributes = null
826834
}
827835

836+
val password = when {
837+
!binding.shareProcessSetPasswordSwitch.isChecked -> ""
838+
share?.isPasswordProtected == true && !passwordModified -> null
839+
else -> binding.shareProcessEnterPassword.text.toString().trim()
840+
}
841+
828842
fileOperationsHelper?.updateShareInformation(
829843
share,
830844
permission,
831845
binding.shareProcessHideDownloadCheckbox.isChecked,
832-
binding.shareProcessEnterPassword.text.toString().trim(),
846+
password,
833847
chosenExpDateInMills,
834848
binding.shareProcessChangeName.text.toString().trim()
835849
)

app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,15 +770,14 @@ public void updateShareInformation(OCShare share,
770770
Log_OC.i(TAG, "Label: " + label);
771771
Log_OC.i(TAG, "Attributes: " + attributes);
772772

773-
774773
Intent updateShareIntent = new Intent(fileActivity, OperationsService.class);
775774
updateShareIntent.setAction(OperationsService.ACTION_UPDATE_SHARE_INFO);
776775
updateShareIntent.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount());
777776
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_ID, id);
778777
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_REMOTE_ID, share.getRemoteId());
779778
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS, permissions);
780779
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_HIDE_FILE_DOWNLOAD, hideFileDownload);
781-
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PASSWORD, (password == null) ? "" : password);
780+
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PASSWORD, password);
782781
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_EXPIRATION_DATE_IN_MILLIS, expirationTimeInMillis);
783782
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PUBLIC_LABEL, (label == null) ? "" : label);
784783
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_ATTRIBUTES, attributes);

0 commit comments

Comments
 (0)