Merge pull request #8188 from nextcloud/passwordDialog

Password dialog
This commit is contained in:
Andy Scherzinger 2021-03-19 10:39:18 +01:00 committed by GitHub
commit 3249ab3c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 17 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -136,6 +136,26 @@ public class DialogFragmentIT extends AbstractIT {
showDialog(sut);
}
@Test
@ScreenshotTest
public void testEnforcedPasswordDialog() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
SharePasswordDialogFragment sut = SharePasswordDialogFragment.newInstance(new OCFile("/"), true, false);
showDialog(sut);
}
@Test
@ScreenshotTest
public void testOptionalPasswordDialog() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
SharePasswordDialogFragment sut = SharePasswordDialogFragment.newInstance(new OCFile("/"), true, true);
showDialog(sut);
}
@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {

View File

@ -175,7 +175,7 @@ public class SendShareDialog extends BottomSheetDialogFragment {
private void shareByLink() {
if (file.isSharedViaLink()) {
((FileActivity) getActivity()).getFileOperationsHelper().getFileWithLink(file);
} else if (sharingPublicPasswordEnforced) {
} else if (sharingPublicPasswordEnforced || sharingPublicAskForPassword) {
// password enforced by server, request to the user before trying to create
requestPasswordForShareViaLink();
} else {

View File

@ -72,6 +72,23 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE));
ThemeButtonUtils.themeBorderlessButton(getResources().getColor(R.color.highlight_textColor_Warning),
alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL));
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
String password = binding.sharePassword.getText().toString();
if (!askForPassword && TextUtils.isEmpty(password)) {
DisplayUtils.showSnackMessage(binding.getRoot(), R.string.share_link_empty_password);
return;
}
if (share == null) {
setPassword(createShare, file, password);
} else {
setPassword(share, password);
}
alertDialog.dismiss();
});
}
}
@ -143,19 +160,22 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
ThemeColorUtils.primaryColor(getActivity()));
binding.sharePassword.requestFocus();
int negativeButtonCaption;
int title;
if (askForPassword) {
title = R.string.share_link_optional_password_title;
negativeButtonCaption = R.string.common_skip;
} else {
title = R.string.share_link_password_title;
negativeButtonCaption = R.string.common_cancel;
}
// Build the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(view)
.setPositiveButton(R.string.common_ok, this)
.setNegativeButton(R.string.common_cancel, this)
.setPositiveButton(R.string.common_ok, null)
.setNegativeButton(negativeButtonCaption, this)
.setNeutralButton(R.string.common_delete, this)
.setTitle(title);
Dialog d = builder.create();
@ -170,20 +190,7 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE) {
String password = binding.sharePassword.getText().toString();
if (!askForPassword && TextUtils.isEmpty(password)) {
DisplayUtils.showSnackMessage(binding.getRoot(), R.string.share_link_empty_password);
return;
}
if (share == null) {
setPassword(createShare, file, password);
} else {
setPassword(share, password);
}
} else if (which == AlertDialog.BUTTON_NEUTRAL) {
if (which == AlertDialog.BUTTON_NEUTRAL) {
if (share == null) {
setPassword(createShare, file, null);
} else {

View File

@ -126,6 +126,7 @@
<string name="common_delete">Delete</string>
<string name="common_send">Send</string>
<string name="common_share">Share</string>
<string name="common_skip">Skip</string>
<string name="about_title">About</string>
<string name="delete_account">Remove account</string>
<string name="delete_account_warning">Remove account %s and delete all local files?\n\nDeletion cannot be undone.</string>