diff --git a/packages/google_sign_in/google_sign_in_android/CHANGELOG.md b/packages/google_sign_in/google_sign_in_android/CHANGELOG.md index cebeb8c017f0..38624c575a70 100644 --- a/packages/google_sign_in/google_sign_in_android/CHANGELOG.md +++ b/packages/google_sign_in/google_sign_in_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 7.2.9 + +* Simplifies internal code for Kotlin/Java interoperability. + ## 7.2.8 * Bumps kotlin_version to 2.3.0. diff --git a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java index a04cefff1c17..505eb38ff835 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java +++ b/packages/google_sign_in/google_sign_in_android/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java @@ -215,7 +215,7 @@ public void getCredential( try { String serverClientId = params.getServerClientId(); if (serverClientId == null || serverClientId.isEmpty()) { - ResultUtilsKt.completeWithGetCredentialFailure( + ResultUtilsKt.completeWithValue( callback, new GetCredentialFailure( GetCredentialFailureType.MISSING_SERVER_CLIENT_ID, @@ -228,7 +228,7 @@ public void getCredential( // the API docs. Activity activity = getActivity(); if (activity == null) { - ResultUtilsKt.completeWithGetCredentialFailure( + ResultUtilsKt.completeWithValue( callback, new GetCredentialFailure( GetCredentialFailureType.NO_ACTIVITY, "No activity available", null)); @@ -280,7 +280,7 @@ public void onResult(GetCredentialResponse response) { GoogleIdTokenCredential googleIdTokenCredential = credentialConverter.createFrom(credential); Uri profilePictureUri = googleIdTokenCredential.getProfilePictureUri(); - ResultUtilsKt.completeWithGetGetCredentialResult( + ResultUtilsKt.completeWithValue( callback, new GetCredentialSuccess( new PlatformGoogleIdTokenCredential( @@ -291,7 +291,7 @@ public void onResult(GetCredentialResponse response) { googleIdTokenCredential.getIdToken(), profilePictureUri == null ? null : profilePictureUri.toString()))); } else { - ResultUtilsKt.completeWithGetCredentialFailure( + ResultUtilsKt.completeWithValue( callback, new GetCredentialFailure( GetCredentialFailureType.UNEXPECTED_CREDENTIAL_TYPE, @@ -318,12 +318,12 @@ public void onError(@NonNull GetCredentialException e) { } // Errors are reported through the return value as structured data, rather than // a Result error's PlatformException. - ResultUtilsKt.completeWithGetCredentialFailure( + ResultUtilsKt.completeWithValue( callback, new GetCredentialFailure(type, e.getMessage(), null)); } }); } catch (RuntimeException e) { - ResultUtilsKt.completeWithGetCredentialFailure( + ResultUtilsKt.completeWithValue( callback, new GetCredentialFailure( GetCredentialFailureType.UNKNOWN, @@ -400,7 +400,7 @@ public void authorize( if (promptIfUnauthorized) { Activity activity = getActivity(); if (activity == null) { - ResultUtilsKt.completeWithAuthorizeFailure( + ResultUtilsKt.completeWithValue( callback, new AuthorizeFailure( AuthorizeFailureType.NO_ACTIVITY, "No activity available", null)); @@ -422,7 +422,7 @@ public void authorize( /* options */ null); } catch (IntentSender.SendIntentException e) { pendingAuthorizationCallback = null; - ResultUtilsKt.completeWithAuthorizeFailure( + ResultUtilsKt.completeWithValue( callback, new AuthorizeFailure( AuthorizeFailureType.PENDING_INTENT_EXCEPTION, @@ -430,12 +430,12 @@ public void authorize( null)); } } else { - ResultUtilsKt.completeWithAuthorizeFailure( + ResultUtilsKt.completeWithValue( callback, new AuthorizeFailure(AuthorizeFailureType.UNAUTHORIZED, null, null)); } } else { - ResultUtilsKt.completeWithAuthorizationResult( + ResultUtilsKt.completeWithValue( callback, new PlatformAuthorizationResult( authorizationResult.getAccessToken(), @@ -445,12 +445,12 @@ public void authorize( }) .addOnFailureListener( e -> - ResultUtilsKt.completeWithAuthorizeFailure( + ResultUtilsKt.completeWithValue( callback, new AuthorizeFailure( AuthorizeFailureType.AUTHORIZE_FAILURE, e.getMessage(), null))); } catch (RuntimeException e) { - ResultUtilsKt.completeWithAuthorizeFailure( + ResultUtilsKt.completeWithValue( callback, new AuthorizeFailure( AuthorizeFailureType.API_EXCEPTION, @@ -488,7 +488,7 @@ public boolean onActivityResult(int requestCode, int resultCode, @Nullable Inten try { AuthorizationResult authorizationResult = authorizationClientFactory.create(context).getAuthorizationResultFromIntent(data); - ResultUtilsKt.completeWithAuthorizationResult( + ResultUtilsKt.completeWithValue( pendingAuthorizationCallback, new PlatformAuthorizationResult( authorizationResult.getAccessToken(), @@ -496,7 +496,7 @@ public boolean onActivityResult(int requestCode, int resultCode, @Nullable Inten authorizationResult.getGrantedScopes())); return true; } catch (ApiException e) { - ResultUtilsKt.completeWithAuthorizeFailure( + ResultUtilsKt.completeWithValue( pendingAuthorizationCallback, new AuthorizeFailure(AuthorizeFailureType.API_EXCEPTION, e.getMessage(), null)); } diff --git a/packages/google_sign_in/google_sign_in_android/android/src/main/kotlin/io/flutter/plugins/googlesignin/ResultUtils.kt b/packages/google_sign_in/google_sign_in_android/android/src/main/kotlin/io/flutter/plugins/googlesignin/ResultUtils.kt index 6ebd833fe05b..7487d5637216 100644 --- a/packages/google_sign_in/google_sign_in_android/android/src/main/kotlin/io/flutter/plugins/googlesignin/ResultUtils.kt +++ b/packages/google_sign_in/google_sign_in_android/android/src/main/kotlin/io/flutter/plugins/googlesignin/ResultUtils.kt @@ -4,20 +4,6 @@ package io.flutter.plugins.googlesignin -fun completeWithGetGetCredentialResult( - callback: (Result) -> Unit, - result: GetCredentialResult -) { - callback(Result.success(result)) -} - -fun completeWithGetCredentialFailure( - callback: (Result) -> Unit, - failure: GetCredentialFailure -) { - callback(Result.success(failure)) -} - fun completeWithUnitSuccess(callback: (Result) -> Unit) { callback(Result.success(Unit)) } @@ -26,16 +12,6 @@ fun completeWithUnitError(callback: (Result) -> Unit, failure: FlutterErro callback(Result.failure(failure)) } -fun completeWithAuthorizationResult( - callback: (Result) -> Unit, - result: PlatformAuthorizationResult -) { - callback(Result.success(result)) -} - -fun completeWithAuthorizeFailure( - callback: (Result) -> Unit, - failure: AuthorizeFailure -) { - callback(Result.success(failure)) +fun completeWithValue(callback: (Result) -> Unit, value: T) { + callback(Result.success(value)) } diff --git a/packages/google_sign_in/google_sign_in_android/pubspec.yaml b/packages/google_sign_in/google_sign_in_android/pubspec.yaml index 272833c8b971..244cf1d3f6fd 100644 --- a/packages/google_sign_in/google_sign_in_android/pubspec.yaml +++ b/packages/google_sign_in/google_sign_in_android/pubspec.yaml @@ -2,7 +2,7 @@ name: google_sign_in_android description: Android implementation of the google_sign_in plugin. repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22 -version: 7.2.8 +version: 7.2.9 environment: sdk: ^3.9.0