Skip to content

update master #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/connectivity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.4.5+4

* Stability and Maintainability: update documentations.

## 0.4.5+3

* Remove AndroidX warnings.
Expand Down
8 changes: 0 additions & 8 deletions packages/connectivity/example/README.md

This file was deleted.

3 changes: 3 additions & 0 deletions packages/connectivity/lib/connectivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:meta/meta.dart';
/// None: Device not connected to any network
enum ConnectivityResult { wifi, mobile, none }

/// Discover network connectivity configurations: Distinguish between WI-FI and cellular, check WI-FI status and more.
class Connectivity {
/// Constructs a singleton instance of [Connectivity].
///
Expand All @@ -35,11 +36,13 @@ class Connectivity {

Stream<ConnectivityResult> _onConnectivityChanged;

/// Exposed for testing purposes and should not be used by users of the plugin.
@visibleForTesting
static const MethodChannel methodChannel = MethodChannel(
'plugins.flutter.io/connectivity',
);

/// Exposed for testing purposes and should not be used by users of the plugin.
@visibleForTesting
static const EventChannel eventChannel = EventChannel(
'plugins.flutter.io/connectivity_status',
Expand Down
2 changes: 1 addition & 1 deletion packages/connectivity/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for discovering the state of the network (WiFi &
mobile/cellular) connectivity on Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/connectivity
version: 0.4.5+3
version: 0.4.5+4

flutter:
plugin:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 4.0.13

* Fix `GoogleUserCircleAvatar` to handle new style profile image URLs.

## 4.0.12

* Move google_sign_in plugin to google_sign_in/google_sign_in to prepare for federated implementations.

## 4.0.11

* Update iOS CocoaPod dependency to 5.0 to fix deprecated API usage issue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ Future<void> _handleSignIn() async {

## Example

Find the example wiring in the [Google sign-in example application](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/example/lib/main.dart).
Find the example wiring in the [Google sign-in example application](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/google_sign_in/example/lib/main.dart).

## API details

See the [google_sign_in.dart](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/lib/google_sign_in.dart) for more API details.
See the [google_sign_in.dart](https://github.com/flutter/plugins/blob/master/packages/google_sign_in/google_sign_in/lib/google_sign_in.dart) for more API details.

## Issues and feedback

Expand Down
70 changes: 70 additions & 0 deletions packages/google_sign_in/google_sign_in/lib/src/fife.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// A regular expression that matches against the "size directive" path
/// segment of Google profile image URLs.
///
/// The format is is "`/sNN-c/`", where `NN` is the max width/height of the
/// image, and "`c`" indicates we want the image cropped.
final RegExp sizeDirective = RegExp(r'^s[0-9]{1,5}(-c)?$');

/// Adds [size] (and crop) directive to [photoUrl].
///
/// There are two formats for photoUrls coming from the Sign In backend.
///
/// The two formats can be told apart by the number of path segments in the
/// URL (path segments: parts of the URL separated by slashes "/"):
///
/// * If the URL has 2 or less path segments, it is a *new* style URL.
/// * If the URL has more than 2 path segments, it is an old style URL.
///
/// Old style URLs encode the image transformation directives as the last
/// path segment. Look at the [sizeDirective] Regular Expression for more
/// information about these URLs.
///
/// New style URLs carry the same directives at the end of the URL,
/// after an = sign, like: "`=s120-c-fSoften=1,50,0`".
///
/// Directives may contain the "=" sign (`fSoften=1,50,0`), but it seems the
/// base URL of the images don't. "Everything after the first = sign" is a
/// good heuristic to split new style URLs.
///
/// Each directive is separated from others by dashes. Directives are the same
/// as described in the [sizeDirective] RegExp.
///
/// Modified image URLs are recomposed by performing the parsing steps in reverse.
String addSizeDirectiveToUrl(String photoUrl, double size) {
final Uri profileUri = Uri.parse(photoUrl);
final List<String> pathSegments = List<String>.from(profileUri.pathSegments);
if (pathSegments.length <= 2) {
final String imagePath = pathSegments.last;
// Does this have any existing transformation directives?
final int directiveSeparator = imagePath.indexOf('=');
if (directiveSeparator >= 0) {
// Split the baseUrl from the sizing directive by the first "="
final String baseUrl = imagePath.substring(0, directiveSeparator);
final String directive = imagePath.substring(directiveSeparator + 1);
// Split the directive by "-"
final Set<String> directives = Set<String>.from(directive.split('-'))
// Remove the size directive, if present, and any empty values
..removeWhere((String s) => s.isEmpty || sizeDirective.hasMatch(s))
// Add the size and crop directives
..addAll(<String>['c', 's${size.round()}']);
// Recompose the URL by performing the reverse of the parsing
pathSegments.last = '$baseUrl=${directives.join("-")}';
} else {
pathSegments.last = '${pathSegments.last}=c-s${size.round()}';
}
} else {
// Old style URLs
pathSegments
..removeWhere(sizeDirective.hasMatch)
..insert(pathSegments.length - 1, 's${size.round()}-c');
}
return Uri(
scheme: profileUri.scheme,
host: profileUri.host,
pathSegments: pathSegments,
).toString();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'src/common.dart';
import 'src/fife.dart' as fife;

/// Builds a CircleAvatar profile image of the appropriate resolution
class GoogleUserCircleAvatar extends StatelessWidget {
Expand All @@ -33,7 +34,7 @@ class GoogleUserCircleAvatar extends StatelessWidget {
///
/// The format is is "`/sNN-c/`", where `NN` is the max width/height of the
/// image, and "`c`" indicates we want the image cropped.
static final RegExp sizeDirective = RegExp(r'^s[0-9]{1,5}(-c)?$');
static final RegExp sizeDirective = fife.sizeDirective;

/// The Google user's identity; guaranteed to be non-null.
final GoogleIdentity identity;
Expand Down Expand Up @@ -67,8 +68,7 @@ class GoogleUserCircleAvatar extends StatelessWidget {
);
}

/// Adds sizing information to [photoUrl], inserted as the last path segment
/// before the image filename. The format is described in [sizeDirective].
/// Adds correct sizing information to [photoUrl].
///
/// Falls back to the default profile photo if [photoUrl] is [null].
static String _sizedProfileImageUrl(String photoUrl, double size) {
Expand All @@ -77,17 +77,7 @@ class GoogleUserCircleAvatar extends StatelessWidget {
// the default profile photo as a last resort.
return 'https://lh3.googleusercontent.com/a/default-user=s${size.round()}-c';
}
final Uri profileUri = Uri.parse(photoUrl);
final List<String> pathSegments =
List<String>.from(profileUri.pathSegments);
pathSegments
..removeWhere(sizeDirective.hasMatch)
..insert(pathSegments.length - 1, 's${size.round()}-c');
return Uri(
scheme: profileUri.scheme,
host: profileUri.host,
pathSegments: pathSegments,
).toString();
return fife.addSizeDirectiveToUrl(photoUrl, size);
}

Widget _buildClippedImage(BuildContext context, BoxConstraints constraints) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: google_sign_in
description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in
version: 4.0.11
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
version: 4.0.13

flutter:
plugin:
Expand Down
66 changes: 66 additions & 0 deletions packages/google_sign_in/google_sign_in/test/fife_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:google_sign_in/src/fife.dart';

void main() {
group('addSizeDirectiveToUrl', () {
const double size = 20;

group('Old style URLs', () {
const String base =
'https://lh3.googleusercontent.com/-ukEAtRyRhw8/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3rfhID9XACtdb9q_xK43VSXQvBV11Q.CMID';
const String expected = '$base/s20-c/photo.jpg';

test('with directives, sets size', () {
final String url = '$base/s64-c/photo.jpg';
expect(addSizeDirectiveToUrl(url, size), expected);
});

test('no directives, sets size and crop', () {
final String url = '$base/photo.jpg';
expect(addSizeDirectiveToUrl(url, size), expected);
});

test('no crop, sets size and crop', () {
final String url = '$base/s64/photo.jpg';
expect(addSizeDirectiveToUrl(url, size), expected);
});
});

group('New style URLs', () {
const String base =
'https://lh3.googleusercontent.com/a-/AAuE7mC0Lh4F4uDtEaY7hpe-GIsbDpqfMZ3_2UhBQ8Qk';
const String expected = '$base=c-s20';

test('with directives, sets size', () {
final String url = '$base=s120-c';
expect(addSizeDirectiveToUrl(url, size), expected);
});

test('no directives, sets size and crop', () {
final String url = base;
expect(addSizeDirectiveToUrl(url, size), expected);
});

test('no directives, but with an equals sign, sets size and crop', () {
final String url = '$base=';
expect(addSizeDirectiveToUrl(url, size), expected);
});

test('no crop, adds crop', () {
final String url = '$base=s120';
expect(addSizeDirectiveToUrl(url, size), expected);
});

test('many directives, sets size and crop, preserves other directives',
() {
final String url = '$base=s120-c-fSoften=1,50,0';
final String expected = '$base=c-fSoften=1,50,0-s20';
expect(addSizeDirectiveToUrl(url, size), expected);
});
});
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

* Initial release.
27 changes: 27 additions & 0 deletions packages/google_sign_in/google_sign_in_platform_interface/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# google_sign_in_platform_interface

A common platform interface for the [`google_sign_in`][1] plugin.

This interface allows platform-specific implementations of the `google_sign_in`
plugin, as well as the plugin itself, to ensure they are supporting the
same interface.

# Usage

To implement a new platform-specific implementation of `google_sign_in`, extend
[`GoogleSignInPlatform`][2] with an implementation that performs the
platform-specific behavior, and when you register your plugin, set the default
`GoogleSignInPlatform` by calling
`GoogleSignInPlatform.instance = MyPlatformGoogleSignIn()`.

# Note on breaking changes

Strongly prefer non-breaking changes (such as adding a method to the interface)
over breaking changes for this package.

See https://flutter.dev/go/platform-interface-breaking-changes for a discussion
on why a less-clean interface is preferable to a breaking change.

[1]: ../google_sign_in
[2]: lib/google_sign_in_platform_interface.dart
Loading