diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e63c7fe..113fcfc 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -125,7 +125,7 @@ android { abortOnError = false } composeOptions { - kotlinCompilerExtensionVersion = "1.5.14" + kotlinCompilerExtensionVersion = "1.5.15" } packaging { resources.excludes.addAll( diff --git a/app/src/main/kotlin/nl/eduid/di/module/EduIdModule.kt b/app/src/main/kotlin/nl/eduid/di/module/EduIdModule.kt index d11e604..31992d8 100644 --- a/app/src/main/kotlin/nl/eduid/di/module/EduIdModule.kt +++ b/app/src/main/kotlin/nl/eduid/di/module/EduIdModule.kt @@ -20,6 +20,7 @@ import nl.eduid.di.auth.TokenProvider import nl.eduid.di.repository.EduIdRepository import nl.eduid.di.repository.StorageRepository import nl.eduid.env.EnvironmentProvider +import nl.eduid.network.ConnectivityInterceptor import nl.eduid.screens.personalinfo.PersonalInfoRepository import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor @@ -31,9 +32,7 @@ import retrofit2.converter.scalars.ScalarsConverterFactory import java.util.concurrent.TimeUnit import javax.inject.Singleton -/** - * Module which serves the repositories. - */ +/** Module which serves the repositories. */ @Module @InstallIn(SingletonComponent::class) internal object RepositoryModule { @@ -86,12 +85,13 @@ internal object RepositoryModule { okHttpClient: OkHttpClient, ): OkHttpClient { val builder = okHttpClient.newBuilder() - if (BuildConfig.BUILD_TYPE == "debug") { + if (BuildConfig.DEBUG) { builder.addInterceptor(loggingInterceptor) } return builder.addInterceptor(tokenInterceptor) .authenticator(tokenAuthenticator) + .addInterceptor(ConnectivityInterceptor()) .build() } diff --git a/app/src/main/kotlin/nl/eduid/network/ConnectivityInterceptor.kt b/app/src/main/kotlin/nl/eduid/network/ConnectivityInterceptor.kt new file mode 100644 index 0000000..362a70e --- /dev/null +++ b/app/src/main/kotlin/nl/eduid/network/ConnectivityInterceptor.kt @@ -0,0 +1,40 @@ +package nl.eduid.network + +import android.net.TrafficStats +import okhttp3.Interceptor +import okhttp3.Protocol +import okhttp3.Response +import okhttp3.ResponseBody.Companion.toResponseBody +import timber.log.Timber +import java.net.HttpURLConnection +import java.net.SocketTimeoutException +import java.net.UnknownHostException + +class ConnectivityInterceptor : Interceptor { + private companion object { + const val NO_INTERNET = "No internet connection" + } + + override fun intercept(chain: Interceptor.Chain): Response { + TrafficStats.setThreadStatsTag(Thread.currentThread().id.toInt()) + return try { + chain.proceed(chain.request()) + } catch (e: UnknownHostException) { + processException(e, chain) + } catch (e: SocketTimeoutException) { + processException(e, chain) + } + } + + private fun processException(e: Exception, chain: Interceptor.Chain): Response { + Timber.d("$NO_INTERNET: exception ${e.message}", e) + return Response + .Builder() + .code(HttpURLConnection.HTTP_CLIENT_TIMEOUT) + .message(NO_INTERNET) + .request(chain.request()) + .protocol(Protocol.HTTP_1_1) + .body(NO_INTERNET.toResponseBody(null)) + .build() + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index b015671..ac14b5b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,4 +6,5 @@ plugins { alias(libs.plugins.ksp) apply false alias(libs.plugins.hilt) apply false alias(libs.plugins.google.gms.gradle) apply false + alias(libs.plugins.kotlinx.serializer) apply false } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 83fd7fe..64770df 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,24 +3,24 @@ android-sdk-compile = "34" android-sdk-target = "34" android-sdk-min = "24" - androidGradlePlugin = "8.2.2" hilt = "2.51.1" -kotlin = "1.9.24" -ksp = "1.9.24-1.0.20" +kotlin = "1.9.25" +ksp = "1.9.25-1.0.20" gmsServicePlugin = "4.4.2" -androidxComposeBom = "2024.05.00" -coroutines = "1.8.0" +androidxComposeBom = "2024.08.00" +coroutines = "1.8.1" navigation = "2.7.7" room = "2.6.1" #Lifecycle version must match the compose version: "To use Lifecycle 2.8.0-alpha03, ensure you are using at least Compose UI 1.7.0-alpha05." #https://issuetracker.google.com/issues/336842920 -lifecycle = "2.7.0" -camera = "1.3.3" +lifecycle = "2.8.4" +camera = "1.3.4" okhttp = "4.12.0" retrofit = "2.11.0" moshi = "1.15.1" rebugger = "1.0.0-rc02" +kotlinx-serialization = "1.6.3" [libraries] @@ -30,22 +30,22 @@ kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-c kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" } kotlinx-coroutines-playServices = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-play-services", version.ref = "coroutines" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization" } -dagger-hilt-gradle = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "hilt" } dagger-hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" } dagger-hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" } dagger-hilt-testing = { module = "com.google.dagger:hilt-android-testing", version.ref = "hilt" } dagger-hilt-fragment = "androidx.hilt:hilt-navigation-fragment:1.2.0" -androidx-activity = "androidx.activity:activity-ktx:1.9.0" +androidx-activity = "androidx.activity:activity-ktx:1.9.1" androidx-autofill = "androidx.autofill:autofill:1.1.0" androidx-biometric = "androidx.biometric:biometric-ktx:1.2.0-alpha05" #Compose BOM androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidxComposeBom" } -androidx-compose-activity = "androidx.activity:activity-compose:1.9.0" +androidx-compose-activity = "androidx.activity:activity-compose:1.9.1" androidx-compose-navigation = "androidx.navigation:navigation-compose:2.7.7" androidx-compose-hilt-navigation = "androidx.hilt:hilt-navigation-compose:1.2.0" -androidx-concurrent = "androidx.concurrent:concurrent-futures-ktx:1.1.0" +androidx-concurrent = "androidx.concurrent:concurrent-futures-ktx:1.2.0" androidx-constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.4" androidx-compose-constraint = "androidx.constraintlayout:constraintlayout-compose:1.0.1" androidx-core = "androidx.core:core-ktx:1.13.1" @@ -53,10 +53,10 @@ androidx-datastore = "androidx.datastore:datastore-preferences:1.1.1" androidx-localBroadcastManager = "androidx.localbroadcastmanager:localbroadcastmanager:1.1.0" androidx-recyclerview = "androidx.recyclerview:recyclerview:1.3.2" androidx-splashscreen = "androidx.core:core-splashscreen:1.0.1" -androidx-testing-core = "androidx.test:core-ktx:1.6.0-beta01" -androidx-testing-epsresso = "androidx.test.espresso:espresso-core:3.6.0-beta01" -androidx-testing-junit = "androidx.test.ext:junit-ktx:1.2.0-beta01" -androidx-testing-rules = "androidx.test:rules:1.6.0-beta01" +androidx-testing-core = "androidx.test:core-ktx:1.6.1" +androidx-testing-epsresso = "androidx.test.espresso:espresso-core:3.6.1" +androidx-testing-junit = "androidx.test.ext:junit-ktx:1.2.1" +androidx-testing-rules = "androidx.test:rules:1.6.1" androidx-testing-uiautomator = "androidx.test.uiautomator:uiautomator:2.3.0" androidx-lifecycle-common = { module = "androidx.lifecycle:lifecycle-common-java8", version.ref = "lifecycle" } @@ -83,8 +83,8 @@ androidx-camera-view = { module = "androidx.camera:camera-view", version.ref = " appauth = "net.openid:appauth:0.11.1" jwtdecode = "com.auth0.android:jwtdecode:2.0.2" google-android-material = "com.google.android.material:material:1.12.0" -google-mlkit-barcode = "com.google.mlkit:barcode-scanning:17.2.0" -google-firebase-messaging = "com.google.firebase:firebase-messaging-ktx:24.0.0" +google-mlkit-barcode = "com.google.mlkit:barcode-scanning:17.3.0" +google-firebase-messaging = "com.google.firebase:firebase-messaging-ktx:24.0.1" material3-html-text = "de.charlex.compose.material3:material3-html-text:2.0.0-beta01" okhttp-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } @@ -93,22 +93,21 @@ okhttp-logging = { module = "com.squareup.okhttp3:logging-interceptor", version. retrofit-retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" } retrofit-converter-moshi = { module = "com.squareup.retrofit2:converter-moshi", version.ref = "retrofit" } retrofit-converter-scalars = { module = "com.squareup.retrofit2:converter-scalars", version.ref = "retrofit" } +retrofit-converter-standard = { module = "com.squareup.retrofit2:converter-kotlinx-serialization", version.ref = "retrofit" } moshi-moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" } moshi-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshi" } rebugger = { module = "io.github.theapache64:rebugger", version.ref = "rebugger" } permission = "com.github.fondesa:kpermissions:3.4.0" -coil = "io.coil-kt:coil:2.6.0" -coilCompose = "io.coil-kt:coil-compose:2.6.0" +coil = "io.coil-kt:coil:2.7.0" +coilCompose = "io.coil-kt:coil-compose:2.7.0" betterLink = "me.saket:better-link-movement-method:2.2.0" timber = "com.jakewharton.timber:timber:5.0.1" junit = "junit:junit:4.13.2" # Dependencies of the included build-logic -android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" } -kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" } androidx-lifecycle-process = { group = "androidx.lifecycle", name = "lifecycle-process", version.ref = "lifecycle" } [plugins] @@ -118,7 +117,6 @@ android-nav-safeargs = { id = "androidx.navigation.safeargs", version.ref = "nav google-gms-gradle = { id = "com.google.gms.google-services", version.ref = "gmsServicePlugin" } hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } -kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } -kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlinx-serializer = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }