Skip to content

Commit 9268090

Browse files
committed
initial change password flow
1 parent 755bec0 commit 9268090

File tree

4 files changed

+115
-0
lines changed

4 files changed

+115
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.anotherdev.sample.firebase.auth;
2+
3+
import android.content.Context;
4+
import android.view.View;
5+
import android.widget.EditText;
6+
7+
public class ChangePasswordDialog extends MultipleTextInputDialog {
8+
9+
private EditText currentPasswordEditText;
10+
private EditText newPasswordEditText;
11+
private EditText verifyPasswordEditText;
12+
13+
14+
public ChangePasswordDialog(Context context) {
15+
super(context);
16+
}
17+
18+
@Override
19+
protected int getLayoutRes() {
20+
return R.layout.view_change_password_input;
21+
}
22+
23+
@Override
24+
protected void onConfigureView(View view) {
25+
super.onConfigureView(view);
26+
currentPasswordEditText = view.findViewById(R.id.old_password_edittext);
27+
newPasswordEditText = view.findViewById(R.id.new_password_edittext);
28+
verifyPasswordEditText = view.findViewById(R.id.verify_password_edittext);
29+
}
30+
31+
@Override
32+
public ChangePasswordDialog setListener(int viewId, boolean dismissOnClick, View.OnClickListener listener) {
33+
super.setListener(viewId, dismissOnClick, listener);
34+
return this;
35+
}
36+
37+
@Override
38+
public ChangePasswordDialog setConfirmButtonText(int confirmTextRes) {
39+
super.setConfirmButtonText(confirmTextRes);
40+
return this;
41+
}
42+
43+
@Override
44+
protected void dispatchOnConfirmClick() {
45+
// TODO implement this
46+
}
47+
}

app/src/main/java/com/anotherdev/sample/firebase/auth/LoginActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ private void startProfileEditing() {
151151
}
152152

153153
private void startPasswordChange() {
154+
FirebaseUser user = firebaseAuth.getCurrentUser();
155+
if (user != null) {
156+
new ChangePasswordDialog(this)
157+
.show();
158+
}
154159
}
155160

156161
private void changePassword(String oldPassword, String newPassword) {
@@ -165,6 +170,7 @@ private void changePassword(String oldPassword, String newPassword) {
165170
return reAuthUser.updatePassword(newPassword);
166171
})
167172
.observeOn(AndroidSchedulers.mainThread())
173+
.doOnComplete(() -> dialog("", "Password changed"))
168174
.doOnError(this::dialog)
169175
.subscribe(Functions.EMPTY_ACTION, RxUtil.ON_ERROR_LOG_V3));
170176
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical"
4+
android:padding="8dp"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<com.google.android.material.textfield.TextInputLayout
9+
android:layout_margin="8dp"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:hint="@string/current_password">
13+
14+
<com.google.android.material.textfield.TextInputEditText
15+
android:id="@+id/old_password_edittext"
16+
android:inputType="textPassword"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content" />
19+
20+
</com.google.android.material.textfield.TextInputLayout>
21+
22+
<com.google.android.material.textfield.TextInputLayout
23+
android:layout_margin="8dp"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:hint="@string/new_password">
27+
28+
<com.google.android.material.textfield.TextInputEditText
29+
android:id="@+id/new_password_edittext"
30+
android:inputType="textPassword"
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content" />
33+
34+
</com.google.android.material.textfield.TextInputLayout>
35+
36+
<com.google.android.material.textfield.TextInputLayout
37+
android:layout_margin="8dp"
38+
android:layout_width="match_parent"
39+
android:layout_height="wrap_content"
40+
android:hint="@string/verify_password">
41+
42+
<com.google.android.material.textfield.TextInputEditText
43+
android:id="@+id/verify_password_edittext"
44+
android:inputType="textPassword"
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content" />
47+
48+
</com.google.android.material.textfield.TextInputLayout>
49+
50+
<androidx.appcompat.widget.AppCompatButton
51+
android:id="@+id/positive_button"
52+
android:text="@android:string/ok"
53+
android:textColor="@android:color/white"
54+
android:backgroundTint="@color/colorPrimary"
55+
android:layout_margin="8dp"
56+
android:layout_width="match_parent"
57+
android:layout_height="56dp" />
58+
59+
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414

1515
<string name="edit_profile">Edit Profile</string>
1616
<string name="change_password">Change Password</string>
17+
<string name="current_password">Current Password</string>
18+
<string name="new_password">New Password</string>
19+
<string name="verify_password">Verify Password</string>
1720

1821
</resources>

0 commit comments

Comments
 (0)