Skip to content

Commit 19787df

Browse files
committed
refactor: changes in API design docs
replaced sealed with abstract class, data with regular class use isXX prefix for booleans
1 parent a5a944a commit 19787df

File tree

5 files changed

+66
-69
lines changed

5 files changed

+66
-69
lines changed

auth/src/main/java/com/firebase/ui/auth/compose/configuration/AuthProvider.kt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package com.firebase.ui.auth.compose.configuration
1616

1717
import android.graphics.Color
1818
import androidx.compose.ui.graphics.vector.ImageVector
19-
import com.firebase.ui.auth.util.data.ProviderAvailability
2019
import com.google.firebase.auth.ActionCodeSettings
2120
import com.google.firebase.auth.EmailAuthProvider
2221
import com.google.firebase.auth.FacebookAuthProvider
@@ -53,7 +52,7 @@ internal enum class Provider(val id: String) {
5352
}
5453

5554
/**
56-
* Base class for OAuth authentication providers with common properties.
55+
* Base abstract class for OAuth authentication providers with common properties.
5756
*/
5857
abstract class OAuthProvider(
5958
override val providerId: String,
@@ -62,22 +61,22 @@ abstract class OAuthProvider(
6261
) : AuthProvider(providerId)
6362

6463
/**
65-
* Base sealed class for authentication providers.
64+
* Base abstract class for authentication providers.
6665
*/
67-
sealed class AuthProvider(open val providerId: String) {
66+
abstract class AuthProvider(open val providerId: String) {
6867
/**
6968
* Email/Password authentication provider configuration.
7069
*/
71-
data class Email(
70+
class Email(
7271
/**
7372
* Requires the user to provide a display name. Defaults to true.
7473
*/
75-
val requireDisplayName: Boolean = true,
74+
val isDisplayNameRequired: Boolean = true,
7675

7776
/**
7877
* Enables email link sign-in, Defaults to false.
7978
*/
80-
val enableEmailLinkSignIn: Boolean = false,
79+
val isEmailLinkSignInEnabled: Boolean = false,
8180

8281
/**
8382
* Settings for email link actions.
@@ -87,7 +86,7 @@ sealed class AuthProvider(open val providerId: String) {
8786
/**
8887
* Allows new accounts to be created. Defaults to true.
8988
*/
90-
val allowNewAccounts: Boolean = true,
89+
val isNewAccountsAllowed: Boolean = true,
9190

9291
/**
9392
* The minimum length for a password. Defaults to 6.
@@ -100,7 +99,7 @@ sealed class AuthProvider(open val providerId: String) {
10099
val passwordValidationRules: List<PasswordRule>
101100
) : AuthProvider(providerId = Provider.EMAIL.id) {
102101
fun validate() {
103-
if (enableEmailLinkSignIn) {
102+
if (isEmailLinkSignInEnabled) {
104103
val actionCodeSettings = actionCodeSettings
105104
?: requireNotNull(actionCodeSettings) {
106105
"ActionCodeSettings cannot be null when using " +
@@ -118,7 +117,7 @@ sealed class AuthProvider(open val providerId: String) {
118117
/**
119118
* Phone number authentication provider configuration.
120119
*/
121-
data class Phone(
120+
class Phone(
122121
/**
123122
* The default country code to pre-select.
124123
*/
@@ -142,18 +141,18 @@ sealed class AuthProvider(open val providerId: String) {
142141
/**
143142
* Enables instant verification of the phone number. Defaults to true.
144143
*/
145-
val enableInstantVerification: Boolean = true,
144+
val isInstantVerificationEnabled: Boolean = true,
146145

147146
/**
148147
* Enables automatic retrieval of the SMS code. Defaults to true.
149148
*/
150-
val enableAutoRetrieval: Boolean = true
149+
val isAutoRetrievalEnabled: Boolean = true
151150
) : AuthProvider(providerId = Provider.PHONE.id)
152151

153152
/**
154153
* Google Sign-In provider configuration.
155154
*/
156-
data class Google(
155+
class Google(
157156
/**
158157
* The list of scopes to request.
159158
*/
@@ -192,7 +191,7 @@ sealed class AuthProvider(open val providerId: String) {
192191
/**
193192
* Facebook Login provider configuration.
194193
*/
195-
data class Facebook(
194+
class Facebook(
196195
/**
197196
* The list of scopes (permissions) to request. Defaults to email and public_profile.
198197
*/
@@ -216,7 +215,7 @@ sealed class AuthProvider(open val providerId: String) {
216215
/**
217216
* Twitter/X authentication provider configuration.
218217
*/
219-
data class Twitter(
218+
class Twitter(
220219
/**
221220
* A map of custom OAuth parameters.
222221
*/
@@ -229,7 +228,7 @@ sealed class AuthProvider(open val providerId: String) {
229228
/**
230229
* Github authentication provider configuration.
231230
*/
232-
data class Github(
231+
class Github(
233232
/**
234233
* The list of scopes to request. Defaults to user:email.
235234
*/
@@ -248,7 +247,7 @@ sealed class AuthProvider(open val providerId: String) {
248247
/**
249248
* Microsoft authentication provider configuration.
250249
*/
251-
data class Microsoft(
250+
class Microsoft(
252251
/**
253252
* The list of scopes to request. Defaults to openid, profile, email.
254253
*/
@@ -272,7 +271,7 @@ sealed class AuthProvider(open val providerId: String) {
272271
/**
273272
* Yahoo authentication provider configuration.
274273
*/
275-
data class Yahoo(
274+
class Yahoo(
276275
/**
277276
* The list of scopes to request. Defaults to openid, profile, email.
278277
*/
@@ -291,7 +290,7 @@ sealed class AuthProvider(open val providerId: String) {
291290
/**
292291
* Apple Sign-In provider configuration.
293292
*/
294-
data class Apple(
293+
class Apple(
295294
/**
296295
* The list of scopes to request. Defaults to name and email.
297296
*/
@@ -320,7 +319,7 @@ sealed class AuthProvider(open val providerId: String) {
320319
/**
321320
* A generic OAuth provider for any unsupported provider.
322321
*/
323-
data class GenericOAuth(
322+
class GenericOAuth(
324323
/**
325324
* The provider ID as configured in the Firebase console.
326325
*/

auth/src/main/java/com/firebase/ui/auth/compose/configuration/AuthUIConfiguration.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ class AuthUIConfigurationBuilder {
3737
var theme: AuthUITheme = AuthUITheme.Default
3838
var stringProvider: AuthUIStringProvider? = null
3939
var locale: Locale? = null
40-
var enableCredentialManager: Boolean = true
41-
var enableMfa: Boolean = true
42-
var enableAnonymousUpgrade: Boolean = false
40+
var isCredentialManagerEnabled: Boolean = true
41+
var isMfaEnabled: Boolean = true
42+
var isAnonymousUpgradeEnabled: Boolean = false
4343
var tosUrl: String? = null
4444
var privacyPolicyUrl: String? = null
4545
var logo: ImageVector? = null
4646
var actionCodeSettings: ActionCodeSettings? = null
47-
var allowNewEmailAccounts: Boolean = true
48-
var requireDisplayName: Boolean = true
49-
var alwaysShowProviderChoice: Boolean = false
47+
var isNewEmailAccountsAllowed: Boolean = true
48+
var isDisplayNameRequired: Boolean = true
49+
var isProviderChoiceAlwaysShown: Boolean = false
5050

5151
fun providers(block: AuthProvidersBuilder.() -> Unit) {
5252
val builder = AuthProvidersBuilder()
@@ -61,16 +61,16 @@ class AuthUIConfigurationBuilder {
6161
theme = theme,
6262
stringProvider = stringProvider,
6363
locale = locale,
64-
enableCredentialManager = enableCredentialManager,
65-
enableMfa = enableMfa,
66-
enableAnonymousUpgrade = enableAnonymousUpgrade,
64+
isCredentialManagerEnabled = isCredentialManagerEnabled,
65+
isMfaEnabled = isMfaEnabled,
66+
isAnonymousUpgradeEnabled = isAnonymousUpgradeEnabled,
6767
tosUrl = tosUrl,
6868
privacyPolicyUrl = privacyPolicyUrl,
6969
logo = logo,
7070
actionCodeSettings = actionCodeSettings,
71-
allowNewEmailAccounts = allowNewEmailAccounts,
72-
requireDisplayName = requireDisplayName,
73-
alwaysShowProviderChoice = alwaysShowProviderChoice
71+
isNewEmailAccountsAllowed = isNewEmailAccountsAllowed,
72+
isDisplayNameRequired = isDisplayNameRequired,
73+
isProviderChoiceAlwaysShown = isProviderChoiceAlwaysShown
7474
)
7575
}
7676

@@ -119,7 +119,7 @@ class AuthUIConfigurationBuilder {
119119
/**
120120
* Configuration object for the authentication flow.
121121
*/
122-
data class AuthUIConfiguration(
122+
class AuthUIConfiguration(
123123
/**
124124
* The list of enabled authentication providers.
125125
*/
@@ -143,17 +143,17 @@ data class AuthUIConfiguration(
143143
/**
144144
* Enables integration with Android's Credential Manager API. Defaults to true.
145145
*/
146-
val enableCredentialManager: Boolean = true,
146+
val isCredentialManagerEnabled: Boolean = true,
147147

148148
/**
149149
* Enables Multi-Factor Authentication support. Defaults to true.
150150
*/
151-
val enableMfa: Boolean = true,
151+
val isMfaEnabled: Boolean = true,
152152

153153
/**
154154
* Allows upgrading an anonymous user to a new credential.
155155
*/
156-
val enableAnonymousUpgrade: Boolean = false,
156+
val isAnonymousUpgradeEnabled: Boolean = false,
157157

158158
/**
159159
* The URL for the terms of service.
@@ -178,15 +178,15 @@ data class AuthUIConfiguration(
178178
/**
179179
* Allows new email accounts to be created. Defaults to true.
180180
*/
181-
val allowNewEmailAccounts: Boolean = true,
181+
val isNewEmailAccountsAllowed: Boolean = true,
182182

183183
/**
184184
* Requires the user to provide a display name on sign-up. Defaults to true.
185185
*/
186-
val requireDisplayName: Boolean = true,
186+
val isDisplayNameRequired: Boolean = true,
187187

188188
/**
189189
* Always shows the provider selection screen, even if only one is enabled.
190190
*/
191-
val alwaysShowProviderChoice: Boolean = false,
191+
val isProviderChoiceAlwaysShown: Boolean = false,
192192
)

auth/src/main/java/com/firebase/ui/auth/compose/configuration/AuthUITheme.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private val LocalAuthUITheme = staticCompositionLocalOf { AuthUITheme.Default }
3333
/**
3434
* Theming configuration for the entire Auth UI.
3535
*/
36-
data class AuthUITheme(
36+
class AuthUITheme(
3737
/**
3838
* The color scheme to use.
3939
*/
@@ -56,10 +56,10 @@ data class AuthUITheme(
5656
) {
5757

5858
/**
59-
* A data class nested within AuthUITheme that defines the visual appearance of a specific
59+
* A class nested within AuthUITheme that defines the visual appearance of a specific
6060
* provider button, allowing for per-provider branding and customization.
6161
*/
62-
data class ProviderStyle(
62+
class ProviderStyle(
6363
/**
6464
* The background color of the button.
6565
*/

auth/src/main/java/com/firebase/ui/auth/compose/configuration/PasswordRule.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
package com.firebase.ui.auth.compose.configuration
1616

1717
/**
18-
* A sealed class representing a set of validation rules that can be applied to a password field,
18+
* An abstract class representing a set of validation rules that can be applied to a password field,
1919
* typically within the [AuthProvider.Email] configuration.
2020
*/
21-
sealed class PasswordRule {
21+
abstract class PasswordRule {
2222
/**
2323
* Requires the password to have at least a certain number of characters.
2424
*/
25-
data class MinimumLength(val value: Int) : PasswordRule()
25+
class MinimumLength(val value: Int) : PasswordRule()
2626

2727
/**
2828
* Requires the password to contain at least one uppercase letter (A-Z).
@@ -48,5 +48,5 @@ sealed class PasswordRule {
4848
* Defines a custom validation rule using a regular expression and provides a specific error
4949
* message on failure.
5050
*/
51-
data class Custom(val regex: Regex, val errorMessage: String)
51+
class Custom(val regex: Regex, val errorMessage: String)
5252
}

auth/src/test/java/com/firebase/ui/auth/compose/configuration/AuthUIConfigurationTest.kt

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ class AuthUIConfigurationTest {
4343
assertThat(config.theme).isEqualTo(AuthUITheme.Default)
4444
assertThat(config.stringProvider).isNull()
4545
assertThat(config.locale).isNull()
46-
assertThat(config.enableCredentialManager).isTrue()
47-
assertThat(config.enableMfa).isTrue()
48-
assertThat(config.enableAnonymousUpgrade).isFalse()
46+
assertThat(config.isCredentialManagerEnabled).isTrue()
47+
assertThat(config.isMfaEnabled).isTrue()
48+
assertThat(config.isAnonymousUpgradeEnabled).isFalse()
4949
assertThat(config.tosUrl).isNull()
5050
assertThat(config.privacyPolicyUrl).isNull()
5151
assertThat(config.logo).isNull()
5252
assertThat(config.actionCodeSettings).isNull()
53-
assertThat(config.allowNewEmailAccounts).isTrue()
54-
assertThat(config.requireDisplayName).isTrue()
55-
assertThat(config.alwaysShowProviderChoice).isFalse()
53+
assertThat(config.isNewEmailAccountsAllowed).isTrue()
54+
assertThat(config.isDisplayNameRequired).isTrue()
55+
assertThat(config.isProviderChoiceAlwaysShown).isFalse()
5656
}
5757

5858
@Test
@@ -87,32 +87,32 @@ class AuthUIConfigurationTest {
8787
theme = customTheme
8888
stringProvider = customStringProvider
8989
locale = customLocale
90-
enableCredentialManager = false
91-
enableMfa = false
92-
enableAnonymousUpgrade = true
90+
isCredentialManagerEnabled = false
91+
isMfaEnabled = false
92+
isAnonymousUpgradeEnabled = true
9393
tosUrl = "https://example.com/tos"
9494
privacyPolicyUrl = "https://example.com/privacy"
9595
logo = Icons.Default.AccountCircle
9696
actionCodeSettings = customActionCodeSettings
97-
allowNewEmailAccounts = false
98-
requireDisplayName = false
99-
alwaysShowProviderChoice = true
97+
isNewEmailAccountsAllowed = false
98+
isDisplayNameRequired = false
99+
isProviderChoiceAlwaysShown = true
100100
}
101101

102102
assertThat(config.providers).hasSize(2)
103103
assertThat(config.theme).isEqualTo(customTheme)
104104
assertThat(config.stringProvider).isEqualTo(customStringProvider)
105105
assertThat(config.locale).isEqualTo(customLocale)
106-
assertThat(config.enableCredentialManager).isFalse()
107-
assertThat(config.enableMfa).isFalse()
108-
assertThat(config.enableAnonymousUpgrade).isTrue()
106+
assertThat(config.isCredentialManagerEnabled).isFalse()
107+
assertThat(config.isMfaEnabled).isFalse()
108+
assertThat(config.isAnonymousUpgradeEnabled).isTrue()
109109
assertThat(config.tosUrl).isEqualTo("https://example.com/tos")
110110
assertThat(config.privacyPolicyUrl).isEqualTo("https://example.com/privacy")
111111
assertThat(config.logo).isEqualTo(Icons.Default.AccountCircle)
112112
assertThat(config.actionCodeSettings).isEqualTo(customActionCodeSettings)
113-
assertThat(config.allowNewEmailAccounts).isFalse()
114-
assertThat(config.requireDisplayName).isFalse()
115-
assertThat(config.alwaysShowProviderChoice).isTrue()
113+
assertThat(config.isNewEmailAccountsAllowed).isFalse()
114+
assertThat(config.isDisplayNameRequired).isFalse()
115+
assertThat(config.isProviderChoiceAlwaysShown).isTrue()
116116
}
117117

118118
// ===========================================================================================
@@ -184,7 +184,7 @@ class AuthUIConfigurationTest {
184184
authUIConfiguration {
185185
providers {
186186
provider(AuthProvider.Email(
187-
enableEmailLinkSignIn = true,
187+
isEmailLinkSignInEnabled = true,
188188
actionCodeSettings = null,
189189
passwordValidationRules = listOf()
190190
))
@@ -201,7 +201,7 @@ class AuthUIConfigurationTest {
201201
authUIConfiguration {
202202
providers {
203203
provider(AuthProvider.Email(
204-
enableEmailLinkSignIn = true,
204+
isEmailLinkSignInEnabled = true,
205205
actionCodeSettings = customActionCodeSettings,
206206
passwordValidationRules = listOf()
207207
))
@@ -232,9 +232,7 @@ class AuthUIConfigurationTest {
232232
)
233233
)
234234
}
235-
236-
enableCredentialManager = true
237-
enableCredentialManager = false
235+
isCredentialManagerEnabled = true
238236
}
239237

240238
assertThat(config.providers).hasSize(2)

0 commit comments

Comments
 (0)