Skip to content
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

Prevent rationale dialog from showing twice #195

Merged
merged 2 commits into from
Jan 12, 2018
Merged

Conversation

samtstern
Copy link
Contributor

This addresses issue #193

Change-Id: Idf2806ea3dc84fa34a6cbe2eae7b723a4c8b4f72
@samtstern samtstern added this to the 1.1.2 milestone Jan 11, 2018
@samtstern
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

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

Choose a reason for hiding this comment

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

Same comment as above.

@@ -24,8 +28,17 @@ public void showRequestPermissionRationale(@NonNull String rationale,
@StyleRes int theme,
int requestCode,
@NonNull String... perms) {
FragmentManager fm = getFragmentManager();
Copy link
Contributor

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

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

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

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
@samtstern
Copy link
Contributor Author

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

@samtstern samtstern mentioned this pull request Jan 12, 2018
@samtstern samtstern merged commit 623baa9 into master Jan 12, 2018
@SUPERCILEX
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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants