12
12
* limitations under the License.
13
13
*/
14
14
15
- package com .firebase .ui .auth .ui . email ;
15
+ package com .firebase .ui .auth .ui ;
16
16
17
17
import android .content .Intent ;
18
18
import android .support .annotation .NonNull ;
19
19
20
20
import com .firebase .ui .auth .R ;
21
21
import com .firebase .ui .auth .choreographer .ControllerConstants ;
22
- import com .firebase .ui .auth .ui .NoControllerBaseActivity ;
23
22
import com .firebase .ui .auth .ui .account_link .WelcomeBackIDPPrompt ;
23
+ import com .firebase .ui .auth .ui .email .RegisterEmailActivity ;
24
+ import com .firebase .ui .auth .ui .email .SignInActivity ;
24
25
import com .google .android .gms .tasks .OnCompleteListener ;
25
26
import com .google .android .gms .tasks .Task ;
26
27
import com .google .firebase .auth .EmailAuthProvider ;
30
31
import java .util .Arrays ;
31
32
import java .util .List ;
32
33
33
- public abstract class AcquireEmailActivity extends NoControllerBaseActivity {
34
- protected static final int RC_REGISTER_ACCOUNT = 14 ;
35
- protected static final int RC_WELCOME_BACK_IDP = 15 ;
36
- protected static final int RC_SIGN_IN = 16 ;
37
- private static final List <Integer > REQUEST_CODES = Arrays .asList (
34
+ public class AcquireEmailHelper {
35
+ public static final int RC_REGISTER_ACCOUNT = 14 ;
36
+ public static final int RC_WELCOME_BACK_IDP = 15 ;
37
+ public static final int RC_SIGN_IN = 16 ;
38
+ public static final List <Integer > REQUEST_CODES = Arrays .asList (
38
39
RC_REGISTER_ACCOUNT ,
39
40
RC_WELCOME_BACK_IDP ,
40
41
RC_SIGN_IN
41
42
);
42
43
43
- protected void checkAccountExists (final String email ) {
44
- FirebaseAuth firebaseAuth = getFirebaseAuth ();
45
- showLoadingDialog (R .string .progress_dialog_loading );
44
+ private ActivityHelper mActivityHelper ;
45
+
46
+ public AcquireEmailHelper (ActivityHelper activityHelper ) {
47
+ mActivityHelper = activityHelper ;
48
+ }
49
+
50
+ public void checkAccountExists (final String email ) {
51
+ FirebaseAuth firebaseAuth = mActivityHelper .getFirebaseAuth ();
52
+ mActivityHelper .showLoadingDialog (R .string .progress_dialog_loading );
46
53
if (email != null && !email .isEmpty ()) {
47
54
firebaseAuth .fetchProvidersForEmail (email ).addOnCompleteListener (
48
55
new OnCompleteListener <ProviderQueryResult >() {
@@ -56,53 +63,51 @@ public void onComplete(@NonNull Task<ProviderQueryResult> task) {
56
63
}
57
64
58
65
private void startEmailHandler (String email , List <String > providers ) {
59
- dismissDialog ();
66
+ mActivityHelper . dismissDialog ();
60
67
if (providers == null || providers .isEmpty ()) {
61
68
// account doesn't exist yet
62
69
Intent registerIntent = RegisterEmailActivity .createIntent (
63
- AcquireEmailActivity . this ,
70
+ mActivityHelper . getApplicationContext () ,
64
71
email ,
65
- mTermsOfServiceUrl ,
66
- mAppName
72
+ mActivityHelper . termsOfServiceUrl ,
73
+ mActivityHelper . appName
67
74
);
68
- startActivityForResult (registerIntent , RC_REGISTER_ACCOUNT );
75
+ mActivityHelper . startActivityForResult (registerIntent , RC_REGISTER_ACCOUNT );
69
76
return ;
70
77
} else {
71
78
// account does exist
72
79
for (String provider : providers ) {
73
80
if (provider .equalsIgnoreCase (EmailAuthProvider .PROVIDER_ID )) {
74
81
Intent signInIntent = SignInActivity .createIntent (
75
- this ,
76
- mAppName ,
82
+ mActivityHelper . getApplicationContext () ,
83
+ mActivityHelper . appName ,
77
84
email ,
78
- mProviderParcels
85
+ mActivityHelper . providerParcels
79
86
);
80
- startActivityForResult (signInIntent , RC_SIGN_IN );
87
+ mActivityHelper . startActivityForResult (signInIntent , RC_SIGN_IN );
81
88
return ;
82
89
}
83
90
Intent intent = WelcomeBackIDPPrompt .createIntent (
84
- AcquireEmailActivity . this ,
91
+ mActivityHelper . getApplicationContext () ,
85
92
provider ,
86
- mProviderParcels ,
87
- mAppName ,
93
+ mActivityHelper . providerParcels ,
94
+ mActivityHelper . appName ,
88
95
email );
89
- startActivityForResult (intent , RC_WELCOME_BACK_IDP );
96
+ mActivityHelper . startActivityForResult (intent , RC_WELCOME_BACK_IDP );
90
97
return ;
91
98
}
92
99
93
100
Intent signInIntent = new Intent (
94
- AcquireEmailActivity . this , SignInActivity .class );
101
+ mActivityHelper . getApplicationContext () , SignInActivity .class );
95
102
signInIntent .putExtra (ControllerConstants .EXTRA_EMAIL , email );
96
- startActivityForResult (signInIntent , RC_SIGN_IN );
103
+ mActivityHelper . startActivityForResult (signInIntent , RC_SIGN_IN );
97
104
return ;
98
105
}
99
106
}
100
107
101
- @ Override
102
- protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
103
- super .onActivityResult (requestCode , resultCode , data );
108
+ public void onActivityResult (int requestCode , int resultCode , Intent data ) {
104
109
if (REQUEST_CODES .contains (requestCode )) {
105
- finish (resultCode , new Intent ());
110
+ mActivityHelper . finish (resultCode , new Intent ());
106
111
}
107
112
}
108
113
}
0 commit comments