Skip to content

Add support for privacy policy URLs in sign-up #727

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

Merged
merged 6 commits into from
May 31, 2017
Merged

Add support for privacy policy URLs in sign-up #727

merged 6 commits into from
May 31, 2017

Conversation

WillieCubed
Copy link
Contributor

This addresses and resolves #690.
(Sorry it took a bit, I had to find a way to add URL to the existing text spans.)

@samtstern
Copy link
Contributor

@TheCraftKid this looks great! Can you provide a quick screenshot for me?

@samtstern
Copy link
Contributor

The code looks great but tests are broken, I think there is somewhere in tests where we are using the new FlowParameters() constructor and you're not passing a privacy URL, so it's breaking.

@samtstern samtstern self-requested a review May 26, 2017 00:17
@WillieCubed
Copy link
Contributor Author

WillieCubed commented May 26, 2017

Hey, I fixed the tests, but I'm trying to build the app to get a screenshot, and keep getting this error:

Error:org.gradle.api.GradleException: No matching client found for package name 'com.firebase.uidemo'.

Copy link
Collaborator

@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 Not so fast, I think there's a bit of broken code. 😨

@TheCraftKid Awesome, start! 😄 There's a little work to do, but it's almost there!

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/google_privacy_label"/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add another button like the Firebase Analytics privacy policy or something? Otherwise a single radio button is kinda useless... 😄

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 was looking for some kind of Fireabse privacy policy, but I could only find terms of service. That's a good idea.

}

return GOOGLE_PRIVACY_POLICY_URL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

See my comment in the xml layout. If you don't want to add another privacy policy, we could just have it return null. Otherwise, this doesn't make much sense...

int start = mAgreementText.length();
spannableStringBuilder.setSpan(foregroundColorSpan, start, start + link.length(), 0);

mAgreementText.append(" and the ");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of doing this which isn't translatable, could we instead combine the setUpTermsOfService and setUpPrivacyPolicy methods to make the two clickable bits of text in one go? This should simplify things and fix the bug below.


mAgreementText.append(" and the ");
mAgreementText.append(spannableStringBuilder);
mAgreementText.setOnClickListener(new View.OnClickListener() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this will work. Try clicking the Terms of Service link and it will open the privacy policy instead. Oops! 😄 You'll need to make only the bits of text clickable instead of the entire view like so: https://stackoverflow.com/a/10697453/4548500.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, there's another bug I just thought about: if the dev provides a PP but not a TOS, the agreement text will be something like and the privacy policy. I'm thinking about how we can rewrite this in a sustainable way.

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 was debating whether to combine setting the terms of service and privacy policy text in a single method, but I was a bit afraid to touch anything else. We can use two template strings in strings.xml for the possibility that either link doesn't exist.

Copy link
Collaborator

@SUPERCILEX SUPERCILEX May 26, 2017

Choose a reason for hiding this comment

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

Yeah, that's what I did. Since you mentioned having issues with the Spans, I went ahead and created a patch for you: Fix_various_bugs.zip.

If you want to give it a go yourself, hack at it! 😄 Otherwise, just extract the zip and then apply the patch in Android Studio by calling up the shortcut: Ctrl/Cmd + Shift + A -> "Apply patch".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wow, thanks! With the string templates, I'm curious why you didn't use the normal Java ones. Is there any technical problem with doing so?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I needed a way to manually inject the strings so that I could get their start and end indices:

    private void replaceTarget(String target, @StringRes int replacementRes, String url) {
        int targetIndex = mBuilder.toString().indexOf(target);
        if (targetIndex != -1) {
            String replacement = mContext.getString(replacementRes);
            mBuilder.replace(targetIndex, targetIndex + target.length(), replacement);

            int end = targetIndex + replacement.length();
            mBuilder.setSpan(mLinkSpan, targetIndex, end, 0);
            mBuilder.setSpan(new CustomTabsSpan(url), targetIndex, end, 0);
        }
    }

If you have any idea how to improve this mess, go for it! 😄

@SUPERCILEX
Copy link
Collaborator

@TheCraftKid For your build error, make sure the Firebase test project you setup has a matching package: https://stackoverflow.com/a/39301178/4548500.

Here's mine:
image

mBuilder.getChars(0, mBuilder.length(), currentPreambleChars, 0);
String currentPreamble = String.valueOf(currentPreambleChars);

int targetIndex = currentPreamble.indexOf(target);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@TheCraftKid whoops, forgot to mention that I updated my patch. Turns out the SpannableStringBuilder#toString() method does exactly what I just did so all of that can be replaced with mBuilder.toString().indexOf(target);

import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ui.FlowParameters;

public class PreambleHandler {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@samtstern LGTM now, but can you think of ways to improve this?

@samtstern
Copy link
Contributor

samtstern commented May 26, 2017

@TheCraftKid and @SUPERCILEX thank you both for getting this all ready. I won't actually have time to verify and merge this until after the long weekend, so just warning you in advance of my silence. But we're gonna get this in.

@SUPERCILEX
Copy link
Collaborator

@samtstern Awesome! 😄

@TheCraftKid Could you push the code simplification with toString I mentioned?

This

char[] currentPreambleChars = new char[mBuilder.length()];
mBuilder.getChars(0, mBuilder.length(), currentPreambleChars, 0);
String currentPreamble = String.valueOf(currentPreambleChars);

int targetIndex = currentPreamble.indexOf(target);

should turn into this

int targetIndex = mBuilder.toString().indexOf(target);

@samtstern samtstern merged commit cea4ec1 into firebase:version-2.0.0-dev May 31, 2017
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