From 7260eb29969c0e3b638e4fa19a88626cff11d11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gajda?= Date: Mon, 23 Sep 2024 23:42:49 +0200 Subject: [PATCH] Update connect and read timeouts --- app/build.gradle.kts | 4 +-- .../com/pawegio/homebudget/HomeBudgetApi.kt | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9fdc9fc..e19786d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -105,10 +105,10 @@ dependencies { implementation("org.koin:koin-androidx-viewmodel:2.2.2") implementation("com.google.android.material:material:1.9.0") implementation("com.google.android.gms:play-services-auth:20.6.0") - implementation("com.google.api-client:google-api-client-android:1.23.0") { + implementation("com.google.api-client:google-api-client-android:2.7.0") { exclude("org.apache.httpcomponents") } - implementation("com.google.apis:google-api-services-sheets:v4-rev581-1.25.0") { + implementation("com.google.apis:google-api-services-sheets:v4-rev612-1.25.0") { exclude("org.apache.httpcomponents") } implementation("com.github.raquezha:InlineActivityResult:1.0.0-jitpack") diff --git a/app/src/main/java/com/pawegio/homebudget/HomeBudgetApi.kt b/app/src/main/java/com/pawegio/homebudget/HomeBudgetApi.kt index 91bc6aa..875f5c3 100644 --- a/app/src/main/java/com/pawegio/homebudget/HomeBudgetApi.kt +++ b/app/src/main/java/com/pawegio/homebudget/HomeBudgetApi.kt @@ -8,13 +8,19 @@ import com.google.android.gms.auth.api.signin.GoogleSignIn import com.google.android.gms.auth.api.signin.GoogleSignInOptions import com.google.android.gms.common.api.ApiException import com.google.android.gms.common.api.Scope -import com.google.api.client.extensions.android.http.AndroidHttp import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException +import com.google.api.client.http.HttpRequestInitializer +import com.google.api.client.http.javanet.NetHttpTransport import com.google.api.client.json.jackson2.JacksonFactory import com.google.api.services.sheets.v4.Sheets import com.google.api.services.sheets.v4.SheetsScopes -import com.google.api.services.sheets.v4.model.* +import com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest +import com.google.api.services.sheets.v4.model.CellData +import com.google.api.services.sheets.v4.model.GridRange +import com.google.api.services.sheets.v4.model.RepeatCellRequest +import com.google.api.services.sheets.v4.model.Request +import com.google.api.services.sheets.v4.model.ValueRange import com.google.firebase.crashlytics.FirebaseCrashlytics import com.pawegio.homebudget.util.ColumnResolver import com.pawegio.homebudget.util.currentActivity @@ -26,6 +32,7 @@ import java.math.BigDecimal import java.time.LocalDate import java.time.Month + interface HomeBudgetApi { val isSignedIn: Boolean suspend fun signIn() @@ -66,12 +73,22 @@ class HomeBudgetApiImpl( private val sheetsService by lazy { credential.selectedAccount = account?.account?.takeIf { it.name != null } ?: repository.account Sheets.Builder( - AndroidHttp.newCompatibleTransport(), + NetHttpTransport(), JacksonFactory.getDefaultInstance(), credential - ).setApplicationName(USER_AGENT).build() + ) + .setApplicationName(USER_AGENT) + .setHttpRequestInitializer(createHttpRequestInitializer(credential)) + .build() } + private fun createHttpRequestInitializer(requestInitializer: HttpRequestInitializer): HttpRequestInitializer = + HttpRequestInitializer { httpRequest -> + requestInitializer.initialize(httpRequest) + httpRequest.setConnectTimeout(3 * 60_000) + httpRequest.setReadTimeout(3 * 60_000) + } + private val spreadsheetId get() = repository.spreadsheetId override suspend fun signIn() {