-
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
Changes from 5 commits
cde044f
cb92c8f
97c1df2
2e9daf6
3d4a798
b48cba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,34 @@ | |
|
||
</RadioGroup> | ||
|
||
<TextView | ||
style="@style/Base.TextAppearance.AppCompat.Subhead" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginTop="16dp" | ||
android:text="@string/privacy_policy_header"/> | ||
|
||
<RadioGroup | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
<RadioButton | ||
android:id="@+id/google_privacy" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:checked="true" | ||
android:text="@string/google_privacy_label"/> | ||
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. 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 commentThe 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. |
||
|
||
<RadioButton | ||
android:id="@+id/firebase_privacy" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/firebase_privacy_label"/> | ||
|
||
</RadioGroup> | ||
|
||
<TextView | ||
style="@style/Base.TextAppearance.AppCompat.Subhead" | ||
android:layout_width="wrap_content" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
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) { | ||
char[] currentPreambleChars = new char[mBuilder.length()]; | ||
mBuilder.getChars(0, mBuilder.length(), currentPreambleChars, 0); | ||
String currentPreamble = String.valueOf(currentPreambleChars); | ||
|
||
int targetIndex = currentPreamble.indexOf(target); | ||
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. @TheCraftKid whoops, forgot to mention that I updated my patch. Turns out the |
||
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)); | ||
} | ||
} | ||
} |
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.
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...