Skip to content

Commit dfa3fca

Browse files
JoeSilentJoeVladimir Yalovy
andauthored
[BKNDLSS-27029]: Android initApp with domain (#513)
* [BKNDLSS-27029]: Android initApp with domain Co-authored-by: Vladimir Yalovy <vladimir@themidnightcoders.com>
1 parent 1c7a5cb commit dfa3fca

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/com/backendless/AndroidBackendlessPrefs.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public void onCreate( Object context )
4747

4848
public String getApplicationId()
4949
{
50-
return getAuthKeys().getApplicationId();
50+
final AuthKeys authKeys = getAuthKeys();
51+
return authKeys == null ? null : authKeys.getApplicationId();
5152
}
5253

5354
public String getApiKey()
@@ -78,6 +79,30 @@ public String getUrl()
7879
return this.url;
7980
}
8081

82+
public AndroidBackendlessPrefs setCustomDomain( String customDomain )
83+
{
84+
if( sharedPreferences == null )
85+
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
86+
87+
SharedPreferences.Editor editor = sharedPreferences.edit();
88+
editor.putString( Type.CUSTOM_DOMAIN_KEY.name64(), customDomain );
89+
editor.commit();
90+
91+
this.customDomain = customDomain;
92+
return this;
93+
}
94+
95+
public String getCustomDomain()
96+
{
97+
if( sharedPreferences == null )
98+
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
99+
100+
if( this.customDomain == null )
101+
this.customDomain = sharedPreferences.getString( Type.CUSTOM_DOMAIN_KEY.name64(), Backendless.getUrl() );
102+
103+
return this.customDomain;
104+
}
105+
81106
public synchronized Map getHeaders()
82107
{
83108
if( headers == null )
@@ -90,7 +115,7 @@ private boolean restoreHeadersFromPreferences()
90115
{
91116
if( sharedPreferences == null )
92117
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
93-
118+
94119
String rawHeaders = sharedPreferences.getString( Type.HEADERS.name64(), null );
95120

96121
if( rawHeaders != null )
@@ -115,7 +140,7 @@ private synchronized AuthKeys getAuthKeys()
115140
if( authKeys == null )
116141
restoreAuthKeysFromPreferences();
117142

118-
if (authKeys == null)
143+
if( authKeys == null && getCustomDomain() == null )
119144
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
120145

121146
return authKeys;
@@ -125,7 +150,7 @@ private boolean restoreAuthKeysFromPreferences()
125150
{
126151
if( sharedPreferences == null )
127152
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
128-
153+
129154
String applicationId = sharedPreferences.getString( Type.APPLICATION_ID_KEY.name64(), null );
130155
String apiKey = sharedPreferences.getString( Type.API_KEY.name64(), null );
131156

@@ -165,7 +190,7 @@ private void cleanHeadersFromPreferences()
165190
{
166191
if( sharedPreferences == null )
167192
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );
168-
193+
169194
if( sharedPreferences.contains( Type.HEADERS.name64() ) )
170195
{
171196
SharedPreferences.Editor editor = sharedPreferences.edit();
@@ -203,6 +228,7 @@ enum Type
203228
APPLICATION_ID_KEY,
204229
API_KEY,
205230
URL_KEY,
231+
CUSTOM_DOMAIN_KEY,
206232
HEADERS,
207233
PUSH_TEMPLATES,
208234
NOTIFICATION_ID_GENERATOR;

0 commit comments

Comments
 (0)