Skip to content

Commit 7415825

Browse files
SUPERCILEXsamtstern
authored andcommitted
Cleanup (#470)
1 parent 48e138f commit 7415825

26 files changed

+397
-463
lines changed

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@
6464
* If an alternative app instance is in use, call
6565
* {@link AuthUI#getInstance(FirebaseApp) AuthUI.getInstance(app} instead, passing the
6666
* appropriate app instance.
67-
*
67+
* <p>
6868
* <h2>Sign-in</h2>
69-
*
69+
* <p>
7070
* If a user is not currently signed in (as can be determined by checking
7171
* {@code auth.getCurrentUser() != null}, where {@code auth} is the {@link FirebaseAuth}
7272
* associated with your {@link FirebaseApp}) then the sign-in process can be started by creating
7373
* a sign-in intent using {@link SignInIntentBuilder}. A builder instance can be retrieved by
7474
* calling {@link AuthUI#createSignInIntentBuilder()}.
75-
*
75+
* <p>
7676
* <p>The builder provides the following customization options for the authentication flow
7777
* implemented by this library:
78-
*
78+
* <p>
7979
* <ul>
8080
* <li>The set of authentication methods desired can be specified.</li>
8181
* <li>The terms of service URL for your app can be specified, which is included as a link
@@ -86,23 +86,23 @@
8686
* the flow for consistent customization of colors and typography.
8787
* </li>
8888
* </ul>
89-
*
90-
*
89+
* <p>
90+
* <p>
9191
* <h3>Sign-in examples</h3>
92-
*
92+
* <p>
9393
* If no customization is required, and only email authentication is required, the sign-in flow
9494
* can be started as follows:
95-
*
95+
* <p>
9696
* <pre>
9797
* {@code
9898
* startActivityForResult(
9999
* AuthUI.getInstance().createSignInIntentBuilder().build(),
100100
* RC_SIGN_IN);
101101
* }
102102
* </pre>
103-
*
103+
* <p>
104104
* If Google Sign-in and Facebook Sign-in are also required, then this can be replaced with:
105-
*
105+
* <p>
106106
* <pre>
107107
* {@code
108108
* startActivityForResult(
@@ -119,9 +119,9 @@
119119
* RC_SIGN_IN);
120120
* }
121121
* </pre>
122-
*
122+
* <p>
123123
* Finally, if a terms of service URL and a custom theme are required:
124-
*
124+
* <p>
125125
* <pre>
126126
* {@code
127127
* startActivityForResult(
@@ -134,16 +134,16 @@
134134
* RC_SIGN_IN);
135135
* }
136136
* </pre>
137-
*
137+
* <p>
138138
* <h3>Handling the Sign-in response</h3>
139-
*
139+
* <p>
140140
* The authentication flow provides only two response codes:
141141
* {@link ResultCodes#OK RESULT_OK} if a user is signed in,
142142
* and {@link ResultCodes#CANCELED RESULT_CANCELLED} if sign in
143143
* failed. No further information on failure is provided as it is not typically useful; the only
144144
* recourse for most apps if sign in fails is to ask the user to sign in again later, or proceed
145145
* with an anonymous account if supported.
146-
*
146+
* <p>
147147
* <pre>
148148
* {@code
149149
* @Override
@@ -162,11 +162,11 @@
162162
* }
163163
* }
164164
* </pre>
165-
*
165+
* <p>
166166
* <h2>Sign-out</h2>
167-
*
167+
* <p>
168168
* With the integrations provided by AuthUI, signing out a user is a multi-stage process:
169-
*
169+
* <p>
170170
* <ol>
171171
* <li>The user must be signed out of the {@link FirebaseAuth} instance.</li>
172172
* <li>Smart Lock for Passwords must be instructed to disable automatic sign-in, in
@@ -180,11 +180,11 @@
180180
* would also prevent the user from switching between accounts on the same provider.
181181
* </li>
182182
* </ol>
183-
*
183+
* <p>
184184
* In order to make this process easier, AuthUI provides a simple
185185
* {@link AuthUI#signOut(Activity) signOut} method to encapsulate this behavior. The method returns
186186
* a {@link Task} which is marked completed once all necessary sign-out operations are completed:
187-
*
187+
* <p>
188188
* <pre>
189189
* {@code
190190
* public void onClick(View v) {
@@ -200,30 +200,30 @@
200200
* }
201201
* }
202202
* </pre>
203-
*
203+
* <p>
204204
* <h2>IDP Provider configuration</h2>
205-
*
205+
* <p>
206206
* Interacting with identity providers typically requires some additional client configuration.
207207
* AuthUI currently supports Google Sign-in and Facebook Sign-in, and currently requires the
208208
* basic configuration for these providers to be specified via string properties:
209-
*
209+
* <p>
210210
* <ul>
211-
*
211+
* <p>
212212
* <li>Google Sign-in: If your app build uses the
213213
* <a href="https://developers.google.com/android/guides/google-services-plugin">Google
214214
* Services Gradle Plugin</a>, no additional configuration is required. If not, please override
215215
* {@code R.string.default_web_client_id} to provide your
216216
* <a href="https://developers.google.com/identity/sign-in/web/devconsole-project">Google OAuth
217217
* web client id.</a>
218218
* </li>
219-
*
219+
* <p>
220220
* <li>Facebook Sign-in: Please override the string resource
221221
* {@code facebook_application_id} to provide the
222222
* <a href="https://developers.facebook.com/docs/apps/register">App ID</a> for your app as
223223
* registered on the
224224
* <a href="https://developers.facebook.com/apps">Facebook Developer Dashboard</a>.
225225
* </li>
226-
*
226+
* <p>
227227
* </ul>
228228
*/
229229
public class AuthUI {
@@ -276,6 +276,40 @@ private AuthUI(FirebaseApp app) {
276276
mAuth = FirebaseAuth.getInstance(mApp);
277277
}
278278

279+
/**
280+
* Retrieves the {@link AuthUI} instance associated with the default app, as returned by
281+
* {@code FirebaseApp.getInstance()}.
282+
*
283+
* @throws IllegalStateException if the default app is not initialized.
284+
*/
285+
public static AuthUI getInstance() {
286+
return getInstance(FirebaseApp.getInstance());
287+
}
288+
289+
/**
290+
* Retrieves the {@link AuthUI} instance associated the the specified app.
291+
*/
292+
public static AuthUI getInstance(FirebaseApp app) {
293+
AuthUI authUi;
294+
synchronized (INSTANCES) {
295+
authUi = INSTANCES.get(app);
296+
if (authUi == null) {
297+
authUi = new AuthUI(app);
298+
INSTANCES.put(app, authUi);
299+
}
300+
}
301+
return authUi;
302+
}
303+
304+
/**
305+
* Default theme used by {@link SignInIntentBuilder#setTheme(int)} if no theme
306+
* customization is required.
307+
*/
308+
@StyleRes
309+
public static int getDefaultTheme() {
310+
return R.style.FirebaseUI;
311+
}
312+
279313
/**
280314
* Signs the current user out, if one is signed in.
281315
*
@@ -380,44 +414,9 @@ public SignInIntentBuilder createSignInIntentBuilder() {
380414
return new SignInIntentBuilder();
381415
}
382416

383-
/**
384-
* Retrieves the {@link AuthUI} instance associated with the default app, as returned by
385-
* {@code FirebaseApp.getInstance()}.
386-
*
387-
* @throws IllegalStateException if the default app is not initialized.
388-
*/
389-
public static AuthUI getInstance() {
390-
return getInstance(FirebaseApp.getInstance());
391-
}
392-
393-
/**
394-
* Retrieves the {@link AuthUI} instance associated the the specified app.
395-
*/
396-
public static AuthUI getInstance(FirebaseApp app) {
397-
AuthUI authUi;
398-
synchronized (INSTANCES) {
399-
authUi = INSTANCES.get(app);
400-
if (authUi == null) {
401-
authUi = new AuthUI(app);
402-
INSTANCES.put(app, authUi);
403-
}
404-
}
405-
return authUi;
406-
}
407-
408-
/**
409-
* Default theme used by {@link SignInIntentBuilder#setTheme(int)} if no theme
410-
* customization is required.
411-
*/
412-
@StyleRes
413-
public static int getDefaultTheme() {
414-
return R.style.FirebaseUI;
415-
}
416-
417-
418417
/**
419418
* Configuration for an identity provider.
420-
*
419+
* <p>
421420
* In the simplest case, you can supply the provider ID and build the config like this:
422421
* {@code new IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()}
423422
*/
@@ -430,6 +429,11 @@ private IdpConfig(@NonNull String providerId, List<String> scopes) {
430429
mProviderId = providerId;
431430
}
432431

432+
private IdpConfig(Parcel in) {
433+
mProviderId = in.readString();
434+
mScopes = in.createStringArrayList();
435+
}
436+
433437
public String getProviderId() {
434438
return mProviderId;
435439
}
@@ -438,11 +442,6 @@ public List<String> getScopes() {
438442
return mScopes;
439443
}
440444

441-
protected IdpConfig(Parcel in) {
442-
mProviderId = in.readString();
443-
mScopes = in.createStringArrayList();
444-
}
445-
446445
public static final Creator<IdpConfig> CREATOR = new Creator<IdpConfig>() {
447446
@Override
448447
public IdpConfig createFromParcel(Parcel in) {
@@ -488,14 +487,14 @@ public Builder(@NonNull String providerId) {
488487
/**
489488
* Specifies the additional permissions that the application will request for this
490489
* identity provider.
491-
*
490+
* <p>
492491
* For Facebook permissions see:
493492
* https://developers.facebook.com/docs/facebook-login/android
494493
* https://developers.facebook.com/docs/facebook-login/permissions
495-
*
494+
* <p>
496495
* For Google permissions see:
497496
* https://developers.google.com/identity/protocols/googlescopes
498-
*
497+
* <p>
499498
* Twitter permissions are only configurable through the Twitter developer console.
500499
*/
501500
public Builder setPermissions(List<String> permissions) {
@@ -556,7 +555,7 @@ public SignInIntentBuilder setTosUrl(@Nullable String tosUrl) {
556555
/**
557556
* Specified the set of supported authentication providers. At least one provider must
558557
* be specified. There may only be one instance of each provider.
559-
*
558+
* <p>
560559
* <p>If no providers are explicitly specified by calling this method, then the email
561560
* provider is the default supported provider.
562561
*
@@ -583,7 +582,7 @@ public SignInIntentBuilder setProviders(@NonNull List<IdpConfig> idpConfigs) {
583582
* Specifies the set of supported authentication providers. At least one provider
584583
* must be specified, and the set of providers must be a subset of
585584
* {@link #SUPPORTED_PROVIDERS}. There may only be one instance of each provider.
586-
*
585+
* <p>
587586
* <p>If no providers are explicitly specified by calling this method, then
588587
* {@link #EMAIL_PROVIDER email} is the default supported provider.
589588
*
@@ -605,7 +604,7 @@ public SignInIntentBuilder setProviders(@NonNull String... providers) {
605604

606605
/**
607606
* Enables or disables the use of Smart Lock for Passwords in the sign in flow.
608-
*
607+
* <p>
609608
* <p>SmartLock is enabled by default
610609
*/
611610
public SignInIntentBuilder setIsSmartLockEnabled(boolean enabled) {

auth/src/main/java/com/firebase/ui/auth/IdpResponse.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,28 @@ private IdpResponse(
6565
mErrorCode = errorCode;
6666
}
6767

68-
public static final Creator<IdpResponse> CREATOR = new Creator<IdpResponse>() {
69-
@Override
70-
public IdpResponse createFromParcel(Parcel in) {
71-
return new IdpResponse(
72-
in.readString(),
73-
in.readString(),
74-
in.readString(),
75-
in.readString(),
76-
in.readInt()
77-
);
68+
/**
69+
* Extract the {@link IdpResponse} from the flow's result intent.
70+
*
71+
* @param resultIntent The intent which {@code onActivityResult} was called with.
72+
* @return The IdpResponse containing the token(s) from signing in with the Idp
73+
*/
74+
@Nullable
75+
public static IdpResponse fromResultIntent(Intent resultIntent) {
76+
if (resultIntent != null) {
77+
return resultIntent.getParcelableExtra(ExtraConstants.EXTRA_IDP_RESPONSE);
78+
} else {
79+
return null;
7880
}
81+
}
7982

80-
@Override
81-
public IdpResponse[] newArray(int size) {
82-
return new IdpResponse[size];
83-
}
84-
};
83+
public static Intent getIntent(IdpResponse response) {
84+
return new Intent().putExtra(ExtraConstants.EXTRA_IDP_RESPONSE, response);
85+
}
86+
87+
public static Intent getErrorCodeIntent(int errorCode) {
88+
return getIntent(new IdpResponse(errorCode));
89+
}
8590

8691
/**
8792
* Get the type of provider. e.g. {@link AuthUI#GOOGLE_PROVIDER}
@@ -134,26 +139,21 @@ public void writeToParcel(Parcel dest, int flags) {
134139
dest.writeInt(mErrorCode);
135140
}
136141

137-
/**
138-
* Extract the {@link IdpResponse} from the flow's result intent.
139-
*
140-
* @param resultIntent The intent which {@code onActivityResult} was called with.
141-
* @return The IdpResponse containing the token(s) from signing in with the Idp
142-
*/
143-
@Nullable
144-
public static IdpResponse fromResultIntent(Intent resultIntent) {
145-
if (resultIntent != null) {
146-
return resultIntent.getParcelableExtra(ExtraConstants.EXTRA_IDP_RESPONSE);
147-
} else {
148-
return null;
142+
public static final Creator<IdpResponse> CREATOR = new Creator<IdpResponse>() {
143+
@Override
144+
public IdpResponse createFromParcel(Parcel in) {
145+
return new IdpResponse(
146+
in.readString(),
147+
in.readString(),
148+
in.readString(),
149+
in.readString(),
150+
in.readInt()
151+
);
149152
}
150-
}
151-
152-
public static Intent getIntent(IdpResponse response) {
153-
return new Intent().putExtra(ExtraConstants.EXTRA_IDP_RESPONSE, response);
154-
}
155153

156-
public static Intent getErrorCodeIntent(int errorCode) {
157-
return getIntent(new IdpResponse(errorCode));
158-
}
154+
@Override
155+
public IdpResponse[] newArray(int size) {
156+
return new IdpResponse[size];
157+
}
158+
};
159159
}

0 commit comments

Comments
 (0)