@@ -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 )
0 commit comments