-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SdkComponent and move configuration fetch out of BraintreeClient (#…
…1203) * Move getting configuration out of BraintreeClient and move dependencies that require context to a SdkComponent singleton * Update unit tests * Add latency analytics event to configuration call * Add a TODO for removing the circular dependency between AnalyticsClient and ConfigurationLoader
Showing
13 changed files
with
325 additions
and
200 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
4 changes: 1 addition & 3 deletions
4
BraintreeCore/src/main/java/com/braintreepayments/api/core/ConfigurationLoaderCallback.kt
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package com.braintreepayments.api.core | ||
|
||
import com.braintreepayments.api.sharedutils.HttpResponseTiming | ||
|
||
internal fun interface ConfigurationLoaderCallback { | ||
fun onResult(result: Configuration?, error: Exception?, timing: HttpResponseTiming?) | ||
fun onResult(result: ConfigurationLoaderResult) | ||
} |
16 changes: 16 additions & 0 deletions
16
BraintreeCore/src/main/java/com/braintreepayments/api/core/ConfigurationLoaderResult.kt
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,16 @@ | ||
package com.braintreepayments.api.core | ||
|
||
import com.braintreepayments.api.sharedutils.HttpResponseTiming | ||
|
||
/** | ||
* Result of calling [ConfigurationLoader.loadConfiguration] | ||
*/ | ||
internal sealed class ConfigurationLoaderResult { | ||
|
||
data class Success( | ||
val configuration: Configuration, | ||
val timing: HttpResponseTiming? = null | ||
) : ConfigurationLoaderResult() | ||
|
||
data class Failure(val error: Exception) : ConfigurationLoaderResult() | ||
} |
2 changes: 1 addition & 1 deletion
2
BraintreeCore/src/main/java/com/braintreepayments/api/core/CoreAnalytics.kt
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.braintreepayments.api.core | ||
|
||
internal object CoreAnalytics { | ||
const val apiRequestLatency = "core:api-request-latency" | ||
const val API_REQUEST_LATENCY = "core:api-request-latency" | ||
} |
51 changes: 51 additions & 0 deletions
51
BraintreeCore/src/main/java/com/braintreepayments/api/core/SdkComponent.kt
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,51 @@ | ||
package com.braintreepayments.api.core | ||
|
||
import android.content.Context | ||
import androidx.work.WorkManager | ||
|
||
/** | ||
* Component class that is created when the BT SDK is launched. It contains dependencies that need to be injected that | ||
* contain Context. | ||
*/ | ||
internal class SdkComponent( | ||
applicationContext: Context, | ||
) { | ||
val analyticsDatabase: AnalyticsDatabase = AnalyticsDatabase.getInstance(applicationContext) | ||
val workManager: WorkManager = WorkManager.getInstance(applicationContext) | ||
val configurationCache: ConfigurationCache = ConfigurationCache.getInstance(applicationContext) | ||
|
||
companion object { | ||
private var instance: SdkComponent? = null | ||
|
||
/** | ||
* Creates and returns a new instance of [SdkComponent], or returns the existing instance. | ||
*/ | ||
fun create(applicationContext: Context): SdkComponent { | ||
return instance ?: SdkComponent(applicationContext).also { sdkComponent -> | ||
instance = sdkComponent | ||
} | ||
} | ||
|
||
/** | ||
* Returns the instance of [SdkComponent] | ||
*/ | ||
fun getInstance(): SdkComponent { | ||
return checkNotNull(instance) | ||
} | ||
} | ||
} | ||
|
||
internal class AnalyticsDatabaseProvider { | ||
val analyticsDatabase: AnalyticsDatabase | ||
get() = SdkComponent.getInstance().analyticsDatabase | ||
} | ||
|
||
internal class WorkManagerProvider { | ||
val workManager: WorkManager | ||
get() = SdkComponent.getInstance().workManager | ||
} | ||
|
||
internal class ConfigurationCacheProvider { | ||
val configurationCache: ConfigurationCache | ||
get() = SdkComponent.getInstance().configurationCache | ||
} |
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