Эх сурвалжийг харах

Password dialog:
- enforced password: prevent dismiss if empty password
- optional password: rename cancel button to skip

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

tobiasKaminsky 4 жил өмнө
parent
commit
42a0dff86a

+ 1 - 1
src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java

@@ -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 {

+ 23 - 16
src/main/java/com/owncloud/android/ui/dialog/SharePasswordDialogFragment.java

@@ -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 {

+ 1 - 0
src/main/res/values/strings.xml

@@ -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>