Skip to content

Commit

Permalink
Update connect and read timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
pawegio committed Sep 23, 2024
1 parent ac46a27 commit 7260eb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
25 changes: 21 additions & 4 deletions app/src/main/java/com/pawegio/homebudget/HomeBudgetApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +32,7 @@ import java.math.BigDecimal
import java.time.LocalDate
import java.time.Month


interface HomeBudgetApi {
val isSignedIn: Boolean
suspend fun signIn()
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 7260eb2

Please sign in to comment.