Skip to content

Commit

Permalink
[BKNDLSS-27029]: Android initApp with domain (#513)
Browse files Browse the repository at this point in the history
* [BKNDLSS-27029]: Android initApp with domain

Co-authored-by: Vladimir Yalovy <[email protected]>
  • Loading branch information
JoeSilentJoe and Vladimir Yalovy authored Dec 8, 2021
1 parent 1c7a5cb commit dfa3fca
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/com/backendless/AndroidBackendlessPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void onCreate( Object context )

public String getApplicationId()
{
return getAuthKeys().getApplicationId();
final AuthKeys authKeys = getAuthKeys();
return authKeys == null ? null : authKeys.getApplicationId();
}

public String getApiKey()
Expand Down Expand Up @@ -78,6 +79,30 @@ public String getUrl()
return this.url;
}

public AndroidBackendlessPrefs setCustomDomain( String customDomain )
{
if( sharedPreferences == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString( Type.CUSTOM_DOMAIN_KEY.name64(), customDomain );
editor.commit();

this.customDomain = customDomain;
return this;
}

public String getCustomDomain()
{
if( sharedPreferences == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

if( this.customDomain == null )
this.customDomain = sharedPreferences.getString( Type.CUSTOM_DOMAIN_KEY.name64(), Backendless.getUrl() );

return this.customDomain;
}

public synchronized Map getHeaders()
{
if( headers == null )
Expand All @@ -90,7 +115,7 @@ private boolean restoreHeadersFromPreferences()
{
if( sharedPreferences == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

String rawHeaders = sharedPreferences.getString( Type.HEADERS.name64(), null );

if( rawHeaders != null )
Expand All @@ -115,7 +140,7 @@ private synchronized AuthKeys getAuthKeys()
if( authKeys == null )
restoreAuthKeysFromPreferences();

if (authKeys == null)
if( authKeys == null && getCustomDomain() == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

return authKeys;
Expand All @@ -125,7 +150,7 @@ private boolean restoreAuthKeysFromPreferences()
{
if( sharedPreferences == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

String applicationId = sharedPreferences.getString( Type.APPLICATION_ID_KEY.name64(), null );
String apiKey = sharedPreferences.getString( Type.API_KEY.name64(), null );

Expand Down Expand Up @@ -165,7 +190,7 @@ private void cleanHeadersFromPreferences()
{
if( sharedPreferences == null )
throw new IllegalStateException( ExceptionMessage.NOT_INITIALIZED );

if( sharedPreferences.contains( Type.HEADERS.name64() ) )
{
SharedPreferences.Editor editor = sharedPreferences.edit();
Expand Down Expand Up @@ -203,6 +228,7 @@ enum Type
APPLICATION_ID_KEY,
API_KEY,
URL_KEY,
CUSTOM_DOMAIN_KEY,
HEADERS,
PUSH_TEMPLATES,
NOTIFICATION_ID_GENERATOR;
Expand Down

0 comments on commit dfa3fca

Please sign in to comment.