Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@mklim
Copy link
Contributor

@mklim mklim commented Oct 4, 2019

Description

Migrate android intent to the new embedding.

  • Refactors the existing plugin logic into two new classes.
  • Adds an implementation of the plugin for the new embedding.
  • Adds a simple unit test. It's not a very thorough one but does check that the new embedding's set up handlers work correctly.
  • Adds a simple e2e test verifying that one of the getter APIs functions correctly.

Related Issues

flutter/flutter#41849

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • x ] The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

*
* <p>It may be null initially, but should be set before calling {@link #launch}.
*/
UrlLauncher(@Nullable Context activityContext) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really need an Activity Context then I would recommend only accepting an Activity. It will enforce your requirements with the type system and avoid any future developer mistakes by overlooking the significance of activityContext vs context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I took a second look at the original code, and I oversimplified. Half the time it was using an activity and half the time it was using application context. Split it out into separate objects and kept the Activity as that class following this suggestion.

}

@Override
public void onDetachedFromActivityForConfigChanges() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation: consider declaring the methods in the order that they are likely to be called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged. I prefer bottom line up front style (most "important" methods first), but it's a very subjective ranking.

*
* <p>Instantiate this in an add to app scenario to gracefully handle activity and context changes.
*/
public final class UrlLauncherPlugin implements FlutterPlugin, ActivityAware {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this class need a static registerWith() method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it in a UrlLauncherPluginRegistrar class. I'm not 100% on that being the best place for it, but I wanted to move it as far away from here as possible to try and make it harder to accidentally initialize the "old" vs the "new" version of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, our plugins infra expects Android and iOS to use the same name for the class that holds registerWith. I moved it back.

@mklim
Copy link
Contributor Author

mklim commented Oct 11, 2019

This should now be ready to land. The latest commit updated the pubspec, added in the Gradle fix to keep this working on stable, and added a simple e2e test.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a few nits.

*
* <p>See {@code dev.flutter.plugins.urllauncherexample.MainActivity} for an example.
*/
public UrlLauncherPlugin() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, removed.

<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthew-carroll seems to suggest this to be moved.
#2164 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@cyanglaz
Copy link
Contributor

also remember to upgrade the flutter version in example app.

@mklim
Copy link
Contributor Author

mklim commented Oct 15, 2019

also remember to upgrade the flutter version in example app.

Good catch, done.

@mklim mklim merged commit 8150245 into flutter:master Oct 15, 2019
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new UrlLauncherPlugin());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we should have a TODO to remove this when the generated registrant for the v2 embedder is on stable

mormih pushed a commit to mormih/plugins that referenced this pull request Nov 17, 2019
Migrate android intent to the new embedding.

- Refactors the existing plugin logic into two new classes.
- Adds an implementation of the plugin for the new embedding.
- Adds a simple unit test. It's not a very thorough one but does check that the new embedding's set up handlers work correctly.
- Adds a simple e2e test verifying that one of the getter APIs functions correctly.
sungmin-park pushed a commit to sungmin-park/flutter-plugins that referenced this pull request Dec 17, 2019
Migrate android intent to the new embedding.

- Refactors the existing plugin logic into two new classes.
- Adds an implementation of the plugin for the new embedding.
- Adds a simple unit test. It's not a very thorough one but does check that the new embedding's set up handlers work correctly.
- Adds a simple e2e test verifying that one of the getter APIs functions correctly.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants