diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 6fd1f7c..cbe2830 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -4,7 +4,7 @@ on: pull_request: jobs: - test: + build: runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v4 diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 64dd6dd..fc56988 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + + android:theme="@style/Theme.UnleashAndroid"> Unit) { +fun UnleashAndroidTheme(content: @Composable () -> Unit) { MaterialTheme( colorScheme = MaterialTheme.colorScheme.copy( diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e2e5330..40c7f09 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,19 +3,19 @@ agp = "8.4.2" kotlin = "1.9.0" coreKtx = "1.13.1" junit = "4.13.2" -androidxTestExt = "1.1.5" -espressoCore = "3.5.1" +androidxTestExt = "1.2.1" +espressoCore = "3.6.1" appcompat = "1.7.0" material = "1.12.0" work = "2.9.0" okhttp = "4.12.0" jackson = "2.17.1" assertj = "3.26.0" -lifecycleProcess = "2.8.2" -kotlinxCoroutinesTest = "1.7.1" -activityCompose = "1.8.0" +lifecycleProcess = "2.8.3" +kotlinxCoroutinesTest = "1.7.3" +activityCompose = "1.9.0" runtimeLivedata = "1.6.8" -material3 = "1.0.0" +material3 = "1.2.1" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } diff --git a/unleashandroidsdk/src/main/java/io/getunleash/android/DefaultUnleash.kt b/unleashandroidsdk/src/main/java/io/getunleash/android/DefaultUnleash.kt index 9d19ce0..88bfa6d 100644 --- a/unleashandroidsdk/src/main/java/io/getunleash/android/DefaultUnleash.kt +++ b/unleashandroidsdk/src/main/java/io/getunleash/android/DefaultUnleash.kt @@ -11,10 +11,10 @@ import io.getunleash.android.cache.InMemoryToggleCache import io.getunleash.android.cache.ObservableCache import io.getunleash.android.cache.ObservableToggleCache import io.getunleash.android.cache.ToggleCache -import io.getunleash.android.data.DataStrategy import io.getunleash.android.data.UnleashContext import io.getunleash.android.data.Variant import io.getunleash.android.events.UnleashEventListener +import io.getunleash.android.http.ClientBuilder import io.getunleash.android.http.NetworkStatusHelper import io.getunleash.android.metrics.MetricsCollector import io.getunleash.android.metrics.MetricsSender @@ -34,10 +34,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeout -import okhttp3.Cache -import okhttp3.OkHttpClient import okhttp3.internal.toImmutableList -import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicBoolean @@ -69,17 +66,18 @@ class DefaultUnleash( private val networkStatusHelper = NetworkStatusHelper(androidContext) init { + val httpClientBuilder = ClientBuilder(unleashConfig, androidContext) val metricsSender = if (unleashConfig.metricsStrategy.enabled) MetricsSender( unleashConfig, - buildHttpClient("metrics", androidContext, unleashConfig.metricsStrategy) + httpClientBuilder.build("metrics", unleashConfig.metricsStrategy) ) else NoOpMetrics() fetcher = if (unleashConfig.pollingStrategy.enabled) UnleashFetcher( unleashConfig, - buildHttpClient("poller", androidContext, unleashConfig.pollingStrategy), + httpClientBuilder.build("poller", unleashConfig.pollingStrategy), unleashContextState.asStateFlow() ) else null metrics = metricsSender @@ -146,27 +144,6 @@ class DefaultUnleash( return localBackup } - private fun buildHttpClient( - clientName: String, - androidContext: Context, - strategy: DataStrategy - ): OkHttpClient { - return OkHttpClient.Builder() - .readTimeout(strategy.httpReadTimeout, TimeUnit.MILLISECONDS) - .connectTimeout(strategy.httpConnectionTimeout, TimeUnit.MILLISECONDS) - .cache( - Cache( - directory = CacheDirectoryProvider( - unleashConfig.localStorageConfig, - androidContext - ).getCacheDirectory( - "unleash_${clientName}_http_cache", true - ), - maxSize = strategy.httpCacheSize - ) - ).build() - } - override fun isEnabled(toggleName: String, defaultValue: Boolean): Boolean { val enabled = cache.get(toggleName)?.enabled ?: defaultValue metrics.count(toggleName, enabled) diff --git a/unleashandroidsdk/src/main/java/io/getunleash/android/http/ClientBuilder.kt b/unleashandroidsdk/src/main/java/io/getunleash/android/http/ClientBuilder.kt new file mode 100644 index 0000000..01f86b3 --- /dev/null +++ b/unleashandroidsdk/src/main/java/io/getunleash/android/http/ClientBuilder.kt @@ -0,0 +1,31 @@ +package io.getunleash.android.http + +import android.content.Context +import io.getunleash.android.UnleashConfig +import io.getunleash.android.cache.CacheDirectoryProvider +import io.getunleash.android.data.DataStrategy +import okhttp3.Cache +import okhttp3.OkHttpClient +import java.util.concurrent.TimeUnit + +class ClientBuilder(private val unleashConfig: UnleashConfig, private val androidContext: Context) { + fun build( + clientName: String, + strategy: DataStrategy + ): OkHttpClient { + return OkHttpClient.Builder() + .readTimeout(strategy.httpReadTimeout, TimeUnit.MILLISECONDS) + .connectTimeout(strategy.httpConnectionTimeout, TimeUnit.MILLISECONDS) + .cache( + Cache( + directory = CacheDirectoryProvider( + unleashConfig.localStorageConfig, + androidContext + ).getCacheDirectory( + "unleash_${clientName}_http_cache", true + ), + maxSize = strategy.httpCacheSize + ) + ).build() + } +} \ No newline at end of file