12
12
import android .widget .ProgressBar ;
13
13
import android .widget .TextView ;
14
14
15
- import com .firebase .ui .auth .ErrorCodes ;
16
- import com .firebase .ui .auth .FirebaseUiException ;
15
+ import com .firebase .ui .auth .AuthUI ;
17
16
import com .firebase .ui .auth .R ;
18
17
import com .firebase .ui .auth .data .model .FlowParameters ;
19
18
import com .firebase .ui .auth .data .model .User ;
22
21
import com .firebase .ui .auth .util .data .PrivacyDisclosureUtils ;
23
22
import com .firebase .ui .auth .util .ui .ImeHelper ;
24
23
import com .firebase .ui .auth .util .ui .fieldvalidators .EmailFieldValidator ;
25
- import com .firebase .ui .auth .viewmodel .ResourceObserver ;
26
24
import com .google .android .material .snackbar .Snackbar ;
27
25
import com .google .android .material .textfield .TextInputLayout ;
28
- import com .google .firebase .FirebaseNetworkException ;
29
26
import com .google .firebase .auth .EmailAuthProvider ;
30
27
31
28
import androidx .annotation .NonNull ;
@@ -48,7 +45,8 @@ public class CheckEmailFragment extends FragmentBase implements
48
45
49
46
public static final String TAG = "CheckEmailFragment" ;
50
47
private CheckEmailHandler mHandler ;
51
- private Button mNextButton ;
48
+ private Button mSignInButton ;
49
+ private Button mSignUpButton ;
52
50
private ProgressBar mProgressBar ;
53
51
private EditText mEmailEditText ;
54
52
private TextInputLayout mEmailLayout ;
@@ -72,17 +70,16 @@ public View onCreateView(@NonNull LayoutInflater inflater,
72
70
73
71
@ Override
74
72
public void onViewCreated (@ NonNull View view , @ Nullable Bundle savedInstanceState ) {
75
- mNextButton = view .findViewById (R .id .button_next );
73
+ mSignInButton = view .findViewById (R .id .button_sign_in );
74
+ mSignUpButton = view .findViewById (R .id .button_sign_up );
76
75
mProgressBar = view .findViewById (R .id .top_progress_bar );
77
76
78
- // Email field and validator
79
77
mEmailLayout = view .findViewById (R .id .email_layout );
80
78
mEmailEditText = view .findViewById (R .id .email );
81
79
mEmailFieldValidator = new EmailFieldValidator (mEmailLayout );
82
80
mEmailLayout .setOnClickListener (this );
83
81
mEmailEditText .setOnClickListener (this );
84
82
85
- // Hide header
86
83
TextView headerText = view .findViewById (R .id .header_text );
87
84
if (headerText != null ) {
88
85
headerText .setVisibility (View .GONE );
@@ -94,7 +91,9 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
94
91
mEmailEditText .setImportantForAutofill (View .IMPORTANT_FOR_AUTOFILL_NO );
95
92
}
96
93
97
- mNextButton .setOnClickListener (this );
94
+ // Set listeners for our new sign‑in and sign‑up buttons.
95
+ mSignInButton .setOnClickListener (this );
96
+ mSignUpButton .setOnClickListener (this );
98
97
99
98
TextView termsText = view .findViewById (R .id .email_tos_and_pp_text );
100
99
TextView footerText = view .findViewById (R .id .email_footer_tos_and_pp_text );
@@ -124,54 +123,16 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
124
123
}
125
124
mListener = (CheckEmailListener ) activity ;
126
125
127
- mHandler .getOperation ().observe (getViewLifecycleOwner (), new ResourceObserver <User >(
128
- this , R .string .fui_progress_dialog_checking_accounts ) {
129
- @ Override
130
- protected void onSuccess (@ NonNull User user ) {
131
- String email = user .getEmail ();
132
- String provider = user .getProviderId ();
126
+ // Removed the observer on mHandler.getOperation() since we no longer rely on provider info.
133
127
128
+ if (savedInstanceState == null ) {
129
+ String email = getArguments ().getString (ExtraConstants .EMAIL );
130
+ if (!TextUtils .isEmpty (email )) {
134
131
mEmailEditText .setText (email );
135
- //noinspection ConstantConditions new user
136
- if (provider == null ) {
137
- mListener .onNewUser (new User .Builder (EmailAuthProvider .PROVIDER_ID , email )
138
- .setName (user .getName ())
139
- .setPhotoUri (user .getPhotoUri ())
140
- .build ());
141
- } else if (provider .equals (EmailAuthProvider .PROVIDER_ID )
142
- || provider .equals (EMAIL_LINK_PROVIDER )) {
143
- mListener .onExistingEmailUser (user );
144
- } else {
145
- mListener .onExistingIdpUser (user );
146
- }
132
+ // Previously auto-triggering the check is now removed.
133
+ } else if (getFlowParams ().enableHints ) {
134
+ mHandler .fetchCredential ();
147
135
}
148
-
149
- @ Override
150
- protected void onFailure (@ NonNull Exception e ) {
151
- if (e instanceof FirebaseUiException
152
- && ((FirebaseUiException ) e ).getErrorCode () == ErrorCodes .DEVELOPER_ERROR ) {
153
- mListener .onDeveloperFailure (e );
154
- }
155
-
156
- if (e instanceof FirebaseNetworkException ) {
157
- Snackbar .make (getView (), getString (R .string .fui_no_internet ), Snackbar .LENGTH_SHORT ).show ();
158
- }
159
-
160
- // Otherwise just let the user enter their data
161
- }
162
- });
163
-
164
- if (savedInstanceState != null ) {
165
- return ;
166
- }
167
-
168
- // Check for email
169
- String email = getArguments ().getString (ExtraConstants .EMAIL );
170
- if (!TextUtils .isEmpty (email )) {
171
- mEmailEditText .setText (email );
172
- validateAndProceed ();
173
- } else if (getFlowParams ().enableHints ) {
174
- mHandler .fetchCredential ();
175
136
}
176
137
}
177
138
@@ -184,34 +145,63 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
184
145
public void onClick (View view ) {
185
146
int id = view .getId ();
186
147
187
- if (id == R .id .button_next ) {
188
- validateAndProceed ();
148
+ if (id == R .id .button_sign_in ) {
149
+ signIn ();
150
+ } else if (id == R .id .button_sign_up ) {
151
+ signUp ();
189
152
} else if (id == R .id .email_layout || id == R .id .email ) {
190
153
mEmailLayout .setError (null );
191
154
}
192
155
}
193
156
194
157
@ Override
195
158
public void onDonePressed () {
196
- validateAndProceed ();
159
+ // When the user hits “done” on the keyboard, default to sign‑in.
160
+ signIn ();
161
+ }
162
+
163
+ private String getEmailProvider () {
164
+ // Iterate through all IdpConfig entries
165
+ for (AuthUI .IdpConfig config : getFlowParams ().providers ) {
166
+ // Assuming there is a getter for the provider ID
167
+ if (EmailAuthProvider .EMAIL_LINK_SIGN_IN_METHOD .equals (config .getProviderId ())) {
168
+ return EmailAuthProvider .EMAIL_LINK_SIGN_IN_METHOD ;
169
+ }
170
+ }
171
+ // Default to standard email/password
172
+ return EmailAuthProvider .PROVIDER_ID ;
173
+ }
174
+
175
+ private void signIn () {
176
+ String email = mEmailEditText .getText ().toString ();
177
+ if (mEmailFieldValidator .validate (email )) {
178
+ String provider = getEmailProvider ();
179
+ User user = new User .Builder (provider , email ).build ();
180
+ mListener .onExistingEmailUser (user );
181
+ }
197
182
}
198
183
199
- private void validateAndProceed () {
184
+ private void signUp () {
200
185
String email = mEmailEditText .getText ().toString ();
201
186
if (mEmailFieldValidator .validate (email )) {
202
- mHandler .fetchProvider (email );
187
+ String provider = getEmailProvider ();
188
+ User user = new User .Builder (provider , email ).build ();
189
+ mListener .onNewUser (user );
203
190
}
204
191
}
205
192
206
193
@ Override
207
194
public void showProgress (int message ) {
208
- mNextButton .setEnabled (false );
195
+ // Disable both buttons while progress is showing.
196
+ mSignInButton .setEnabled (false );
197
+ mSignUpButton .setEnabled (false );
209
198
mProgressBar .setVisibility (View .VISIBLE );
210
199
}
211
200
212
201
@ Override
213
202
public void hideProgress () {
214
- mNextButton .setEnabled (true );
203
+ mSignInButton .setEnabled (true );
204
+ mSignUpButton .setEnabled (true );
215
205
mProgressBar .setVisibility (View .INVISIBLE );
216
206
}
217
207
@@ -221,7 +211,7 @@ public void hideProgress() {
221
211
interface CheckEmailListener {
222
212
223
213
/**
224
- * Email entered belongs to an existing email user.
214
+ * Email entered belongs to an existing email user (sign‑in flow) .
225
215
*/
226
216
void onExistingEmailUser (User user );
227
217
@@ -231,7 +221,7 @@ interface CheckEmailListener {
231
221
void onExistingIdpUser (User user );
232
222
233
223
/**
234
- * Email entered does not belong to an existing user.
224
+ * Email entered does not belong to an existing user (sign‑up flow) .
235
225
*/
236
226
void onNewUser (User user );
237
227
@@ -240,4 +230,4 @@ interface CheckEmailListener {
240
230
*/
241
231
void onDeveloperFailure (Exception e );
242
232
}
243
- }
233
+ }
0 commit comments