14
14
15
15
package com.firebase.ui.auth.compose.configuration
16
16
17
+ import android.content.Context
17
18
import java.util.Locale
18
19
import com.google.firebase.auth.ActionCodeSettings
19
20
import androidx.compose.ui.graphics.vector.ImageVector
21
+ import com.firebase.ui.auth.compose.configuration.stringprovider.AuthUIStringProvider
22
+ import com.firebase.ui.auth.compose.configuration.stringprovider.DefaultAuthUIStringProvider
20
23
21
- fun actionCodeSettings (
22
- block : ActionCodeSettings .Builder .() -> Unit
23
- ) = ActionCodeSettings .newBuilder().apply (block).build()
24
+ fun actionCodeSettings (block : ActionCodeSettings .Builder .() -> Unit ) =
25
+ ActionCodeSettings .newBuilder().apply (block).build()
24
26
25
- fun authUIConfiguration (block : AuthUIConfigurationBuilder .() -> Unit ): AuthUIConfiguration {
26
- val builder = AuthUIConfigurationBuilder ()
27
- builder.block()
28
- return builder.build()
29
- }
27
+ fun authUIConfiguration (block : AuthUIConfigurationBuilder .() -> Unit ) =
28
+ AuthUIConfigurationBuilder ().apply (block).build()
30
29
31
30
@DslMarker
32
31
annotation class AuthUIConfigurationDsl
33
32
34
33
@AuthUIConfigurationDsl
35
34
class AuthUIConfigurationBuilder {
35
+ var context: Context ? = null
36
36
private val providers = mutableListOf<AuthProvider >()
37
37
var theme: AuthUITheme = AuthUITheme .Default
38
- var stringProvider: AuthUIStringProvider ? = null
39
38
var locale: Locale ? = null
39
+ var stringProvider: AuthUIStringProvider ? = null
40
40
var isCredentialManagerEnabled: Boolean = true
41
41
var isMfaEnabled: Boolean = true
42
42
var isAnonymousUpgradeEnabled: Boolean = false
@@ -48,36 +48,16 @@ class AuthUIConfigurationBuilder {
48
48
var isDisplayNameRequired: Boolean = true
49
49
var isProviderChoiceAlwaysShown: Boolean = false
50
50
51
- fun providers (block : AuthProvidersBuilder .() -> Unit ) {
52
- val builder = AuthProvidersBuilder ()
53
- builder.block()
54
- providers.addAll(builder.build())
55
- }
51
+ fun providers (block : AuthProvidersBuilder .() -> Unit ) =
52
+ providers.addAll(AuthProvidersBuilder ().apply (block).build())
56
53
57
54
internal fun build (): AuthUIConfiguration {
58
- validate()
59
- return AuthUIConfiguration (
60
- providers = providers.toList(),
61
- theme = theme,
62
- stringProvider = stringProvider,
63
- locale = locale,
64
- isCredentialManagerEnabled = isCredentialManagerEnabled,
65
- isMfaEnabled = isMfaEnabled,
66
- isAnonymousUpgradeEnabled = isAnonymousUpgradeEnabled,
67
- tosUrl = tosUrl,
68
- privacyPolicyUrl = privacyPolicyUrl,
69
- logo = logo,
70
- actionCodeSettings = actionCodeSettings,
71
- isNewEmailAccountsAllowed = isNewEmailAccountsAllowed,
72
- isDisplayNameRequired = isDisplayNameRequired,
73
- isProviderChoiceAlwaysShown = isProviderChoiceAlwaysShown
74
- )
75
- }
55
+ val context = requireNotNull(context) {
56
+ " Application context is required"
57
+ }
76
58
77
- private fun validate () {
78
- // At least one provider
79
- if (providers.isEmpty()) {
80
- throw IllegalArgumentException (" At least one provider must be configured" )
59
+ require(providers.isNotEmpty()) {
60
+ " At least one provider must be configured"
81
61
}
82
62
83
63
// No unsupported providers
@@ -113,13 +93,36 @@ class AuthUIConfigurationBuilder {
113
93
else -> null
114
94
}
115
95
}
96
+
97
+ return AuthUIConfiguration (
98
+ context = context,
99
+ providers = providers.toList(),
100
+ theme = theme,
101
+ locale = locale,
102
+ stringProvider = stringProvider ? : DefaultAuthUIStringProvider (context, locale),
103
+ isCredentialManagerEnabled = isCredentialManagerEnabled,
104
+ isMfaEnabled = isMfaEnabled,
105
+ isAnonymousUpgradeEnabled = isAnonymousUpgradeEnabled,
106
+ tosUrl = tosUrl,
107
+ privacyPolicyUrl = privacyPolicyUrl,
108
+ logo = logo,
109
+ actionCodeSettings = actionCodeSettings,
110
+ isNewEmailAccountsAllowed = isNewEmailAccountsAllowed,
111
+ isDisplayNameRequired = isDisplayNameRequired,
112
+ isProviderChoiceAlwaysShown = isProviderChoiceAlwaysShown
113
+ )
116
114
}
117
115
}
118
116
119
117
/* *
120
118
* Configuration object for the authentication flow.
121
119
*/
122
120
class AuthUIConfiguration (
121
+ /* *
122
+ * Application context
123
+ */
124
+ val context : Context ,
125
+
123
126
/* *
124
127
* The list of enabled authentication providers.
125
128
*/
@@ -131,14 +134,14 @@ class AuthUIConfiguration(
131
134
val theme : AuthUITheme = AuthUITheme .Default ,
132
135
133
136
/* *
134
- * A custom provider for localized strings .
137
+ * The locale for internationalization .
135
138
*/
136
- val stringProvider : AuthUIStringProvider ? = null ,
139
+ val locale : Locale ? = null ,
137
140
138
141
/* *
139
- * The locale for internationalization .
142
+ * A custom provider for localized strings .
140
143
*/
141
- val locale : Locale ? = null ,
144
+ val stringProvider : AuthUIStringProvider = DefaultAuthUIStringProvider (context, locale) ,
142
145
143
146
/* *
144
147
* Enables integration with Android's Credential Manager API. Defaults to true.
0 commit comments