Added show button to authentication dialog
This commit is contained in:
parent
bb1d5fc169
commit
0399052866
|
@ -1,38 +1,50 @@
|
||||||
package de.danoeh.antennapod.dialog;
|
package de.danoeh.antennapod.dialog;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.text.method.HideReturnsTransformationMethod;
|
||||||
import android.widget.EditText;
|
import android.text.method.PasswordTransformationMethod;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.databinding.AuthenticationDialogBinding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a dialog with a username and password text field and an optional checkbox to save username and preferences.
|
* Displays a dialog with a username and password text field and an optional checkbox to save username and preferences.
|
||||||
*/
|
*/
|
||||||
public abstract class AuthenticationDialog extends AlertDialog.Builder {
|
public abstract class AuthenticationDialog extends AlertDialog.Builder {
|
||||||
|
boolean passwordHidden = true;
|
||||||
|
|
||||||
public AuthenticationDialog(Context context, int titleRes, boolean enableUsernameField,
|
public AuthenticationDialog(Context context, int titleRes, boolean enableUsernameField,
|
||||||
String usernameInitialValue, String passwordInitialValue) {
|
String usernameInitialValue, String passwordInitialValue) {
|
||||||
super(context);
|
super(context);
|
||||||
setTitle(titleRes);
|
setTitle(titleRes);
|
||||||
View rootView = View.inflate(context, R.layout.authentication_dialog, null);
|
AuthenticationDialogBinding viewBinding = AuthenticationDialogBinding.inflate(LayoutInflater.from(context));
|
||||||
setView(rootView);
|
setView(viewBinding.getRoot());
|
||||||
|
|
||||||
final EditText etxtUsername = rootView.findViewById(R.id.etxtUsername);
|
viewBinding.usernameEditText.setEnabled(enableUsernameField);
|
||||||
final EditText etxtPassword = rootView.findViewById(R.id.etxtPassword);
|
|
||||||
|
|
||||||
etxtUsername.setEnabled(enableUsernameField);
|
|
||||||
if (usernameInitialValue != null) {
|
if (usernameInitialValue != null) {
|
||||||
etxtUsername.setText(usernameInitialValue);
|
viewBinding.usernameEditText.setText(usernameInitialValue);
|
||||||
}
|
}
|
||||||
if (passwordInitialValue != null) {
|
if (passwordInitialValue != null) {
|
||||||
etxtPassword.setText(passwordInitialValue);
|
viewBinding.passwordEditText.setText(passwordInitialValue);
|
||||||
}
|
}
|
||||||
|
viewBinding.showPasswordButton.setOnClickListener(v -> {
|
||||||
|
if (passwordHidden) {
|
||||||
|
viewBinding.passwordEditText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
|
||||||
|
viewBinding.showPasswordButton.setAlpha(1.0f);
|
||||||
|
} else {
|
||||||
|
viewBinding.passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
|
||||||
|
viewBinding.showPasswordButton.setAlpha(0.6f);
|
||||||
|
}
|
||||||
|
passwordHidden = !passwordHidden;
|
||||||
|
});
|
||||||
|
|
||||||
setOnCancelListener(dialog -> onCancelled());
|
setOnCancelListener(dialog -> onCancelled());
|
||||||
setOnDismissListener(dialog -> onCancelled());
|
setOnDismissListener(dialog -> onCancelled());
|
||||||
setNegativeButton(R.string.cancel_label, null);
|
setNegativeButton(R.string.cancel_label, null);
|
||||||
setPositiveButton(R.string.confirm_label, (dialog, which)
|
setPositiveButton(R.string.confirm_label, (dialog, which)
|
||||||
-> onConfirmed(etxtUsername.getText().toString(), etxtPassword.getText().toString()));
|
-> onConfirmed(viewBinding.usernameEditText.getText().toString(),
|
||||||
|
viewBinding.passwordEditText.getText().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
|
|
|
@ -1,30 +1,59 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/etxtUsername"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
android:orientation="vertical"
|
||||||
android:layout_margin="16dp"
|
android:padding="16dp">
|
||||||
android:hint="@string/username_label"
|
|
||||||
android:focusable="true"
|
|
||||||
android:focusableInTouchMode="true"
|
|
||||||
android:cursorVisible="true"/>
|
|
||||||
|
|
||||||
<EditText
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/etxtPassword"
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_marginBottom="8dp">
|
||||||
android:layout_margin="16dp"
|
|
||||||
android:inputType="textPassword"
|
|
||||||
android:hint="@string/password_label"
|
|
||||||
android:focusable="true"
|
|
||||||
android:focusableInTouchMode="true"
|
|
||||||
android:cursorVisible="true"/>
|
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/usernameEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/username_label"
|
||||||
|
android:lines="1"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/passwordEditText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="@string/password_label"
|
||||||
|
android:inputType="textPassword"
|
||||||
|
android:lines="1"/>
|
||||||
|
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<com.joanzapata.iconify.widget.IconTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/showPasswordButton"
|
||||||
|
android:text="{fa-eye}"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:alpha="0.6"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginStart="8dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -95,7 +95,6 @@
|
||||||
<string name="description_label">Description</string>
|
<string name="description_label">Description</string>
|
||||||
<string name="episodes_suffix">\u0020episodes</string>
|
<string name="episodes_suffix">\u0020episodes</string>
|
||||||
<string name="processing_label">Processing</string>
|
<string name="processing_label">Processing</string>
|
||||||
<string name="save_username_password_label">Save username and password</string>
|
|
||||||
<string name="close_label">Close</string>
|
<string name="close_label">Close</string>
|
||||||
<string name="retry_label">Retry</string>
|
<string name="retry_label">Retry</string>
|
||||||
<string name="auto_download_label">Include in auto downloads</string>
|
<string name="auto_download_label">Include in auto downloads</string>
|
||||||
|
|
Loading…
Reference in New Issue