-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
samtstern
merged 6 commits into
firebase:version-2.0.0-dev
from
WillieCubed:version-2.0.0-dev
May 31, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cde044f
Add sign-in intent builder support for privacy policy URLS.
WillieCubed cb92c8f
Update app sample to include privacy policy URL option
WillieCubed 97c1df2
Fix auth library tests
WillieCubed 2e9daf6
Add additional privacy policy URL to demo app
WillieCubed 3d4a798
Fix text span link bugs
WillieCubed b48cba9
Simplify method replaceTarget
WillieCubed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
auth/src/main/java/com/firebase/ui/auth/ui/email/PreambleHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.firebase.ui.auth.ui.email; | ||
|
||
import android.content.Context; | ||
import android.net.Uri; | ||
import android.support.annotation.ColorInt; | ||
import android.support.annotation.StringRes; | ||
import android.support.customtabs.CustomTabsIntent; | ||
import android.support.v4.content.ContextCompat; | ||
import android.text.SpannableStringBuilder; | ||
import android.text.TextUtils; | ||
import android.text.method.LinkMovementMethod; | ||
import android.text.style.ClickableSpan; | ||
import android.text.style.ForegroundColorSpan; | ||
import android.util.TypedValue; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.firebase.ui.auth.R; | ||
import com.firebase.ui.auth.ui.FlowParameters; | ||
|
||
public class PreambleHandler { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @samtstern LGTM now, but can you think of ways to improve this? |
||
private static final String TOS_TARGET = "%TOS%"; | ||
private static final String PP_TARGET = "%PP%"; | ||
|
||
private final Context mContext; | ||
private final FlowParameters mFlowParameters; | ||
private final ForegroundColorSpan mLinkSpan; | ||
|
||
private SpannableStringBuilder mBuilder; | ||
|
||
public PreambleHandler(Context context, FlowParameters parameters) { | ||
mContext = context; | ||
mFlowParameters = parameters; | ||
mLinkSpan = new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.linkColor)); | ||
|
||
setupCreateAccountPreamble(); | ||
} | ||
|
||
public void setPreamble(TextView textView) { | ||
textView.setMovementMethod(LinkMovementMethod.getInstance()); | ||
textView.setText(mBuilder); | ||
} | ||
|
||
private void setupCreateAccountPreamble() { | ||
int preambleType = getPreambleType(); | ||
if (preambleType == -1) { | ||
return; | ||
} | ||
|
||
String[] preambles = | ||
mContext.getResources().getStringArray(R.array.create_account_preamble); | ||
mBuilder = new SpannableStringBuilder(preambles[preambleType]); | ||
|
||
replaceTarget(TOS_TARGET, R.string.terms_of_service, mFlowParameters.termsOfServiceUrl); | ||
replaceTarget(PP_TARGET, R.string.privacy_policy, mFlowParameters.privacyPolicyUrl); | ||
} | ||
|
||
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); | ||
} | ||
} | ||
|
||
/** | ||
* 0 means we have both a TOS and a PP | ||
* <p>1 means we only have a TOS | ||
* <p>2 means we only have a PP | ||
* <p>-1 means we have neither | ||
*/ | ||
private int getPreambleType() { | ||
int preambleType; | ||
|
||
boolean hasTos = !TextUtils.isEmpty(mFlowParameters.termsOfServiceUrl); | ||
boolean hasPp = !TextUtils.isEmpty(mFlowParameters.privacyPolicyUrl); | ||
|
||
if (hasTos && hasPp) { | ||
preambleType = 0; | ||
} else if (hasTos) { | ||
preambleType = 1; | ||
} else if (hasPp) { | ||
preambleType = 2; | ||
} else { | ||
preambleType = -1; | ||
} | ||
|
||
return preambleType; | ||
} | ||
|
||
private class CustomTabsSpan extends ClickableSpan { | ||
private final String mUrl; | ||
private final CustomTabsIntent mCustomTabsIntent; | ||
|
||
public CustomTabsSpan(String url) { | ||
mUrl = url; | ||
|
||
// Getting default color | ||
TypedValue typedValue = new TypedValue(); | ||
mContext.getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true); | ||
@ColorInt int color = typedValue.data; | ||
|
||
mCustomTabsIntent = new CustomTabsIntent.Builder() | ||
.setToolbarColor(color) | ||
.setShowTitle(true) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void onClick(View widget) { | ||
mCustomTabsIntent.launchUrl(mContext, Uri.parse(mUrl)); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 you add another button like the Firebase Analytics privacy policy or something? Otherwise a single radio button is kinda useless... 😄
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 was looking for some kind of Fireabse privacy policy, but I could only find terms of service. That's a good idea.