-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[quick_actions] Android support only calling initialize once #4204
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
While this does change a test file, there's no actually testing of the new functionality. Per separate discussion, that will need a native integration test that actually drives a quick actions flow.
private static final String CHANNEL_ID = "plugins.flutter.io/quick_actions"; | ||
protected static boolean isInitialized = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this static? Wouldn't each instance of the plugin need to be initialized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds like the use case is to support a single initialization. If that is the case, it could still be an instance field.
That said, I don't there's such a case as registering/initializing the same plugin name more than once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed as it's unnecessary. Thanks.
@@ -43,6 +47,10 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) { | |||
@Override | |||
public void onAttachedToActivity(ActivityPluginBinding binding) { | |||
handler.setActivity(binding.getActivity()); | |||
binding.addOnNewIntentListener(this); | |||
if (isInitialized) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this (and the new method) needed? I don't see any deferment logic, so couldn't it just send the call unconditionally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah my bad. Initially I thought it'll call onNewIntent when the Dart side isn't initialized yet, which means it'll make a redundant method call which would just vanish. But after checking again, the method call does go through to Dart.
Removed the if block, the static field, and the new method. Thanks for catching this.
@@ -24,6 +25,7 @@ class MethodChannelQuickActions extends QuickActionsPlatform { | |||
assert(call.method == 'launch'); | |||
handler(call.arguments); | |||
}); | |||
unawaited(channel.invokeMethod<String?>('initialize')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're going to call a new method, you should make it a no-op on iOS to avoid getting useless error messages (although per other comments, it's not clear to me that this is necessary).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed as it's not necessary.
Adding @blasten to review the Android intent flow aspect of this. |
@@ -60,6 +69,15 @@ public void onDetachedFromActivityForConfigChanges() { | |||
onDetachedFromActivity(); | |||
} | |||
|
|||
@Override | |||
public boolean onNewIntent(Intent intent) { | |||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return false; | |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) { | |
return false; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done.
} | ||
return false; | ||
} | ||
|
||
private void setupChannel(BinaryMessenger messenger, Context context, Activity activity) { | ||
channel = new MethodChannel(messenger, CHANNEL_ID); | ||
handler = new MethodCallHandlerImpl(context, activity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MethodCallHandlerImpl could take an object that implements an interface. Then, QuickActionsPlugin could implement the interface. Lastly, pass the reference when it constructs MethodCallHandlerImpl
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface implementation sets isInitialized = true;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. But as per stuartmorgan@'s comment above, removed the field as it's not necessary.
@@ -43,6 +47,10 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) { | |||
@Override | |||
public void onAttachedToActivity(ActivityPluginBinding binding) { | |||
handler.setActivity(binding.getActivity()); | |||
binding.addOnNewIntentListener(this); | |||
if (isInitialized) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we add comments to the code? That will help the next maintainer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cfcd743
to
8a1b505
Compare
8a1b505
to
f9d1341
Compare
Thanks for the reviews! 😄 Responded to the comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation LGTM, but it may also need a test.
@bparrishMines is there a plan to backfill this plugin as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation LGTM, but it may also need a test.
Yes, this will need a test per my initial comment.
@bparrishMines is there a plan to backfill this plugin as well?
The scaffolding is in place now so it should be possible to add an integration test to this PR.
Per @bparrishMines 's suggestions in a separate discussion, added unit tests for the new functionality |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't actually clear to me from the offline discussion why unit tests are better here than UI tests of the actual flow (which would ensure that whole user flow behaves as expected), but it looks like this has reasonable coverage of the change so LGTM.
Fixes flutter/flutter#87259
Pre-launch Checklist
dart format
.)[shared_preferences]
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.