@@ -30,18 +30,23 @@ object GliaWidgetsConfigManager {
30
30
saveVisitorContextAssetIdIfPresent(data, applicationContext)
31
31
saveSiteIdToPrefs(data, applicationContext)
32
32
33
- // We're not checking availability for every query param separately because this is for acceptance tests and we assume that link would be correct
34
- return if (SECRET_KEY == data.lastPathSegment) {
33
+ // We're not checking availability for every query param separately because this is for acceptance tests and we assume that link would be correct
34
+ if (SECRET_KEY == data.lastPathSegment) {
35
35
saveSiteApiKeyAuthToPrefs(data, applicationContext)
36
- obtainConfigFromSecretDeepLink(data, applicationContext)
37
36
} else {
38
37
throw RuntimeException (" deep link must start with \" glia://widgets/secret\" " )
39
38
}
39
+
40
+ // By this point all settings from deep link where saved to the shared prefs overriding the
41
+ // defaults combining both together
42
+ return createDefaultConfig(
43
+ context = applicationContext,
44
+ region = REGION_ACCEPTANCE
45
+ )
40
46
}
41
47
42
48
private fun saveVisitorContextAssetIdIfPresent (data : Uri , applicationContext : Context ) {
43
- val visitorContextAssetId = data.getQueryParameter(VISITOR_CONTEXT_ASSET_ID_KEY )
44
- ? : return
49
+ val visitorContextAssetId = data.getQueryParameter(VISITOR_CONTEXT_ASSET_ID_KEY ) ? : return
45
50
val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(applicationContext)
46
51
sharedPreferences.edit().putString(
47
52
applicationContext.getString(R .string.pref_context_asset_id),
@@ -53,14 +58,16 @@ object GliaWidgetsConfigManager {
53
58
val queueId = data.getQueryParameter(QUEUE_ID_KEY ) ? : return
54
59
val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(applicationContext)
55
60
sharedPreferences.edit()
56
- .putString(applicationContext.getString(R .string.pref_queue_id), queueId).apply ()
61
+ .putString(applicationContext.getString(R .string.pref_queue_id), queueId)
62
+ .apply ()
57
63
}
58
64
59
65
private fun saveSiteIdToPrefs (data : Uri , applicationContext : Context ) {
60
66
val siteId = data.getQueryParameter(SITE_ID_KEY ) ? : return
61
67
val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(applicationContext)
62
68
sharedPreferences.edit()
63
- .putString(applicationContext.getString(R .string.pref_site_id), siteId).apply ()
69
+ .putString(applicationContext.getString(R .string.pref_site_id), siteId)
70
+ .apply ()
64
71
}
65
72
66
73
private fun saveSiteApiKeyAuthToPrefs (data : Uri , applicationContext : Context ) {
@@ -74,60 +81,32 @@ object GliaWidgetsConfigManager {
74
81
.apply ()
75
82
}
76
83
77
- private fun obtainConfigFromSecretDeepLink (
78
- data : Uri ,
79
- applicationContext : Context
80
- ): GliaWidgetsConfig {
81
- return GliaWidgetsConfig .Builder ()
82
- .setSiteApiKey(
83
- SiteApiKey (
84
- data.getQueryParameter(API_KEY_ID_KEY )!! , data.getQueryParameter(
85
- API_KEY_SECRET_KEY
86
- )!!
87
- )
88
- )
89
- .setSiteId(data.getQueryParameter(SITE_ID_KEY ))
90
- .setRegion(REGION_ACCEPTANCE )
91
- .setContext(applicationContext)
92
- .build()
93
- }
94
-
84
+ @JvmStatic
95
85
@JvmOverloads
96
86
fun createDefaultConfig (
97
- applicationContext : Context ,
98
- uiJsonRemoteConfig : String? = null
99
- ): GliaWidgetsConfig {
100
- val sharedPreferences = PreferenceManager .getDefaultSharedPreferences(applicationContext)
101
- return configWithSiteApiKeyAuth(sharedPreferences, applicationContext, uiJsonRemoteConfig)
102
- }
103
-
104
- private fun configWithSiteApiKeyAuth (
105
- preferences : SharedPreferences ,
106
- applicationContext : Context ,
107
- uiJsonRemoteConfig : String?
87
+ context : Context ,
88
+ preferences : SharedPreferences = PreferenceManager .getDefaultSharedPreferences(context),
89
+ uiJsonRemoteConfig : String? = null,
90
+ region : String = REGION_BETA
108
91
): GliaWidgetsConfig {
109
92
val apiKeyId = preferences.getString(
110
- applicationContext .getString(R .string.pref_api_key_id),
111
- applicationContext .getString(R .string.glia_api_key_id)
93
+ context .getString(R .string.pref_api_key_id),
94
+ context .getString(R .string.glia_api_key_id)
112
95
)
113
96
val apiKeySecret = preferences.getString(
114
- applicationContext .getString(R .string.pref_api_key_secret),
115
- applicationContext .getString(R .string.glia_api_key_secret)
97
+ context .getString(R .string.pref_api_key_secret),
98
+ context .getString(R .string.glia_api_key_secret)
116
99
)
117
100
val siteId = preferences.getString(
118
- applicationContext .getString(R .string.pref_site_id),
119
- applicationContext .getString(R .string.site_id)
101
+ context .getString(R .string.pref_site_id),
102
+ context .getString(R .string.site_id)
120
103
)
121
- val companyName =
122
- preferences.getString(applicationContext.getString(R .string.pref_company_name), " " )
123
- val useOverlay =
124
- preferences.getBoolean(applicationContext.getString(R .string.pref_use_overlay), true )
125
- val bounded = applicationContext.getString(R .string.screen_sharing_mode_app_bounded)
126
- val unbounded = applicationContext.getString(R .string.screen_sharing_mode_unbounded)
127
- val screenSharingMode: ScreenSharing .Mode
128
- screenSharingMode = if (preferences.getString(
129
- applicationContext.getString(R .string.pref_screen_sharing_mode),
130
- unbounded
104
+ val companyName = preferences.getString(context.getString(R .string.pref_company_name), " " )
105
+ val useOverlay = preferences.getBoolean(context.getString(R .string.pref_use_overlay), true )
106
+ val bounded = context.getString(R .string.screen_sharing_mode_app_bounded)
107
+ val unbounded = context.getString(R .string.screen_sharing_mode_unbounded)
108
+ val screenSharingMode = if (preferences.getString(
109
+ context.getString(R .string.pref_screen_sharing_mode), unbounded
131
110
) == bounded
132
111
) {
133
112
ScreenSharing .Mode .APP_BOUNDED
@@ -137,11 +116,11 @@ object GliaWidgetsConfigManager {
137
116
return GliaWidgetsConfig .Builder ()
138
117
.setSiteApiKey(SiteApiKey (apiKeyId!! , apiKeySecret!! ))
139
118
.setSiteId(siteId)
140
- .setRegion(REGION_BETA )
119
+ .setRegion(region )
141
120
.setCompanyName(companyName)
142
121
.setUseOverlay(useOverlay)
143
122
.setScreenSharingMode(screenSharingMode)
144
- .setContext(applicationContext )
123
+ .setContext(context )
145
124
.setUiJsonRemoteConfig(uiJsonRemoteConfig)
146
125
.build()
147
126
}
0 commit comments