-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '36-introduce-setup-for-cloudsdk' into 'master'
Resolve "Introduce setup for CloudSDK" Closes #36 See merge request pace/mobile/android/pace-cloud-sdk!30
- Loading branch information
Showing
38 changed files
with
361 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cloud.pace.sdk | ||
|
||
import android.content.Context | ||
import cloud.pace.sdk.api.API | ||
import cloud.pace.sdk.appkit.AppKit | ||
import cloud.pace.sdk.appkit.persistence.SharedPreferencesModel | ||
import cloud.pace.sdk.utils.CloudSDKKoinComponent | ||
import cloud.pace.sdk.utils.Configuration | ||
import cloud.pace.sdk.utils.KoinConfig | ||
import org.koin.core.inject | ||
|
||
object PACECloudSDK : CloudSDKKoinComponent { | ||
|
||
private val sharedPreferencesModel: SharedPreferencesModel by inject() | ||
internal lateinit var configuration: Configuration | ||
|
||
/** | ||
* Sets up [PACECloudSDK] with the passed [configuration]. | ||
* This needs to be called before any of its "Kits" can be used. | ||
* | ||
* @param context The context. | ||
*/ | ||
fun setup(context: Context, configuration: Configuration) { | ||
this.configuration = configuration | ||
|
||
API.setupAPI("${configuration.environment.apiUrl}/poi/2020-4/", configuration.apiKey, emptyMap()) | ||
AppKit.locationAccuracy = configuration.locationAccuracy | ||
KoinConfig.setupCloudSDK(context, configuration.environment, configuration.apiKey) | ||
AppKit.updateUserAgent() | ||
sharedPreferencesModel.deleteAllAppStates() | ||
} | ||
|
||
/** | ||
* Replaces the list of optional [extensions] at the end of the user agent (separated with a space). | ||
*/ | ||
fun setUserAgentExtensions(extensions: List<String>) { | ||
if (::configuration.isInitialized) { | ||
configuration.extensions = extensions | ||
AppKit.updateUserAgent() | ||
} | ||
} | ||
|
||
internal fun setLocationAccuracy(locationAccuracy: Int?) { | ||
if (::configuration.isInitialized) { | ||
configuration.locationAccuracy = locationAccuracy | ||
} | ||
} | ||
|
||
internal fun setAccessToken(accessToken: String?) { | ||
if (::configuration.isInitialized) { | ||
configuration.accessToken = accessToken | ||
AppKit.updateUserAgent() | ||
} | ||
} | ||
|
||
internal fun resetAccessToken() { | ||
if (::configuration.isInitialized) { | ||
configuration.accessToken = null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.