Skip to content

Commit

Permalink
Fix token not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Li committed May 24, 2021
1 parent fdaefbe commit 58566ee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
7 changes: 5 additions & 2 deletions sdk/src/main/java/com/mapbox/maps/MapInitOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ fun MapOptions.Builder.applyDefaultParams(context: Context): MapOptions.Builder
* Get a default [ResourceOptions.Builder] with token from default [CredentialsManager]
* @property context the context of the application.
*/
fun ResourceOptions.Builder.applyDefaultParams(context: Context): ResourceOptions.Builder = also {
fun ResourceOptions.Builder.applyDefaultParams(
context: Context,
token: String? = null
): ResourceOptions.Builder = also {
// make sure that directory `/mapbox/maps` exists
val databaseDirectoryPath = "${context.filesDir.absolutePath}/$DATABASE_PATH"
val databaseDirectory = File(databaseDirectoryPath)
Expand All @@ -104,7 +107,7 @@ fun ResourceOptions.Builder.applyDefaultParams(context: Context): ResourceOption
}
}

accessToken(CredentialsManager.default.getAccessToken(context))
accessToken(token ?: CredentialsManager.default.getAccessToken(context))
cachePath("$databaseDirectoryPath/$DATABASE_NAME")
cacheSize(DEFAULT_CACHE_SIZE) // 50 mb
}
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/mapbox/maps/ResourceOptionsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class ResourceOptionsManager(
* The default shared instance with default resource options.
*/
@Synchronized
fun getDefault(context: Context): ResourceOptionsManager {
fun getDefault(context: Context, token: String? = null): ResourceOptionsManager {
if (!this::default.isInitialized) {
default = ResourceOptionsManager(
ResourceOptions.Builder().applyDefaultParams(context)
ResourceOptions.Builder().applyDefaultParams(context, token)
.build()
)
}
Expand Down
9 changes: 2 additions & 7 deletions sdk/src/main/java/com/mapbox/maps/ResourcesAttributeParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@ internal object ResourcesAttributeParser {
typedArray: TypedArray,
credentialsManager: CredentialsManager
): ResourceOptions {
val builder = ResourceOptionsManager.getDefault(context).resourceOptions.toBuilder()

if (typedArray.hasValue(R.styleable.mapbox_MapView_mapbox_resourcesAccessToken)) {
builder.accessToken(
typedArray.getString(R.styleable.mapbox_MapView_mapbox_resourcesAccessToken)
?: credentialsManager.getAccessToken(context)
)
}
val token = typedArray.getString(R.styleable.mapbox_MapView_mapbox_resourcesAccessToken)
val builder = ResourceOptionsManager.getDefault(context, token).resourceOptions.toBuilder()

if (typedArray.hasValue(R.styleable.mapbox_MapView_mapbox_resourcesBaseUrl)) {
builder.baseURL(typedArray.getString(R.styleable.mapbox_MapView_mapbox_resourcesBaseUrl))
Expand Down

0 comments on commit 58566ee

Please sign in to comment.