Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Prevent rationale dialog from showing twice #195

Merged
samtstern merged 2 commits into master from fix-issue-193
Jan 12, 2018
Merged

Conversation

@samtstern
Copy link
Contributor

@samtstern samtstern commented Jan 11, 2018

This addresses issue #193

Change-Id: Idf2806ea3dc84fa34a6cbe2eae7b723a4c8b4f72
Copy link
Contributor Author

@SUPERCILEX any reason not to do this?

Copy link
Contributor

@SUPERCILEX SUPERCILEX left a comment

Choose a reason for hiding this comment

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

@samtstern Minor comments plus a warning about a possible edge case.

I've been feeling a bit under the weather this past week which is why I haven't responded as quickly as usual. 🌧 Hopefully that 3-day weekend will help me! 😄


// Check if fragment is already showing
Fragment fragment = fm.findFragmentByTag(RationaleDialogFragment.TAG);
if (fragment != null && fragment instanceof RationaleDialogFragment) {
Copy link
Contributor

@SUPERCILEX SUPERCILEX Jan 12, 2018

Choose a reason for hiding this comment

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

The null check is redundant since instanceof does it for you.


// Check if fragment is already showing
Fragment fragment = fm.findFragmentByTag(RationaleDialogFragmentCompat.TAG);
if (fragment != null && fragment instanceof RationaleDialogFragmentCompat) {
Copy link
Contributor

@SUPERCILEX SUPERCILEX Jan 12, 2018

Choose a reason for hiding this comment

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

Same comment as above.

@StyleRes int theme,
int requestCode,
@NonNull String... perms) {
FragmentManager fm = getFragmentManager();
Copy link
Contributor

@SUPERCILEX SUPERCILEX Jan 12, 2018

Choose a reason for hiding this comment

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

There's an edge case when dealing with fragments: since the activity and child fragment managers are different, findFragmentByTag could still return null even if the dialog is showing in another manager. AFAIK, it doesn't matter which fragment manager is used to display a dialog so the SupportFragmentPermissionHelper could look like this to fix the bug:

@Override
public FragmentManager getSupportFragmentManager() {
 Fragment f = getHost();
 FragmentActivity activity = f.getActivity();
 if (activity != null) {
 return activity.getSupportFragmentManager();
 } else {
 // Not sure what else we can do here
 return f.getChildFragmentManager();
 }
}

TBH, this edge case should be so rare that it doesn't really matter... your call.

Copy link
Contributor Author

@samtstern samtstern Jan 12, 2018

Choose a reason for hiding this comment

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

Thanks for the tip! I'll do what you suggested.

Man child fragment managers are a special kind of no fun.

Copy link

@Zhelyazko Zhelyazko Jan 26, 2018
edited
Loading

Choose a reason for hiding this comment

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

Edit: Nevermind. I just saw that there is a new version of the library (1.1.3) which has this fixed.


When a permission is requested from a support library Fragment this implementation of SupportFragmentPermissionHelper.getSupportFragmentManager() will prevent the Fragment from receiving the onRequestPermissionsResult() callback.
I was debugging a case when a rationale dialog was shown, followed by the system's Request permission dialog. As the Activity's fragment manager is used, it's the Activity which has its onRequestPermissionsResult() called, and not the Fragment's one

Copy link
Contributor Author

@samtstern samtstern Jan 26, 2018

Choose a reason for hiding this comment

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

@Zhelyazko thanks for the comment anyway!

Change-Id: I02907904fdb9e1b5b2db2684c8c606ad50865089
Copy link
Contributor Author

@SUPERCILEX thanks for the review and feel better! Enjoy the long weekend.

@samtstern samtstern merged commit 623baa9 into master Jan 12, 2018
Copy link
Contributor

Thanks! I plan to review the FirebaseUI PR after lunch so you'll be seeing more of me before the weekend. 😂

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers

@Zhelyazko Zhelyazko Zhelyazko left review comments

@SUPERCILEX SUPERCILEX SUPERCILEX left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

1.1.2

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /