Replace button click functions

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-10-16 13:31:41 +02:00
parent 0a11d4519f
commit e4d9c91674
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF

View file

@ -21,7 +21,6 @@
package com.owncloud.android.ui.dialog; package com.owncloud.android.ui.dialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
@ -53,7 +52,7 @@ import androidx.fragment.app.DialogFragment;
* <p> * <p>
* Triggers the share when the password is introduced. * Triggers the share when the password is introduced.
*/ */
public class SharePasswordDialogFragment extends DialogFragment implements DialogInterface.OnClickListener, Injectable { public class SharePasswordDialogFragment extends DialogFragment implements Injectable {
private static final String ARG_FILE = "FILE"; private static final String ARG_FILE = "FILE";
private static final String ARG_SHARE = "SHARE"; private static final String ARG_SHARE = "SHARE";
@ -190,14 +189,14 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
binding.sharePassword.setText(""); binding.sharePassword.setText("");
viewThemeUtils.material.colorTextInputLayout(binding.sharePasswordContainer); viewThemeUtils.material.colorTextInputLayout(binding.sharePasswordContainer);
int negativeButtonCaption; int neutralButtonTextId;
int title; int title;
if (askForPassword) { if (askForPassword) {
title = R.string.share_link_optional_password_title; title = R.string.share_link_optional_password_title;
negativeButtonCaption = R.string.common_skip; neutralButtonTextId = R.string.common_skip;
} else { } else {
title = R.string.share_link_password_title; title = R.string.share_link_password_title;
negativeButtonCaption = R.string.common_cancel; neutralButtonTextId = R.string.common_cancel;
} }
// Build the dialog // Build the dialog
@ -205,8 +204,12 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
builder.setView(view) builder.setView(view)
.setPositiveButton(R.string.common_ok, null) .setPositiveButton(R.string.common_ok, null)
.setNegativeButton(negativeButtonCaption, this) .setNegativeButton(R.string.common_delete, (dialog, which) -> callSetPassword())
.setNeutralButton(R.string.common_delete, this) .setNeutralButton(neutralButtonTextId, (dialog, which) -> {
if (askForPassword) {
callSetPassword();
}
})
.setTitle(title); .setTitle(title);
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(view.getContext(), builder); viewThemeUtils.dialog.colorMaterialAlertDialogBackground(view.getContext(), builder);
@ -214,20 +217,11 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
return builder.create(); return builder.create();
} }
@Override private void callSetPassword() {
public void onClick(DialogInterface dialog, int which) { if (share == null) {
if (which == AlertDialog.BUTTON_NEUTRAL) { setPassword(createShare, file, null);
if (share == null) { } else {
setPassword(createShare, file, null); setPassword(share, null);
} else {
setPassword(share, null);
}
} else if (which == AlertDialog.BUTTON_NEGATIVE && askForPassword) {
if (share == null) {
setPassword(createShare, file, null);
} else {
setPassword(share, null);
}
} }
} }