Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Translucent animation flickering when checking for already granted permission #81

Closed
rfgamaral opened this issue Aug 10, 2016 · 9 comments
Milestone

Comments

@rfgamaral
Copy link

rfgamaral commented Aug 10, 2016

Expected behaviour

If all requested permissions are already granted when invoking one of the Dexter.checkPermission(s)(OnSameThread), startTransparentActivityIfNeeded() should not start DexterActivity. Thus preventing any kind of flicker and animation when opening/closing activities.

Actual behaviour

When checking for permissions already granted, I get a slight flicker and slide animation with a translucent activity with a few shadows.

Steps to reproduce

I have no clue... I have two classes, implemented with the same exact pattern, one of them shows the flicker, the other doesn't. They check for different permissions but I tried to replicate everything in the working class into the non-working class but I can't get it to work.

For some strange reason, I have a piece of code fully working (no flicker, no animation) and another piece of code not working (shows flicker, shows animation). I can't really understand the differences between them to describe the steps to reproduce.

That's why I'm suggesting to not even start DexterActivity if all required permissions are already granted. I know this is supposed to be a translucent activity, but why are we opening it if we are going to close it right away since there are no dialogs to show?

Version of the library

v2.3.0

@rfgamaral
Copy link
Author

@Serchinastico Any thoughts on this?

@Serchinastico Serchinastico added this to the 3.0.0 milestone Sep 1, 2016
@Serchinastico
Copy link
Contributor

Hi @rfgamaral

First of all, sorry for the late response.

This is a known issue, is worded differently in #47 but the cause is the same. As you said, we are creating the Dexter activity even in cases where it's not needed. There is a PR, #73, that solves the issue and its ready to be released for v3.0.0.

We still have to do some more testing before doing the release, I'll try to prepare a SNAPSHOT version just in case you want to see by yourself if it solves your problem.

I'll close the issue once v3.0.0 is released.

Thanks for reporting, cheers!

@rfgamaral
Copy link
Author

Didn't notice #47 was the same issue I was having...

A SNAPSHOT version would be great and I could help testing new stuff if you want. I suppose v3 is going to be breaking because of the fluent API, correct? Is that the only breaking change?

@Serchinastico
Copy link
Contributor

Yes, v3.0.0 changes the API by a fluent version and makes error handling using a callback instead of exception-driven.

We just published a snapshot version with sonatype. If you want to give it a try you probably will need to allow snapshot versions explicitly and download it from there.

Let us know how that goes.

@rfgamaral
Copy link
Author

rfgamaral commented Sep 6, 2016

I'm trying to convert my code to the fluent API but I'm not sure I'm doing it right...

Before:

if (Dexter.isRequestOngoing()) {
    return;
}

PermissionListener snackbarPermissionListener = SnackbarOnDeniedPermissionListener.Builder
    .with((ViewGroup) mActivity.findViewById(android.R.id.content), R.string.msg_error_storage_write_access)
    .withOpenSettingsButton(R.string.action_settings)
    .withCallback(new Snackbar.Callback() {

        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            mCallback.onUpdateCheckerFinished();
        }

    })
    .build();

PermissionListener emptyPermissionListener = new EmptyPermissionListener() {

    @Override
    public void onPermissionGranted(PermissionGrantedResponse response) {
        downloadNewVersionWithProgressDialog();
    }

    @Override
    public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
        token.continuePermissionRequest();
    }

};

Dexter.checkPermission(new CompositePermissionListener(emptyPermissionListener, snackbarPermissionListener),
    Manifest.permission.WRITE_EXTERNAL_STORAGE);

Now:

PermissionListener snackbarPermissionListener = SnackbarOnDeniedPermissionListener.Builder
    .with((ViewGroup) mActivity.findViewById(android.R.id.content), R.string.msg_error_storage_write_access)
    .withOpenSettingsButton(R.string.action_settings)
    .withCallback(new Snackbar.Callback() {

        @Override
        public void onDismissed(Snackbar snackbar, int event) {
            mCallback.onUpdateCheckerFinished();
        }

    })
    .build();

PermissionListener emptyPermissionListener = new EmptyPermissionListener() {

    @Override
    public void onPermissionGranted(PermissionGrantedResponse response) {
        downloadNewVersionWithProgressDialog();
    }

    @Override
    public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
        token.continuePermissionRequest();
    }

};

Dexter.withActivity(mActivity)
    .withPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
    .withListener(new CompositePermissionListener(emptyPermissionListener, snackbarPermissionListener))
    .check();

Is there something I'm missing? Does it look good?

@rfgamaral
Copy link
Author

I just tested the implementation above and all seems to be working. Permissions are requested as usual and no more transparent activity, yeaaaaaah. Good job :)

Let me know if there's any way I'm missing with the new fluent API to simplify my code above.

I know this is just a SNAPSHOT, but how stable for production do you think this is?

@Serchinastico
Copy link
Contributor

Hi @rfgamaral

Your code looks good! It might need some more lines but, hopefully, the new API will make it harder for newcomers to write buggy code. It's also way better for us, with this new API we will be able to add new features to Dexter avoiding the myriad of methods we had before (optional parameters forced us to duplicate methods).

I really can't answer you to the last question, we've been doing a lot of testing but we need some more time. In the end, it's a snapshot version, so it shouldn't be used in production at all (things are susceptible to change and may break your build).

Thank you very much for your time and contributions 😄

@rfgamaral
Copy link
Author

rfgamaral commented Sep 6, 2016

Your code looks good! It might need some more lines but(...)

What do you mean?

Thank you very much for your time and contributions 😄

No problem. I just wish I had more time to contribute to open-source projects :)

P.S: Feel free to close this issue if you want :)

@Serchinastico
Copy link
Contributor

Your code looks good! It might need some more lines but(...)

What do you mean?

I mean that perhaps the fluent API is more verbose than the old one but that's fine, there is nothing wrong with your code 😋

I'll close it for now!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants