@@ -8,13 +8,15 @@ import com.google.gson.JsonParser
88import org.openedx.core.domain.model.AgreementUrls
99import java.io.InputStreamReader
1010
11+ @Suppress(" TooManyFunctions" )
1112class Config (context : Context ) {
1213
1314 private var configProperties: JsonObject = try {
1415 val inputStream = context.assets.open(" config/config.json" )
15- val config = Gson ().fromJson (InputStreamReader (inputStream), JsonObject :: class .java )
16+ val config = JsonParser .parseReader (InputStreamReader (inputStream))
1617 config.asJsonObject
1718 } catch (e: Exception ) {
19+ e.printStackTrace()
1820 JsonObject ()
1921 }
2022
@@ -26,10 +28,6 @@ class Config(context: Context) {
2628 return getString(API_HOST_URL )
2729 }
2830
29- fun getSSOURL (): String {
30- return getString(SSO_URL , " " )
31- }
32-
3331 fun getUriScheme (): String {
3432 return getString(URI_SCHEME )
3533 }
@@ -94,10 +92,6 @@ class Config(context: Context) {
9492 return getObjectOrNewInstance(DASHBOARD , DashboardConfig ::class .java)
9593 }
9694
97- fun getDownloadsConfig (): AppLevelDownloadsConfig {
98- return getExperimentalFeaturesConfig().appLevelDownloadsConfig
99- }
100-
10195 fun getBranchConfig (): BranchConfig {
10296 return getObjectOrNewInstance(BRANCH , BranchConfig ::class .java)
10397 }
@@ -114,37 +108,16 @@ class Config(context: Context) {
114108 return getObjectOrNewInstance(UI_COMPONENTS , UIConfig ::class .java)
115109 }
116110
117- fun isBrowserLoginEnabled (): Boolean {
118- return getBoolean(BROWSER_LOGIN , false )
119- }
120-
121- fun isBrowserRegistrationEnabled (): Boolean {
122- return getBoolean(BROWSER_REGISTRATION , false )
123- }
124-
125- private fun getExperimentalFeaturesConfig (): ExperimentalFeaturesConfig {
126- return getObjectOrNewInstance(EXPERIMENTAL_FEATURES , ExperimentalFeaturesConfig ::class .java)
127- }
128-
129111 fun isRegistrationEnabled (): Boolean {
130112 return getBoolean(REGISTRATION_ENABLED , true )
131113 }
132114
133- fun isLoginRegistrationEnabled (): Boolean {
134- return getBoolean(LOGIN_REGISTRATION_ENABLED , true )
135- }
136-
137- fun isSSOLoginEnabled (): Boolean {
138- return getBoolean(SAML_SSO_LOGIN_ENABLED , false )
139- }
140-
141- fun isSSODefaultLoginButton (): Boolean {
142- return getBoolean(SAML_SSO_DEFAULT_LOGIN_BUTTON , false )
115+ fun isBrowserLoginEnabled (): Boolean {
116+ return getBoolean(BROWSER_LOGIN , false )
143117 }
144118
145- fun getSSOButtonTitle (key : String , defaultValue : String ): String {
146- val element = getObject(SSO_BUTTON_TITLE )
147- return element?.asJsonObject?.get(key)?.asString ? : defaultValue
119+ fun isBrowserRegistrationEnabled (): Boolean {
120+ return getBoolean(BROWSER_REGISTRATION , false )
148121 }
149122
150123 private fun getString (key : String , defaultValue : String = ""): String {
@@ -170,26 +143,22 @@ class Config(context: Context) {
170143 try {
171144 cls.getDeclaredConstructor().newInstance()
172145 } catch (e: InstantiationException ) {
173- throw RuntimeException (e)
146+ throw ConfigParsingException (e)
174147 } catch (e: IllegalAccessException ) {
175- throw RuntimeException (e)
148+ throw ConfigParsingException (e)
176149 }
177150 }
178151 }
179152
153+ class ConfigParsingException (cause : Throwable ) : Exception(cause)
154+
180155 private fun getObject (key : String ): JsonElement ? {
181156 return configProperties.get(key)
182157 }
183158
184159 companion object {
185160 private const val APPLICATION_ID = " APPLICATION_ID"
186161 private const val API_HOST_URL = " API_HOST_URL"
187- private const val SSO_URL = " SSO_URL"
188- private const val SSO_FINISHED_URL = " SSO_FINISHED_URL"
189- private const val SSO_BUTTON_TITLE = " SSO_BUTTON_TITLE"
190- private const val SAML_SSO_LOGIN_ENABLED = " SAML_SSO_LOGIN_ENABLED"
191- private const val SAML_SSO_DEFAULT_LOGIN_BUTTON = " SAML_SSO_DEFAULT_LOGIN_BUTTON"
192- private const val LOGIN_REGISTRATION_ENABLED = " LOGIN_REGISTRATION_ENABLED"
193162 private const val URI_SCHEME = " URI_SCHEME"
194163 private const val OAUTH_CLIENT_ID = " OAUTH_CLIENT_ID"
195164 private const val TOKEN_TYPE = " TOKEN_TYPE"
@@ -204,13 +173,12 @@ class Config(context: Context) {
204173 private const val GOOGLE = " GOOGLE"
205174 private const val MICROSOFT = " MICROSOFT"
206175 private const val PRE_LOGIN_EXPERIENCE_ENABLED = " PRE_LOGIN_EXPERIENCE_ENABLED"
176+ private const val REGISTRATION_ENABLED = " REGISTRATION_ENABLED"
207177 private const val BROWSER_LOGIN = " BROWSER_LOGIN"
208178 private const val BROWSER_REGISTRATION = " BROWSER_REGISTRATION"
209- private const val REGISTRATION_ENABLED = " REGISTRATION_ENABLED"
210179 private const val DISCOVERY = " DISCOVERY"
211180 private const val PROGRAM = " PROGRAM"
212181 private const val DASHBOARD = " DASHBOARD"
213- private const val EXPERIMENTAL_FEATURES = " EXPERIMENTAL_FEATURES"
214182 private const val BRANCH = " BRANCH"
215183 private const val UI_COMPONENTS = " UI_COMPONENTS"
216184 private const val PLATFORM_NAME = " PLATFORM_NAME"
@@ -220,4 +188,4 @@ class Config(context: Context) {
220188 NATIVE ,
221189 WEBVIEW
222190 }
223- }
191+ }
0 commit comments