diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
index 0c6c63e73..a0530fb95 100644
--- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
+++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java
@@ -256,7 +256,8 @@ public class OnlineFeedViewActivity extends AppCompatActivity {
} else if (status.getReason() == DownloadError.ERROR_UNAUTHORIZED) {
if (!isFinishing() && !isPaused) {
dialog = new FeedViewAuthenticationDialog(OnlineFeedViewActivity.this,
- R.string.authentication_notification_title, downloader.getDownloadRequest().getSource());
+ R.string.authentication_notification_title,
+ downloader.getDownloadRequest().getSource()).create();
dialog.show();
}
} else {
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java
index 2c41b8cb8..073f7b550 100644
--- a/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java
+++ b/app/src/main/java/de/danoeh/antennapod/dialog/AuthenticationDialog.java
@@ -1,51 +1,29 @@
package de.danoeh.antennapod.dialog;
-import android.app.Dialog;
+import android.app.AlertDialog;
import android.content.Context;
-import android.os.Bundle;
import android.view.View;
-import android.view.Window;
-import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
-
import de.danoeh.antennapod.R;
/**
* Displays a dialog with a username and password text field and an optional checkbox to save username and preferences.
*/
-public abstract class AuthenticationDialog extends Dialog {
+public abstract class AuthenticationDialog extends AlertDialog.Builder {
- private final int titleRes;
- private final boolean enableUsernameField;
- private final boolean showSaveCredentialsCheckbox;
- private final String usernameInitialValue;
- private final String passwordInitialValue;
-
- public AuthenticationDialog(Context context, int titleRes, boolean enableUsernameField, boolean showSaveCredentialsCheckbox, String usernameInitialValue, String passwordInitialValue) {
+ public AuthenticationDialog(Context context, int titleRes, boolean enableUsernameField,
+ boolean showSaveCredentialsCheckbox, String usernameInitialValue,
+ String passwordInitialValue) {
super(context);
- this.titleRes = titleRes;
- this.enableUsernameField = enableUsernameField;
- this.showSaveCredentialsCheckbox = showSaveCredentialsCheckbox;
- this.usernameInitialValue = usernameInitialValue;
- this.passwordInitialValue = passwordInitialValue;
- }
+ setTitle(titleRes);
+ View rootView = View.inflate(context, R.layout.authentication_dialog, null);
+ setView(rootView);
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.authentication_dialog);
- final EditText etxtUsername = findViewById(R.id.etxtUsername);
- final EditText etxtPassword = findViewById(R.id.etxtPassword);
- final CheckBox saveUsernamePassword = findViewById(R.id.chkSaveUsernamePassword);
- final Button butConfirm = findViewById(R.id.butConfirm);
- final Button butCancel = findViewById(R.id.butCancel);
+ final EditText etxtUsername = rootView.findViewById(R.id.etxtUsername);
+ final EditText etxtPassword = rootView.findViewById(R.id.etxtPassword);
+ final CheckBox saveUsernamePassword = rootView.findViewById(R.id.chkSaveUsernamePassword);
- if (titleRes != 0) {
- setTitle(titleRes);
- } else {
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- }
etxtUsername.setEnabled(enableUsernameField);
if (showSaveCredentialsCheckbox) {
saveUsernamePassword.setVisibility(View.VISIBLE);
@@ -59,13 +37,10 @@ public abstract class AuthenticationDialog extends Dialog {
etxtPassword.setText(passwordInitialValue);
}
setOnCancelListener(dialog -> onCancelled());
- butCancel.setOnClickListener(v -> cancel());
- butConfirm.setOnClickListener(v -> {
- onConfirmed(etxtUsername.getText().toString(),
- etxtPassword.getText().toString(),
- showSaveCredentialsCheckbox && saveUsernamePassword.isChecked());
- dismiss();
- });
+ setNegativeButton(R.string.cancel_label, null);
+ setPositiveButton(R.string.confirm_label, (dialog, which)
+ -> onConfirmed(etxtUsername.getText().toString(), etxtPassword.getText().toString(),
+ showSaveCredentialsCheckbox && saveUsernamePassword.isChecked()));
}
protected void onCancelled() {
diff --git a/app/src/main/res/layout/authentication_dialog.xml b/app/src/main/res/layout/authentication_dialog.xml
index 187045c63..1661eaea1 100644
--- a/app/src/main/res/layout/authentication_dialog.xml
+++ b/app/src/main/res/layout/authentication_dialog.xml
@@ -4,88 +4,33 @@
android:layout_height="match_parent"
android:orientation="vertical" >
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_margin="16dp"
+ android:text="@string/save_username_password_label"/>
\ No newline at end of file